C-language stat function

Source: Internet
Author: User
Tags function prototype

C-language stat functionStat

#include <sys/stat.h> #include <unistd.h>
function prototype: int stat (const char * file_name, struct stat * buf)
* * Function Description: **stat function get file_name points to the file status of the file and saves the file information to the struct buf , execution successfully returns 0, failure returns-1, The error code is stored in errno
struct struct STAT parameter description:

struct stat{dev_t st_dev;//device file's device number ino_t St_ino;//inode file's index node mode_t st_mode; type of//protection file and access rights limited to nlink_t St_nlink;    Number of hard links connects to the file with a file value of 1 that has just been created. uid_t St_uid; User ID of the owner of the owners file gid_t st_gid; Group ID of the owner of the file owners of the groups identification code dev_t St_rdev; Device type If this file is an appliance device file, its equipment number off_t st_size; Total size, in bytes file size, calculated in bytes unsigned long st_blksize;    BlockSize the I/O buffer size for the filesystem I/O file system. unsigned long st_blocks;    Number of blocks allocated occupies a chunk of files, each chunk size is 512 bytes. time_t St_atime;    Time of lastaccess file was last accessed or executed, and generally only changed with Mknod, Utime, read, write, and Tructate. time_t St_mtime; Time of last modification file was modified at the end of the day, generally only in Mknod, Utime and write will change time_t st_ctime; Time of last changes i-node the most recent change, this parameter is updated when the file owner, group, and permissions are changed};

St_mode Description:

1, s_ifmt0170000Bit masks for file types2, S_ifsock0140000Scoket3, S_iflnk0120000Symbolic connection4, S_ifreg0100000General documents5, s_ifblk0060000Block device6, S_ifdir0040000Directory7, S_IFCHR0020000Character device8, S_ififo0010000Advanced First Out9, S_isuid04000File (set User-id on execution) bitTen, S_isgid02000File (set Group-id on execution) bit One, S_ISVTX01000Sticky bits of the file A, S_irusr (S_iread)00400File owners have Read permissions -, S_iwusr (S_iwrite)00200File owner with writable permission -, S_ixusr (s_iexec)00100File owner has executable permissions the, S_IRGRP00040User groups with readable permissions -, S_IWGRP00020User groups have writable permissions -, S_IXGRP00010User groups with executable permissions -, 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 these types of macro definitions +, S_islnk (St_mode) to determine if it is a symbolic connection A, S_isreg (St_mode) is a generic file at, S_isdir (St_mode) is a directory -, S_ISCHR (St_mode) is a character device file -, S_isblk (s3e) is FIFO -, S_issock (St_mode) is a socket if a directory has a sticky bit (s_isvtx), then the file in this directory can only be deleted or renamed by the file owner, this directory owner, or root.

C-language stat function

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.