C语言-判断文件是否存在
1 #include <stdbool.h> 2 #include <sys/types.h> 3 #include <sys/stat.h> 4 #include <unistd.h> 5 6 bool file_exist(const char *path) // 返回值:0 - 不存在, 1 - 存在 7 { 8 struct stat st; 9 10 return (stat(path, &st) == 0) && (!S_ISDIR(st.st_mode)); 11 }