From 8a3e5a8b05ad0a7fab63595b6b4eafec56f63f89 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Thu, 21 Dec 2017 12:34:40 +0000 Subject: Add dirfd sysdep, because Solaris sucks --- configure | 1 + package/deps.mak | 4 +++- src/include/skalibs/direntry.h | 1 + src/libstddjb/dir_fd.c | 23 +++++++++++++++++++++++ src/sysdeps/trydirfd.c | 19 +++++++++++++++++++ 5 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/libstddjb/dir_fd.c create mode 100644 src/sysdeps/trydirfd.c diff --git a/configure b/configure index 2873aed..69b339d 100755 --- a/configure +++ b/configure @@ -507,6 +507,7 @@ EOF choose clr ancilautoclose ANCILAUTOCLOSE 'auto-close after fd-passing' choose c cmsgcloexec CMSGCLOEXEC 'MSG_CMSG_CLOEXEC' choose clr devurandom DEVURANDOM '/dev/urandom' + choose cl dirfd DIRFD 'dirfd()' choose c eproto EPROTO EPROTO choose cl eventfd EVENTFD 'eventfd()' choose cl flock FLOCK 'flock()' diff --git a/package/deps.mak b/package/deps.mak index b263960..25adeff 100644 --- a/package/deps.mak +++ b/package/deps.mak @@ -31,7 +31,7 @@ src/include/skalibs/iobuffer.h: src/include/skalibs/buffer.h src/include/skalibs src/include/skalibs/iopause.h: src/include/skalibs/tai.h src/include/skalibs/kolbak.h: src/include/skalibs/unixmessage.h src/include/skalibs/lolstdio.h: src/include/skalibs/bufalloc.h src/include/skalibs/buffer.h src/include/skalibs/strerr2.h -src/include/skalibs/mininetstring.h: src/include/skalibs/gccattributes.h src/include/skalibs/stralloc.h +src/include/skalibs/mininetstring.h: src/include/skalibs/stralloc.h src/include/skalibs/netstring.h: src/include/skalibs/buffer.h src/include/skalibs/stralloc.h src/include/skalibs/posixplz.h: src/include/skalibs/gccattributes.h src/include/skalibs/random.h: src/include/skalibs/stralloc.h @@ -48,6 +48,7 @@ src/include/skalibs/stddjb.h: src/include/skalibs/alarm.h src/include/skalibs/al src/include/skalibs/strerr.h: src/include/skalibs/gccattributes.h src/include/skalibs/strerr2.h: src/include/skalibs/strerr.h src/include/skalibs/tai.h: src/include/skalibs/gccattributes.h src/include/skalibs/uint64.h +src/include/skalibs/textclient.h: src/include/skalibs/tai.h src/include/skalibs/textmessage.h src/include/skalibs/textmessage.h: src/include/skalibs/allreadwrite.h src/include/skalibs/bufalloc.h src/include/skalibs/buffer.h src/include/skalibs/gccattributes.h src/include/skalibs/stralloc.h src/include/skalibs/tai.h src/include/skalibs/unix-timed.h: src/include/skalibs/bufalloc.h src/include/skalibs/buffer.h src/include/skalibs/functypes.h src/include/skalibs/stralloc.h src/include/skalibs/tai.h src/include/skalibs/unix-transactional.h: src/include/skalibs/stralloc.h src/include/skalibs/uint64.h @@ -270,6 +271,7 @@ src/libstddjb/child_spawn2.o src/libstddjb/child_spawn2.lo: src/libstddjb/child_ src/libstddjb/coe.o src/libstddjb/coe.lo: src/libstddjb/coe.c src/include/skalibs/djbunix.h src/libstddjb/deepsleepuntil.o src/libstddjb/deepsleepuntil.lo: src/libstddjb/deepsleepuntil.c src/include/skalibs/iopause.h src/include/skalibs/tai.h src/libstddjb/dir_close.o src/libstddjb/dir_close.lo: src/libstddjb/dir_close.c src/include/skalibs/direntry.h +src/libstddjb/dir_fd.o src/libstddjb/dir_fd.lo: src/libstddjb/dir_fd.c src/include/skalibs/direntry.h src/include/skalibs/nonposix.h src/include/skalibs/sysdeps.h src/libstddjb/env_addmodif.o src/libstddjb/env_addmodif.lo: src/libstddjb/env_addmodif.c src/include/skalibs/env.h src/include/skalibs/stralloc.h src/libstddjb/env_get.o src/libstddjb/env_get.lo: src/libstddjb/env_get.c src/include/skalibs/env.h src/include/skalibs/posixplz.h src/libstddjb/env_get2.o src/libstddjb/env_get2.lo: src/libstddjb/env_get2.c src/include/skalibs/bytestr.h src/include/skalibs/env.h 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 +#include +#include + +#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 + +int main (void) +{ + DIR *dir = opendir(".") ; + return dirfd(dir) ; +} -- cgit v1.2.3