On Fri, 11 Jul 2003 10:39:08 +0200, Anthony wrote:
Hi,
Removing files seems to be rather clumsy in C (not C++).
I am trying next piece of code to delete a file (under W32);
int errno;
errno = remove("FSelCancelled");
After exiting the app the file is still on the system, so not deleted
at all.
If I check the return code, I see value for errno = -1.
On the several doc. pags for remove I see return codes 7 (EBIG), 13
(EACCESS) , etc, etc. till 18 (EXDEV), but not an error code -1.
So, what's wrong ?
Thanks.
Anthony
You're mixing up return value and error code. I'll quote the man page:
RETURN VALUE
On success, zero is returned. On error, -1 is returned, and
errno is set appropriately.
if remove() returns -1, check errno. You can use perror() to print the
last error in a human-readable way. These human-readable strings are
stored in *sys_errlist[], defined in errno.h, if you have something
against perror().
#include <stdio.h>
int main ()
{
if (remove ("somefile") < -1) perror ("removing file");
else printf ("i'm happy\n");
}
--
main(int c,char*k,char*s){c>0?main(0,"adceoX$_k6][^hn","-7\
0#05&'40$.6'+).3+1%30"),puts(""):*s?c=!c?-*s:(putchar(45),c
),putchar(main(c,k+=*s-c*-1,s+1)):(s=0);return!s?10:10+*k;}