summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/include/skalibs/direntry.h1
-rw-r--r--src/libstddjb/dir_fd.c23
-rw-r--r--src/sysdeps/trydirfd.c19
3 files changed, 43 insertions, 0 deletions
diff --git a/src/include/skalibs/direntry.h b/src/include/skalibs/direntry.h
index 518ce77..70bd190 100644
--- a/src/include/skalibs/direntry.h
+++ b/src/include/skalibs/direntry.h
@@ -8,5 +8,6 @@
typedef struct dirent direntry, direntry_t, *direntry_ref, *direntry_t_ref ;
extern int dir_close (DIR *) ;
+extern int dir_fd (DIR *) ; /* Solaris doesn't have dirfd() */
#endif
diff --git a/src/libstddjb/dir_fd.c b/src/libstddjb/dir_fd.c
new file mode 100644
index 0000000..403853f
--- /dev/null
+++ b/src/libstddjb/dir_fd.c
@@ -0,0 +1,23 @@
+/* ISC license. */
+
+#include <skalibs/sysdeps.h>
+#include <skalibs/nonposix.h>
+#include <skalibs/direntry.h>
+
+#ifdef SKALIBS_HASDIRFD
+
+int dir_fd (DIR *dir)
+{
+ return dirfd(dir) ;
+}
+
+#else
+
+ /* Pokes at the internals of DIR - no choice here */
+
+int dir_fd (DIR *dir)
+{
+ return dir->dd_fd ;
+}
+
+#endif
diff --git a/src/sysdeps/trydirfd.c b/src/sysdeps/trydirfd.c
new file mode 100644
index 0000000..c2eccf2
--- /dev/null
+++ b/src/sysdeps/trydirfd.c
@@ -0,0 +1,19 @@
+/* ISC license. */
+
+#undef _POSIX_C_SOURCE
+#undef _XOPEN_SOURCE
+
+#ifndef _NETBSD_SOURCE
+#define _NETBSD_SOURCE
+#endif
+#ifndef __EXTENSIONS__
+#define __EXTENSIONS__
+#endif
+
+#include <dirent.h>
+
+int main (void)
+{
+ DIR *dir = opendir(".") ;
+ return dirfd(dir) ;
+}