blob: 70750d8b1ae909039c1e95d37ccab60b2f0096b0 [file] [log] [blame]
Guido van Rossume7b146f2000-02-04 15:28:42 +00001"""Constants/functions for interpreting results of os.stat() and os.lstat().
2
3Suggested usage: from stat import *
4"""
5
Guido van Rossum3bc034b1992-03-31 19:03:19 +00006# XXX Strictly spoken, this module may have to be adapted for each POSIX
7# implementation; in practice, however, the numeric constants used by
8# stat() are almost universal (even for stat() emulations on non-UNIX
Guido van Rossum7aeb4b91994-08-23 13:32:20 +00009# systems like MS-DOS).
Guido van Rossum6b47ed11990-10-21 16:17:08 +000010
Guido van Rossum3bc034b1992-03-31 19:03:19 +000011# Indices for stat struct members in tuple returned by os.stat()
Guido van Rossum6b47ed11990-10-21 16:17:08 +000012
13ST_MODE = 0
14ST_INO = 1
15ST_DEV = 2
16ST_NLINK = 3
17ST_UID = 4
18ST_GID = 5
19ST_SIZE = 6
20ST_ATIME = 7
21ST_MTIME = 8
22ST_CTIME = 9
23
Guido van Rossum3bc034b1992-03-31 19:03:19 +000024# Extract bits from the mode
25
Guido van Rossum468c4481990-10-31 11:25:23 +000026def S_IMODE(mode):
Tim Peters495ad3c2001-01-15 01:36:40 +000027 return mode & 07777
Guido van Rossum3bc034b1992-03-31 19:03:19 +000028
Guido van Rossum6b47ed11990-10-21 16:17:08 +000029def S_IFMT(mode):
Tim Peters495ad3c2001-01-15 01:36:40 +000030 return mode & 0170000
Guido van Rossum3bc034b1992-03-31 19:03:19 +000031
32# Constants used as S_IFMT() for various file types
33# (not all are implemented on all systems)
Guido van Rossum6b47ed11990-10-21 16:17:08 +000034
35S_IFDIR = 0040000
36S_IFCHR = 0020000
37S_IFBLK = 0060000
38S_IFREG = 0100000
39S_IFIFO = 0010000
40S_IFLNK = 0120000
41S_IFSOCK = 0140000
42
Guido van Rossum3bc034b1992-03-31 19:03:19 +000043# Functions to test for each file type
44
Guido van Rossum6b47ed11990-10-21 16:17:08 +000045def S_ISDIR(mode):
Tim Peters495ad3c2001-01-15 01:36:40 +000046 return S_IFMT(mode) == S_IFDIR
Guido van Rossum6b47ed11990-10-21 16:17:08 +000047
48def S_ISCHR(mode):
Tim Peters495ad3c2001-01-15 01:36:40 +000049 return S_IFMT(mode) == S_IFCHR
Guido van Rossum6b47ed11990-10-21 16:17:08 +000050
51def S_ISBLK(mode):
Tim Peters495ad3c2001-01-15 01:36:40 +000052 return S_IFMT(mode) == S_IFBLK
Guido van Rossum6b47ed11990-10-21 16:17:08 +000053
54def S_ISREG(mode):
Tim Peters495ad3c2001-01-15 01:36:40 +000055 return S_IFMT(mode) == S_IFREG
Guido van Rossum6b47ed11990-10-21 16:17:08 +000056
57def S_ISFIFO(mode):
Tim Peters495ad3c2001-01-15 01:36:40 +000058 return S_IFMT(mode) == S_IFIFO
Guido van Rossum6b47ed11990-10-21 16:17:08 +000059
60def S_ISLNK(mode):
Tim Peters495ad3c2001-01-15 01:36:40 +000061 return S_IFMT(mode) == S_IFLNK
Guido van Rossum6b47ed11990-10-21 16:17:08 +000062
63def S_ISSOCK(mode):
Tim Peters495ad3c2001-01-15 01:36:40 +000064 return S_IFMT(mode) == S_IFSOCK
Guido van Rossum8899a9c1992-05-06 11:38:27 +000065
66# Names for permission bits
67
68S_ISUID = 04000
69S_ISGID = 02000
70S_ENFMT = S_ISGID
71S_ISVTX = 01000
72S_IREAD = 00400
73S_IWRITE = 00200
74S_IEXEC = 00100
75S_IRWXU = 00700
76S_IRUSR = 00400
77S_IWUSR = 00200
78S_IXUSR = 00100
79S_IRWXG = 00070
80S_IRGRP = 00040
81S_IWGRP = 00020
82S_IXGRP = 00010
83S_IRWXO = 00007
84S_IROTH = 00004
85S_IWOTH = 00002
86S_IXOTH = 00001