Linux stat system call to get file information.

Source: Internet
Author: User
Tags readable

Stat function Prototypes:

intstat*pathstat*buf);

struct STAT Description

structStat {mode_t St_mode;//files corresponding to the mode, files, directories, etc.ino_t St_ino;//inode Node Numberdev_t St_dev;//Device numberdev_t St_rdev;//Special Equipment numbernlink_t St_nlink;number of connections to//filesuid_t St_uid;//File ownergid_t St_gid;//The group to which the file owner correspondsoff_t st_size;//Normal file, corresponding file byte numbertime_t St_atime;//The last time the file was visitedtime_t St_mtime;//When the file content was last modifiedtime_t St_ctime;//File status change timeblksize_t st_blksize;//The block size corresponding to the file contentsblkcnt_t st_blocks;//The number of blocks corresponding to Wei Jian content};

The St_mode in the stat structure defines the following conditions:

S_ifmt0170000Bit mask for file type S_ifsock0140000Scoket S_iflnk0120000Symbolic Connection S_ifreg0100000General file S_ifblk0060000Block Device S_ifdir0040000Catalogue S_IFCHR0020000Character Device S_ififo0010000Advanced First Out S_isuid04000of the file (Setuser-ID  onexecution) Bit S_isgid02000of the file (Setgroup-ID  onexecution) Bit s_isvtx01000Sticky bit s_irusr (s_iread) of the file00400File owner with readable permissions s_iwusr (s_iwrite)00200File owner with writable permission s_ixusr (s_iexec)00100The file owner has executable permissions S_irgrp00040User group with readable permissions S_iwgrp00020User group with writable permission S_ixgrp00010User group with executable permission S_iroth00004Other users have Read permissions S_iwoth00002Other users have writable permissions S_ixoth00001Other users with executable permissions The above file types are defined in POSIX to check the macro definitions for these types: S_islnk (St_mode) determines whether the symbolic connection S_isreg (St_mode) is a generic file S_isdir (S T_mode) Whether the directory S_ISCHR (St_mode) is a character appliance file S_isblk (s3e) is a FIFO S_issock (St_mode) is a socket

Sample program:
Gets the size of the file.

int main(){    stat m_stat;    stat("./a.txt",&m_stat);    printf("%ld\n",m_stat.st_size);    return0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Linux stat system call to get file information.

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.