#include <unistd.h> | |
#include <errno.h> | |
int remove(const char *file){ | |
/* First try to unlink since this is more frequently the necessary action. */ | |
if(unlink(file) != 0 | |
/* If it is indeed a directory... */ | |
&& (errno != EISDIR | |
/* ...try to remove it. */ | |
|| rmdir(file) != 0)) | |
/* Cannot remove the object for whatever reason. */ | |
return -1; | |
return 0; | |
} |