summaryrefslogtreecommitdiff
path: root/tests/d_type-check
diff options
context:
space:
mode:
Diffstat (limited to 'tests/d_type-check')
-rw-r--r--tests/d_type-check37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/d_type-check b/tests/d_type-check
new file mode 100644
index 000000000..e40904907
--- /dev/null
+++ b/tests/d_type-check
@@ -0,0 +1,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 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)