AIX:struct dirent d_type
来源:互联网 发布:剑灵人男捏脸数据截图 编辑:程序博客网 时间:2024/05/19 16:06
AIX:struct dirent d_type
今天做一个小功能,实现起来时需要判断一个目录下各个目录项对应的类型:
可能是普通文件类型;
可能是目录类型;
可能是SOCKET类型…
#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <sys/types.h>#include <dirent.h>int main(){ DIR *dir; struct dirent *item; dir = opendir("/home/filter"); while ((item = readdir(dir)) != NULL) { if (item->d_type & DT_DIR) { printf("%s\n", item->d_name); } } closedir(dir); return 0;}
这段代码在Linux上编译运行没啥问题,但是在AIX环境下就编译不通过。
Linux下:
[filter@localhost ~]$ uname -aLinux localhost.localdomain 2.6.18-371.el5 #1 SMP Thu Sep 5 21:21:44 EDT 2013 x86_64 x86_64 x86_64 GNU/Linux[filter@localhost ~]$ gcc -o main main.c[filter@localhost ~]$ ./main...abc.mozilla.ssh
AIX下:
ismp@aix68113:/home/ismp>uname -a AIX aix68113 1 6 00F7CAA94C00ismp@aix68113:/home/ismp>cc -o main main.c"main.c", line 16.27: 1506-022 (S) "d_type" is not a member of "struct dirent"."main.c", line 16.36: 1506-045 (S) Undeclared identifier DT_DIR.
没有编译通过。
查看对应的头文件:
Linux下:
/usr/include/dirent.h/usr/include/bits/dirent.hstruct dirent {#ifndef __USE_FILE_OFFSET64 __ino_t d_ino; __off_t d_off;#else __ino64_t d_ino; __off64_t d_off;#endif unsigned short int d_reclen; unsigned char d_type; char d_name[256]; /* We must not include limits.h! */ };
AIX下:
/usr/include/dirent.h/usr/include/sys/dir.h#define _D_NAME_MAX 255struct dirent { __ulong64_t d_offset; /* real off after this entry */ ino_t d_ino; /* inode number of entry */ ushort_t d_reclen; /* length of this record */ ushort_t d_namlen; /* length of string in d_name */ char d_name[_D_NAME_MAX+1]; /* name must be no longer than this */ /* redefine w/#define when name decided */};
AIX下man手册:
man dirent.h ulong_t d_offset; /* actual offset of this entry */ ino_t d_ino; /* inode number of entry */ ushort_t d_reclen; /* length of this entry */ ushort_t d_namlen; /* length of string in d_name */ char d_name[_D_NAME_MAX+1]; /* name of entry (filename) */
可见,在AIX下,struct dirent没有d_type这个字段。
附上Linux下d_type值表:
/usr/include/dirent.h/* File types for `d_type'. */enum { DT_UNKNOWN = 0,# define DT_UNKNOWN DT_UNKNOWN DT_FIFO = 1,# define DT_FIFO DT_FIFO DT_CHR = 2,# define DT_CHR DT_CHR DT_DIR = 4,# define DT_DIR DT_DIR DT_BLK = 6,# define DT_BLK DT_BLK DT_REG = 8,# define DT_REG DT_REG DT_LNK = 10,# define DT_LNK DT_LNK DT_SOCK = 12,# define DT_SOCK DT_SOCK DT_WHT = 14# define DT_WHT DT_WHT };
其他说明:
This member is a BSD extension. The symbol _DIRENT_HAVE_D_TYPE is defined if this member is available. On systems where it is used, it corresponds to the file type bits in the st_mode member of struct stat. If the value cannot be determined the member value is DT_UNKNOWN.来源:http://www.gnu.org/software/libc/manual/html_node/Directory-Entries.html
阅读全文
1 0
- AIX:struct dirent d_type
- dirent d_type类型
- 关于readdir返回值中struct dirent.d_type的取值问题
- dirent结构体中d_type
- struct dirent
- struct dirent
- 用dirent的d_type获取目录下的文件类型失败?!
- linux xfs文件系统 无法用readdir获取 dirent文件类型d_type
- struct dirent成员
- struct dirent和DIR
- Linux下的struct dirent
- file属性读取 Struct dirent struct stat
- struct dirent的char d_name[1]成员
- struct dirent 和 DIR结构体 详解
- struct dirent和DIR结构体
- linux xfs文件系统无法用readdir获取dirent文件类型d_type则用stat获取暨stat函数讲解
- Linux下struct dirent,DIR,struct stat使用例子
- dirent
- 反射
- 解决MySql 数据库 提示:1045 access denied for user 'root'@'localhost' using password yes
- 软件架构设计原则和大数据平台架构层
- Android 7.0调用系统相机返回路径问题
- C#相关的网站、资源和书籍
- AIX:struct dirent d_type
- 冒泡排序、插入排序、选择排序、希尔排序、堆排序、归并排序等常用排序算法的比较
- 121. Best Time to Buy and Sell Stock
- 西风多少恨,吹不散眉弯
- php 微信支付 服务号 求神评 求 神引
- IntelliJ Idea 集成svn 和使用
- 利用ida pro的flare功能识别静态链接函数签名
- 阿里大于短信平台Python版教程
- Win10 VS2015 OpenGL + freeglut + glew + glm 環境配置整理(32位元 debug + 64位元 debug)