文档下载 文档下载导航
设为首页 | 加入收藏
搜索 请输入内容:  
 导航当前位置: 文档下载 > 所有分类 > IT/计算机 > 计算机软件及应用 > Linux stat函数讲解
侵权投诉

Linux stat函数讲解

Linux stat函数讲解

[日期:2011-02-13] 来源:Linux社区 作者:ACb0y

Linux stat函数讲解:

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

#include <unistd.h>

定义函数: int stat(const char *file_name, struct stat *buf);

函数说明: 通过文件名filename获取文件信息,并保存在buf所指的结构体stat中 返回值: 执行成功则返回0,失败返回-1,错误代码存于errno

错误代码:

ENOENT 参数file_name指定的文件不存在

ENOTDIR 路径中的目录存在但却非真正的目录

ELOOP 欲打开的文件有过多符号连接问题,上限为16符号连接

EFAULT 参数buf为无效指针,指向无法存在的内存空间

EACCESS 存取文件时被拒绝

ENOMEM 核心内存不足

ENAMETOOLONG 参数file_name的路径名称太长

#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);

}

-----------------------------------------------------

struct stat {

dev_t st_dev; //文件的设备编号

ino_t st_ino; //节点

mode_t st_mode; //文件的类型和存取的权限

nlink_t st_nlink; //连到该文件的硬连接数目,刚建立的文件值为1 uid_t st_uid; //用户ID

gid_t st_gid; //组ID

dev_t st_rdev; //(设备类型)若此文件为设备文件,则为其设备编号 off_t st_size; //文件字节数(文件大小)

unsigned long st_blksize; //块大小(文件系统的I/O 缓冲区大小)

unsigned long st_blocks; //块数

time_t st_atime; //最后一次访问时间

time_t st_mtime; //最后一次修改时间

time_t st_ctime; //最后一次改变时间(指属性)

};

先前所描述的st_mode 则定义了下列数种情况:

第1页

你可能喜欢

热门文档

相关文档

  • linux stat函数讲解

    linux stat函数讲解_计算机软件及应用_IT/计算机_专业资料。stat函数讲解 表头文件: #include <sys/stat.h> #include <unistd.h> 定义函数: int stat(const ...

  • Linux_stat函数讲解

    Linux_stat函数讲解_IT/计算机_专业资料。Linux_stat函数讲解#include <stdio.h> #include <stdlib.h> #include <string.h> struct student{ char name[32]...

  • Linux stat函数讲解

    Linux stat函数讲解 [日期:2011-02-13] 来源:Linux社区 作者:ACb0y Linux stat函数讲解: 表头文件: #include <sys/stat.h> #include <unistd.h> 定义函数:...

  • stat函数详细讲解

    stat函数详细讲解_计算机软件及应用_IT/计算机_专业资料。stat函数详细讲解... linux中select函数 8页 1下载券 open函数 4页 免费 kmd-br.pharm.tech....

  • stat函数详解

    stat函数详解_IT/计算机_专业资料。STAT 和 STAT64 函数详解 stat 函数讲解... Linux stat函数讲解 3页 免费 c语言多进程多线程编程 67页 免费 LACP 暂无...

  • Linux下DIR,dirent,stat等结构体详解

    Linux下DIR,dirent,stat等结构体详解_计算机软件及应用_IT/计算机_专业资料。...(, __lock) }; DIR 结构体类似于 FILE,是一个内部结构,以下几个函数用...

  • linux c 常用函数 -- 文件权限控制

    Linux stat函数讲解 3页 免费 linux目录操作函数 7页 免费 pcb4 26页 1...access(判断是否具有存取文件的权限) 相关函数 stat,open,chmod,chown,setuid,...

  • Stat_Chapter_17

    Linux stat函数讲解 3页 免费 Linux中C语言open函数打... 3页 免费 Stat_Chapter_16 31页 免费Stat_Chapte...

  • linux_netstat命令详解

    linux_netstat命令详解_IT/计算机_专业资料。linux功能说明:Netstat用于显示与IP、TCP、UDP和ICMP协议相关的统计数据,一般用于检验本机各端口的网络连接情况。 语 ...

站点地图 | 文档上传 | 侵权投诉 | 手机版
本站所有资源均来自互联网,本站只负责收集和整理,均不承担任何法律责任,如有侵权等其它行为请联系我们.
文档下载 Copyright 2013 doc.guandang.net All Rights Reserved.  -  email