hcrypto: Add dirfd definition for solaris
authorSimon Wilkinson <sxw@inf.ed.ac.uk>
Thu, 19 Aug 2010 23:14:49 +0000 (00:14 +0100)
committerDerrick Brashear <shadow@dementia.org>
Thu, 23 Sep 2010 09:11:15 +0000 (02:11 -0700)
Add an implementation of dirfd to our local roken implementation for
platforms that don't have one.

Code taken from Heimdal.

Change-Id: I4284c18430b6f49200886f5340191a14dcf34b57
Reviewed-on: http://gerrit.openafs.org/2608
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Tested-by: Derrick Brashear <shadow@dementia.org>

acinclude.m4
src/cf/have-struct-field.m4 [new file with mode: 0644]
src/crypto/hcrypto/Makefile.in
src/crypto/hcrypto/roken.h

index 8782488..98c6771 100644 (file)
@@ -1454,6 +1454,24 @@ struct labeltest struct_labeltest = {
 [AC_MSG_RESULT(no)
 ])
 
+AC_MSG_CHECKING([checking for dirfd])
+AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
+#ifdef HAVE_DIRENT_H
+#include <dirent.h>
+#endif
+]],
+        [[DIR *d = 0; dirfd(d);]])],
+        [ac_rk_have_dirfd=yes], [ac_rk_have_dirfd=no])
+if test "$ac_rk_have_dirfd" = "yes" ; then
+        AC_DEFINE_UNQUOTED(HAVE_DIRFD, 1, [have a dirfd function/macro])
+fi
+AC_MSG_RESULT($ac_rk_have_dirfd)
+
+OPENAFS_HAVE_STRUCT_FIELD(DIR, dd_fd, [#include <sys/types.h>
+#ifdef HAVE_DIRENT_H
+#include <dirent.h>
+#endif])
+
 dnl Eventually, this will look for the system one, or for OpenSSL
 LIB_hcrypto="-lafshcrypto"
 AC_SUBST(LIB_hcrypto)
diff --git a/src/cf/have-struct-field.m4 b/src/cf/have-struct-field.m4
new file mode 100644 (file)
index 0000000..36f75c9
--- /dev/null
@@ -0,0 +1,19 @@
+dnl Borrowed from Heimdal, but renamed as I don't think we
+dnl should be shipping AC_ macros.
+
+AC_DEFUN([OPENAFS_HAVE_STRUCT_FIELD], [
+define(cache_val, translit(ac_cv_type_$1_$2, [A-Z ], [a-z_]))
+AC_CACHE_CHECK([for $2 in $1], cache_val,[
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[$3]],
+        [[$1 x; memset(&x, 0, sizeof(x)); x.$2]])],
+        [cache_val=yes],
+        [cache_val=no])
+])
+if test "$cache_val" = yes; then
+        define(foo, translit(HAVE_$1_$2, [a-z ], [A-Z_]))
+        AC_DEFINE(foo, 1, [Define if $1 has field $2.])
+        undefine([foo])
+fi
+undefine([cache_val])
+])
+
index 10a2aea..436ffe4 100644 (file)
@@ -165,7 +165,7 @@ dsa.o: ${UPSTREAM}/hcrypto/dsa.c
        ${CCRULE}
 
 evp.o: ${UPSTREAM}/hcrypto/evp.c
-       ${CCRULE}
+       ${CCRULE} -DHAVE_CONFIG_H
 
 evp-hcrypto.o: ${UPSTREAM}/hcrypto/evp-hcrypto.c
        ${CCRULE}
index 93805b5..c830eae 100644 (file)
@@ -37,5 +37,15 @@ ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL
     strlcpy (char *, const char *, size_t);
 #endif
 
+#ifndef HAVE_DIRFD
+# ifdef HAVE_DIR_DD_FD
+#  define dirfd(x) ((x)->dd_fd)
+# else
+#  ifndef _WIN32 /* Windows code never calls dirfd */
+#   error Missing dirfd() and ->dd_fd
+#  endif
+# endif
+#endif
+
 /* This is a bodge, but it's only used by the tests */
 #define emalloc(x) malloc(x)