Oops! It appears that you have disabled your Javascript. In order for you to see this page as it is meant to appear, we ask that you please re-enable your Javascript!

linux C -判斷檔案是否存在

判斷檔案是否存在, 提供以下API (linux C)

* @brief check file existing
* @param fname – file name to check
* @return int – 0: not exist; 1: exist
int util_file_exist(char *fname)
struct stat fstat;

if (lstat(fname,&fstat)==-1)
return 0;
if (S_ISREG(fstat.st_mode))
return 1;
return 0;

順便一提, linux C 是一本好用的工具書! 裡面列舉出大部分linux C的API與簡易範例與說明!