summaryrefslogtreecommitdiff
path: root/reference/C/FUNCTIONS/stat.html
blob: 601aeaafdf7b2bdb33447ef2764efc779b8cf7bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<title>stat/fstat/lstat functions.</title>

<head>
<script language="JavaScript">
</script>
</head>

<body bgcolor=#ffffcc>
<hr>
<center>
<h1>stat/fstat/lstat functions.</h1>
</center>
<hr>
<p>

All three functions return information about a file. Please note 
that devices are seen as files to Unix, so you could 'stat' things
like /dev/mouse to see when the mouse was last moved.<p>

<b>stat</b> return the status of a file.<p>

<b>fstat</b> stats an open file.<p>

<b>lstat</b> reports on a link, not the file it points too.<p>
<pre>
Libraries: sys/stat.h
	   unistd.h

Syntax:    struct stat stat_p;
           stat ("martin", &stat_p);

Stat Structure:

           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 */
           };

</pre>

<b>st_mode</b> can be used with the following macros to discover the 
type of file being statted.

<a name=filetype>
<pre>
	S_ISLNK(st_mode)  is it a symbolic link

        S_ISREG(st_mode)  regular file

        S_ISDIR(st_mode)  directory

        S_ISCHR(st_mode)  character device

        S_ISBLK(st_mode)  block device

        S_ISFIFO(st_mode) fifo

        S_ISSOCK(st_mode) socket	
</pre>

These functions return a large amount of information. See the man page 
(below) for details. You will need to understand 
<a href="../SYNTAX/struct.html">structures</a> to work with stat.<p>

<img src=../../GRAPHICS/man.gif>
<a href="../MAN/stat.htm">
man page to provide all the details.</a>
<p>
<hr>
<h2>Examples</h2>
<img src=../../GRAPHICS/computer.gif>
<a href="../EXAMPLES/stat.c">
example program.</a>
<p>
<hr>
<h2>See also:</h2>
<img src=../../GRAPHICS/whiteball.gif>
<a href=directory.html>POSIX functions to read directory information.</a>
<p>
<hr>
<h2>Note</h2>
I have seen a problem with the 'access time', it only seems to get updated
if the file system is local. If the filesystem is NFS mounted and
accessed via 'cat' or 'head' the access date is not updated.


<p>

<hr>
<p>
<center>
<table border=2 width="80%" bgcolor="ivory">
<tr align=center>
<td width="25%">
<a href="../cref.html">                  Top</a>
</td><td width="25%">
<a href="../master_index.html">          Master Index</a>
</td><td width="25%">
<a href="../SYNTAX/keywords.html">                 Keywords</a>
</td><td width="25%">
<a href="funcref.htm">      Functions</a>
</td>
</tr>
</table>
</center>
<p>
<hr>
<address>Martin Leslie 
</address><p>
</body>
</html>