1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
#!/usr/bin/python
# Exit 0 if "." has useful d_type information, else 1.
# Intended to exit 0 only on Linux/GNU systems.
import sys
fail = 1
try:
import ctypes
(DT_UNKNOWN, DT_DIR,) = (0, 4,)
class dirent(ctypes.Structure):
_fields_ = [
("d_ino", ctypes.c_long),
("d_off", ctypes.c_long),
("d_reclen", ctypes.c_ushort),
("d_type", ctypes.c_ubyte),
("d_name", ctypes.c_char*256)]
direntp = ctypes.POINTER(dirent)
# FIXME: find a way to avoid hard-coding libc's so-name.
libc = ctypes.cdll.LoadLibrary("libc.so.6")
libc.readdir.restype = direntp
dirp = libc.opendir(".")
if dirp:
ep = libc.readdir(dirp)
if ep:
name = ep.contents.d_name
if (name == "." or name == "..") and ep.contents.d_type == DT_DIR:
fail = 0
except:
pass
sys.exit(fail)
|