zoukankan      html  css  js  c++  java
  • C获取文件大小stat()

    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 */
    };
  • 相关阅读:
    EzHttp 流传输调用代码示例
    使用EzHttp框架 开发基于HTTP协议的CS轻应用
    [转]Installing Memcached on Windows
    SQLiteServer+SQLiteClient 用于.Net项目的SQLite服务端程序和客户端类库
    ERROR: Pillow-5.2.0-cp35-cp35m-win_amd64.whl is not a supported wheel on this platform.
    Linux下的tar压缩解压缩命令详解
    scp 基于 SSH 的安全远程服务器文件拷贝
    大批量删除列表中元素的方法,自己用本办法做的
    Python 列表 pop() 方法
    可遍历的数据对象enumerate() 方法的使用
  • 原文地址:https://www.cnblogs.com/yanhc/p/1635818.html
Copyright © 2011-2022 走看看