



(8 votes)/* checkfile.c written by detour@metalshell.com * * simple function to check for a file * * http://www.metalshell.com/ * */ #include <stdio.h> #include <sys/stat.h> int isFile(const char *fname); int main(int argc, char *argv[]) { if (argc != 2) { printf("Usage: %s filename\n", argv[0]); exit(0); } if(isFile(argv[1])) { printf("%s is a file.\n", argv[1]); } return 0; } int isFile(const char *fname) { struct stat sbuf; if (lstat(fname, &sbuf) == -1) { fprintf(stderr, "lstat() Failed.\n"); return 0; } if(S_ISREG(sbuf.st_mode)) { return 1; } return 0; }