#!/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)