BSD 3 development
[unix-history] / usr / man / man2 / stat.2
CommitLineData
e6817382
BJ
1.TH STAT 2
2.SH NAME
3stat, fstat \- get file status
4.SH SYNOPSIS
5.B #include <sys/types.h>
6.br
7.B #include <sys/stat.h>
8.PP
9.B stat(name, buf)
10.br
11.B char *name;
12.br
13.B struct stat *buf;
14.PP
15.B fstat(fildes, buf)
16.br
17.B struct stat *buf;
18.SH DESCRIPTION
19.I Stat
20obtains detailed information about a named file.
21.I Fstat
22obtains the same information about an open file
23known by the file descriptor from a successful
24.I open, creat, dup
25or
26.IR pipe (2)
27call.
28.PP
29.I Name
30points to a null-terminated string naming
31a file;
32.I buf
33is the address of a buffer
34into which information is placed concerning the file.
35It is unnecessary to have any
36permissions at all with respect to the file, but all directories
37leading to the file must be searchable.
38The layout of the structure pointed to by buf
39as defined in
40.I <stat.h>
41is given below.
42.I St_mode
43is encoded according to the `#define' statements.
44.PP
45.nf
46.so /usr/include/sys/stat.h
47.fi
48.PP
49The mode bits 0000070 and 0000007 encode group and
50others permissions (see
51.IR chmod (2)).
52The defined types,
53.I
54ino_t, off_t, time_t,
55name various width integer values;
56.I dev_t
57encodes
58major and minor device numbers;
59their exact definitions are in
60the include file <sys/types.h>
61(see
62.IR types (5).
63.PP
64When
65.I fildes
66is associated with a pipe,
67.I fstat
68reports an ordinary file with an i-node number,
69restricted permissions,
70and a not necessarily meaningful length.
71.PP
72.I st_atime
73is the file was last read.
74For reasons of efficiency, it is not set when a directory
75is searched, although this would be more logical.
76.I st_mtime
77is the time the file was last written or created.
78It is not set by changes of owner, group, link count, or mode.
79.I st_ctime
80is set both both by writing and changing the i-node.
81.SH "SEE ALSO"
82ls(1), filsys(5)
83.SH DIAGNOSTICS
84Zero is returned if a status is available;
85\-1 if the file cannot be found.
86.SH ASSEMBLER
87(stat = 18.)
88.br
89.B sys stat; name; buf
90.PP
91(fstat = 28.)
92.br
93(file descriptor in r0)
94.br
95.B sys fstat; buf