使用lstat()判断文件类型 分类: H_HISTORY 2013-02-24 11:48 703人阅读 评论(0) 收藏
2013-02-24 11:48
309 查看
#include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> #define _GNU_SOURCE int main (int argc, char *argv[]){ struct stat buf; for(int i = 1; i < argc; i++){ if(lstat(argv[i], &buf) < 0){ printf("lstat invoke error."); continue; } printf("%s is a ", argv[i]); if (S_ISREG(buf.st_mode)){ printf("regular file."); }else if(S_ISDIR(buf.st_mode)){ printf("direcotry."); }else if(S_ISBLK(buf.st_mode)){ printf("block device."); }else if(S_ISCHR(buf.st_mode)){ printf("character device."); }else if(S_ISFIFO(buf.st_mode)){ printf("FIFO."); }else if(S_ISLNK(buf.st_mode)){ printf("soft link."); }else if(S_ISSOCK(buf.st_mode)){ printf("socket."); }else printf("Unkown type."); } printf("\n"); exit(0); }
编译时出现以下错误:
filetype.c: In function ‘main’: filetype.c:14:9: warning: implicit declaration of function ‘lstat’ [-Wimplicit-function-declaration] filetype.c:31:9: warning: implicit declaration of function ‘S_ISSOCK’ [-Wimplicit-function-declaration] /tmp/ccLbzony.o: In function `main': filetype.c:(.text+0x182): undefined reference to `S_ISSOCK' collect2: error: ld returned 1 exit status第一个不warning不影响运行,第二个又是怎么回事?
相关文章推荐
- 使用stat()函数判断文件类型
- 使用apache.tika判断文件类型
- 使用lstat()判断文件类型
- 使用lstat()判断文件类型
- 使用lstat()判断文件类型
- js使用file上传图片-----(1)选择文件类型的判断和图片的显示
- Python使用filetype精确判断文件类型
- 使用lstat()判断文件类型
- 使用lstat()判断文件类型
- C# 中使用正则表达式验证 以及 各种约束判断
- Java得到一个整数的绝对值,不使用任何判断和比较语句,包括API.
- 微信开发后台处理消息时使用反射,去掉繁琐的if判断
- 百度判断手机终端并自动跳转js代码及使用实例
- 在JS中使用layui复选框根据个人判断所拥有的权限
- Linq:切勿使用 Count() > 0 来判断集合非空
- momgo查询,使用临时变量判断
- android Camera 如何判断当前使用的摄像头是前置还是后置
- 使用Python判断质数(素数)的简单方法讲解
- C# 判断文件是否在使用的状态FSDF
- Linq:切勿使用 Count() > 0 来判断集合非空