Detailed description of function Stat ()

Source: Internet
Author: User
First, let's take a look at the solution of msdn: Stat (): Get status information on a file. parameters: Path: pointer to a string containing the path of existing file. buffer: pointer to a structure that stores results.
int _stat(   const char *path,   struct _stat *buffer );
 
The definition of Schema _ stat is on the Sys \ stat. H plane. You can view the content on your own, including the main fields:
 
St_gid

Numeric identifier of group that owns the file (Unix-specific) this field will always be zero on Windows systems. A redirected file is classified as a Windows file.

St_atime

Time of last access of file. Valid on NTFS but not on FAT formatted disk drives.

St_ctime

Time of creation of file. Valid on NTFS but not on FAT formatted disk drives.

St_dev

Drive Number of the disk containing the file (sameSt_rdev).

St_ino

Number of the information node (the inode) for the file (Unix-specific ). on UNIX file systems, the inode describes the file date and time stamps, permissions, and content. when files are hard-linked to one another, they share the same inode. the inode, and thereforeSt_ino, Has no meaning in the fat, HPFs, or NTFS file systems.

St_mode

Bit mask for file-mode information._ S_ifdirBit is set if path specifies a directory;_ S_ifregBit is set if path specifies an ordinary file or a device. User read/write bits are set according to the file's permission mode; User Execute bits are set according to the filename extension.

St_mtime

Time of last modification of file.

St_nlink

Always 1 on non-NTFS file systems.

St_rdev

Drive Number of the disk containing the file (sameSt_dev).

St_size

Size of the file in bytes; a 64-bit integer for variations withI64Suffix.

St_uid

Numeric identifier of user who owns file (Unix-specific). This field will always be zero on Windows systems. A redirected file is classified as a Windows file.

If path refers to a device,St_size, Various time fields,St_dev, AndSt_rdevFields in_ StatStructure are meaningless. Because Stat. h uses the _ dev_t type that is defined in types. H, you must include types. h before Stat. h in your code.

 
The following uses a demo to describe the function usage.
# Include <stdio. h> # include <sys/types. h> # include <sys/STAT. h> int main (INT argc, char * argv []) {struct _ stat Buf; int result = 0; char * filename = "D: \ test.txt "; // note the delimiter Conversion Result = _ Stat (filename, & BUF); If (result = 0) {printf ("\ nfile infomation \ n "); printf ("file size = [% d] \ n", Buf. st_size); printf ("file Dev = [% C] \ n", Buf. st_rdev + 'A'); // Add the large a return 0;} return-1 ;}

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.