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 */
    };
  • 相关阅读:
    算法总结之 两个链表生成相加链表
    算法总结之 复制含有随机指针节点的链表
    算法总结之 将单向链表按某值划分成左边小、中间相等、右边大的形式
    在PHP5.3以上版本运行ecshop和ecmall出现的问题及解决方案
    windows下配置nginx+php环境
    ecmall程序结构图与数据库表分析
    ecmall数据字典
    Ecmall二次开发-增删改查操作
    PHP7:10件事情你需要知道的
    PHP命名空间规则解析及高级功能3
  • 原文地址:https://www.cnblogs.com/yanhc/p/1635818.html
Copyright © 2011-2022 走看看