• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C获取文件大小stat()

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

 

NAME

stat - get file status

SYNOPSIS

#include <sys/stat.h>

int stat(const char *restrict
path, struct stat *restrict buf);

DESCRIPTION

The stat() function shall obtain information about the named file and write it to the area pointed to by the buf argument. The path argument points to a pathname naming a file. Read, write, or execute permission of the named file is not required. An implementation that provides additional or alternate file access control mechanisms may, under implementation-defined conditions, cause stat() to fail. In particular, the system may deny the existence of the file specified by path.

If the named file is a symbolic link, the stat() function shall continue pathname resolution using the contents of the symbolic link, and shall return information pertaining to the resulting file if the file exists.

The buf argument is a pointer to a stat structure, as defined in the <sys/stat.h> header, into which information is placed concerning the file.

The stat() function shall update any time-related fields (as described in the Base Definitions volume of IEEE Std 1003.1-2001, Section 4.7, File Times Update), before writing into the stat structure.

Unless otherwise specified, the structure members st_mode, st_ino, st_dev, st_uid, st_gid, st_atime, st_ctime, and st_mtime shall have meaningful values for all file types defined in this volume of IEEE Std 1003.1-2001. The value of the member st_nlink shall be set to the number of links to the file.

RETURN VALUE

Upon successful completion, 0 shall be returned. Otherwise, -1 shall be returned and errno set to indicate the error.

 

1 #include <sys/types.h>
2 #include <sys/stat.h>
3 #include <fcntl.h>
4 
5 struct stat buffer;
6 int         status;
7 ...
8 status = stat("/home/cnd/mod1"&buffer);

 

来自:http://www.opengroup.org/onlinepubs/000095399/functions/stat.html

 

代码
struct stat
{
    _dev_t    st_dev;        
/* Equivalent to drive number 0=A 1=B ... */
    _ino_t    st_ino;        
/* Always zero ? */
    _mode_t    st_mode;    
/* See above constants */
    
short    st_nlink;    /* Number of links. */
    
short    st_uid;        /* User: Maybe significant on NT ? */
    
short    st_gid;        /* Group: Ditto */
    _dev_t    st_rdev;    
/* Seems useless (not even filled in) */
    _off_t    st_size;    
/* File size in bytes */
    time_t    st_atime;    
/* Accessed date (always 00:00 hrs local
                 * on FAT) 
*/
    time_t    st_mtime;    
/* Modified time */
    time_t    st_ctime;    
/* Creation time */
};

 

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
c语言描述的链队列的基本操作发布时间:2022-07-14
下一篇:
C#getPixel和内存法读取灰度图信息发布时间:2022-07-14
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap