fileExists

C

Public Domain

Tests whether a given file path exists

Download (right click, save as, rename as appropriate)

Embed

1
2
3
4
5
6
7
#include <errno.h>
#include <sys/stat.h>

/* Returns 1 if the file exists, 0 if it doesn't, and -1 on error */
int fileExists(const char* path) {
 return lstat(path, NULL) == 0 ? 1 : errno == ENOENT ? 0 : -1;
}