- 函数:
int stat(const char *path, struct stat *buf);
参数
path 里面放一个文件名
buf 里面存放文件信息
通过把文件名传给stat然后判断此文件是否存在
RETURN VALUE
存在返回0
不存在返回-1 - 例:
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
int main()
{
char *name="serve.c";
struct stat *buf;
int a;
a = stat(name,buf);
if(a==0)
{
printf("file exist\n");
}
else if(a==-1)
{
perror("return -1");
exit(-1);
}
return 0;
}