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.