up: programming - C - File I/O  
programming - C - function fstatWhat links here?

prototype

stat, fstat, lstat - get file status


SYNOPSIS

  1. include
  2. include


int stat(const char *file_name, struct stat *buf); int fstat(int filedes, struct stat *buf); int lstat(const char *file_name, struct stat *buf);


DESCRIPTION

These functions return information about the specified file. You do not need any access rights to the file to get this information but you need search rights to all directories named in the path leading to the file.



They all return a stat structure, which is declared as follows:

struct stat {
    dev_t         st_dev;      /* device */
    ino_t         st_ino;      /* inode */
    umode_t       st_mode;     /* protection */
    nlink_t       st_nlink;    /* number of hard links */
    uid_t         st_uid;      /* user ID of owner */
    gid_t         st_gid;      /* group ID of owner */
    dev_t         st_rdev;     /* device type (if inode device) */
    off_t         st_size;     /* total size, in bytes */
    unsigned long st_blksize;  /* blocksize for filesystem I/O */
    unsigned long st_blocks;   /* number of blocks allocated */
    time_t        st_atime;    /* time of last access */
    time_t        st_mtime;    /* time of last modification */
    time_t        st_ctime;    /* time of last change */
};


Note that st_blocks may not always be in terms of blocks of size st_blksize, and that st_blksize may instead pro- vide a notion of the "preferred" blocksize for efficient file system I/O.

Not all of the Linux filesystems implement all of the time fields. Traditionally, st_atime is changed by mknod(2), utime(2), read(2), write(2), and truncate(2).

Traditionally, st_mtime is changed by mknod(2), utime(2), and write(2). The st_mtime is not changed for changes in owner, group, hard link count, or mode.

Traditionally, st_ctime is changed by writing or by setting inode information (i.e., owner, group, link count, mode, etc.).

The following macros are defined to check the file type:



The following flags are defined for the st_mode field:



RETURN VALUE

On success, zero is returned. On error, -1 is returned, and errno is set appropriately.

ERRORS

programming - C - function fstat
programming - C - function strrchr
programming - C - function rewind
Topical Bible - God's promises to Abraham
Topical Bible - Salvation before Christ's advent
programming:windows:CREATESTRUCT
20K NTC with output across load resistor
programming - C - function strcpy
programming:microchip pics:16F84A portb
Topical Bible - God's discipline of the believer
Topical Bible - Levirate marriage
X Windows Functions - Window XCreateSimpleWindow(display, parent, x, y, width, height, border_width, depth, class, visual, valuemask, attributes)
linux - software
Topical Bible - Angel of God
Topical Bible - Jesus the Anointed One
Topical Bible - Jesus in the Old Testament
Topical Bible - God's promises to (about) Ishmael
programming:c:functions:strnpos
filename:programming - C - function fstat
filename:programming%20%2D%20C%20%2D%20function%20fstat
last edit:December 18 2012 19:07:22 (4168 days ago)
ct = 1716070243.000000 = May 18 2024 18:10:43
ft = 1355875642.000000 = December 18 2012 19:07:22
dt = 360194601.000000