about summary refs log tree commit diff
path: root/src/libunixonacid
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2024-04-16 13:57:35 +0000
committerLaurent Bercot <ska@appnovation.com>2024-04-16 13:57:35 +0000
commit8ee2aea6d46215dcfda5cc73a5762800099e9fb1 (patch)
treee5f04f6893ba62982131a9f94c14e441d6fa31c8 /src/libunixonacid
parent47f08d628d75469e2c62901f7b81fe3bf0787b0f (diff)
downloadskalibs-8ee2aea6d46215dcfda5cc73a5762800099e9fb1.tar.gz
skalibs-8ee2aea6d46215dcfda5cc73a5762800099e9fb1.tar.xz
skalibs-8ee2aea6d46215dcfda5cc73a5762800099e9fb1.zip
More support for old MacOS fossils
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/libunixonacid')
-rw-r--r--src/libunixonacid/opendir_at.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/src/libunixonacid/opendir_at.c b/src/libunixonacid/opendir_at.c
index c1de4f1..d5a3221 100644
--- a/src/libunixonacid/opendir_at.c
+++ b/src/libunixonacid/opendir_at.c
@@ -1,19 +1,42 @@
 /* ISC license. */
 
-/* Should not be necessary but old NetBSD/OpenBSD fail to
-   properly expose fdopendir() otherwise */
+#include <skalibs/sysdeps.h>
 #include <skalibs/nonposix.h>
-
 #include <skalibs/direntry.h>
 #include <skalibs/djbunix.h>
 #include <skalibs/unix-transactional.h>
 
+#ifdef SKALIBS_HASFDOPENDIR
+
 DIR *opendir_at (int dfd, char const *name)
 {
   DIR *dir ;
   int fd = openc_readatb(dfd, name) ;
-  if (fd < 0) return 0 ;
+  if (fd == -1) return 0 ;
   dir = fdopendir(fd) ;
   if (!dir) fd_close(fd) ;
   return dir ;
 }
+
+#else
+
+#include <unistd.h>
+#include <stdlib.h>
+
+DIR *opendir_at (int dfd, char const *name)
+{
+  DIR *dir ;
+  int here = open_read(".") ;
+  if (here == -1) return 0 ;
+  if (fchdir(dfd) == -1)
+  {
+    fd_close(here) ;
+    return 0 ;
+  }
+  dir = opendir(name) ;
+  if (fchdir(here) == -1) abort() ;
+  fd_close(here) ;
+  return dir ;
+}
+
+#endif