Mercurial > hg
annotate mercurial/cext/osutil.c @ 45095:8e04607023e5
procutil: ensure that procutil.std{out,err}.write() writes all bytes
Python 3 offers different kind of streams and it’s not guaranteed for all of
them that calling write() writes all bytes.
When Python is started in unbuffered mode, sys.std{out,err}.buffer are
instances of io.FileIO, whose write() can write less bytes for
platform-specific reasons (e.g. Linux has a 0x7ffff000 bytes maximum and could
write less if interrupted by a signal; when writing to Windows consoles, it’s
limited to 32767 bytes to avoid the "not enough space" error). This can lead to
silent loss of data, both when using sys.std{out,err}.buffer (which may in fact
not be a buffered stream) and when using the text streams sys.std{out,err}
(I’ve created a CPython bug report for that:
https://bugs.python.org/issue41221).
Python may fix the problem at some point. For now, we implement our own wrapper
for procutil.std{out,err} that calls the raw stream’s write() method until all
bytes have been written. We don’t use sys.std{out,err} for larger writes, so I
think it’s not worth the effort to patch them.
author | Manuel Jacob <me@manueljacob.de> |
---|---|
date | Fri, 10 Jul 2020 12:27:58 +0200 |
parents | 0424a9134bcf |
children | f93a4e3d35ab |
rev | line source |
---|---|
5396
5105b119edd2
Add osutil module, containing a listdir function.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
1 /* |
5105b119edd2
Add osutil module, containing a listdir function.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
2 osutil.c - native operating system services |
5105b119edd2
Add osutil module, containing a listdir function.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
3 |
5105b119edd2
Add osutil module, containing a listdir function.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
4 Copyright 2007 Matt Mackall and others |
5105b119edd2
Add osutil module, containing a listdir function.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
5 |
5105b119edd2
Add osutil module, containing a listdir function.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
6 This software may be used and distributed according to the terms of |
5105b119edd2
Add osutil module, containing a listdir function.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
7 the GNU General Public License, incorporated herein by reference. |
5105b119edd2
Add osutil module, containing a listdir function.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
8 */ |
5105b119edd2
Add osutil module, containing a listdir function.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
9 |
5463
3b204881f959
osutil: use fdopendir instead of dirfd
Bryan O'Sullivan <bos@serpentine.com>
parents:
5457
diff
changeset
|
10 #define _ATFILE_SOURCE |
42069
668eff08387f
cext: make osutil.c PY_SSIZE_T_CLEAN
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39610
diff
changeset
|
11 #define PY_SSIZE_T_CLEAN |
5397
11caa374f497
osutil.c: include Python.h before the other headers
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5396
diff
changeset
|
12 #include <Python.h> |
34438
b90e8da190da
cext: reorder #include
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32367
diff
changeset
|
13 #include <errno.h> |
8330
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
14 #include <fcntl.h> |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
15 #include <stdio.h> |
27473
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
16 #include <stdlib.h> |
8330
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
17 #include <string.h> |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
18 |
7056
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
19 #ifdef _WIN32 |
34438
b90e8da190da
cext: reorder #include
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32367
diff
changeset
|
20 #include <io.h> |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
9353
diff
changeset
|
21 #include <windows.h> |
7056
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
22 #else |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
9353
diff
changeset
|
23 #include <dirent.h> |
35460
8652ab4046e4
osutil: add a function to unblock signals
Jun Wu <quark@fb.com>
parents:
34861
diff
changeset
|
24 #include <signal.h> |
27473
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
25 #include <sys/socket.h> |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
9353
diff
changeset
|
26 #include <sys/stat.h> |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
9353
diff
changeset
|
27 #include <sys/types.h> |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
9353
diff
changeset
|
28 #include <unistd.h> |
31622
2243ba216f66
statfs: change Linux feature detection
Jun Wu <quark@fb.com>
parents:
31597
diff
changeset
|
29 #ifdef HAVE_LINUX_STATFS |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
30 #include <linux/magic.h> |
31622
2243ba216f66
statfs: change Linux feature detection
Jun Wu <quark@fb.com>
parents:
31597
diff
changeset
|
31 #include <sys/vfs.h> |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
32 #endif |
31597
2d501fb60b2d
osutil: report fstype for BSD and OSX
Jun Wu <quark@fb.com>
parents:
31564
diff
changeset
|
33 #ifdef HAVE_BSD_STATFS |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
34 #include <sys/mount.h> |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
35 #include <sys/param.h> |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
36 #endif |
7056
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
37 #endif |
5396
5105b119edd2
Add osutil module, containing a listdir function.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
38 |
24461
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
39 #ifdef __APPLE__ |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
40 #include <sys/attr.h> |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
41 #include <sys/vnode.h> |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
42 #endif |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
43 |
11359
4eaacccbb2ca
osutil.c: Support for py3k added.
Renato Cunha <renatoc@gmail.com>
parents:
10282
diff
changeset
|
44 #include "util.h" |
4eaacccbb2ca
osutil.c: Support for py3k added.
Renato Cunha <renatoc@gmail.com>
parents:
10282
diff
changeset
|
45 |
9353
3ac42ca1f3e6
osutil: fix compilation with -ansi
Sebastien Binet <binet@cern.ch>
parents:
8723
diff
changeset
|
46 /* some platforms lack the PATH_MAX definition (eg. GNU/Hurd) */ |
8722
48da69ff79bd
Some platforms lack the PATH_MAX definition (eg. GNU/Hurd).
Arne Babenhauserheide <bab@draketo.de>
parents:
7190
diff
changeset
|
47 #ifndef PATH_MAX |
48da69ff79bd
Some platforms lack the PATH_MAX definition (eg. GNU/Hurd).
Arne Babenhauserheide <bab@draketo.de>
parents:
7190
diff
changeset
|
48 #define PATH_MAX 4096 |
48da69ff79bd
Some platforms lack the PATH_MAX definition (eg. GNU/Hurd).
Arne Babenhauserheide <bab@draketo.de>
parents:
7190
diff
changeset
|
49 #endif |
48da69ff79bd
Some platforms lack the PATH_MAX definition (eg. GNU/Hurd).
Arne Babenhauserheide <bab@draketo.de>
parents:
7190
diff
changeset
|
50 |
7056
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
51 #ifdef _WIN32 |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
52 /* |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
53 stat struct compatible with hg expectations |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
54 Mercurial only uses st_mode, st_size and st_mtime |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
55 the rest is kept to minimize changes between implementations |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
56 */ |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
57 struct hg_stat { |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
58 int st_dev; |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
59 int st_mode; |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
60 int st_nlink; |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
61 __int64 st_size; |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
62 int st_mtime; |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
63 int st_ctime; |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
64 }; |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
65 struct listdir_stat { |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
66 PyObject_HEAD |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
67 struct hg_stat st; |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
68 }; |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
69 #else |
5396
5105b119edd2
Add osutil module, containing a listdir function.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
70 struct listdir_stat { |
5421 | 71 PyObject_HEAD |
72 struct stat st; | |
5396
5105b119edd2
Add osutil module, containing a listdir function.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
73 }; |
7056
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
74 #endif |
5396
5105b119edd2
Add osutil module, containing a listdir function.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
75 |
30111
a989fa78dafa
osutil: use PyLongObject on Python 3 for listdir_slot
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30110
diff
changeset
|
76 #ifdef IS_PY3K |
a989fa78dafa
osutil: use PyLongObject on Python 3 for listdir_slot
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30110
diff
changeset
|
77 #define listdir_slot(name) \ |
a989fa78dafa
osutil: use PyLongObject on Python 3 for listdir_slot
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30110
diff
changeset
|
78 static PyObject *listdir_stat_##name(PyObject *self, void *x) \ |
a989fa78dafa
osutil: use PyLongObject on Python 3 for listdir_slot
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30110
diff
changeset
|
79 { \ |
a989fa78dafa
osutil: use PyLongObject on Python 3 for listdir_slot
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30110
diff
changeset
|
80 return PyLong_FromLong(((struct listdir_stat *)self)->st.name); \ |
a989fa78dafa
osutil: use PyLongObject on Python 3 for listdir_slot
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30110
diff
changeset
|
81 } |
a989fa78dafa
osutil: use PyLongObject on Python 3 for listdir_slot
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30110
diff
changeset
|
82 #else |
5396
5105b119edd2
Add osutil module, containing a listdir function.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
83 #define listdir_slot(name) \ |
7190
aecea6934fdd
Some additional space/tab cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
7136
diff
changeset
|
84 static PyObject *listdir_stat_##name(PyObject *self, void *x) \ |
aecea6934fdd
Some additional space/tab cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
7136
diff
changeset
|
85 { \ |
aecea6934fdd
Some additional space/tab cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
7136
diff
changeset
|
86 return PyInt_FromLong(((struct listdir_stat *)self)->st.name); \ |
aecea6934fdd
Some additional space/tab cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
7136
diff
changeset
|
87 } |
30111
a989fa78dafa
osutil: use PyLongObject on Python 3 for listdir_slot
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30110
diff
changeset
|
88 #endif |
5396
5105b119edd2
Add osutil module, containing a listdir function.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
89 |
5431
a7c832abd29c
Fix build error with Sun C compiler.
Bryan O'Sullivan <bos@serpentine.com>
parents:
5430
diff
changeset
|
90 listdir_slot(st_dev) |
a7c832abd29c
Fix build error with Sun C compiler.
Bryan O'Sullivan <bos@serpentine.com>
parents:
5430
diff
changeset
|
91 listdir_slot(st_mode) |
a7c832abd29c
Fix build error with Sun C compiler.
Bryan O'Sullivan <bos@serpentine.com>
parents:
5430
diff
changeset
|
92 listdir_slot(st_nlink) |
7056
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
93 #ifdef _WIN32 |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
94 static PyObject *listdir_stat_st_size(PyObject *self, void *x) |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
95 { |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
96 return PyLong_FromLongLong( |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
97 (PY_LONG_LONG)((struct listdir_stat *)self)->st.st_size); |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
98 } |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
99 #else |
5431
a7c832abd29c
Fix build error with Sun C compiler.
Bryan O'Sullivan <bos@serpentine.com>
parents:
5430
diff
changeset
|
100 listdir_slot(st_size) |
7056
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
101 #endif |
5431
a7c832abd29c
Fix build error with Sun C compiler.
Bryan O'Sullivan <bos@serpentine.com>
parents:
5430
diff
changeset
|
102 listdir_slot(st_mtime) |
a7c832abd29c
Fix build error with Sun C compiler.
Bryan O'Sullivan <bos@serpentine.com>
parents:
5430
diff
changeset
|
103 listdir_slot(st_ctime) |
5396
5105b119edd2
Add osutil module, containing a listdir function.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
104 |
5105b119edd2
Add osutil module, containing a listdir function.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
105 static struct PyGetSetDef listdir_stat_getsets[] = { |
5421 | 106 {"st_dev", listdir_stat_st_dev, 0, 0, 0}, |
107 {"st_mode", listdir_stat_st_mode, 0, 0, 0}, | |
108 {"st_nlink", listdir_stat_st_nlink, 0, 0, 0}, | |
109 {"st_size", listdir_stat_st_size, 0, 0, 0}, | |
110 {"st_mtime", listdir_stat_st_mtime, 0, 0, 0}, | |
111 {"st_ctime", listdir_stat_st_ctime, 0, 0, 0}, | |
112 {0, 0, 0, 0, 0} | |
5396
5105b119edd2
Add osutil module, containing a listdir function.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
113 }; |
5105b119edd2
Add osutil module, containing a listdir function.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
114 |
5105b119edd2
Add osutil module, containing a listdir function.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
115 static PyObject *listdir_stat_new(PyTypeObject *t, PyObject *a, PyObject *k) |
5105b119edd2
Add osutil module, containing a listdir function.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
116 { |
5421 | 117 return t->tp_alloc(t, 0); |
5396
5105b119edd2
Add osutil module, containing a listdir function.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
118 } |
5105b119edd2
Add osutil module, containing a listdir function.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
119 |
5105b119edd2
Add osutil module, containing a listdir function.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
120 static void listdir_stat_dealloc(PyObject *o) |
5105b119edd2
Add osutil module, containing a listdir function.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
121 { |
5421 | 122 o->ob_type->tp_free(o); |
5396
5105b119edd2
Add osutil module, containing a listdir function.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
123 } |
5105b119edd2
Add osutil module, containing a listdir function.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
124 |
36780
f3c314020beb
osutil: implement minimal __getitem__ compatibility on our custom listdir type
Augie Fackler <augie@google.com>
parents:
36620
diff
changeset
|
125 static PyObject *listdir_stat_getitem(PyObject *self, PyObject *key) |
f3c314020beb
osutil: implement minimal __getitem__ compatibility on our custom listdir type
Augie Fackler <augie@google.com>
parents:
36620
diff
changeset
|
126 { |
f3c314020beb
osutil: implement minimal __getitem__ compatibility on our custom listdir type
Augie Fackler <augie@google.com>
parents:
36620
diff
changeset
|
127 long index = PyLong_AsLong(key); |
f3c314020beb
osutil: implement minimal __getitem__ compatibility on our custom listdir type
Augie Fackler <augie@google.com>
parents:
36620
diff
changeset
|
128 if (index == -1 && PyErr_Occurred()) { |
f3c314020beb
osutil: implement minimal __getitem__ compatibility on our custom listdir type
Augie Fackler <augie@google.com>
parents:
36620
diff
changeset
|
129 return NULL; |
f3c314020beb
osutil: implement minimal __getitem__ compatibility on our custom listdir type
Augie Fackler <augie@google.com>
parents:
36620
diff
changeset
|
130 } |
f3c314020beb
osutil: implement minimal __getitem__ compatibility on our custom listdir type
Augie Fackler <augie@google.com>
parents:
36620
diff
changeset
|
131 if (index != 8) { |
f3c314020beb
osutil: implement minimal __getitem__ compatibility on our custom listdir type
Augie Fackler <augie@google.com>
parents:
36620
diff
changeset
|
132 PyErr_Format(PyExc_IndexError, "osutil.stat objects only " |
f3c314020beb
osutil: implement minimal __getitem__ compatibility on our custom listdir type
Augie Fackler <augie@google.com>
parents:
36620
diff
changeset
|
133 "support stat.ST_MTIME in " |
f3c314020beb
osutil: implement minimal __getitem__ compatibility on our custom listdir type
Augie Fackler <augie@google.com>
parents:
36620
diff
changeset
|
134 "__getitem__"); |
f3c314020beb
osutil: implement minimal __getitem__ compatibility on our custom listdir type
Augie Fackler <augie@google.com>
parents:
36620
diff
changeset
|
135 return NULL; |
f3c314020beb
osutil: implement minimal __getitem__ compatibility on our custom listdir type
Augie Fackler <augie@google.com>
parents:
36620
diff
changeset
|
136 } |
f3c314020beb
osutil: implement minimal __getitem__ compatibility on our custom listdir type
Augie Fackler <augie@google.com>
parents:
36620
diff
changeset
|
137 return listdir_stat_st_mtime(self, NULL); |
f3c314020beb
osutil: implement minimal __getitem__ compatibility on our custom listdir type
Augie Fackler <augie@google.com>
parents:
36620
diff
changeset
|
138 } |
f3c314020beb
osutil: implement minimal __getitem__ compatibility on our custom listdir type
Augie Fackler <augie@google.com>
parents:
36620
diff
changeset
|
139 |
f3c314020beb
osutil: implement minimal __getitem__ compatibility on our custom listdir type
Augie Fackler <augie@google.com>
parents:
36620
diff
changeset
|
140 static PyMappingMethods listdir_stat_type_mapping_methods = { |
f3c314020beb
osutil: implement minimal __getitem__ compatibility on our custom listdir type
Augie Fackler <augie@google.com>
parents:
36620
diff
changeset
|
141 (lenfunc)NULL, /* mp_length */ |
f3c314020beb
osutil: implement minimal __getitem__ compatibility on our custom listdir type
Augie Fackler <augie@google.com>
parents:
36620
diff
changeset
|
142 (binaryfunc)listdir_stat_getitem, /* mp_subscript */ |
f3c314020beb
osutil: implement minimal __getitem__ compatibility on our custom listdir type
Augie Fackler <augie@google.com>
parents:
36620
diff
changeset
|
143 (objobjargproc)NULL, /* mp_ass_subscript */ |
f3c314020beb
osutil: implement minimal __getitem__ compatibility on our custom listdir type
Augie Fackler <augie@google.com>
parents:
36620
diff
changeset
|
144 }; |
f3c314020beb
osutil: implement minimal __getitem__ compatibility on our custom listdir type
Augie Fackler <augie@google.com>
parents:
36620
diff
changeset
|
145 |
5396
5105b119edd2
Add osutil module, containing a listdir function.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
146 static PyTypeObject listdir_stat_type = { |
34861
6ece4a85c350
cext: add /* header */ comment to all PyVarObject_HEAD_INIT() calls
Augie Fackler <augie@google.com>
parents:
34438
diff
changeset
|
147 PyVarObject_HEAD_INIT(NULL, 0) /* header */ |
5421 | 148 "osutil.stat", /*tp_name*/ |
149 sizeof(struct listdir_stat), /*tp_basicsize*/ | |
150 0, /*tp_itemsize*/ | |
151 (destructor)listdir_stat_dealloc, /*tp_dealloc*/ | |
152 0, /*tp_print*/ | |
153 0, /*tp_getattr*/ | |
154 0, /*tp_setattr*/ | |
155 0, /*tp_compare*/ | |
156 0, /*tp_repr*/ | |
157 0, /*tp_as_number*/ | |
158 0, /*tp_as_sequence*/ | |
36780
f3c314020beb
osutil: implement minimal __getitem__ compatibility on our custom listdir type
Augie Fackler <augie@google.com>
parents:
36620
diff
changeset
|
159 &listdir_stat_type_mapping_methods, /*tp_as_mapping*/ |
5421 | 160 0, /*tp_hash */ |
161 0, /*tp_call*/ | |
162 0, /*tp_str*/ | |
163 0, /*tp_getattro*/ | |
164 0, /*tp_setattro*/ | |
165 0, /*tp_as_buffer*/ | |
166 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ | |
167 "stat objects", /* tp_doc */ | |
168 0, /* tp_traverse */ | |
169 0, /* tp_clear */ | |
170 0, /* tp_richcompare */ | |
171 0, /* tp_weaklistoffset */ | |
172 0, /* tp_iter */ | |
173 0, /* tp_iternext */ | |
174 0, /* tp_methods */ | |
175 0, /* tp_members */ | |
176 listdir_stat_getsets, /* tp_getset */ | |
177 0, /* tp_base */ | |
178 0, /* tp_dict */ | |
179 0, /* tp_descr_get */ | |
180 0, /* tp_descr_set */ | |
181 0, /* tp_dictoffset */ | |
182 0, /* tp_init */ | |
183 0, /* tp_alloc */ | |
184 listdir_stat_new, /* tp_new */ | |
5396
5105b119edd2
Add osutil module, containing a listdir function.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
185 }; |
5105b119edd2
Add osutil module, containing a listdir function.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
186 |
7056
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
187 #ifdef _WIN32 |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
188 |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
189 static int to_python_time(const FILETIME *tm) |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
190 { |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
191 /* number of seconds between epoch and January 1 1601 */ |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
192 const __int64 a0 = (__int64)134774L * (__int64)24L * (__int64)3600L; |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
193 /* conversion factor from 100ns to 1s */ |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
194 const __int64 a1 = 10000000; |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
195 /* explicit (int) cast to suspend compiler warnings */ |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
196 return (int)((((__int64)tm->dwHighDateTime << 32) |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
197 + tm->dwLowDateTime) / a1 - a0); |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
198 } |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
199 |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
200 static PyObject *make_item(const WIN32_FIND_DATAA *fd, int wantstat) |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
201 { |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
202 PyObject *py_st; |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
203 struct hg_stat *stp; |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
204 |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
205 int kind = (fd->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
206 ? _S_IFDIR : _S_IFREG; |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
207 |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
208 if (!wantstat) |
36619
1f8c3fadbb8e
py3: bulk-replace bytes format specifier passed to Py_BuildValue()
Yuya Nishihara <yuya@tcha.org>
parents:
35515
diff
changeset
|
209 return Py_BuildValue(PY23("si", "yi"), fd->cFileName, kind); |
7056
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
210 |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
211 py_st = PyObject_CallObject((PyObject *)&listdir_stat_type, NULL); |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
212 if (!py_st) |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
213 return NULL; |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
214 |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
215 stp = &((struct listdir_stat *)py_st)->st; |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
216 /* |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
217 use kind as st_mode |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
218 rwx bits on Win32 are meaningless |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
219 and Hg does not use them anyway |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
220 */ |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
221 stp->st_mode = kind; |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
222 stp->st_mtime = to_python_time(&fd->ftLastWriteTime); |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
223 stp->st_ctime = to_python_time(&fd->ftCreationTime); |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
224 if (kind == _S_IFREG) |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
9353
diff
changeset
|
225 stp->st_size = ((__int64)fd->nFileSizeHigh << 32) |
7056
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
226 + fd->nFileSizeLow; |
36619
1f8c3fadbb8e
py3: bulk-replace bytes format specifier passed to Py_BuildValue()
Yuya Nishihara <yuya@tcha.org>
parents:
35515
diff
changeset
|
227 return Py_BuildValue(PY23("siN", "yiN"), fd->cFileName, |
7056
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
228 kind, py_st); |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
229 } |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
230 |
42069
668eff08387f
cext: make osutil.c PY_SSIZE_T_CLEAN
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39610
diff
changeset
|
231 static PyObject *_listdir(char *path, Py_ssize_t plen, int wantstat, char *skip) |
7056
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
232 { |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
233 PyObject *rval = NULL; /* initialize - return value */ |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
234 PyObject *list; |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
235 HANDLE fh; |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
236 WIN32_FIND_DATAA fd; |
7098
8a5c88c7e97b
osutil.c: refactor argument parsing, allow skip=None being passed
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7059
diff
changeset
|
237 char *pattern; |
7056
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
238 |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
239 /* build the path + \* pattern string */ |
31468
b9dd03ed564f
osutil: use Python memory allocator in _listdir
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30409
diff
changeset
|
240 pattern = PyMem_Malloc(plen + 3); /* path + \* + \0 */ |
7056
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
241 if (!pattern) { |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
242 PyErr_NoMemory(); |
7098
8a5c88c7e97b
osutil.c: refactor argument parsing, allow skip=None being passed
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7059
diff
changeset
|
243 goto error_nomem; |
7056
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
244 } |
28593
e60c492a0d9b
osutil: stop using strcpy
Augie Fackler <augie@google.com>
parents:
27970
diff
changeset
|
245 memcpy(pattern, path, plen); |
7056
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
246 |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
247 if (plen > 0) { |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
248 char c = path[plen-1]; |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
249 if (c != ':' && c != '/' && c != '\\') |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
250 pattern[plen++] = '\\'; |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
251 } |
28593
e60c492a0d9b
osutil: stop using strcpy
Augie Fackler <augie@google.com>
parents:
27970
diff
changeset
|
252 pattern[plen++] = '*'; |
e60c492a0d9b
osutil: stop using strcpy
Augie Fackler <augie@google.com>
parents:
27970
diff
changeset
|
253 pattern[plen] = '\0'; |
7056
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
254 |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
255 fh = FindFirstFileA(pattern, &fd); |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
256 if (fh == INVALID_HANDLE_VALUE) { |
7059
6a76cf980999
Improve error handling in osutil.c
Petr Kodl <petrkodl@gmail.com>
parents:
7056
diff
changeset
|
257 PyErr_SetFromWindowsErrWithFilename(GetLastError(), path); |
7056
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
258 goto error_file; |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
259 } |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
260 |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
261 list = PyList_New(0); |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
262 if (!list) |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
263 goto error_list; |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
264 |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
265 do { |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
266 PyObject *item; |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
267 |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
268 if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
269 if (!strcmp(fd.cFileName, ".") |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
270 || !strcmp(fd.cFileName, "..")) |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
271 continue; |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
272 |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
273 if (skip && !strcmp(fd.cFileName, skip)) { |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
274 rval = PyList_New(0); |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
275 goto error; |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
276 } |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
277 } |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
278 |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
279 item = make_item(&fd, wantstat); |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
280 if (!item) |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
281 goto error; |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
282 |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
283 if (PyList_Append(list, item)) { |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
284 Py_XDECREF(item); |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
285 goto error; |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
286 } |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
287 |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
288 Py_XDECREF(item); |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
289 } while (FindNextFileA(fh, &fd)); |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
290 |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
291 if (GetLastError() != ERROR_NO_MORE_FILES) { |
7059
6a76cf980999
Improve error handling in osutil.c
Petr Kodl <petrkodl@gmail.com>
parents:
7056
diff
changeset
|
292 PyErr_SetFromWindowsErrWithFilename(GetLastError(), path); |
7056
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
293 goto error; |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
294 } |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
295 |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
296 rval = list; |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
297 Py_XINCREF(rval); |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
298 error: |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
299 Py_XDECREF(list); |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
300 error_list: |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
301 FindClose(fh); |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
302 error_file: |
31468
b9dd03ed564f
osutil: use Python memory allocator in _listdir
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30409
diff
changeset
|
303 PyMem_Free(pattern); |
7098
8a5c88c7e97b
osutil.c: refactor argument parsing, allow skip=None being passed
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7059
diff
changeset
|
304 error_nomem: |
7056
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
305 return rval; |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
306 } |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
307 |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
308 #else |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
309 |
7031
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
310 int entkind(struct dirent *ent) |
5425
830f6e280c90
osutils: pull file stat loop into its own function
Matt Mackall <mpm@selenic.com>
parents:
5424
diff
changeset
|
311 { |
7031
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
312 #ifdef DT_REG |
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
313 switch (ent->d_type) { |
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
314 case DT_REG: return S_IFREG; |
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
315 case DT_DIR: return S_IFDIR; |
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
316 case DT_LNK: return S_IFLNK; |
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
317 case DT_BLK: return S_IFBLK; |
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
318 case DT_CHR: return S_IFCHR; |
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
319 case DT_FIFO: return S_IFIFO; |
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
320 case DT_SOCK: return S_IFSOCK; |
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
321 } |
5463
3b204881f959
osutil: use fdopendir instead of dirfd
Bryan O'Sullivan <bos@serpentine.com>
parents:
5457
diff
changeset
|
322 #endif |
7033
892d27fb04a5
osutil: fix some braindamage
Matt Mackall <mpm@selenic.com>
parents:
7031
diff
changeset
|
323 return -1; |
5425
830f6e280c90
osutils: pull file stat loop into its own function
Matt Mackall <mpm@selenic.com>
parents:
5424
diff
changeset
|
324 } |
830f6e280c90
osutils: pull file stat loop into its own function
Matt Mackall <mpm@selenic.com>
parents:
5424
diff
changeset
|
325 |
18019
e248bff2d8dd
osutil: factor out creation and init of listdir_stat
Bryan O'Sullivan <bryano@fb.com>
parents:
16747
diff
changeset
|
326 static PyObject *makestat(const struct stat *st) |
e248bff2d8dd
osutil: factor out creation and init of listdir_stat
Bryan O'Sullivan <bryano@fb.com>
parents:
16747
diff
changeset
|
327 { |
18021 | 328 PyObject *stat; |
18019
e248bff2d8dd
osutil: factor out creation and init of listdir_stat
Bryan O'Sullivan <bryano@fb.com>
parents:
16747
diff
changeset
|
329 |
18021 | 330 stat = PyObject_CallObject((PyObject *)&listdir_stat_type, NULL); |
331 if (stat) | |
332 memcpy(&((struct listdir_stat *)stat)->st, st, sizeof(*st)); | |
333 return stat; | |
18019
e248bff2d8dd
osutil: factor out creation and init of listdir_stat
Bryan O'Sullivan <bryano@fb.com>
parents:
16747
diff
changeset
|
334 } |
e248bff2d8dd
osutil: factor out creation and init of listdir_stat
Bryan O'Sullivan <bryano@fb.com>
parents:
16747
diff
changeset
|
335 |
24460
73477e755cd2
osutil._listdir: rename to _listdir_stat
Siddharth Agarwal <sid0@fb.com>
parents:
23966
diff
changeset
|
336 static PyObject *_listdir_stat(char *path, int pathlen, int keepstat, |
73477e755cd2
osutil._listdir: rename to _listdir_stat
Siddharth Agarwal <sid0@fb.com>
parents:
23966
diff
changeset
|
337 char *skip) |
5396
5105b119edd2
Add osutil module, containing a listdir function.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
338 { |
23962
1f3b94e8dc40
osutil: fix leak of stat in makestat when Py_BuildValue fails
Augie Fackler <augie@google.com>
parents:
23961
diff
changeset
|
339 PyObject *list, *elem, *stat = NULL, *ret = NULL; |
7098
8a5c88c7e97b
osutil.c: refactor argument parsing, allow skip=None being passed
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7059
diff
changeset
|
340 char fullpath[PATH_MAX + 10]; |
7136
d834ed27199f
_listdir only uses dfd if AT_SYMLINK_NOFOLLOW is defined
Brendan Cully <brendan@kublai.com>
parents:
7098
diff
changeset
|
341 int kind, err; |
7031
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
342 struct stat st; |
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
343 struct dirent *ent; |
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
344 DIR *dir; |
7136
d834ed27199f
_listdir only uses dfd if AT_SYMLINK_NOFOLLOW is defined
Brendan Cully <brendan@kublai.com>
parents:
7098
diff
changeset
|
345 #ifdef AT_SYMLINK_NOFOLLOW |
d834ed27199f
_listdir only uses dfd if AT_SYMLINK_NOFOLLOW is defined
Brendan Cully <brendan@kublai.com>
parents:
7098
diff
changeset
|
346 int dfd = -1; |
d834ed27199f
_listdir only uses dfd if AT_SYMLINK_NOFOLLOW is defined
Brendan Cully <brendan@kublai.com>
parents:
7098
diff
changeset
|
347 #endif |
5396
5105b119edd2
Add osutil module, containing a listdir function.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
348 |
7059
6a76cf980999
Improve error handling in osutil.c
Petr Kodl <petrkodl@gmail.com>
parents:
7056
diff
changeset
|
349 if (pathlen >= PATH_MAX) { |
14873
f79d47813b8b
osutil: emulate os.listdir's OSError for long names (issue2898)
Matt Mackall <mpm@selenic.com>
parents:
13748
diff
changeset
|
350 errno = ENAMETOOLONG; |
f79d47813b8b
osutil: emulate os.listdir's OSError for long names (issue2898)
Matt Mackall <mpm@selenic.com>
parents:
13748
diff
changeset
|
351 PyErr_SetFromErrnoWithFilename(PyExc_OSError, path); |
7098
8a5c88c7e97b
osutil.c: refactor argument parsing, allow skip=None being passed
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7059
diff
changeset
|
352 goto error_value; |
7059
6a76cf980999
Improve error handling in osutil.c
Petr Kodl <petrkodl@gmail.com>
parents:
7056
diff
changeset
|
353 } |
7031
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
354 strncpy(fullpath, path, PATH_MAX); |
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
355 fullpath[pathlen] = '/'; |
5396
5105b119edd2
Add osutil module, containing a listdir function.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
356 |
7033
892d27fb04a5
osutil: fix some braindamage
Matt Mackall <mpm@selenic.com>
parents:
7031
diff
changeset
|
357 #ifdef AT_SYMLINK_NOFOLLOW |
892d27fb04a5
osutil: fix some braindamage
Matt Mackall <mpm@selenic.com>
parents:
7031
diff
changeset
|
358 dfd = open(path, O_RDONLY); |
892d27fb04a5
osutil: fix some braindamage
Matt Mackall <mpm@selenic.com>
parents:
7031
diff
changeset
|
359 if (dfd == -1) { |
892d27fb04a5
osutil: fix some braindamage
Matt Mackall <mpm@selenic.com>
parents:
7031
diff
changeset
|
360 PyErr_SetFromErrnoWithFilename(PyExc_OSError, path); |
7098
8a5c88c7e97b
osutil.c: refactor argument parsing, allow skip=None being passed
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7059
diff
changeset
|
361 goto error_value; |
7033
892d27fb04a5
osutil: fix some braindamage
Matt Mackall <mpm@selenic.com>
parents:
7031
diff
changeset
|
362 } |
892d27fb04a5
osutil: fix some braindamage
Matt Mackall <mpm@selenic.com>
parents:
7031
diff
changeset
|
363 dir = fdopendir(dfd); |
892d27fb04a5
osutil: fix some braindamage
Matt Mackall <mpm@selenic.com>
parents:
7031
diff
changeset
|
364 #else |
892d27fb04a5
osutil: fix some braindamage
Matt Mackall <mpm@selenic.com>
parents:
7031
diff
changeset
|
365 dir = opendir(path); |
892d27fb04a5
osutil: fix some braindamage
Matt Mackall <mpm@selenic.com>
parents:
7031
diff
changeset
|
366 #endif |
5421 | 367 if (!dir) { |
7031
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
368 PyErr_SetFromErrnoWithFilename(PyExc_OSError, path); |
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
369 goto error_dir; |
23961
bc851e2851b1
osutil.c: clean up space before a tab
Augie Fackler <augie@google.com>
parents:
18027
diff
changeset
|
370 } |
5396
5105b119edd2
Add osutil module, containing a listdir function.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
371 |
5421 | 372 list = PyList_New(0); |
7031
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
373 if (!list) |
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
374 goto error_list; |
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
375 |
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
376 while ((ent = readdir(dir))) { |
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
377 if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, "..")) |
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
378 continue; |
5416
ca890c0c3f1f
osutil.c: style fix - delete trailing end-of-line spaces
Giorgos Keramidas <keramida@ceid.upatras.gr>
parents:
5398
diff
changeset
|
379 |
7031
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
380 kind = entkind(ent); |
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
381 if (kind == -1 || keepstat) { |
7033
892d27fb04a5
osutil: fix some braindamage
Matt Mackall <mpm@selenic.com>
parents:
7031
diff
changeset
|
382 #ifdef AT_SYMLINK_NOFOLLOW |
892d27fb04a5
osutil: fix some braindamage
Matt Mackall <mpm@selenic.com>
parents:
7031
diff
changeset
|
383 err = fstatat(dfd, ent->d_name, &st, |
892d27fb04a5
osutil: fix some braindamage
Matt Mackall <mpm@selenic.com>
parents:
7031
diff
changeset
|
384 AT_SYMLINK_NOFOLLOW); |
892d27fb04a5
osutil: fix some braindamage
Matt Mackall <mpm@selenic.com>
parents:
7031
diff
changeset
|
385 #else |
892d27fb04a5
osutil: fix some braindamage
Matt Mackall <mpm@selenic.com>
parents:
7031
diff
changeset
|
386 strncpy(fullpath + pathlen + 1, ent->d_name, |
892d27fb04a5
osutil: fix some braindamage
Matt Mackall <mpm@selenic.com>
parents:
7031
diff
changeset
|
387 PATH_MAX - pathlen); |
24462
40b05303ac32
osutil: mark end of string with null char, not 0
Siddharth Agarwal <sid0@fb.com>
parents:
24461
diff
changeset
|
388 fullpath[PATH_MAX] = '\0'; |
7033
892d27fb04a5
osutil: fix some braindamage
Matt Mackall <mpm@selenic.com>
parents:
7031
diff
changeset
|
389 err = lstat(fullpath, &st); |
892d27fb04a5
osutil: fix some braindamage
Matt Mackall <mpm@selenic.com>
parents:
7031
diff
changeset
|
390 #endif |
7031
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
391 if (err == -1) { |
16747
6476a21337a6
osutil: handle deletion race with readdir/stat (issue3463)
Matt Mackall <mpm@selenic.com>
parents:
15098
diff
changeset
|
392 /* race with file deletion? */ |
6476a21337a6
osutil: handle deletion race with readdir/stat (issue3463)
Matt Mackall <mpm@selenic.com>
parents:
15098
diff
changeset
|
393 if (errno == ENOENT) |
6476a21337a6
osutil: handle deletion race with readdir/stat (issue3463)
Matt Mackall <mpm@selenic.com>
parents:
15098
diff
changeset
|
394 continue; |
7031
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
395 strncpy(fullpath + pathlen + 1, ent->d_name, |
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
396 PATH_MAX - pathlen); |
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
397 fullpath[PATH_MAX] = 0; |
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
398 PyErr_SetFromErrnoWithFilename(PyExc_OSError, |
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
399 fullpath); |
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
400 goto error; |
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
401 } |
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
402 kind = st.st_mode & S_IFMT; |
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
403 } |
5396
5105b119edd2
Add osutil module, containing a listdir function.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
404 |
7034
0d513661d6c2
listdir: add support for aborting if a certain path is found
Matt Mackall <mpm@selenic.com>
parents:
7033
diff
changeset
|
405 /* quit early? */ |
0d513661d6c2
listdir: add support for aborting if a certain path is found
Matt Mackall <mpm@selenic.com>
parents:
7033
diff
changeset
|
406 if (skip && kind == S_IFDIR && !strcmp(ent->d_name, skip)) { |
0d513661d6c2
listdir: add support for aborting if a certain path is found
Matt Mackall <mpm@selenic.com>
parents:
7033
diff
changeset
|
407 ret = PyList_New(0); |
0d513661d6c2
listdir: add support for aborting if a certain path is found
Matt Mackall <mpm@selenic.com>
parents:
7033
diff
changeset
|
408 goto error; |
0d513661d6c2
listdir: add support for aborting if a certain path is found
Matt Mackall <mpm@selenic.com>
parents:
7033
diff
changeset
|
409 } |
0d513661d6c2
listdir: add support for aborting if a certain path is found
Matt Mackall <mpm@selenic.com>
parents:
7033
diff
changeset
|
410 |
7031
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
411 if (keepstat) { |
18019
e248bff2d8dd
osutil: factor out creation and init of listdir_stat
Bryan O'Sullivan <bryano@fb.com>
parents:
16747
diff
changeset
|
412 stat = makestat(&st); |
7031
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
413 if (!stat) |
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
414 goto error; |
36619
1f8c3fadbb8e
py3: bulk-replace bytes format specifier passed to Py_BuildValue()
Yuya Nishihara <yuya@tcha.org>
parents:
35515
diff
changeset
|
415 elem = Py_BuildValue(PY23("siN", "yiN"), ent->d_name, |
1f8c3fadbb8e
py3: bulk-replace bytes format specifier passed to Py_BuildValue()
Yuya Nishihara <yuya@tcha.org>
parents:
35515
diff
changeset
|
416 kind, stat); |
7031
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
417 } else |
36619
1f8c3fadbb8e
py3: bulk-replace bytes format specifier passed to Py_BuildValue()
Yuya Nishihara <yuya@tcha.org>
parents:
35515
diff
changeset
|
418 elem = Py_BuildValue(PY23("si", "yi"), ent->d_name, |
1f8c3fadbb8e
py3: bulk-replace bytes format specifier passed to Py_BuildValue()
Yuya Nishihara <yuya@tcha.org>
parents:
35515
diff
changeset
|
419 kind); |
7031
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
420 if (!elem) |
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
421 goto error; |
23962
1f3b94e8dc40
osutil: fix leak of stat in makestat when Py_BuildValue fails
Augie Fackler <augie@google.com>
parents:
23961
diff
changeset
|
422 stat = NULL; |
7031
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
423 |
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
424 PyList_Append(list, elem); |
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
425 Py_DECREF(elem); |
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
426 } |
5421 | 427 |
7031
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
428 ret = list; |
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
429 Py_INCREF(ret); |
5421 | 430 |
7031
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
431 error: |
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
432 Py_DECREF(list); |
23962
1f3b94e8dc40
osutil: fix leak of stat in makestat when Py_BuildValue fails
Augie Fackler <augie@google.com>
parents:
23961
diff
changeset
|
433 Py_XDECREF(stat); |
7031
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
434 error_list: |
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
435 closedir(dir); |
31471
95be8b7181d3
osutil: fix potential wrong fd close
Jun Wu <quark@fb.com>
parents:
31468
diff
changeset
|
436 /* closedir also closes its dirfd */ |
95be8b7181d3
osutil: fix potential wrong fd close
Jun Wu <quark@fb.com>
parents:
31468
diff
changeset
|
437 goto error_value; |
7031
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
438 error_dir: |
7033
892d27fb04a5
osutil: fix some braindamage
Matt Mackall <mpm@selenic.com>
parents:
7031
diff
changeset
|
439 #ifdef AT_SYMLINK_NOFOLLOW |
892d27fb04a5
osutil: fix some braindamage
Matt Mackall <mpm@selenic.com>
parents:
7031
diff
changeset
|
440 close(dfd); |
892d27fb04a5
osutil: fix some braindamage
Matt Mackall <mpm@selenic.com>
parents:
7031
diff
changeset
|
441 #endif |
7098
8a5c88c7e97b
osutil.c: refactor argument parsing, allow skip=None being passed
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7059
diff
changeset
|
442 error_value: |
7031
19e8d034932e
osutil: major listdir cleanup
Matt Mackall <mpm@selenic.com>
parents:
7022
diff
changeset
|
443 return ret; |
5421 | 444 } |
5396
5105b119edd2
Add osutil module, containing a listdir function.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
445 |
24461
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
446 #ifdef __APPLE__ |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
447 |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
448 typedef struct { |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
449 u_int32_t length; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
450 attrreference_t name; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
451 fsobj_type_t obj_type; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
452 struct timespec mtime; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
453 #if __LITTLE_ENDIAN__ |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
454 mode_t access_mask; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
455 uint16_t padding; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
456 #else |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
457 uint16_t padding; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
458 mode_t access_mask; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
459 #endif |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
460 off_t size; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
461 } __attribute__((packed)) attrbuf_entry; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
462 |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
463 int attrkind(attrbuf_entry *entry) |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
464 { |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
465 switch (entry->obj_type) { |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
466 case VREG: return S_IFREG; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
467 case VDIR: return S_IFDIR; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
468 case VLNK: return S_IFLNK; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
469 case VBLK: return S_IFBLK; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
470 case VCHR: return S_IFCHR; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
471 case VFIFO: return S_IFIFO; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
472 case VSOCK: return S_IFSOCK; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
473 } |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
474 return -1; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
475 } |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
476 |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
477 /* get these many entries at a time */ |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
478 #define LISTDIR_BATCH_SIZE 50 |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
479 |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
480 static PyObject *_listdir_batch(char *path, int pathlen, int keepstat, |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
481 char *skip, bool *fallback) |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
482 { |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
483 PyObject *list, *elem, *stat = NULL, *ret = NULL; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
484 int kind, err; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
485 unsigned long index; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
486 unsigned int count, old_state, new_state; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
487 bool state_seen = false; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
488 attrbuf_entry *entry; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
489 /* from the getattrlist(2) man page: a path can be no longer than |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
490 (NAME_MAX * 3 + 1) bytes. Also, "The getattrlist() function will |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
491 silently truncate attribute data if attrBufSize is too small." So |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
492 pass in a buffer big enough for the worst case. */ |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
493 char attrbuf[LISTDIR_BATCH_SIZE * (sizeof(attrbuf_entry) + NAME_MAX * 3 + 1)]; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
494 unsigned int basep_unused; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
495 |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
496 struct stat st; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
497 int dfd = -1; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
498 |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
499 /* these must match the attrbuf_entry struct, otherwise you'll end up |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
500 with garbage */ |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
501 struct attrlist requested_attr = {0}; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
502 requested_attr.bitmapcount = ATTR_BIT_MAP_COUNT; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
503 requested_attr.commonattr = (ATTR_CMN_NAME | ATTR_CMN_OBJTYPE | |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
504 ATTR_CMN_MODTIME | ATTR_CMN_ACCESSMASK); |
27877
f6d1e92fdf8c
mac: ignore resource fork when checking file sizes
Matt Mackall <mpm@selenic.com>
parents:
27473
diff
changeset
|
505 requested_attr.fileattr = ATTR_FILE_DATALENGTH; |
24461
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
506 |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
507 *fallback = false; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
508 |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
509 if (pathlen >= PATH_MAX) { |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
510 errno = ENAMETOOLONG; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
511 PyErr_SetFromErrnoWithFilename(PyExc_OSError, path); |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
512 goto error_value; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
513 } |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
514 |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
515 dfd = open(path, O_RDONLY); |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
516 if (dfd == -1) { |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
517 PyErr_SetFromErrnoWithFilename(PyExc_OSError, path); |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
518 goto error_value; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
519 } |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
520 |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
521 list = PyList_New(0); |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
522 if (!list) |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
523 goto error_dir; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
524 |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
525 do { |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
526 count = LISTDIR_BATCH_SIZE; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
527 err = getdirentriesattr(dfd, &requested_attr, &attrbuf, |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
528 sizeof(attrbuf), &count, &basep_unused, |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
529 &new_state, 0); |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
530 if (err < 0) { |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
531 if (errno == ENOTSUP) { |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
532 /* We're on a filesystem that doesn't support |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
533 getdirentriesattr. Fall back to the |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
534 stat-based implementation. */ |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
535 *fallback = true; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
536 } else |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
537 PyErr_SetFromErrnoWithFilename(PyExc_OSError, path); |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
538 goto error; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
539 } |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
540 |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
541 if (!state_seen) { |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
542 old_state = new_state; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
543 state_seen = true; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
544 } else if (old_state != new_state) { |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
545 /* There's an edge case with getdirentriesattr. Consider |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
546 the following initial list of files: |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
547 |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
548 a |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
549 b |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
550 <-- |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
551 c |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
552 d |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
553 |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
554 If the iteration is paused at the arrow, and b is |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
555 deleted before it is resumed, getdirentriesattr will |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
556 not return d at all! Ordinarily we're expected to |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
557 restart the iteration from the beginning. To avoid |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
558 getting stuck in a retry loop here, fall back to |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
559 stat. */ |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
560 *fallback = true; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
561 goto error; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
562 } |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
563 |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
564 entry = (attrbuf_entry *)attrbuf; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
565 |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
566 for (index = 0; index < count; index++) { |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
567 char *filename = ((char *)&entry->name) + |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
568 entry->name.attr_dataoffset; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
569 |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
570 if (!strcmp(filename, ".") || !strcmp(filename, "..")) |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
571 continue; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
572 |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
573 kind = attrkind(entry); |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
574 if (kind == -1) { |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
575 PyErr_Format(PyExc_OSError, |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
576 "unknown object type %u for file " |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
577 "%s%s!", |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
578 entry->obj_type, path, filename); |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
579 goto error; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
580 } |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
581 |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
582 /* quit early? */ |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
583 if (skip && kind == S_IFDIR && !strcmp(filename, skip)) { |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
584 ret = PyList_New(0); |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
585 goto error; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
586 } |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
587 |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
588 if (keepstat) { |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
589 /* from the getattrlist(2) man page: "Only the |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
590 permission bits ... are valid". */ |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
591 st.st_mode = (entry->access_mask & ~S_IFMT) | kind; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
592 st.st_mtime = entry->mtime.tv_sec; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
593 st.st_size = entry->size; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
594 stat = makestat(&st); |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
595 if (!stat) |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
596 goto error; |
36619
1f8c3fadbb8e
py3: bulk-replace bytes format specifier passed to Py_BuildValue()
Yuya Nishihara <yuya@tcha.org>
parents:
35515
diff
changeset
|
597 elem = Py_BuildValue(PY23("siN", "yiN"), |
1f8c3fadbb8e
py3: bulk-replace bytes format specifier passed to Py_BuildValue()
Yuya Nishihara <yuya@tcha.org>
parents:
35515
diff
changeset
|
598 filename, kind, stat); |
24461
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
599 } else |
36619
1f8c3fadbb8e
py3: bulk-replace bytes format specifier passed to Py_BuildValue()
Yuya Nishihara <yuya@tcha.org>
parents:
35515
diff
changeset
|
600 elem = Py_BuildValue(PY23("si", "yi"), |
1f8c3fadbb8e
py3: bulk-replace bytes format specifier passed to Py_BuildValue()
Yuya Nishihara <yuya@tcha.org>
parents:
35515
diff
changeset
|
601 filename, kind); |
24461
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
602 if (!elem) |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
603 goto error; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
604 stat = NULL; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
605 |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
606 PyList_Append(list, elem); |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
607 Py_DECREF(elem); |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
608 |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
609 entry = (attrbuf_entry *)((char *)entry + entry->length); |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
610 } |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
611 } while (err == 0); |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
612 |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
613 ret = list; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
614 Py_INCREF(ret); |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
615 |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
616 error: |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
617 Py_DECREF(list); |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
618 Py_XDECREF(stat); |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
619 error_dir: |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
620 close(dfd); |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
621 error_value: |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
622 return ret; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
623 } |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
624 |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
625 #endif /* __APPLE__ */ |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
626 |
24460
73477e755cd2
osutil._listdir: rename to _listdir_stat
Siddharth Agarwal <sid0@fb.com>
parents:
23966
diff
changeset
|
627 static PyObject *_listdir(char *path, int pathlen, int keepstat, char *skip) |
73477e755cd2
osutil._listdir: rename to _listdir_stat
Siddharth Agarwal <sid0@fb.com>
parents:
23966
diff
changeset
|
628 { |
24461
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
629 #ifdef __APPLE__ |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
630 PyObject *ret; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
631 bool fallback = false; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
632 |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
633 ret = _listdir_batch(path, pathlen, keepstat, skip, &fallback); |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
634 if (ret != NULL || !fallback) |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
635 return ret; |
05ccfe6763f1
osutil: use getdirentriesattr on OS X if possible
Siddharth Agarwal <sid0@fb.com>
parents:
24460
diff
changeset
|
636 #endif |
24460
73477e755cd2
osutil._listdir: rename to _listdir_stat
Siddharth Agarwal <sid0@fb.com>
parents:
23966
diff
changeset
|
637 return _listdir_stat(path, pathlen, keepstat, skip); |
73477e755cd2
osutil._listdir: rename to _listdir_stat
Siddharth Agarwal <sid0@fb.com>
parents:
23966
diff
changeset
|
638 } |
73477e755cd2
osutil._listdir: rename to _listdir_stat
Siddharth Agarwal <sid0@fb.com>
parents:
23966
diff
changeset
|
639 |
18026
ddc0323db78b
osutil: write a C implementation of statfiles for unix
Bryan O'Sullivan <bryano@fb.com>
parents:
18021
diff
changeset
|
640 static PyObject *statfiles(PyObject *self, PyObject *args) |
ddc0323db78b
osutil: write a C implementation of statfiles for unix
Bryan O'Sullivan <bryano@fb.com>
parents:
18021
diff
changeset
|
641 { |
18027
4ca434500dbf
osutil: tab damage, how i hate thee
Bryan O'Sullivan <bryano@fb.com>
parents:
18026
diff
changeset
|
642 PyObject *names, *stats; |
4ca434500dbf
osutil: tab damage, how i hate thee
Bryan O'Sullivan <bryano@fb.com>
parents:
18026
diff
changeset
|
643 Py_ssize_t i, count; |
18026
ddc0323db78b
osutil: write a C implementation of statfiles for unix
Bryan O'Sullivan <bryano@fb.com>
parents:
18021
diff
changeset
|
644 |
18027
4ca434500dbf
osutil: tab damage, how i hate thee
Bryan O'Sullivan <bryano@fb.com>
parents:
18026
diff
changeset
|
645 if (!PyArg_ParseTuple(args, "O:statfiles", &names)) |
4ca434500dbf
osutil: tab damage, how i hate thee
Bryan O'Sullivan <bryano@fb.com>
parents:
18026
diff
changeset
|
646 return NULL; |
18026
ddc0323db78b
osutil: write a C implementation of statfiles for unix
Bryan O'Sullivan <bryano@fb.com>
parents:
18021
diff
changeset
|
647 |
18027
4ca434500dbf
osutil: tab damage, how i hate thee
Bryan O'Sullivan <bryano@fb.com>
parents:
18026
diff
changeset
|
648 count = PySequence_Length(names); |
4ca434500dbf
osutil: tab damage, how i hate thee
Bryan O'Sullivan <bryano@fb.com>
parents:
18026
diff
changeset
|
649 if (count == -1) { |
4ca434500dbf
osutil: tab damage, how i hate thee
Bryan O'Sullivan <bryano@fb.com>
parents:
18026
diff
changeset
|
650 PyErr_SetString(PyExc_TypeError, "not a sequence"); |
4ca434500dbf
osutil: tab damage, how i hate thee
Bryan O'Sullivan <bryano@fb.com>
parents:
18026
diff
changeset
|
651 return NULL; |
4ca434500dbf
osutil: tab damage, how i hate thee
Bryan O'Sullivan <bryano@fb.com>
parents:
18026
diff
changeset
|
652 } |
18026
ddc0323db78b
osutil: write a C implementation of statfiles for unix
Bryan O'Sullivan <bryano@fb.com>
parents:
18021
diff
changeset
|
653 |
18027
4ca434500dbf
osutil: tab damage, how i hate thee
Bryan O'Sullivan <bryano@fb.com>
parents:
18026
diff
changeset
|
654 stats = PyList_New(count); |
4ca434500dbf
osutil: tab damage, how i hate thee
Bryan O'Sullivan <bryano@fb.com>
parents:
18026
diff
changeset
|
655 if (stats == NULL) |
4ca434500dbf
osutil: tab damage, how i hate thee
Bryan O'Sullivan <bryano@fb.com>
parents:
18026
diff
changeset
|
656 return NULL; |
18026
ddc0323db78b
osutil: write a C implementation of statfiles for unix
Bryan O'Sullivan <bryano@fb.com>
parents:
18021
diff
changeset
|
657 |
18027
4ca434500dbf
osutil: tab damage, how i hate thee
Bryan O'Sullivan <bryano@fb.com>
parents:
18026
diff
changeset
|
658 for (i = 0; i < count; i++) { |
23966
2d2c0a8eeeb8
osutil: fix memory leak of PyBytes of path in statfiles
Augie Fackler <augie@google.com>
parents:
23962
diff
changeset
|
659 PyObject *stat, *pypath; |
18027
4ca434500dbf
osutil: tab damage, how i hate thee
Bryan O'Sullivan <bryano@fb.com>
parents:
18026
diff
changeset
|
660 struct stat st; |
4ca434500dbf
osutil: tab damage, how i hate thee
Bryan O'Sullivan <bryano@fb.com>
parents:
18026
diff
changeset
|
661 int ret, kind; |
4ca434500dbf
osutil: tab damage, how i hate thee
Bryan O'Sullivan <bryano@fb.com>
parents:
18026
diff
changeset
|
662 char *path; |
18026
ddc0323db78b
osutil: write a C implementation of statfiles for unix
Bryan O'Sullivan <bryano@fb.com>
parents:
18021
diff
changeset
|
663 |
26983
f9f2f29ce023
osutil: make statfiles check for interrupts periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
26982
diff
changeset
|
664 /* With a large file count or on a slow filesystem, |
f9f2f29ce023
osutil: make statfiles check for interrupts periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
26982
diff
changeset
|
665 don't block signals for long (issue4878). */ |
f9f2f29ce023
osutil: make statfiles check for interrupts periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
26982
diff
changeset
|
666 if ((i % 1000) == 999 && PyErr_CheckSignals() == -1) |
f9f2f29ce023
osutil: make statfiles check for interrupts periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
26982
diff
changeset
|
667 goto bail; |
f9f2f29ce023
osutil: make statfiles check for interrupts periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
26982
diff
changeset
|
668 |
23966
2d2c0a8eeeb8
osutil: fix memory leak of PyBytes of path in statfiles
Augie Fackler <augie@google.com>
parents:
23962
diff
changeset
|
669 pypath = PySequence_GetItem(names, i); |
2d2c0a8eeeb8
osutil: fix memory leak of PyBytes of path in statfiles
Augie Fackler <augie@google.com>
parents:
23962
diff
changeset
|
670 if (!pypath) |
26982
fa6685ea7ad8
osutil: don't leak on statfiles error
Bryan O'Sullivan <bos@serpentine.com>
parents:
24462
diff
changeset
|
671 goto bail; |
30098
301ef65e8ebb
osutil: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28593
diff
changeset
|
672 path = PyBytes_AsString(pypath); |
18027
4ca434500dbf
osutil: tab damage, how i hate thee
Bryan O'Sullivan <bryano@fb.com>
parents:
18026
diff
changeset
|
673 if (path == NULL) { |
23966
2d2c0a8eeeb8
osutil: fix memory leak of PyBytes of path in statfiles
Augie Fackler <augie@google.com>
parents:
23962
diff
changeset
|
674 Py_DECREF(pypath); |
18027
4ca434500dbf
osutil: tab damage, how i hate thee
Bryan O'Sullivan <bryano@fb.com>
parents:
18026
diff
changeset
|
675 PyErr_SetString(PyExc_TypeError, "not a string"); |
4ca434500dbf
osutil: tab damage, how i hate thee
Bryan O'Sullivan <bryano@fb.com>
parents:
18026
diff
changeset
|
676 goto bail; |
4ca434500dbf
osutil: tab damage, how i hate thee
Bryan O'Sullivan <bryano@fb.com>
parents:
18026
diff
changeset
|
677 } |
4ca434500dbf
osutil: tab damage, how i hate thee
Bryan O'Sullivan <bryano@fb.com>
parents:
18026
diff
changeset
|
678 ret = lstat(path, &st); |
23966
2d2c0a8eeeb8
osutil: fix memory leak of PyBytes of path in statfiles
Augie Fackler <augie@google.com>
parents:
23962
diff
changeset
|
679 Py_DECREF(pypath); |
18027
4ca434500dbf
osutil: tab damage, how i hate thee
Bryan O'Sullivan <bryano@fb.com>
parents:
18026
diff
changeset
|
680 kind = st.st_mode & S_IFMT; |
4ca434500dbf
osutil: tab damage, how i hate thee
Bryan O'Sullivan <bryano@fb.com>
parents:
18026
diff
changeset
|
681 if (ret != -1 && (kind == S_IFREG || kind == S_IFLNK)) { |
4ca434500dbf
osutil: tab damage, how i hate thee
Bryan O'Sullivan <bryano@fb.com>
parents:
18026
diff
changeset
|
682 stat = makestat(&st); |
4ca434500dbf
osutil: tab damage, how i hate thee
Bryan O'Sullivan <bryano@fb.com>
parents:
18026
diff
changeset
|
683 if (stat == NULL) |
4ca434500dbf
osutil: tab damage, how i hate thee
Bryan O'Sullivan <bryano@fb.com>
parents:
18026
diff
changeset
|
684 goto bail; |
4ca434500dbf
osutil: tab damage, how i hate thee
Bryan O'Sullivan <bryano@fb.com>
parents:
18026
diff
changeset
|
685 PyList_SET_ITEM(stats, i, stat); |
4ca434500dbf
osutil: tab damage, how i hate thee
Bryan O'Sullivan <bryano@fb.com>
parents:
18026
diff
changeset
|
686 } else { |
4ca434500dbf
osutil: tab damage, how i hate thee
Bryan O'Sullivan <bryano@fb.com>
parents:
18026
diff
changeset
|
687 Py_INCREF(Py_None); |
4ca434500dbf
osutil: tab damage, how i hate thee
Bryan O'Sullivan <bryano@fb.com>
parents:
18026
diff
changeset
|
688 PyList_SET_ITEM(stats, i, Py_None); |
4ca434500dbf
osutil: tab damage, how i hate thee
Bryan O'Sullivan <bryano@fb.com>
parents:
18026
diff
changeset
|
689 } |
4ca434500dbf
osutil: tab damage, how i hate thee
Bryan O'Sullivan <bryano@fb.com>
parents:
18026
diff
changeset
|
690 } |
18026
ddc0323db78b
osutil: write a C implementation of statfiles for unix
Bryan O'Sullivan <bryano@fb.com>
parents:
18021
diff
changeset
|
691 |
18027
4ca434500dbf
osutil: tab damage, how i hate thee
Bryan O'Sullivan <bryano@fb.com>
parents:
18026
diff
changeset
|
692 return stats; |
18026
ddc0323db78b
osutil: write a C implementation of statfiles for unix
Bryan O'Sullivan <bryano@fb.com>
parents:
18021
diff
changeset
|
693 |
ddc0323db78b
osutil: write a C implementation of statfiles for unix
Bryan O'Sullivan <bryano@fb.com>
parents:
18021
diff
changeset
|
694 bail: |
18027
4ca434500dbf
osutil: tab damage, how i hate thee
Bryan O'Sullivan <bryano@fb.com>
parents:
18026
diff
changeset
|
695 Py_DECREF(stats); |
4ca434500dbf
osutil: tab damage, how i hate thee
Bryan O'Sullivan <bryano@fb.com>
parents:
18026
diff
changeset
|
696 return NULL; |
18026
ddc0323db78b
osutil: write a C implementation of statfiles for unix
Bryan O'Sullivan <bryano@fb.com>
parents:
18021
diff
changeset
|
697 } |
ddc0323db78b
osutil: write a C implementation of statfiles for unix
Bryan O'Sullivan <bryano@fb.com>
parents:
18021
diff
changeset
|
698 |
27473
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
699 /* |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
700 * recvfds() simply does not release GIL during blocking io operation because |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
701 * command server is known to be single-threaded. |
27970
3d23700cf4a9
osutil: disable compilation of recvfds() on unsupported platforms
Yuya Nishihara <yuya@tcha.org>
parents:
27877
diff
changeset
|
702 * |
3d23700cf4a9
osutil: disable compilation of recvfds() on unsupported platforms
Yuya Nishihara <yuya@tcha.org>
parents:
27877
diff
changeset
|
703 * Old systems such as Solaris don't provide CMSG_LEN, msg_control, etc. |
3d23700cf4a9
osutil: disable compilation of recvfds() on unsupported platforms
Yuya Nishihara <yuya@tcha.org>
parents:
27877
diff
changeset
|
704 * Currently, recvfds() is not supported on these platforms. |
27473
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
705 */ |
27970
3d23700cf4a9
osutil: disable compilation of recvfds() on unsupported platforms
Yuya Nishihara <yuya@tcha.org>
parents:
27877
diff
changeset
|
706 #ifdef CMSG_LEN |
27473
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
707 |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
708 static ssize_t recvfdstobuf(int sockfd, int **rfds, void *cbuf, size_t cbufsize) |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
709 { |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
710 char dummy[1]; |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
711 struct iovec iov = {dummy, sizeof(dummy)}; |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
712 struct msghdr msgh = {0}; |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
713 struct cmsghdr *cmsg; |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
714 |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
715 msgh.msg_iov = &iov; |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
716 msgh.msg_iovlen = 1; |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
717 msgh.msg_control = cbuf; |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
718 msgh.msg_controllen = (socklen_t)cbufsize; |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
719 if (recvmsg(sockfd, &msgh, 0) < 0) |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
720 return -1; |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
721 |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
722 for (cmsg = CMSG_FIRSTHDR(&msgh); cmsg; |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
723 cmsg = CMSG_NXTHDR(&msgh, cmsg)) { |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
724 if (cmsg->cmsg_level != SOL_SOCKET || |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
725 cmsg->cmsg_type != SCM_RIGHTS) |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
726 continue; |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
727 *rfds = (int *)CMSG_DATA(cmsg); |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
728 return (cmsg->cmsg_len - CMSG_LEN(0)) / sizeof(int); |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
729 } |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
730 |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
731 *rfds = cbuf; |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
732 return 0; |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
733 } |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
734 |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
735 static PyObject *recvfds(PyObject *self, PyObject *args) |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
736 { |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
737 int sockfd; |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
738 int *rfds = NULL; |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
739 ssize_t rfdscount, i; |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
740 char cbuf[256]; |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
741 PyObject *rfdslist = NULL; |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
742 |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
743 if (!PyArg_ParseTuple(args, "i", &sockfd)) |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
744 return NULL; |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
745 |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
746 rfdscount = recvfdstobuf(sockfd, &rfds, cbuf, sizeof(cbuf)); |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
747 if (rfdscount < 0) |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
748 return PyErr_SetFromErrno(PyExc_OSError); |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
749 |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
750 rfdslist = PyList_New(rfdscount); |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
751 if (!rfdslist) |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
752 goto bail; |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
753 for (i = 0; i < rfdscount; i++) { |
30110
79f438f5dd02
osutil: use PyLongObject in recvfds
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30098
diff
changeset
|
754 PyObject *obj = PyLong_FromLong(rfds[i]); |
27473
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
755 if (!obj) |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
756 goto bail; |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
757 PyList_SET_ITEM(rfdslist, i, obj); |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
758 } |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
759 return rfdslist; |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
760 |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
761 bail: |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
762 Py_XDECREF(rfdslist); |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
763 return NULL; |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
764 } |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
765 |
27970
3d23700cf4a9
osutil: disable compilation of recvfds() on unsupported platforms
Yuya Nishihara <yuya@tcha.org>
parents:
27877
diff
changeset
|
766 #endif /* CMSG_LEN */ |
30409
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
767 |
42961
460f8bf58020
osutil: allow disabling setprocname via a define passed to the compiler
Kyle Lippincott <spectral@google.com>
parents:
42069
diff
changeset
|
768 /* allow disabling setprocname via compiler flags */ |
460f8bf58020
osutil: allow disabling setprocname via a define passed to the compiler
Kyle Lippincott <spectral@google.com>
parents:
42069
diff
changeset
|
769 #ifndef SETPROCNAME_USE_NONE |
30409
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
770 #if defined(HAVE_SETPROCTITLE) |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
771 /* setproctitle is the first choice - available in FreeBSD */ |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
772 #define SETPROCNAME_USE_SETPROCTITLE |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
773 #elif (defined(__linux__) || defined(__APPLE__)) && PY_MAJOR_VERSION == 2 |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
774 /* rewrite the argv buffer in place - works in Linux and OS X. Py_GetArgcArgv |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
775 * in Python 3 returns the copied wchar_t **argv, thus unsupported. */ |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
776 #define SETPROCNAME_USE_ARGVREWRITE |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
777 #else |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
778 #define SETPROCNAME_USE_NONE |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
779 #endif |
42961
460f8bf58020
osutil: allow disabling setprocname via a define passed to the compiler
Kyle Lippincott <spectral@google.com>
parents:
42069
diff
changeset
|
780 #endif /* ndef SETPROCNAME_USE_NONE */ |
30409
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
781 |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
782 #ifndef SETPROCNAME_USE_NONE |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
783 static PyObject *setprocname(PyObject *self, PyObject *args) |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
784 { |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
785 const char *name = NULL; |
36620
186c6df3a373
py3: bulk-replace 'const char*' format specifier passed to PyArg_ParseTuple*()
Yuya Nishihara <yuya@tcha.org>
parents:
36619
diff
changeset
|
786 if (!PyArg_ParseTuple(args, PY23("s", "y"), &name)) |
30409
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
787 return NULL; |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
788 |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
789 #if defined(SETPROCNAME_USE_SETPROCTITLE) |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
790 setproctitle("%s", name); |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
791 #elif defined(SETPROCNAME_USE_ARGVREWRITE) |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
792 { |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
793 static char *argvstart = NULL; |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
794 static size_t argvsize = 0; |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
795 if (argvstart == NULL) { |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
796 int argc = 0, i; |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
797 char **argv = NULL; |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
798 char *argvend; |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
799 extern void Py_GetArgcArgv(int *argc, char ***argv); |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
800 Py_GetArgcArgv(&argc, &argv); |
42962
d6227c6c0814
osutil: tolerate Py_GetArgcArgv not being set up properly
Kyle Lippincott <spectral@google.com>
parents:
42961
diff
changeset
|
801 /* Py_GetArgcArgv may not do much if a custom python |
d6227c6c0814
osutil: tolerate Py_GetArgcArgv not being set up properly
Kyle Lippincott <spectral@google.com>
parents:
42961
diff
changeset
|
802 * launcher is used that doesn't record the information |
d6227c6c0814
osutil: tolerate Py_GetArgcArgv not being set up properly
Kyle Lippincott <spectral@google.com>
parents:
42961
diff
changeset
|
803 * it needs. Let's handle this gracefully instead of |
d6227c6c0814
osutil: tolerate Py_GetArgcArgv not being set up properly
Kyle Lippincott <spectral@google.com>
parents:
42961
diff
changeset
|
804 * segfaulting. */ |
d6227c6c0814
osutil: tolerate Py_GetArgcArgv not being set up properly
Kyle Lippincott <spectral@google.com>
parents:
42961
diff
changeset
|
805 if (argv != NULL) |
d6227c6c0814
osutil: tolerate Py_GetArgcArgv not being set up properly
Kyle Lippincott <spectral@google.com>
parents:
42961
diff
changeset
|
806 argvend = argvstart = argv[0]; |
d6227c6c0814
osutil: tolerate Py_GetArgcArgv not being set up properly
Kyle Lippincott <spectral@google.com>
parents:
42961
diff
changeset
|
807 else |
d6227c6c0814
osutil: tolerate Py_GetArgcArgv not being set up properly
Kyle Lippincott <spectral@google.com>
parents:
42961
diff
changeset
|
808 argvend = argvstart = NULL; |
30409
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
809 |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
810 /* Check the memory we can use. Typically, argv[i] and |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
811 * argv[i + 1] are continuous. */ |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
812 for (i = 0; i < argc; ++i) { |
44586
0424a9134bcf
osutil: move declaration to top of the scope
Yuya Nishihara <yuya@tcha.org>
parents:
42962
diff
changeset
|
813 size_t len; |
30409
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
814 if (argv[i] > argvend || argv[i] < argvstart) |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
815 break; /* not continuous */ |
44586
0424a9134bcf
osutil: move declaration to top of the scope
Yuya Nishihara <yuya@tcha.org>
parents:
42962
diff
changeset
|
816 len = strlen(argv[i]); |
30409
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
817 argvend = argv[i] + len + 1 /* '\0' */; |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
818 } |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
819 if (argvend > argvstart) /* sanity check */ |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
820 argvsize = argvend - argvstart; |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
821 } |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
822 |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
823 if (argvstart && argvsize > 1) { |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
824 int n = snprintf(argvstart, argvsize, "%s", name); |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
825 if (n >= 0 && (size_t)n < argvsize) |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
826 memset(argvstart + n, 0, argvsize - n); |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
827 } |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
828 } |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
829 #endif |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
830 |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
831 Py_RETURN_NONE; |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
832 } |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
833 #endif /* ndef SETPROCNAME_USE_NONE */ |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
834 |
31622
2243ba216f66
statfs: change Linux feature detection
Jun Wu <quark@fb.com>
parents:
31597
diff
changeset
|
835 #if defined(HAVE_BSD_STATFS) |
31676
f7aeb1f4b110
statfs: refactor inner function as a mapping from statfs to string
Yuya Nishihara <yuya@tcha.org>
parents:
31675
diff
changeset
|
836 static const char *describefstype(const struct statfs *pbuf) |
f7aeb1f4b110
statfs: refactor inner function as a mapping from statfs to string
Yuya Nishihara <yuya@tcha.org>
parents:
31675
diff
changeset
|
837 { |
31597
2d501fb60b2d
osutil: report fstype for BSD and OSX
Jun Wu <quark@fb.com>
parents:
31564
diff
changeset
|
838 /* BSD or OSX provides a f_fstypename field */ |
31623 | 839 return pbuf->f_fstypename; |
31676
f7aeb1f4b110
statfs: refactor inner function as a mapping from statfs to string
Yuya Nishihara <yuya@tcha.org>
parents:
31675
diff
changeset
|
840 } |
31622
2243ba216f66
statfs: change Linux feature detection
Jun Wu <quark@fb.com>
parents:
31597
diff
changeset
|
841 #elif defined(HAVE_LINUX_STATFS) |
31676
f7aeb1f4b110
statfs: refactor inner function as a mapping from statfs to string
Yuya Nishihara <yuya@tcha.org>
parents:
31675
diff
changeset
|
842 static const char *describefstype(const struct statfs *pbuf) |
f7aeb1f4b110
statfs: refactor inner function as a mapping from statfs to string
Yuya Nishihara <yuya@tcha.org>
parents:
31675
diff
changeset
|
843 { |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
844 /* Begin of Linux filesystems */ |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
845 #ifdef ADFS_SUPER_MAGIC |
31623 | 846 if (pbuf->f_type == ADFS_SUPER_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
847 return "adfs"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
848 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
849 #ifdef AFFS_SUPER_MAGIC |
31623 | 850 if (pbuf->f_type == AFFS_SUPER_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
851 return "affs"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
852 #endif |
31627
814733e4c02a
statfs: detect more filesystems on Linux
Jun Wu <quark@fb.com>
parents:
31623
diff
changeset
|
853 #ifdef AUTOFS_SUPER_MAGIC |
814733e4c02a
statfs: detect more filesystems on Linux
Jun Wu <quark@fb.com>
parents:
31623
diff
changeset
|
854 if (pbuf->f_type == AUTOFS_SUPER_MAGIC) |
814733e4c02a
statfs: detect more filesystems on Linux
Jun Wu <quark@fb.com>
parents:
31623
diff
changeset
|
855 return "autofs"; |
814733e4c02a
statfs: detect more filesystems on Linux
Jun Wu <quark@fb.com>
parents:
31623
diff
changeset
|
856 #endif |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
857 #ifdef BDEVFS_MAGIC |
31623 | 858 if (pbuf->f_type == BDEVFS_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
859 return "bdevfs"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
860 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
861 #ifdef BEFS_SUPER_MAGIC |
31623 | 862 if (pbuf->f_type == BEFS_SUPER_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
863 return "befs"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
864 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
865 #ifdef BFS_MAGIC |
31623 | 866 if (pbuf->f_type == BFS_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
867 return "bfs"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
868 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
869 #ifdef BINFMTFS_MAGIC |
31623 | 870 if (pbuf->f_type == BINFMTFS_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
871 return "binfmtfs"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
872 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
873 #ifdef BTRFS_SUPER_MAGIC |
31623 | 874 if (pbuf->f_type == BTRFS_SUPER_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
875 return "btrfs"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
876 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
877 #ifdef CGROUP_SUPER_MAGIC |
31623 | 878 if (pbuf->f_type == CGROUP_SUPER_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
879 return "cgroup"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
880 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
881 #ifdef CIFS_MAGIC_NUMBER |
31623 | 882 if (pbuf->f_type == CIFS_MAGIC_NUMBER) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
883 return "cifs"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
884 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
885 #ifdef CODA_SUPER_MAGIC |
31623 | 886 if (pbuf->f_type == CODA_SUPER_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
887 return "coda"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
888 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
889 #ifdef COH_SUPER_MAGIC |
31623 | 890 if (pbuf->f_type == COH_SUPER_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
891 return "coh"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
892 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
893 #ifdef CRAMFS_MAGIC |
31623 | 894 if (pbuf->f_type == CRAMFS_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
895 return "cramfs"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
896 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
897 #ifdef DEBUGFS_MAGIC |
31623 | 898 if (pbuf->f_type == DEBUGFS_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
899 return "debugfs"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
900 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
901 #ifdef DEVFS_SUPER_MAGIC |
31623 | 902 if (pbuf->f_type == DEVFS_SUPER_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
903 return "devfs"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
904 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
905 #ifdef DEVPTS_SUPER_MAGIC |
31623 | 906 if (pbuf->f_type == DEVPTS_SUPER_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
907 return "devpts"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
908 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
909 #ifdef EFIVARFS_MAGIC |
31623 | 910 if (pbuf->f_type == EFIVARFS_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
911 return "efivarfs"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
912 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
913 #ifdef EFS_SUPER_MAGIC |
31623 | 914 if (pbuf->f_type == EFS_SUPER_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
915 return "efs"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
916 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
917 #ifdef EXT_SUPER_MAGIC |
31623 | 918 if (pbuf->f_type == EXT_SUPER_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
919 return "ext"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
920 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
921 #ifdef EXT2_OLD_SUPER_MAGIC |
31623 | 922 if (pbuf->f_type == EXT2_OLD_SUPER_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
923 return "ext2"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
924 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
925 #ifdef EXT2_SUPER_MAGIC |
31623 | 926 if (pbuf->f_type == EXT2_SUPER_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
927 return "ext2"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
928 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
929 #ifdef EXT3_SUPER_MAGIC |
31623 | 930 if (pbuf->f_type == EXT3_SUPER_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
931 return "ext3"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
932 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
933 #ifdef EXT4_SUPER_MAGIC |
31623 | 934 if (pbuf->f_type == EXT4_SUPER_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
935 return "ext4"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
936 #endif |
31627
814733e4c02a
statfs: detect more filesystems on Linux
Jun Wu <quark@fb.com>
parents:
31623
diff
changeset
|
937 #ifdef F2FS_SUPER_MAGIC |
814733e4c02a
statfs: detect more filesystems on Linux
Jun Wu <quark@fb.com>
parents:
31623
diff
changeset
|
938 if (pbuf->f_type == F2FS_SUPER_MAGIC) |
814733e4c02a
statfs: detect more filesystems on Linux
Jun Wu <quark@fb.com>
parents:
31623
diff
changeset
|
939 return "f2fs"; |
814733e4c02a
statfs: detect more filesystems on Linux
Jun Wu <quark@fb.com>
parents:
31623
diff
changeset
|
940 #endif |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
941 #ifdef FUSE_SUPER_MAGIC |
31623 | 942 if (pbuf->f_type == FUSE_SUPER_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
943 return "fuse"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
944 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
945 #ifdef FUTEXFS_SUPER_MAGIC |
31623 | 946 if (pbuf->f_type == FUTEXFS_SUPER_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
947 return "futexfs"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
948 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
949 #ifdef HFS_SUPER_MAGIC |
31623 | 950 if (pbuf->f_type == HFS_SUPER_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
951 return "hfs"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
952 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
953 #ifdef HOSTFS_SUPER_MAGIC |
31623 | 954 if (pbuf->f_type == HOSTFS_SUPER_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
955 return "hostfs"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
956 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
957 #ifdef HPFS_SUPER_MAGIC |
31623 | 958 if (pbuf->f_type == HPFS_SUPER_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
959 return "hpfs"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
960 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
961 #ifdef HUGETLBFS_MAGIC |
31623 | 962 if (pbuf->f_type == HUGETLBFS_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
963 return "hugetlbfs"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
964 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
965 #ifdef ISOFS_SUPER_MAGIC |
31623 | 966 if (pbuf->f_type == ISOFS_SUPER_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
967 return "isofs"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
968 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
969 #ifdef JFFS2_SUPER_MAGIC |
31623 | 970 if (pbuf->f_type == JFFS2_SUPER_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
971 return "jffs2"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
972 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
973 #ifdef JFS_SUPER_MAGIC |
31623 | 974 if (pbuf->f_type == JFS_SUPER_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
975 return "jfs"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
976 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
977 #ifdef MINIX_SUPER_MAGIC |
31623 | 978 if (pbuf->f_type == MINIX_SUPER_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
979 return "minix"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
980 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
981 #ifdef MINIX2_SUPER_MAGIC |
31623 | 982 if (pbuf->f_type == MINIX2_SUPER_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
983 return "minix2"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
984 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
985 #ifdef MINIX3_SUPER_MAGIC |
31623 | 986 if (pbuf->f_type == MINIX3_SUPER_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
987 return "minix3"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
988 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
989 #ifdef MQUEUE_MAGIC |
31623 | 990 if (pbuf->f_type == MQUEUE_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
991 return "mqueue"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
992 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
993 #ifdef MSDOS_SUPER_MAGIC |
31623 | 994 if (pbuf->f_type == MSDOS_SUPER_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
995 return "msdos"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
996 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
997 #ifdef NCP_SUPER_MAGIC |
31623 | 998 if (pbuf->f_type == NCP_SUPER_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
999 return "ncp"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1000 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1001 #ifdef NFS_SUPER_MAGIC |
31623 | 1002 if (pbuf->f_type == NFS_SUPER_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1003 return "nfs"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1004 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1005 #ifdef NILFS_SUPER_MAGIC |
31623 | 1006 if (pbuf->f_type == NILFS_SUPER_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1007 return "nilfs"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1008 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1009 #ifdef NTFS_SB_MAGIC |
31623 | 1010 if (pbuf->f_type == NTFS_SB_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1011 return "ntfs-sb"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1012 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1013 #ifdef OCFS2_SUPER_MAGIC |
31623 | 1014 if (pbuf->f_type == OCFS2_SUPER_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1015 return "ocfs2"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1016 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1017 #ifdef OPENPROM_SUPER_MAGIC |
31623 | 1018 if (pbuf->f_type == OPENPROM_SUPER_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1019 return "openprom"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1020 #endif |
31627
814733e4c02a
statfs: detect more filesystems on Linux
Jun Wu <quark@fb.com>
parents:
31623
diff
changeset
|
1021 #ifdef OVERLAYFS_SUPER_MAGIC |
814733e4c02a
statfs: detect more filesystems on Linux
Jun Wu <quark@fb.com>
parents:
31623
diff
changeset
|
1022 if (pbuf->f_type == OVERLAYFS_SUPER_MAGIC) |
814733e4c02a
statfs: detect more filesystems on Linux
Jun Wu <quark@fb.com>
parents:
31623
diff
changeset
|
1023 return "overlay"; |
814733e4c02a
statfs: detect more filesystems on Linux
Jun Wu <quark@fb.com>
parents:
31623
diff
changeset
|
1024 #endif |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1025 #ifdef PIPEFS_MAGIC |
31623 | 1026 if (pbuf->f_type == PIPEFS_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1027 return "pipefs"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1028 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1029 #ifdef PROC_SUPER_MAGIC |
31623 | 1030 if (pbuf->f_type == PROC_SUPER_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1031 return "proc"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1032 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1033 #ifdef PSTOREFS_MAGIC |
31623 | 1034 if (pbuf->f_type == PSTOREFS_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1035 return "pstorefs"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1036 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1037 #ifdef QNX4_SUPER_MAGIC |
31623 | 1038 if (pbuf->f_type == QNX4_SUPER_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1039 return "qnx4"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1040 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1041 #ifdef QNX6_SUPER_MAGIC |
31623 | 1042 if (pbuf->f_type == QNX6_SUPER_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1043 return "qnx6"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1044 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1045 #ifdef RAMFS_MAGIC |
31623 | 1046 if (pbuf->f_type == RAMFS_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1047 return "ramfs"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1048 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1049 #ifdef REISERFS_SUPER_MAGIC |
31623 | 1050 if (pbuf->f_type == REISERFS_SUPER_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1051 return "reiserfs"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1052 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1053 #ifdef ROMFS_MAGIC |
31623 | 1054 if (pbuf->f_type == ROMFS_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1055 return "romfs"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1056 #endif |
31627
814733e4c02a
statfs: detect more filesystems on Linux
Jun Wu <quark@fb.com>
parents:
31623
diff
changeset
|
1057 #ifdef SECURITYFS_MAGIC |
814733e4c02a
statfs: detect more filesystems on Linux
Jun Wu <quark@fb.com>
parents:
31623
diff
changeset
|
1058 if (pbuf->f_type == SECURITYFS_MAGIC) |
814733e4c02a
statfs: detect more filesystems on Linux
Jun Wu <quark@fb.com>
parents:
31623
diff
changeset
|
1059 return "securityfs"; |
814733e4c02a
statfs: detect more filesystems on Linux
Jun Wu <quark@fb.com>
parents:
31623
diff
changeset
|
1060 #endif |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1061 #ifdef SELINUX_MAGIC |
31623 | 1062 if (pbuf->f_type == SELINUX_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1063 return "selinux"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1064 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1065 #ifdef SMACK_MAGIC |
31623 | 1066 if (pbuf->f_type == SMACK_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1067 return "smack"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1068 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1069 #ifdef SMB_SUPER_MAGIC |
31623 | 1070 if (pbuf->f_type == SMB_SUPER_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1071 return "smb"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1072 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1073 #ifdef SOCKFS_MAGIC |
31623 | 1074 if (pbuf->f_type == SOCKFS_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1075 return "sockfs"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1076 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1077 #ifdef SQUASHFS_MAGIC |
31623 | 1078 if (pbuf->f_type == SQUASHFS_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1079 return "squashfs"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1080 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1081 #ifdef SYSFS_MAGIC |
31623 | 1082 if (pbuf->f_type == SYSFS_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1083 return "sysfs"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1084 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1085 #ifdef SYSV2_SUPER_MAGIC |
31623 | 1086 if (pbuf->f_type == SYSV2_SUPER_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1087 return "sysv2"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1088 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1089 #ifdef SYSV4_SUPER_MAGIC |
31623 | 1090 if (pbuf->f_type == SYSV4_SUPER_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1091 return "sysv4"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1092 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1093 #ifdef TMPFS_MAGIC |
31623 | 1094 if (pbuf->f_type == TMPFS_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1095 return "tmpfs"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1096 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1097 #ifdef UDF_SUPER_MAGIC |
31623 | 1098 if (pbuf->f_type == UDF_SUPER_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1099 return "udf"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1100 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1101 #ifdef UFS_MAGIC |
31623 | 1102 if (pbuf->f_type == UFS_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1103 return "ufs"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1104 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1105 #ifdef USBDEVICE_SUPER_MAGIC |
31623 | 1106 if (pbuf->f_type == USBDEVICE_SUPER_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1107 return "usbdevice"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1108 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1109 #ifdef V9FS_MAGIC |
31623 | 1110 if (pbuf->f_type == V9FS_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1111 return "v9fs"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1112 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1113 #ifdef VXFS_SUPER_MAGIC |
31623 | 1114 if (pbuf->f_type == VXFS_SUPER_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1115 return "vxfs"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1116 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1117 #ifdef XENFS_SUPER_MAGIC |
31623 | 1118 if (pbuf->f_type == XENFS_SUPER_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1119 return "xenfs"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1120 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1121 #ifdef XENIX_SUPER_MAGIC |
31623 | 1122 if (pbuf->f_type == XENIX_SUPER_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1123 return "xenix"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1124 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1125 #ifdef XFS_SUPER_MAGIC |
31623 | 1126 if (pbuf->f_type == XFS_SUPER_MAGIC) |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1127 return "xfs"; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1128 #endif |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1129 /* End of Linux filesystems */ |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1130 return NULL; |
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1131 } |
31676
f7aeb1f4b110
statfs: refactor inner function as a mapping from statfs to string
Yuya Nishihara <yuya@tcha.org>
parents:
31675
diff
changeset
|
1132 #endif /* def HAVE_LINUX_STATFS */ |
31564
102f291807c9
osutil: export a "getfstype" method
Jun Wu <quark@fb.com>
parents:
31563
diff
changeset
|
1133 |
31676
f7aeb1f4b110
statfs: refactor inner function as a mapping from statfs to string
Yuya Nishihara <yuya@tcha.org>
parents:
31675
diff
changeset
|
1134 #if defined(HAVE_BSD_STATFS) || defined(HAVE_LINUX_STATFS) |
f7aeb1f4b110
statfs: refactor inner function as a mapping from statfs to string
Yuya Nishihara <yuya@tcha.org>
parents:
31675
diff
changeset
|
1135 /* given a directory path, return filesystem type name (best-effort) */ |
31677
58d4622bc1ef
statfs: rename pygetfstype to getfstype
Yuya Nishihara <yuya@tcha.org>
parents:
31676
diff
changeset
|
1136 static PyObject *getfstype(PyObject *self, PyObject *args) |
31564
102f291807c9
osutil: export a "getfstype" method
Jun Wu <quark@fb.com>
parents:
31563
diff
changeset
|
1137 { |
102f291807c9
osutil: export a "getfstype" method
Jun Wu <quark@fb.com>
parents:
31563
diff
changeset
|
1138 const char *path = NULL; |
31623 | 1139 struct statfs buf; |
31676
f7aeb1f4b110
statfs: refactor inner function as a mapping from statfs to string
Yuya Nishihara <yuya@tcha.org>
parents:
31675
diff
changeset
|
1140 int r; |
36620
186c6df3a373
py3: bulk-replace 'const char*' format specifier passed to PyArg_ParseTuple*()
Yuya Nishihara <yuya@tcha.org>
parents:
36619
diff
changeset
|
1141 if (!PyArg_ParseTuple(args, PY23("s", "y"), &path)) |
31564
102f291807c9
osutil: export a "getfstype" method
Jun Wu <quark@fb.com>
parents:
31563
diff
changeset
|
1142 return NULL; |
102f291807c9
osutil: export a "getfstype" method
Jun Wu <quark@fb.com>
parents:
31563
diff
changeset
|
1143 |
31623 | 1144 memset(&buf, 0, sizeof(buf)); |
31676
f7aeb1f4b110
statfs: refactor inner function as a mapping from statfs to string
Yuya Nishihara <yuya@tcha.org>
parents:
31675
diff
changeset
|
1145 r = statfs(path, &buf); |
f7aeb1f4b110
statfs: refactor inner function as a mapping from statfs to string
Yuya Nishihara <yuya@tcha.org>
parents:
31675
diff
changeset
|
1146 if (r != 0) |
31678
1ed57a7dd904
statfs: make getfstype() raise OSError
Yuya Nishihara <yuya@tcha.org>
parents:
31677
diff
changeset
|
1147 return PyErr_SetFromErrno(PyExc_OSError); |
36619
1f8c3fadbb8e
py3: bulk-replace bytes format specifier passed to Py_BuildValue()
Yuya Nishihara <yuya@tcha.org>
parents:
35515
diff
changeset
|
1148 return Py_BuildValue(PY23("s", "y"), describefstype(&buf)); |
31564
102f291807c9
osutil: export a "getfstype" method
Jun Wu <quark@fb.com>
parents:
31563
diff
changeset
|
1149 } |
31622
2243ba216f66
statfs: change Linux feature detection
Jun Wu <quark@fb.com>
parents:
31597
diff
changeset
|
1150 #endif /* defined(HAVE_LINUX_STATFS) || defined(HAVE_BSD_STATFS) */ |
31563
cc3ec3027695
osutil: add a C function getting filesystem type
Jun Wu <quark@fb.com>
parents:
31471
diff
changeset
|
1151 |
35515
e01549a7bf0a
osutil: implement getfsmountpoint() on BSD systems
Matt Harbison <matt_harbison@yahoo.com>
parents:
35460
diff
changeset
|
1152 #if defined(HAVE_BSD_STATFS) |
e01549a7bf0a
osutil: implement getfsmountpoint() on BSD systems
Matt Harbison <matt_harbison@yahoo.com>
parents:
35460
diff
changeset
|
1153 /* given a directory path, return filesystem mount point (best-effort) */ |
e01549a7bf0a
osutil: implement getfsmountpoint() on BSD systems
Matt Harbison <matt_harbison@yahoo.com>
parents:
35460
diff
changeset
|
1154 static PyObject *getfsmountpoint(PyObject *self, PyObject *args) |
e01549a7bf0a
osutil: implement getfsmountpoint() on BSD systems
Matt Harbison <matt_harbison@yahoo.com>
parents:
35460
diff
changeset
|
1155 { |
e01549a7bf0a
osutil: implement getfsmountpoint() on BSD systems
Matt Harbison <matt_harbison@yahoo.com>
parents:
35460
diff
changeset
|
1156 const char *path = NULL; |
e01549a7bf0a
osutil: implement getfsmountpoint() on BSD systems
Matt Harbison <matt_harbison@yahoo.com>
parents:
35460
diff
changeset
|
1157 struct statfs buf; |
e01549a7bf0a
osutil: implement getfsmountpoint() on BSD systems
Matt Harbison <matt_harbison@yahoo.com>
parents:
35460
diff
changeset
|
1158 int r; |
36620
186c6df3a373
py3: bulk-replace 'const char*' format specifier passed to PyArg_ParseTuple*()
Yuya Nishihara <yuya@tcha.org>
parents:
36619
diff
changeset
|
1159 if (!PyArg_ParseTuple(args, PY23("s", "y"), &path)) |
35515
e01549a7bf0a
osutil: implement getfsmountpoint() on BSD systems
Matt Harbison <matt_harbison@yahoo.com>
parents:
35460
diff
changeset
|
1160 return NULL; |
e01549a7bf0a
osutil: implement getfsmountpoint() on BSD systems
Matt Harbison <matt_harbison@yahoo.com>
parents:
35460
diff
changeset
|
1161 |
e01549a7bf0a
osutil: implement getfsmountpoint() on BSD systems
Matt Harbison <matt_harbison@yahoo.com>
parents:
35460
diff
changeset
|
1162 memset(&buf, 0, sizeof(buf)); |
e01549a7bf0a
osutil: implement getfsmountpoint() on BSD systems
Matt Harbison <matt_harbison@yahoo.com>
parents:
35460
diff
changeset
|
1163 r = statfs(path, &buf); |
e01549a7bf0a
osutil: implement getfsmountpoint() on BSD systems
Matt Harbison <matt_harbison@yahoo.com>
parents:
35460
diff
changeset
|
1164 if (r != 0) |
e01549a7bf0a
osutil: implement getfsmountpoint() on BSD systems
Matt Harbison <matt_harbison@yahoo.com>
parents:
35460
diff
changeset
|
1165 return PyErr_SetFromErrno(PyExc_OSError); |
36619
1f8c3fadbb8e
py3: bulk-replace bytes format specifier passed to Py_BuildValue()
Yuya Nishihara <yuya@tcha.org>
parents:
35515
diff
changeset
|
1166 return Py_BuildValue(PY23("s", "y"), buf.f_mntonname); |
35515
e01549a7bf0a
osutil: implement getfsmountpoint() on BSD systems
Matt Harbison <matt_harbison@yahoo.com>
parents:
35460
diff
changeset
|
1167 } |
e01549a7bf0a
osutil: implement getfsmountpoint() on BSD systems
Matt Harbison <matt_harbison@yahoo.com>
parents:
35460
diff
changeset
|
1168 #endif /* defined(HAVE_BSD_STATFS) */ |
e01549a7bf0a
osutil: implement getfsmountpoint() on BSD systems
Matt Harbison <matt_harbison@yahoo.com>
parents:
35460
diff
changeset
|
1169 |
35460
8652ab4046e4
osutil: add a function to unblock signals
Jun Wu <quark@fb.com>
parents:
34861
diff
changeset
|
1170 static PyObject *unblocksignal(PyObject *self, PyObject *args) |
8652ab4046e4
osutil: add a function to unblock signals
Jun Wu <quark@fb.com>
parents:
34861
diff
changeset
|
1171 { |
8652ab4046e4
osutil: add a function to unblock signals
Jun Wu <quark@fb.com>
parents:
34861
diff
changeset
|
1172 int sig = 0; |
44586
0424a9134bcf
osutil: move declaration to top of the scope
Yuya Nishihara <yuya@tcha.org>
parents:
42962
diff
changeset
|
1173 sigset_t set; |
35460
8652ab4046e4
osutil: add a function to unblock signals
Jun Wu <quark@fb.com>
parents:
34861
diff
changeset
|
1174 int r; |
8652ab4046e4
osutil: add a function to unblock signals
Jun Wu <quark@fb.com>
parents:
34861
diff
changeset
|
1175 if (!PyArg_ParseTuple(args, "i", &sig)) |
8652ab4046e4
osutil: add a function to unblock signals
Jun Wu <quark@fb.com>
parents:
34861
diff
changeset
|
1176 return NULL; |
8652ab4046e4
osutil: add a function to unblock signals
Jun Wu <quark@fb.com>
parents:
34861
diff
changeset
|
1177 r = sigemptyset(&set); |
8652ab4046e4
osutil: add a function to unblock signals
Jun Wu <quark@fb.com>
parents:
34861
diff
changeset
|
1178 if (r != 0) |
8652ab4046e4
osutil: add a function to unblock signals
Jun Wu <quark@fb.com>
parents:
34861
diff
changeset
|
1179 return PyErr_SetFromErrno(PyExc_OSError); |
8652ab4046e4
osutil: add a function to unblock signals
Jun Wu <quark@fb.com>
parents:
34861
diff
changeset
|
1180 r = sigaddset(&set, sig); |
8652ab4046e4
osutil: add a function to unblock signals
Jun Wu <quark@fb.com>
parents:
34861
diff
changeset
|
1181 if (r != 0) |
8652ab4046e4
osutil: add a function to unblock signals
Jun Wu <quark@fb.com>
parents:
34861
diff
changeset
|
1182 return PyErr_SetFromErrno(PyExc_OSError); |
8652ab4046e4
osutil: add a function to unblock signals
Jun Wu <quark@fb.com>
parents:
34861
diff
changeset
|
1183 r = sigprocmask(SIG_UNBLOCK, &set, NULL); |
8652ab4046e4
osutil: add a function to unblock signals
Jun Wu <quark@fb.com>
parents:
34861
diff
changeset
|
1184 if (r != 0) |
8652ab4046e4
osutil: add a function to unblock signals
Jun Wu <quark@fb.com>
parents:
34861
diff
changeset
|
1185 return PyErr_SetFromErrno(PyExc_OSError); |
8652ab4046e4
osutil: add a function to unblock signals
Jun Wu <quark@fb.com>
parents:
34861
diff
changeset
|
1186 Py_RETURN_NONE; |
8652ab4046e4
osutil: add a function to unblock signals
Jun Wu <quark@fb.com>
parents:
34861
diff
changeset
|
1187 } |
8652ab4046e4
osutil: add a function to unblock signals
Jun Wu <quark@fb.com>
parents:
34861
diff
changeset
|
1188 |
7056
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
1189 #endif /* ndef _WIN32 */ |
2c1f18b88b6a
osutil: implementation for Win32
Petr Kodl <petrkodl@gmail.com>
parents:
7034
diff
changeset
|
1190 |
7098
8a5c88c7e97b
osutil.c: refactor argument parsing, allow skip=None being passed
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7059
diff
changeset
|
1191 static PyObject *listdir(PyObject *self, PyObject *args, PyObject *kwargs) |
8a5c88c7e97b
osutil.c: refactor argument parsing, allow skip=None being passed
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7059
diff
changeset
|
1192 { |
8a5c88c7e97b
osutil.c: refactor argument parsing, allow skip=None being passed
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7059
diff
changeset
|
1193 PyObject *statobj = NULL; /* initialize - optional arg */ |
8a5c88c7e97b
osutil.c: refactor argument parsing, allow skip=None being passed
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7059
diff
changeset
|
1194 PyObject *skipobj = NULL; /* initialize - optional arg */ |
8a5c88c7e97b
osutil.c: refactor argument parsing, allow skip=None being passed
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7059
diff
changeset
|
1195 char *path, *skip = NULL; |
42069
668eff08387f
cext: make osutil.c PY_SSIZE_T_CLEAN
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39610
diff
changeset
|
1196 Py_ssize_t plen; |
668eff08387f
cext: make osutil.c PY_SSIZE_T_CLEAN
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39610
diff
changeset
|
1197 int wantstat; |
7098
8a5c88c7e97b
osutil.c: refactor argument parsing, allow skip=None being passed
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7059
diff
changeset
|
1198 |
8a5c88c7e97b
osutil.c: refactor argument parsing, allow skip=None being passed
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7059
diff
changeset
|
1199 static char *kwlist[] = {"path", "stat", "skip", NULL}; |
8a5c88c7e97b
osutil.c: refactor argument parsing, allow skip=None being passed
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7059
diff
changeset
|
1200 |
36620
186c6df3a373
py3: bulk-replace 'const char*' format specifier passed to PyArg_ParseTuple*()
Yuya Nishihara <yuya@tcha.org>
parents:
36619
diff
changeset
|
1201 if (!PyArg_ParseTupleAndKeywords(args, kwargs, PY23("s#|OO:listdir", |
186c6df3a373
py3: bulk-replace 'const char*' format specifier passed to PyArg_ParseTuple*()
Yuya Nishihara <yuya@tcha.org>
parents:
36619
diff
changeset
|
1202 "y#|OO:listdir"), |
7098
8a5c88c7e97b
osutil.c: refactor argument parsing, allow skip=None being passed
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7059
diff
changeset
|
1203 kwlist, &path, &plen, &statobj, &skipobj)) |
8a5c88c7e97b
osutil.c: refactor argument parsing, allow skip=None being passed
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7059
diff
changeset
|
1204 return NULL; |
8a5c88c7e97b
osutil.c: refactor argument parsing, allow skip=None being passed
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7059
diff
changeset
|
1205 |
8a5c88c7e97b
osutil.c: refactor argument parsing, allow skip=None being passed
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7059
diff
changeset
|
1206 wantstat = statobj && PyObject_IsTrue(statobj); |
8a5c88c7e97b
osutil.c: refactor argument parsing, allow skip=None being passed
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7059
diff
changeset
|
1207 |
8a5c88c7e97b
osutil.c: refactor argument parsing, allow skip=None being passed
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7059
diff
changeset
|
1208 if (skipobj && skipobj != Py_None) { |
11359
4eaacccbb2ca
osutil.c: Support for py3k added.
Renato Cunha <renatoc@gmail.com>
parents:
10282
diff
changeset
|
1209 skip = PyBytes_AsString(skipobj); |
7098
8a5c88c7e97b
osutil.c: refactor argument parsing, allow skip=None being passed
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7059
diff
changeset
|
1210 if (!skip) |
8a5c88c7e97b
osutil.c: refactor argument parsing, allow skip=None being passed
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7059
diff
changeset
|
1211 return NULL; |
8a5c88c7e97b
osutil.c: refactor argument parsing, allow skip=None being passed
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7059
diff
changeset
|
1212 } |
8a5c88c7e97b
osutil.c: refactor argument parsing, allow skip=None being passed
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7059
diff
changeset
|
1213 |
8a5c88c7e97b
osutil.c: refactor argument parsing, allow skip=None being passed
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7059
diff
changeset
|
1214 return _listdir(path, plen, wantstat, skip); |
8a5c88c7e97b
osutil.c: refactor argument parsing, allow skip=None being passed
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7059
diff
changeset
|
1215 } |
8a5c88c7e97b
osutil.c: refactor argument parsing, allow skip=None being passed
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7059
diff
changeset
|
1216 |
8330
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1217 #ifdef _WIN32 |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1218 static PyObject *posixfile(PyObject *self, PyObject *args, PyObject *kwds) |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1219 { |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1220 static char *kwlist[] = {"name", "mode", "buffering", NULL}; |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1221 PyObject *file_obj = NULL; |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1222 char *name = NULL; |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1223 char *mode = "rb"; |
8597
dc1b9e22f288
osutil: silence uninitialized variable warning
Patrick Mezard <pmezard@gmail.com>
parents:
8330
diff
changeset
|
1224 DWORD access = 0; |
8330
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1225 DWORD creation; |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1226 HANDLE handle; |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1227 int fd, flags = 0; |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1228 int bufsize = -1; |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1229 char m0, m1, m2; |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1230 char fpmode[4]; |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1231 int fppos = 0; |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1232 int plus; |
39610
11ed2eadf937
cext: fix warnings when building for py3 on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
36780
diff
changeset
|
1233 #ifndef IS_PY3K |
8330
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1234 FILE *fp; |
39610
11ed2eadf937
cext: fix warnings when building for py3 on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
36780
diff
changeset
|
1235 #endif |
8330
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1236 |
36620
186c6df3a373
py3: bulk-replace 'const char*' format specifier passed to PyArg_ParseTuple*()
Yuya Nishihara <yuya@tcha.org>
parents:
36619
diff
changeset
|
1237 if (!PyArg_ParseTupleAndKeywords(args, kwds, PY23("et|si:posixfile", |
186c6df3a373
py3: bulk-replace 'const char*' format specifier passed to PyArg_ParseTuple*()
Yuya Nishihara <yuya@tcha.org>
parents:
36619
diff
changeset
|
1238 "et|yi:posixfile"), |
186c6df3a373
py3: bulk-replace 'const char*' format specifier passed to PyArg_ParseTuple*()
Yuya Nishihara <yuya@tcha.org>
parents:
36619
diff
changeset
|
1239 kwlist, |
8330
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1240 Py_FileSystemDefaultEncoding, |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1241 &name, &mode, &bufsize)) |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1242 return NULL; |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1243 |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1244 m0 = mode[0]; |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1245 m1 = m0 ? mode[1] : '\0'; |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1246 m2 = m1 ? mode[2] : '\0'; |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1247 plus = m1 == '+' || m2 == '+'; |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1248 |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1249 fpmode[fppos++] = m0; |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1250 if (m1 == 'b' || m2 == 'b') { |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1251 flags = _O_BINARY; |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1252 fpmode[fppos++] = 'b'; |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1253 } |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1254 else |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1255 flags = _O_TEXT; |
13273
764441ecbf2e
osutil: treat open modes 'w' and 'a' as 'w+' and 'a+' in posixfile
Adrian Buehlmann <adrian@cadifra.com>
parents:
11359
diff
changeset
|
1256 if (m0 == 'r' && !plus) { |
764441ecbf2e
osutil: treat open modes 'w' and 'a' as 'w+' and 'a+' in posixfile
Adrian Buehlmann <adrian@cadifra.com>
parents:
11359
diff
changeset
|
1257 flags |= _O_RDONLY; |
764441ecbf2e
osutil: treat open modes 'w' and 'a' as 'w+' and 'a+' in posixfile
Adrian Buehlmann <adrian@cadifra.com>
parents:
11359
diff
changeset
|
1258 access = GENERIC_READ; |
764441ecbf2e
osutil: treat open modes 'w' and 'a' as 'w+' and 'a+' in posixfile
Adrian Buehlmann <adrian@cadifra.com>
parents:
11359
diff
changeset
|
1259 } else { |
764441ecbf2e
osutil: treat open modes 'w' and 'a' as 'w+' and 'a+' in posixfile
Adrian Buehlmann <adrian@cadifra.com>
parents:
11359
diff
changeset
|
1260 /* |
764441ecbf2e
osutil: treat open modes 'w' and 'a' as 'w+' and 'a+' in posixfile
Adrian Buehlmann <adrian@cadifra.com>
parents:
11359
diff
changeset
|
1261 work around http://support.microsoft.com/kb/899149 and |
764441ecbf2e
osutil: treat open modes 'w' and 'a' as 'w+' and 'a+' in posixfile
Adrian Buehlmann <adrian@cadifra.com>
parents:
11359
diff
changeset
|
1262 set _O_RDWR for 'w' and 'a', even if mode has no '+' |
764441ecbf2e
osutil: treat open modes 'w' and 'a' as 'w+' and 'a+' in posixfile
Adrian Buehlmann <adrian@cadifra.com>
parents:
11359
diff
changeset
|
1263 */ |
8330
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1264 flags |= _O_RDWR; |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1265 access = GENERIC_READ | GENERIC_WRITE; |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1266 fpmode[fppos++] = '+'; |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1267 } |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1268 fpmode[fppos++] = '\0'; |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1269 |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1270 switch (m0) { |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1271 case 'r': |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1272 creation = OPEN_EXISTING; |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1273 break; |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1274 case 'w': |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1275 creation = CREATE_ALWAYS; |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1276 break; |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1277 case 'a': |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1278 creation = OPEN_ALWAYS; |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1279 flags |= _O_APPEND; |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1280 break; |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1281 default: |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1282 PyErr_Format(PyExc_ValueError, |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1283 "mode string must begin with one of 'r', 'w', " |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1284 "or 'a', not '%c'", m0); |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1285 goto bail; |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1286 } |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1287 |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1288 handle = CreateFile(name, access, |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1289 FILE_SHARE_READ | FILE_SHARE_WRITE | |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1290 FILE_SHARE_DELETE, |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1291 NULL, |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1292 creation, |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1293 FILE_ATTRIBUTE_NORMAL, |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1294 0); |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1295 |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1296 if (handle == INVALID_HANDLE_VALUE) { |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1297 PyErr_SetFromWindowsErrWithFilename(GetLastError(), name); |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1298 goto bail; |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1299 } |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1300 |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
9353
diff
changeset
|
1301 fd = _open_osfhandle((intptr_t)handle, flags); |
11359
4eaacccbb2ca
osutil.c: Support for py3k added.
Renato Cunha <renatoc@gmail.com>
parents:
10282
diff
changeset
|
1302 |
8330
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1303 if (fd == -1) { |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1304 CloseHandle(handle); |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1305 PyErr_SetFromErrnoWithFilename(PyExc_IOError, name); |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1306 goto bail; |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1307 } |
11359
4eaacccbb2ca
osutil.c: Support for py3k added.
Renato Cunha <renatoc@gmail.com>
parents:
10282
diff
changeset
|
1308 #ifndef IS_PY3K |
8330
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1309 fp = _fdopen(fd, fpmode); |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1310 if (fp == NULL) { |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1311 _close(fd); |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1312 PyErr_SetFromErrnoWithFilename(PyExc_IOError, name); |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1313 goto bail; |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1314 } |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1315 |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1316 file_obj = PyFile_FromFile(fp, name, mode, fclose); |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1317 if (file_obj == NULL) { |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1318 fclose(fp); |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1319 goto bail; |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1320 } |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1321 |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1322 PyFile_SetBufSize(file_obj, bufsize); |
11359
4eaacccbb2ca
osutil.c: Support for py3k added.
Renato Cunha <renatoc@gmail.com>
parents:
10282
diff
changeset
|
1323 #else |
4eaacccbb2ca
osutil.c: Support for py3k added.
Renato Cunha <renatoc@gmail.com>
parents:
10282
diff
changeset
|
1324 file_obj = PyFile_FromFd(fd, name, mode, bufsize, NULL, NULL, NULL, 1); |
4eaacccbb2ca
osutil.c: Support for py3k added.
Renato Cunha <renatoc@gmail.com>
parents:
10282
diff
changeset
|
1325 if (file_obj == NULL) |
4eaacccbb2ca
osutil.c: Support for py3k added.
Renato Cunha <renatoc@gmail.com>
parents:
10282
diff
changeset
|
1326 goto bail; |
4eaacccbb2ca
osutil.c: Support for py3k added.
Renato Cunha <renatoc@gmail.com>
parents:
10282
diff
changeset
|
1327 #endif |
8330
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1328 bail: |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1329 PyMem_Free(name); |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1330 return file_obj; |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1331 } |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1332 #endif |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1333 |
13734
16118b4859a1
util: add Mac-specific check whether we're in a GUI session (issue2553)
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
13302
diff
changeset
|
1334 #ifdef __APPLE__ |
13748
26f8844d1757
osutil: replace #import with #include, and add a check for it
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
13736
diff
changeset
|
1335 #include <ApplicationServices/ApplicationServices.h> |
13734
16118b4859a1
util: add Mac-specific check whether we're in a GUI session (issue2553)
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
13302
diff
changeset
|
1336 |
16118b4859a1
util: add Mac-specific check whether we're in a GUI session (issue2553)
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
13302
diff
changeset
|
1337 static PyObject *isgui(PyObject *self) |
16118b4859a1
util: add Mac-specific check whether we're in a GUI session (issue2553)
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
13302
diff
changeset
|
1338 { |
13736
f3c4421e121c
osutil: fix up check-code issues
Matt Mackall <mpm@selenic.com>
parents:
13734
diff
changeset
|
1339 CFDictionaryRef dict = CGSessionCopyCurrentDictionary(); |
13734
16118b4859a1
util: add Mac-specific check whether we're in a GUI session (issue2553)
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
13302
diff
changeset
|
1340 |
13736
f3c4421e121c
osutil: fix up check-code issues
Matt Mackall <mpm@selenic.com>
parents:
13734
diff
changeset
|
1341 if (dict != NULL) { |
f3c4421e121c
osutil: fix up check-code issues
Matt Mackall <mpm@selenic.com>
parents:
13734
diff
changeset
|
1342 CFRelease(dict); |
15094
258eee414ab7
osutil: avoid accidentally destroying the True object in isgui (issue2937)
Steve Streeting <steve@stevestreeting.com>
parents:
13748
diff
changeset
|
1343 Py_RETURN_TRUE; |
13736
f3c4421e121c
osutil: fix up check-code issues
Matt Mackall <mpm@selenic.com>
parents:
13734
diff
changeset
|
1344 } else { |
15094
258eee414ab7
osutil: avoid accidentally destroying the True object in isgui (issue2937)
Steve Streeting <steve@stevestreeting.com>
parents:
13748
diff
changeset
|
1345 Py_RETURN_FALSE; |
13736
f3c4421e121c
osutil: fix up check-code issues
Matt Mackall <mpm@selenic.com>
parents:
13734
diff
changeset
|
1346 } |
13734
16118b4859a1
util: add Mac-specific check whether we're in a GUI session (issue2553)
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
13302
diff
changeset
|
1347 } |
16118b4859a1
util: add Mac-specific check whether we're in a GUI session (issue2553)
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
13302
diff
changeset
|
1348 #endif |
16118b4859a1
util: add Mac-specific check whether we're in a GUI session (issue2553)
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
13302
diff
changeset
|
1349 |
5396
5105b119edd2
Add osutil module, containing a listdir function.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
1350 static char osutil_doc[] = "Native operating system services."; |
5105b119edd2
Add osutil module, containing a listdir function.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
1351 |
5105b119edd2
Add osutil module, containing a listdir function.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
1352 static PyMethodDef methods[] = { |
5421 | 1353 {"listdir", (PyCFunction)listdir, METH_VARARGS | METH_KEYWORDS, |
1354 "list a directory\n"}, | |
8330
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1355 #ifdef _WIN32 |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1356 {"posixfile", (PyCFunction)posixfile, METH_VARARGS | METH_KEYWORDS, |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1357 "Open a file with POSIX-like semantics.\n" |
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1358 "On error, this function may raise either a WindowsError or an IOError."}, |
18026
ddc0323db78b
osutil: write a C implementation of statfiles for unix
Bryan O'Sullivan <bryano@fb.com>
parents:
18021
diff
changeset
|
1359 #else |
ddc0323db78b
osutil: write a C implementation of statfiles for unix
Bryan O'Sullivan <bryano@fb.com>
parents:
18021
diff
changeset
|
1360 {"statfiles", (PyCFunction)statfiles, METH_VARARGS | METH_KEYWORDS, |
ddc0323db78b
osutil: write a C implementation of statfiles for unix
Bryan O'Sullivan <bryano@fb.com>
parents:
18021
diff
changeset
|
1361 "stat a series of files or symlinks\n" |
ddc0323db78b
osutil: write a C implementation of statfiles for unix
Bryan O'Sullivan <bryano@fb.com>
parents:
18021
diff
changeset
|
1362 "Returns None for non-existent entries and entries of other types.\n"}, |
27970
3d23700cf4a9
osutil: disable compilation of recvfds() on unsupported platforms
Yuya Nishihara <yuya@tcha.org>
parents:
27877
diff
changeset
|
1363 #ifdef CMSG_LEN |
27473
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
1364 {"recvfds", (PyCFunction)recvfds, METH_VARARGS, |
34a37a2e03e6
osutil: implement recvmsg() of SCM_RIGHTS for chg command server
Yuya Nishihara <yuya@tcha.org>
parents:
26983
diff
changeset
|
1365 "receive list of file descriptors via socket\n"}, |
8330
7de68012f86e
Windows: improve performance via buffered I/O
Bryan O'Sullivan <bos@serpentine.com>
parents:
7190
diff
changeset
|
1366 #endif |
30409
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
1367 #ifndef SETPROCNAME_USE_NONE |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
1368 {"setprocname", (PyCFunction)setprocname, METH_VARARGS, |
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
1369 "set process title (best-effort)\n"}, |
27970
3d23700cf4a9
osutil: disable compilation of recvfds() on unsupported platforms
Yuya Nishihara <yuya@tcha.org>
parents:
27877
diff
changeset
|
1370 #endif |
31622
2243ba216f66
statfs: change Linux feature detection
Jun Wu <quark@fb.com>
parents:
31597
diff
changeset
|
1371 #if defined(HAVE_BSD_STATFS) || defined(HAVE_LINUX_STATFS) |
31677
58d4622bc1ef
statfs: rename pygetfstype to getfstype
Yuya Nishihara <yuya@tcha.org>
parents:
31676
diff
changeset
|
1372 {"getfstype", (PyCFunction)getfstype, METH_VARARGS, |
31564
102f291807c9
osutil: export a "getfstype" method
Jun Wu <quark@fb.com>
parents:
31563
diff
changeset
|
1373 "get filesystem type (best-effort)\n"}, |
102f291807c9
osutil: export a "getfstype" method
Jun Wu <quark@fb.com>
parents:
31563
diff
changeset
|
1374 #endif |
35515
e01549a7bf0a
osutil: implement getfsmountpoint() on BSD systems
Matt Harbison <matt_harbison@yahoo.com>
parents:
35460
diff
changeset
|
1375 #if defined(HAVE_BSD_STATFS) |
e01549a7bf0a
osutil: implement getfsmountpoint() on BSD systems
Matt Harbison <matt_harbison@yahoo.com>
parents:
35460
diff
changeset
|
1376 {"getfsmountpoint", (PyCFunction)getfsmountpoint, METH_VARARGS, |
e01549a7bf0a
osutil: implement getfsmountpoint() on BSD systems
Matt Harbison <matt_harbison@yahoo.com>
parents:
35460
diff
changeset
|
1377 "get filesystem mount point (best-effort)\n"}, |
e01549a7bf0a
osutil: implement getfsmountpoint() on BSD systems
Matt Harbison <matt_harbison@yahoo.com>
parents:
35460
diff
changeset
|
1378 #endif |
35460
8652ab4046e4
osutil: add a function to unblock signals
Jun Wu <quark@fb.com>
parents:
34861
diff
changeset
|
1379 {"unblocksignal", (PyCFunction)unblocksignal, METH_VARARGS, |
8652ab4046e4
osutil: add a function to unblock signals
Jun Wu <quark@fb.com>
parents:
34861
diff
changeset
|
1380 "change signal mask to unblock a given signal\n"}, |
30409
0852161588c6
osutil: implement setprocname to set process title for some platforms
Jun Wu <quark@fb.com>
parents:
30111
diff
changeset
|
1381 #endif /* ndef _WIN32 */ |
13734
16118b4859a1
util: add Mac-specific check whether we're in a GUI session (issue2553)
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
13302
diff
changeset
|
1382 #ifdef __APPLE__ |
13736
f3c4421e121c
osutil: fix up check-code issues
Matt Mackall <mpm@selenic.com>
parents:
13734
diff
changeset
|
1383 { |
f3c4421e121c
osutil: fix up check-code issues
Matt Mackall <mpm@selenic.com>
parents:
13734
diff
changeset
|
1384 "isgui", (PyCFunction)isgui, METH_NOARGS, |
f3c4421e121c
osutil: fix up check-code issues
Matt Mackall <mpm@selenic.com>
parents:
13734
diff
changeset
|
1385 "Is a CoreGraphics session available?" |
f3c4421e121c
osutil: fix up check-code issues
Matt Mackall <mpm@selenic.com>
parents:
13734
diff
changeset
|
1386 }, |
13734
16118b4859a1
util: add Mac-specific check whether we're in a GUI session (issue2553)
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
13302
diff
changeset
|
1387 #endif |
5421 | 1388 {NULL, NULL} |
5396
5105b119edd2
Add osutil module, containing a listdir function.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
1389 }; |
5105b119edd2
Add osutil module, containing a listdir function.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
1390 |
36780
f3c314020beb
osutil: implement minimal __getitem__ compatibility on our custom listdir type
Augie Fackler <augie@google.com>
parents:
36620
diff
changeset
|
1391 static const int version = 4; |
32359
dc51700be00c
osutil: add version to help detect breaking binary changes
Jun Wu <quark@fb.com>
parents:
31678
diff
changeset
|
1392 |
11359
4eaacccbb2ca
osutil.c: Support for py3k added.
Renato Cunha <renatoc@gmail.com>
parents:
10282
diff
changeset
|
1393 #ifdef IS_PY3K |
4eaacccbb2ca
osutil.c: Support for py3k added.
Renato Cunha <renatoc@gmail.com>
parents:
10282
diff
changeset
|
1394 static struct PyModuleDef osutil_module = { |
4eaacccbb2ca
osutil.c: Support for py3k added.
Renato Cunha <renatoc@gmail.com>
parents:
10282
diff
changeset
|
1395 PyModuleDef_HEAD_INIT, |
4eaacccbb2ca
osutil.c: Support for py3k added.
Renato Cunha <renatoc@gmail.com>
parents:
10282
diff
changeset
|
1396 "osutil", |
4eaacccbb2ca
osutil.c: Support for py3k added.
Renato Cunha <renatoc@gmail.com>
parents:
10282
diff
changeset
|
1397 osutil_doc, |
4eaacccbb2ca
osutil.c: Support for py3k added.
Renato Cunha <renatoc@gmail.com>
parents:
10282
diff
changeset
|
1398 -1, |
4eaacccbb2ca
osutil.c: Support for py3k added.
Renato Cunha <renatoc@gmail.com>
parents:
10282
diff
changeset
|
1399 methods |
4eaacccbb2ca
osutil.c: Support for py3k added.
Renato Cunha <renatoc@gmail.com>
parents:
10282
diff
changeset
|
1400 }; |
4eaacccbb2ca
osutil.c: Support for py3k added.
Renato Cunha <renatoc@gmail.com>
parents:
10282
diff
changeset
|
1401 |
4eaacccbb2ca
osutil.c: Support for py3k added.
Renato Cunha <renatoc@gmail.com>
parents:
10282
diff
changeset
|
1402 PyMODINIT_FUNC PyInit_osutil(void) |
4eaacccbb2ca
osutil.c: Support for py3k added.
Renato Cunha <renatoc@gmail.com>
parents:
10282
diff
changeset
|
1403 { |
32359
dc51700be00c
osutil: add version to help detect breaking binary changes
Jun Wu <quark@fb.com>
parents:
31678
diff
changeset
|
1404 PyObject *m; |
11359
4eaacccbb2ca
osutil.c: Support for py3k added.
Renato Cunha <renatoc@gmail.com>
parents:
10282
diff
changeset
|
1405 if (PyType_Ready(&listdir_stat_type) < 0) |
4eaacccbb2ca
osutil.c: Support for py3k added.
Renato Cunha <renatoc@gmail.com>
parents:
10282
diff
changeset
|
1406 return NULL; |
4eaacccbb2ca
osutil.c: Support for py3k added.
Renato Cunha <renatoc@gmail.com>
parents:
10282
diff
changeset
|
1407 |
32359
dc51700be00c
osutil: add version to help detect breaking binary changes
Jun Wu <quark@fb.com>
parents:
31678
diff
changeset
|
1408 m = PyModule_Create(&osutil_module); |
dc51700be00c
osutil: add version to help detect breaking binary changes
Jun Wu <quark@fb.com>
parents:
31678
diff
changeset
|
1409 PyModule_AddIntConstant(m, "version", version); |
dc51700be00c
osutil: add version to help detect breaking binary changes
Jun Wu <quark@fb.com>
parents:
31678
diff
changeset
|
1410 return m; |
11359
4eaacccbb2ca
osutil.c: Support for py3k added.
Renato Cunha <renatoc@gmail.com>
parents:
10282
diff
changeset
|
1411 } |
4eaacccbb2ca
osutil.c: Support for py3k added.
Renato Cunha <renatoc@gmail.com>
parents:
10282
diff
changeset
|
1412 #else |
5396
5105b119edd2
Add osutil module, containing a listdir function.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
1413 PyMODINIT_FUNC initosutil(void) |
5105b119edd2
Add osutil module, containing a listdir function.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
1414 { |
32359
dc51700be00c
osutil: add version to help detect breaking binary changes
Jun Wu <quark@fb.com>
parents:
31678
diff
changeset
|
1415 PyObject *m; |
5421 | 1416 if (PyType_Ready(&listdir_stat_type) == -1) |
1417 return; | |
5396
5105b119edd2
Add osutil module, containing a listdir function.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
1418 |
32359
dc51700be00c
osutil: add version to help detect breaking binary changes
Jun Wu <quark@fb.com>
parents:
31678
diff
changeset
|
1419 m = Py_InitModule3("osutil", methods, osutil_doc); |
dc51700be00c
osutil: add version to help detect breaking binary changes
Jun Wu <quark@fb.com>
parents:
31678
diff
changeset
|
1420 PyModule_AddIntConstant(m, "version", version); |
5396
5105b119edd2
Add osutil module, containing a listdir function.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
1421 } |
11359
4eaacccbb2ca
osutil.c: Support for py3k added.
Renato Cunha <renatoc@gmail.com>
parents:
10282
diff
changeset
|
1422 #endif |