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