#include <sys/stat.h>的作用
#include <sys/stat.h>
文件状态,
是unix/linux系统定义文件状态所在的伪标准头文件。
含有类型与函数:
dev_t st_dev Device ID of device containing file.
ino_t st_ino File serial number.
mode_t st_mode Mode of file (see below).
nlink_t st_nlink Number of hard links to the file.
uid_t st_uid User ID of file.
gid_t st_gid Group ID of file.
dev_t st_rdev Device ID (if file is character or block special).
off_t st_size For regular files, the file size in bytes.
For symbolic links, the length in bytes of the
pathname contained in the symbolic link.
For a shared memory object, the length in bytes.
For a typed memory object, the length in bytes.
For other file types, the use of this field is
unspecified.
time_t st_atime Time of last access.
time_t st_mtime Time of last data modification.
time_t st_ctime Time of last status change.
int chmod(const char *, mode_t);
int fchmod(int, mode_t);
int fstat(int, struct stat *);
int lstat(const char *restrict, struct stat *restrict);
int mkdir(const char *, mode_t);
int mkfifo(const char *, mode_t);
int mknod(const char *, mode_t, dev_t);
int stat(const char *restrict, struct stat *restrict);
mode_t umask(mode_t);
使用stat函数最多的可能是ls-l命令,用其可以获得有关一个文件的所有信息。
一般头文件在/usr/include下面,这里是标准C程序头文件,如果你的头文件前加了 <sys/*>,那说明这是系统调用函数头文件,其在/usr/include/sys下面。
函数都是获取文件(普通文件,目录,管道,socket,字符,块()的属性。函数原型#include <sys/stat.h>
int stat(const char *restrict pathname, struct stat *restrict buf);提供文件名字,获取文件对应属性。
int fstat(int filedes, struct stat *buf);通过文件描述符获取文件对应的属性。
int lstat(const char *restrict pathname, struct stat *restrict buf);连接文件描述命,获取文件属性。
文件对应的属性struct stat {
mode_t st_mode; //文件对应的模式,文件,目录等
ino_t st_ino; //inode节点号
dev_t st_dev; //设备号码
dev_t st_rdev; //特殊设备号码
nlink_t st_nlink; //文件的连接数
uid_t st_uid; //文件所有者
gid_t st_gid; //文件所有者对应的组
off_t st_size; //普通文件,对应的文件字节数
time_t st_atime; //文件最后被访问的时间
time_t st_mtime; //文件内容最后被修改的时间
time_t st_ctime; //文件状态改变时间
blksize_t st_blksize; //文件内容对应的块大小
blkcnt_t st_blocks; //伟建内容对应的块数量
};
示例:
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
int main() {
struct stat buf;
stat("/etc/hosts", &buf);
printf("/etc/hosts file size = %d\n", buf.st_size);
}
#include <sys/stat.h>的作用的更多相关文章
- /usr/include/sys/types.h:62: error: conflicting types for ‘dev_t’
/usr/include/sys/types.h:62: error: conflicting types for ‘dev_t’/usr/include/linux/types.h:13: erro ...
- #include <sys/epoll.h> epoll - I/O event notification facility 服务器端 epoll(7) - Linux manual page http://www.man7.org/linux/man-pages/man7/epoll.7.html
epoll使用详解(精髓) - Boblim - 博客园 https://www.cnblogs.com/fnlingnzb-learner/p/5835573.html epoll使用详解(精髓) ...
- Cygwin环境编译/usr/include/sys/_types.h:72:20: 致命错误:stddef.h:can not found
环境介绍: win7_x64 +Cygwin64 gcc :4.8.2 g++:4.8.1 编译 c++的helloworld.cpp 一直失败! 代码如下: #include <iostrea ...
- [C++]Linux之头文件sys/types.h[/usr/include/sys]
1.查找<sys/types.h>文件 一般地,Linux的C头文件<sys/types.h>路径在如题的途径:/usr/include/sys下,然而博主[Linux For ...
- #include <sys/socket.h>找不到头文件
ubuntu下socket编程涉及到头文件sys/socket.h 和sys/types.h.我是用的codeblocks编辑器,当我想查看socket,h头文件时编辑器提示找不到头文件. 我就想可能 ...
- sys/types.h fcntl.h unistd.h sys/stat.h
sys/types.h 是Unix/Linux系统的基本系统数据类型的头文件,含有size_t,time_t,pid_t等类型. 在应用程序源文件中包含 <sys/types.h> 以访问 ...
- [opencv3.2cmake error ] sys/videoio.h no such file or directories
I don't have /usr/include/sys/videoio.h at all Before that , I have ipp download question. So I down ...
- 用ioctl获取无线网络信息 /usr//include/linux/wireless.h
1.UNIX Network Programming环境搭建 Unix NetWork Programming――环境搭建(解决unp.h等源码编译问题) http://blog.csdn.net/a ...
- stdafx.h的作用以及原理
stdafx.h VC工程里面经常见到stdafx.h这个头文件,以前也没有特别注意,但是这个文件用不好经常会出错,所以就GOOGLE了一下,总算是弄清楚了... stdafx的英文全称为:Stand ...
随机推荐
- C/C++ Linux 程序员必须了解的 10 个工具
1. 基本命令http://mally.stanford.edu/~sr/computing/basic-unix.htmlhttp://pangea.stanford.edu/computing/u ...
- MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk
redis 有如标题所示提示, 可从两方面查找原因: 一, 可以看一下,运行redis实例的用户, 是否对redis, 数据保存的目录有写权限(既然是排查错误,不防把redis所在目录权限最大化试一下 ...
- 【小TIP】记录各种错误【更新中】
最好程序一遍通过,为了提高代码能力,这里将用TIP的形式记录来犯过的错误.不断更新中. *已经转移到闪存.. [150214]WA:检查是否数组开小了. [150212]WA:如果程序中有乘号,需要留 ...
- 获取Html中所有img的src
/// <summary> /// 获取所有Img中的Src /// </summary> /// <param name="htmlText"> ...
- 常用布局,div竖直居中
常用两列布局,多列布局和div竖直居中 body { margin:; padding:; } .w200 { width: 200px; } .mar-left200 { margin-left: ...
- CI 模型的使用M与C之间的调用
CI是PHP一个比较轻,并且好用的一个框架 分层也是分的比较清晰的一个 这里先展示MODEL 放在application/models 目录下面user_model.php <?php clas ...
- oracle批量转库工作,比较快捷的方式
select 'create table ' || t.TABLE_NAME || ' as select * from ODS_ZMGLXT.'|| t.TABLE_NAME ||'; ' fr ...
- onresize的定义方式
1.直接在html中定义如<body onresize="doResize()"/> 2.直接给onresize赋值给window和body的onresize赋值如wi ...
- Log4j实现对Java日志的配置全攻略
1. 配置文件 Log4J配置文件的基本格式如下: #配置根Logger log4j.rootLogger = [ level ] , appenderName1 , appenderName2 , ...
- openMPI小集群安装
经过一天的努力,终于完成了openMPI的多节点安装,即小集群安装.本文使用的是openmpi-1.6.5,下载地址见:http://www.open-mpi.org/software/ompi/v1 ...