Skip to content

Commit 4345655

Browse files
committed
POSIX interface: stat.h, types.h
1 parent 9c0c8a8 commit 4345655

File tree

4 files changed

+77
-7
lines changed

4 files changed

+77
-7
lines changed

Cython/Includes/posix/stat.pxd

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
from posix.types cimport (blkcnt_t, blksize_t, dev_t, gid_t, ino_t, mode_t,
2+
nlink_t, off_t, time_t, uid_t)
3+
4+
5+
cdef extern from "sys/stat.h" nogil:
6+
cdef struct struct_stat "stat":
7+
dev_t st_dev
8+
ino_t st_ino
9+
10+
# POSIX prescribes including both <sys/stat.h> and <unistd.h> for these
11+
cdef extern from "unistd.h" nogil:
12+
int fchmod(int, mode_t)
13+
int chmod(const char *, mode_t)
14+
15+
int fstat(int, struct_stat *)
16+
int lstat(const char *, struct_stat *)
17+
int stat(const char *, struct_stat *)
18+
19+
# Macros for st_mode
20+
mode_t S_ISREG(mode_t)
21+
mode_t S_ISDIR(mode_t)
22+
mode_t S_ISCHR(mode_t)
23+
mode_t S_ISBLK(mode_t)
24+
mode_t S_ISFIFO(mode_t)
25+
mode_t S_ISLNK(mode_t)
26+
mode_t S_ISSOCK(mode_t)
27+
28+
mode_t S_IFMT
29+
mode_t S_IFREG
30+
mode_t S_IFDIR
31+
mode_t S_IFCHR
32+
mode_t S_IFBLK
33+
mode_t S_IFIFO
34+
mode_t S_IFLNK
35+
mode_t S_IFSOCK
36+
37+
# Permissions
38+
mode_t S_ISUID
39+
mode_t S_ISGID
40+
mode_t S_ISVTX
41+
42+
mode_t S_IRWXU
43+
mode_t S_IRUSR
44+
mode_t S_IWUSR
45+
mode_t S_IXUSR
46+
47+
mode_t S_IRWXG
48+
mode_t S_IRGRP
49+
mode_t S_IWGRP
50+
mode_t S_IXGRP
51+
52+
mode_t S_IRWXO
53+
mode_t S_IROTH
54+
mode_t S_IWOTH
55+
mode_t S_IXOTH

Cython/Includes/posix/types.pxd

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
cdef extern from "sys/types.h":
2+
ctypedef long blkcnt_t
3+
ctypedef long blksize_t
4+
ctypedef long dev_t
5+
ctypedef long gid_t
6+
ctypedef long ino_t
7+
ctypedef long mode_t
8+
ctypedef long nlink_t
9+
ctypedef long off_t
10+
ctypedef long pid_t
11+
ctypedef long time_t
12+
ctypedef long uid_t

Cython/Includes/posix/unistd.pxd

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# http://www.opengroup.org/onlinepubs/009695399/basedefs/unistd.h.html
22

3+
from posix.types cimport gid_t, pid_t, off_t, uid_t
4+
35
cdef extern from "unistd.h" nogil:
46

57
#:NULL
@@ -32,14 +34,7 @@ cdef extern from "unistd.h" nogil:
3234
enum: STDOUT_FILENO #1
3335
enum: STDERR_FILENO #2
3436

35-
#:ctypedef unsigned size_t
36-
#:ctypedef signed ssize_t
37-
ctypedef int uid_t
38-
ctypedef int gid_t
39-
ctypedef signed off_t
40-
ctypedef signed pid_t
4137
ctypedef unsigned useconds_t
42-
ctypedef signed intptr_t
4338

4439
int access(const char *, int)
4540
unsigned alarm(unsigned)

tests/compile/posix_pxds.pyx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,11 @@ from posix.unistd cimport *
1010
cimport posix.fcntl
1111
from posix cimport fcntl
1212
from posix.fcntl cimport *
13+
14+
cimport posix.types
15+
from posix cimport types
16+
from posix.types cimport *
17+
18+
cimport posix.stat
19+
from posix cimport stat
20+
from posix.stat cimport *

0 commit comments

Comments
 (0)