summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2006-08-28 22:59:17 +0000
committerPaul Eggert <eggert@cs.ucla.edu>2006-08-28 22:59:17 +0000
commite9255b85d00e92866a4edbca355ef59d825e9705 (patch)
tree797a2e4dd40dcbc8a74827ad67cfd8142bfacaa8
parent0a70212f6fdd155158109a8286f0d7b0bdd6c5be (diff)
downloadgnulib-e9255b85d00e92866a4edbca355ef59d825e9705.tar.gz
* lib/fcntl_.h: New file.
* lib/chdir-safer.c (O_DIRECTORY, O_NOFOLLOW): Remove, now that we have the fcntl module. * lib/dirchownmod.c: Likewise. * lib/fts.c: Likewise. * m4/fcntl_h.m4: New file. * modules/fcntl: New file. * modules/chdir-safer (Depends-on): Add fcntl. * modules/fts: Likewise. * modules/mkdir-p: Likewise.
-rw-r--r--ChangeLog5
-rw-r--r--lib/ChangeLog6
-rw-r--r--lib/chdir-safer.c8
-rw-r--r--lib/dirchownmod.c7
-rw-r--r--lib/fcntl_.h100
-rw-r--r--lib/fts.c4
-rw-r--r--m4/ChangeLog4
-rw-r--r--m4/fcntl_h.m450
-rw-r--r--modules/chdir-safer1
-rw-r--r--modules/fcntl34
-rw-r--r--modules/fts1
-rw-r--r--modules/mkdir-p1
12 files changed, 202 insertions, 19 deletions
diff --git a/ChangeLog b/ChangeLog
index b663546945..b886a44245 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2006-08-28 Paul Eggert <eggert@cs.ucla.edu>
+ * modules/fcntl: New file.
+ * modules/chdir-safer (Depends-on): Add fcntl.
+ * modules/fts: Likewise.
+ * modules/mkdir-p: Likewise.
+
* modules/stdint (Makefile.am): Do not substitute ABSOLUTE_INTTYPES_H.
This undoes the most recent change, since we're not addressing the
problem in a different way.
diff --git a/lib/ChangeLog b/lib/ChangeLog
index b8b8d8b01e..ccb82bff5c 100644
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,5 +1,11 @@
2006-08-28 Paul Eggert <eggert@cs.ucla.edu>
+ * fcntl_.h: New file.
+ * chdir-safer.c (O_DIRECTORY, O_NOFOLLOW): Remove, now that we have
+ the fcntl module.
+ * dirchownmod.c: Likewise.
+ * fts.c: Likewise.
+
* inttypes_.h [defined _GL_JUST_INCLUDE_ABSOLUTE_INTTYPES_H]:
Include @ABSOLUTE_INTTYPES_H@ if available, but do nothing else.
* stdint_.h (_GL_JUST_INCLUDE_ABSOLUTE_INTTYPES_H): Define
diff --git a/lib/chdir-safer.c b/lib/chdir-safer.c
index 5c313bcab9..f798ff28f8 100644
--- a/lib/chdir-safer.c
+++ b/lib/chdir-safer.c
@@ -32,14 +32,6 @@
#include <sys/stat.h>
#include "same-inode.h"
-#ifndef O_DIRECTORY
-# define O_DIRECTORY 0
-#endif
-
-#ifndef O_NOFOLLOW
-# define O_NOFOLLOW 0
-#endif
-
/* Like chdir, but fail if DIR is a symbolic link to a directory (or
similar funny business), or if DIR is not readable. This avoids a
minor race condition between when a directory is created or statted
diff --git a/lib/dirchownmod.c b/lib/dirchownmod.c
index 4c76d59acd..84137fad3f 100644
--- a/lib/dirchownmod.c
+++ b/lib/dirchownmod.c
@@ -33,13 +33,6 @@
#include "lchmod.h"
#include "stat-macros.h"
-#ifndef O_DIRECTORY
-# define O_DIRECTORY 0
-#endif
-#ifndef O_NOFOLLOW
-# define O_NOFOLLOW 0
-#endif
-
#ifndef HAVE_FCHMOD
# define HAVE_FCHMOD 0
# undef fchmod
diff --git a/lib/fcntl_.h b/lib/fcntl_.h
new file mode 100644
index 0000000000..a701bcd7b0
--- /dev/null
+++ b/lib/fcntl_.h
@@ -0,0 +1,100 @@
+/* Like <fcntl.h>, but with non-working flags defined to 0.
+
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+/* written by Paul Eggert */
+
+#ifndef _GL_FCNTL_H
+#define _GL_FCNTL_H
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include @ABSOLUTE_FCNTL_H@
+
+#if !defined O_DIRECT && defined O_DIRECTIO
+/* Tru64 spells it `O_DIRECTIO'. */
+# define O_DIRECT O_DIRECTIO
+#endif
+
+#ifndef O_DIRECT
+# define O_DIRECT 0
+#endif
+
+#ifndef O_DIRECTORY
+# define O_DIRECTORY 0
+#endif
+
+#ifndef O_DSYNC
+# define O_DSYNC 0
+#endif
+
+#ifndef O_NDELAY
+# define O_NDELAY 0
+#endif
+
+#ifndef O_NOATIME
+# define O_NOATIME 0
+#endif
+
+#ifndef O_NONBLOCK
+# define O_NONBLOCK O_NDELAY
+#endif
+
+#ifndef O_NOCTTY
+# define O_NOCTTY 0
+#endif
+
+#ifdef O_NOFOLLOW_IS_INEFFECTIVE
+# undef O_NOFOLLOW
+#endif
+#ifndef O_NOFOLLOW
+# define O_NOFOLLOW 0
+#endif
+
+#ifndef O_NOLINKS
+# define O_NOLINKS 0
+#endif
+
+#ifndef O_RSYNC
+# define O_RSYNC 0
+#endif
+
+#ifndef O_SYNC
+# define O_SYNC 0
+#endif
+
+/* For systems that distinguish between text and binary I/O.
+ O_BINARY is usually declared in fcntl.h */
+#if !defined O_BINARY && defined _O_BINARY
+ /* For MSC-compatible compilers. */
+# define O_BINARY _O_BINARY
+# define O_TEXT _O_TEXT
+#endif
+
+#ifdef __BEOS__
+ /* BeOS 5 has O_BINARY and O_TEXT, but they have no effect. */
+# undef O_BINARY
+# undef O_TEXT
+#endif
+
+#ifndef O_BINARY
+# define O_BINARY 0
+# define O_TEXT 0
+#endif
+
+#endif
diff --git a/lib/fts.c b/lib/fts.c
index ea33805eab..f2cc54adca 100644
--- a/lib/fts.c
+++ b/lib/fts.c
@@ -115,10 +115,6 @@ static char sccsid[] = "@(#)fts.c 8.6 (Berkeley) 8/14/94";
# define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
#endif
-#if !defined O_NOFOLLOW
-# define O_NOFOLLOW 0
-#endif
-
/* If this host provides the openat function, then we can avoid
attempting to open "." in some initialization code below. */
#ifdef HAVE_OPENAT
diff --git a/m4/ChangeLog b/m4/ChangeLog
index 6cb1413b5b..ede511e6ec 100644
--- a/m4/ChangeLog
+++ b/m4/ChangeLog
@@ -1,3 +1,7 @@
+2006-08-28 Paul Eggert <eggert@cs.ucla.edu>
+
+ * fcntl_h.m4: New file.
+
2006-08-28 Eric Blake <ebb9@byu.net>
* inttypes.m4 (gl_INTTYPES_H): Fix missing #endif.
diff --git a/m4/fcntl_h.m4 b/m4/fcntl_h.m4
new file mode 100644
index 0000000000..4d904881a3
--- /dev/null
+++ b/m4/fcntl_h.m4
@@ -0,0 +1,50 @@
+# Configure fcntl.h.
+dnl Copyright (C) 2006 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl Written by Paul Eggert.
+
+AC_DEFUN([gl_FCNTL_H],
+[
+ AC_CACHE_CHECK([for working fcntl.h], gl_cv_header_working_fcntl_h,
+ [AC_RUN_IFELSE(
+ [AC_LANG_PROGRAM(
+ [[#include <sys/types.h>
+ #include <sys/stat.h>
+ #include <unistd.h>
+ #include <fcntl.h>
+ #ifndef O_NOFOLLOW
+ #define O_NOFOLLOW 0
+ #endif
+ static int const constants[] =
+ {
+ O_CREAT, O_EXCL, O_NOCTTY, O_TRUNC, O_APPEND,
+ O_NONBLOCK, O_SYNC, O_ACCMODE, O_RDONLY, O_RDWR, O_WRONLY
+ };
+ ]],
+ [[static char const sym[] = "conftest.sym";
+ if (O_NOFOLLOW)
+ {
+ if (symlink (".", sym) != 0)
+ return 1;
+ if (open (sym, O_RDONLY | O_NOFOLLOW) == 0)
+ return 1;
+ }
+ return !constants;]])],
+ [gl_cv_header_working_fcntl_h=yes],
+ [gl_cv_header_working_fcntl_h=no],
+ [gl_cv_header_working_fcntl_h=cross-compiling])])
+
+ if test $gl_cv_header_working_fcntl_h != yes; then
+ AC_DEFINE([O_NOFOLLOW_IS_INEFFECTIVE], 1,
+ [Define to 1 if O_NOFOLLOW is ineffective.])
+ fi
+
+ gl_ABSOLUTE_HEADER([fcntl.h])
+ ABSOLUTE_FCNTL_H=\"$gl_cv_absolute_fcntl_h\"
+ AC_SUBST([ABSOLUTE_FCNTL_H])
+ FCNTL_H='fcntl.h'
+ AC_SUBST([FCNTL_H])
+])
diff --git a/modules/chdir-safer b/modules/chdir-safer
index 0d2f3d23b2..d709ef48e5 100644
--- a/modules/chdir-safer
+++ b/modules/chdir-safer
@@ -7,6 +7,7 @@ lib/chdir-safer.c
m4/chdir-safer.m4
Depends-on:
+fcntl
same-inode
stdbool
diff --git a/modules/fcntl b/modules/fcntl
new file mode 100644
index 0000000000..4d0c83ddc4
--- /dev/null
+++ b/modules/fcntl
@@ -0,0 +1,34 @@
+Description:
+Like <fcntl.h>, but with non-working flags defined to 0.
+
+Files:
+lib/fcntl_.h
+m4/absolute-header.m4
+m4/fcntl_h.m4
+
+Depends-on:
+unistd
+
+configure.ac:
+gl_FCNTL_H
+
+Makefile.am:
+BUILT_SOURCES += $(FCNTL_H)
+EXTRA_DIST += fcntl_.h
+
+# We need the following in order to create <fcntl.h> when the system
+# doesn't have one that works with the given compiler.
+fcntl.h: fcntl_.h
+ sed -e 's|@''ABSOLUTE_FCNTL_H''@|$(ABSOLUTE_FCNTL_H)|g' \
+ < $(srcdir)/fcntl_.h > $@-t
+ mv $@-t $@
+MOSTLYCLEANFILES += fcntl.h fcntl.h-t
+
+Include:
+#include <fcntl.h>
+
+License:
+LGPL
+
+Maintainer:
+all
diff --git a/modules/fts b/modules/fts
index 05a9ddea20..b100fca8c4 100644
--- a/modules/fts
+++ b/modules/fts
@@ -10,6 +10,7 @@ m4/fts.m4
Depends-on:
cycle-check
dirfd
+fcntl
hash
lstat
openat
diff --git a/modules/mkdir-p b/modules/mkdir-p
index 32381d350d..802e4d183b 100644
--- a/modules/mkdir-p
+++ b/modules/mkdir-p
@@ -10,6 +10,7 @@ m4/mkdir-p.m4
Depends-on:
error
+fcntl
gettext-h
lchmod
lchown