本部落格里,若没有特别注明,都是本人原创,转载请注明出处: www.9ri.net
 
 
RSS
 
 
Home » Posts tagged "stat"

Posts Tagged ‘stat’:


stat.h头文件,轻松获取文件属性。

Published on 一月 27th, 2008 by in 与IT沾边

【以前还为了获取文件的长度,费劲从头读取一遍,一个一个字节的算。 做webserver时候,发现原来stat函数可以返回一个结构,里面包括文件的全部属性。 真是曲折啊。】 #i nclude<sys/stat.h> int stat(const char *restrict pathname,struct stat *restrict buf); int fstat(int fields,struct stat *buf); int lstat(const char *restrict pathname,struct stat *restrict buf);  返回值:若成功则返回0,失败则返回-1    一旦给出pathname,stat函数就返回与此命名文件有关的信息结构,fstat函数获取已在描述符fields上打开文件的有关信息。  lstat函数类似于stat.但是当命名的文件是一个符号链接时,lstat返回该符号链接的有关信息,而不是由该符号链接引用文件  的信息。第二个参数buf是指针,它指向一个我们必须提供的结构,这些函数填写由buf指向的结构。该结构的实际定义可能随实现  有所不同.    struct stat{ mode_t st_mode; //文件类型和权限信息 ino_t st_ino; //i结点标识 dev_t st_dev; //device number (file system) dev_t st_rdev; //device number for special files nlink_t

(More)…

Tags: ,
 
© Hardy.九日志
credit

无觅相关文章插件,快速提升流量