Use of stat in C Language

Source: Internet
Author: User

1. Stat struct

The structure is defined in the/usr/include/sys/STAT. h file.

Struct stat finfo;

Stat (sfilename, & finfo );

Int size = finfo. st_size;

Struct stat {

Mode_t st_mode; // file mode, file, directory, etc.

Ino_t st_ino; // I-node number

Dev_t st_dev; // device number

Dev_t st_rdev; // special device number

Nlink_t st_nlink; // number of file connections

Uid_t st_uid; // file owner

Gid_t st_gid; // group corresponding to the file owner

Off_t st_size; // common file, corresponding to the number of bytes

Time_t st_atime; // time when the object was last accessed

Time_t st_mtime; // The last modification time of the file content

Time_t st_ctime; // File status (attribute) Change Time

Blksize_t st_blksize; // block size corresponding to the file content

Blkcnt_t st_blocks; // number of blocks corresponding to the file content

};

Stat Function: Get File Information:

Stat (file_route, & Stat); If the returned value is 0, the operation succeeds. Otherwise, the operation fails.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.