相关函数:stat, lstat, chmod, chown, readlink, utime

头文件:#include <sys/stat.h> #include <unistd.h>

定义函数:int fstat(int fildes, struct stat *buf);

函数说明:fstat()用来将参数fildes 所指的文件状态, 复制到参数buf 所指的结构中(struct stat). Fstat()与stat()作用完全相同, 不同处在于传入的参数为已打开的文件描述词. 详细内容请参考stat().

返回值:执行成功则返回0, 失败返回-1, 错误代码存于errno.

范例
#include <sys/stat.h>
#include <unistd.h>
#include <fcntk.h>
main()
{
struct stat buf;
int fd;
fd = open("/etc/passwd", O_RDONLY);
fstat(fd, &buf);
printf("/etc/passwd file size +%d\n ", buf.st_size);
}
执行:
/etc/passwd file size = 705

fstat的更多相关文章

  1. C语言:stat,fstat和lstat函数

    这三个函数的功能是一致的,都用于获取文件相关信息,但应用于不同的文件对象.对于函数中给出pathname参数,stat函数返回与此命名文件有关的信息结构,fstat函数获取已在描述符fields上打开 ...

  2. 获取文件属性信息之stat、fstat和lstat

    UNIX文件系统是目录和文件组成的一种层次结构.目录(directory)是一个包含许多目录项的文件,在逻辑上,可以认为每个目录项都包含一个文件名,同时还包含说明该文件属性的信息.文件属性是指文件类型 ...

  3. 文件和目录之stat、fstat和lstat函数

    #include <sys/stat.h> int stat( const char *restrict pathname, struct stat *restrict buf ); in ...

  4. fstat - 读取文件相关信息

    #fstat读取到的信息 ["dev"]=> int(16777220) ["ino"]=> int(66880002) ["mode&q ...

  5. fstat().stat()函数

    int stat(const char *path, struct stat *buf); int fstat(int fd, struct stat *buf); 唯一不同是参数不同,其他一样. 文 ...

  6. stat(),lstat(),fstat() 获取文件/目录的相关信息

    stat 的使用 Linux有个命令,ls -l,效果如下: 这个命令能显示文件的类型.操作权限.硬链接数量.属主.所属组.大小.修改时间.文件名.它是怎么获得这些信息的呢,请看下面的讲解. stat ...

  7. stat,fstat,lstat三者区别

    fstat ,lstat,stat; 头文件:#include<sys/stat.h> #include<sys/types.h> #include<unistd.h&g ...

  8. fstat函数

    一.函数原型 #include<sys/stat.h> #include<unistd.h> int fstat(int fildes,struct stat *buf); 返 ...

  9. fopen & fcolse & fseek & ftell & fstat 文件操作函数测试

    1.文件大小查询file_size.c 方法一:fseek + ftell: 方法二:ftell #include <stdio.h> #include <fcntl.h> # ...

  10. 文件权限控制篇access alphasort chdir chmod chown chroot closedir fchdir fchmod fchown fstat ftruncate getcwd

    access(判断是否具有存取文件的权限) 相关函数 stat,open,chmod,chown,setuid,setgid 表头文件 #include<unistd.h> 定义函数 in ...

随机推荐

  1. Redis 搜索引擎优化

    场景 大家如果是做后端开发的,想必都实现过列表查询的接口,当然有的查询条件很简单,一条 SQL 就搞定了,但有的查询条件极其复杂,再加上库表中设计的各种不合理,导致查询接口特别难写,然后加班什么的就不 ...

  2. shiro的/favicon.ico问题

    登录成功之后跳转/favicon.ico问题. 1.spring-shrio.xml里面配置加上 /favicon.ico = anon 2.web.xml中配置中加上: <mime-mappi ...

  3. Mediakit报告设备商的空间不足以执行此操作的纯MAC解法

    使用Mac对磁盘进行分区,显示“Mediakit报告设备商的空间不足以执行此操作”,该怎么办? What 买了一个4TB的移动硬盘,准备进行分区给Time Machine用. 硬盘自带是HDFS的,所 ...

  4. [golang note] 包和导入

    package的作用        √ package是golang最基本的分发单位和工程管理中依赖关系的体现.        √ 每个golang源代码文件开头都拥有一个package声明,表示该g ...

  5. android 显示internet 图片

    try { HttpGet httpRequest = new HttpGet(edtUrl.getText() .toString()); HttpClient httpclient = new D ...

  6. 42. Trapping Rain Water(直方图 存水量 hard)

    Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...

  7. iOS 关于BTC 一些知识点

    1.BTC 用这个网 可以校验 自己的库生成的助记词 地址 是否是合法正常的 https://iancoleman.io/bip39/ 2.知晓 BTC 钱包是否有钱 和交易记录 https://te ...

  8. TOSCA自动化测试工具视频资料

    https://www.udemy.com/ search 'TOCSA' 找到两个免费资料学习

  9. playbook管理配置文件

    前言:在生产环境中,经常需要更改多台机器配置文件,所以用playbook来实现nginx配置文件的管理 一.更新nginx配置文件并重新加载 1. 创建对应目录结构 mkdir -p /etc/ans ...

  10. iOS “弱账号” 暗转 “强账号”

    一.背景 由于某些历史原因,我们产品中50%以上活跃用户是弱账户.即 客户端按照某种规则生成的一个伪id 存在keychain 里,作为这个用户的唯一标识,实现快速登录.正常情况下是不会有问题. 最近 ...