changeset 813:52e69f6710ca 0.4.4

Compile time probe to fish O_NOFOLLOW out of linux headers when fcntl doesn't conform to posix-2008.
author Rob Landley <rob@landley.net>
date Mon, 11 Mar 2013 22:23:46 -0500
parents 5a2b83a92521
children ff5595fb5af2
files lib/portability.h scripts/genconfig.sh
diffstat 2 files changed, 30 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/lib/portability.h	Sat Mar 09 12:01:36 2013 -0600
+++ b/lib/portability.h	Mon Mar 11 22:23:46 2013 -0500
@@ -145,3 +145,5 @@
 ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream);
 ssize_t getline(char **lineptr, size_t *n, FILE *stream);
 #endif
+
+#include "generated/portability.h"
--- a/scripts/genconfig.sh	Sat Mar 09 12:01:36 2013 -0600
+++ b/scripts/genconfig.sh	Mon Mar 11 22:23:46 2013 -0500
@@ -49,5 +49,33 @@
   done
 }
 
+headerprobes()
+{
+  ${CROSS_COMPILE}${CC} -xc -o /dev/null - 2>/dev/null << EOF
+    #include <fcntl.h>
+    #ifndef O_NOFOLLOW
+    #error posix 2008 was a while ago now
+    #endif
+EOF
+  if [ $? -ne 0 ]
+  then
+    rm -f a.out
+    ${CROSS_COMPILE}${CC} -xc - 2>/dev/null << EOF
+      #include <stdio.h>
+      #include <sys/types.h>
+      #include <asm/fcntl.h>
+
+      int main(int argc, char *argv[])
+      {
+        printf("0x%x\n", O_NOFOLLOW);
+      }
+EOF
+    X=$(./a.out) 2>/dev/null
+    rm -f a.out
+    echo "#define O_NOFOLLOW ${X:-0}"
+  fi
+}
+
 probeconfig > generated/Config.probed || rm generated/Config.probed
 genconfig > generated/Config.in || rm generated/Config.in
+headerprobes > generated/portability.h || rm generated/portability.h