From d58c47d9a49805157ff0669afe02fa4f9d8adf78 Mon Sep 17 00:00:00 2001 From: Fabian Groffen Date: Fri, 21 Jan 2011 17:48:14 +0100 Subject: [PATCH] include: emulate dirfd when necessary dirfd is not available on Solaris 10, it is available on latest OpenSolaris releases though. Do some autoconf trickery to determine if providing an alternative dirfd function is necessary and possible. shlibs/blkid/src/read.c: Do not define _XOPEN_SOURCE to 600, or DIR will lose it's dd_fd member again. Rearrange defines and includes to make sense per comments, and not conflict on Solaris. Signed-off-by: Fabian Groffen --- configure.ac | 24 ++++++++++++++++++++++++ include/c.h | 9 +++++++++ shlibs/blkid/src/read.c | 12 +++++++----- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/configure.ac b/configure.ac index 246afd4f..2aadacf5 100644 --- a/configure.ac +++ b/configure.ac @@ -224,6 +224,30 @@ AC_SEARCH_LIBS([socket], [socket], fi]) AC_SUBST([SOCKET_LIBS]) + +have_dirfd=no +AC_CHECK_FUNCS([dirfd], [have_dirfd=yes], [have_dirfd=no]) +if test x"$have_dirfd" = xno ; then + AC_CHECK_DECLS([dirfd], + [have_dirfd=yes], [have_dirfd=no], + [#include + #include ]) +fi + +have_ddfd=no +if test x"$have_dirfd" = xno ; then + AC_CHECK_MEMBERS([DIR.dd_fd], + [have_ddfd=yes], [have_ddfd=no], + [#include + #include ]) +fi + +case "$have_dirfd:$have_ddfd" in +no:no) + AC_MSG_ERROR([cannot find a method to get filedescriptor of directory]) ;; +esac + + dnl Static compilation m4_define([UTIL_STATIC_PROGRAMS], [losetup, mount, umount, fdisk, sfdisk, blkid]) diff --git a/include/c.h b/include/c.h index 83be3565..b37c4422 100644 --- a/include/c.h +++ b/include/c.h @@ -73,5 +73,14 @@ static inline __attribute__((const)) int is_power_of_2(unsigned long num) typedef int64_t loff_t; #endif +#if !defined(HAVE_DIRFD) && (!defined(HAVE_DECL_DIRFD) || HAVE_DECL_DIRFD == 0) && defined(HAVE_DIR_DD_FD) +#include +#include +static inline int dirfd(DIR *d) +{ + return d->dd_fd; +} +#endif + #endif /* UTIL_LINUX_C_H */ diff --git a/shlibs/blkid/src/read.c b/shlibs/blkid/src/read.c index e6aa0836..3ff9ebe9 100644 --- a/shlibs/blkid/src/read.c +++ b/shlibs/blkid/src/read.c @@ -10,7 +10,6 @@ * %End-Header% */ -#define _XOPEN_SOURCE 600 /* for inclusion of strtoull */ #include #include @@ -26,6 +25,13 @@ #include "blkidP.h" +#if HAVE_STDLIB_H +# ifndef _XOPEN_SOURCE +# define _XOPEN_SOURCE 600 /* for inclusion of strtoull */ +# endif +# include +#endif + #ifdef HAVE_STRTOULL #define STRTOULL strtoull /* defined in stdlib.h if you try hard enough */ #else @@ -33,10 +39,6 @@ #define STRTOULL strtoul #endif -#if HAVE_STDLIB_H -#include -#endif - #ifdef TEST_PROGRAM #define blkid_debug_dump_dev(dev) (debug_dump_dev(dev)) static void debug_dump_dev(blkid_dev dev); -- 2.39.5