File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11# Module 'stat'
2-
2+ #
33# Defines constants and functions for interpreting stat/lstat struct
4- # as returned by posix.stat() and posix.lstat() (if it exists).
5-
6- # XXX This module may have to be adapted for UNIXoid systems whose
7- # <sys/stat.h> deviates from AT&T or BSD UNIX; their S_IF* constants
8- # may differ.
9-
4+ # as returned by os.stat() and os.lstat() (if it exists).
5+ #
106# 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 Macintosh or MS-DOS).
1112
12- # Tuple indices for stat struct members
13+ # Indices for stat struct members in tuple returned by os.stat()
1314
1415ST_MODE = 0
1516ST_INO = 1
2223ST_MTIME = 8
2324ST_CTIME = 9
2425
26+ # Extract bits from the mode
27+
2528def S_IMODE (mode ):
26- return mode % 4096
29+ return mode & 07777
30+
2731def S_IFMT (mode ):
28- return mode - mode % 4096
32+ return mode & ~ 07777
33+
34+ # Constants used as S_IFMT() for various file types
35+ # (not all are implemented on all systems)
2936
3037S_IFDIR = 0040000
3138S_IFCHR = 0020000
@@ -35,6 +42,8 @@ def S_IFMT(mode):
3542S_IFLNK = 0120000
3643S_IFSOCK = 0140000
3744
45+ # Functions to test for each file type
46+
3847def S_ISDIR (mode ):
3948 return S_IFMT (mode ) == S_IFDIR
4049
You can’t perform that action at this time.
0 commit comments