blob: 4b53953634c60a061e281473ca3fc179df6d89e6 [file] [log] [blame]
Guido van Rossum7aeb4b91994-08-23 13:32:20 +00001# Module 'stat'
2#
3# Defines constants and functions for interpreting stat/lstat struct
4# as returned by os.stat() and os.lstat() (if it exists).
5#
6# Suggested usage: from stat import *
7#
8# XXX Strictly spoken, this module may have to be adapted for each POSIX
9# implementation; in practice, however, the numeric constants used by
10# stat() are almost universal (even for stat() emulations on non-UNIX
11# systems like MS-DOS).
12
13# Indices for stat struct members in tuple returned by os.stat()
14
15ST_MODE = 0
16ST_INO = 1
17ST_DEV = 2
18ST_NLINK = 3
19ST_UID = 4
20ST_GID = 5
21ST_SIZE = 6
22ST_ATIME = 7
23ST_MTIME = 8
24ST_CTIME = 9
25
26# Extract bits from the mode
27
28def S_IMODE(mode):
29 return 0
30
31def S_IFMT(mode):
32 return mode & 0xFFFF
33
34# Constants used as S_IFMT() for various file types
35# (not all are implemented on all systems)
36
37S_IFDIR = 0x0000
38S_IFREG = 0x0003
39
40# Functions to test for each file type
41
42def S_ISDIR(mode):
43 return S_IFMT(mode) == S_IFDIR
44
45def S_ISCHR(mode):
46 return 0
47
48def S_ISBLK(mode):
49 return 0
50
51def S_ISREG(mode):
52 return S_IFMT(mode) == S_IFREG
53
54def S_ISFIFO(mode):
55 return 0
56
57def S_ISLNK(mode):
58 return 0
59
60def S_ISSOCK(mode):
61 return 0
62
63# Names for permission bits
64
65S_ISUID = 04000
66S_ISGID = 02000
67S_ENFMT = S_ISGID
68S_ISVTX = 01000
69S_IREAD = 00400
70S_IWRITE = 00200
71S_IEXEC = 00100
72S_IRWXU = 00700
73S_IRUSR = 00400
74S_IWUSR = 00200
75S_IXUSR = 00100
76S_IRWXG = 00070
77S_IRGRP = 00040
78S_IWGRP = 00020
79S_IXGRP = 00010
80S_IRWXO = 00007
81S_IROTH = 00004
82S_IWOTH = 00002
83S_IXOTH = 00001