http://www.cnblogs.com/thinksasa/p/4597331.html 2015 这三个函数的功能是一致的,都用于获取文件相关信息,但应用于不同的文件对象。对于函数中给出pathname参数,stat函数返回与此命名文件有关的信息结构,fstat函数获取已在描述符fields上打开文件的有关信息,lstat函数类似于stat但是当命名的文件是一个符号链接时,lstat返回该符号链接的有关信息,而不是由该符号链接引用文件的信息。第二个参数buf是指针,它指向一个用于保存文件描述信息的结构,由函数填写结构内容。该结构的实际定义可能随实现有所不同. 用法: #include int stat(const char *path, struct stat *buf); int fstat(int filedes, struct stat *buf); int lstat(const char *path, struct stat *buf); 参数:
文件类型: S_ISDIR(); S_ISBLK(); S_ISCHR(); S_ISSOCK(); S_ISFIFO(); S_ISLNK(); 返回说明:
示例: #include int main(int argc,char* argv[]) { int i; struct stat buf; char * ptr; for(i=1;i { if(lstat(argv[i],&buf)<0) { perror(”错误原因是:”); continue; } if (S_ISREG(buf.st_mode)) ptr=”普通文件”; if (S_ISDIR(buf.st_mode)) ptr=”目录”; //……and so on… cout<<”参数为:”<<<”的标识是一个”<< } exit(0); }
|
|
来自: 心不留意外尘 > 《ccpp for hardware》