From e9255b85d00e92866a4edbca355ef59d825e9705 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 28 Aug 2006 22:59:17 +0000 Subject: [PATCH] * 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. --- ChangeLog | 5 +++ lib/ChangeLog | 6 ++++ lib/chdir-safer.c | 8 ----- lib/dirchownmod.c | 7 ---- lib/fcntl_.h | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/fts.c | 4 --- m4/ChangeLog | 4 +++ m4/fcntl_h.m4 | 50 ++++++++++++++++++++++++++ modules/chdir-safer | 1 + modules/fcntl | 34 ++++++++++++++++++ modules/fts | 1 + modules/mkdir-p | 1 + 12 files changed, 202 insertions(+), 19 deletions(-) create mode 100644 lib/fcntl_.h create mode 100644 m4/fcntl_h.m4 create mode 100644 modules/fcntl diff --git a/ChangeLog b/ChangeLog index b66354694..b886a4424 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2006-08-28 Paul Eggert + * 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 b8b8d8b01..ccb82bff5 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,5 +1,11 @@ 2006-08-28 Paul Eggert + * 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 5c313bcab..f798ff28f 100644 --- a/lib/chdir-safer.c +++ b/lib/chdir-safer.c @@ -32,14 +32,6 @@ #include #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 4c76d59ac..84137fad3 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 000000000..a701bcd7b --- /dev/null +++ b/lib/fcntl_.h @@ -0,0 +1,100 @@ +/* Like , 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 +#include +#include +#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 ea33805ea..f2cc54adc 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 6cb1413b5..ede511e6e 100644 --- a/m4/ChangeLog +++ b/m4/ChangeLog @@ -1,3 +1,7 @@ +2006-08-28 Paul Eggert + + * fcntl_h.m4: New file. + 2006-08-28 Eric Blake * 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 000000000..4d904881a --- /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 + #include + #include + #include + #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 0d2f3d23b..d709ef48e 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 000000000..4d0c83ddc --- /dev/null +++ b/modules/fcntl @@ -0,0 +1,34 @@ +Description: +Like , 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 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 + +License: +LGPL + +Maintainer: +all diff --git a/modules/fts b/modules/fts index 05a9ddea2..b100fca8c 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 32381d350..802e4d183 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 -- 2.11.0