Mercurial > hg > octave-lyh > gnulib-hg
changeset 9299:ada4d73c37a6
New module 'open'.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sun, 07 Oct 2007 04:39:17 +0200 |
parents | ff18f8290b0a |
children | da8b529f93ee |
files | ChangeLog doc/functions/open.texi lib/fchdir.c lib/fcntl.in.h lib/open.c m4/fcntl_h.m4 m4/open.m4 modules/fcntl modules/open |
diffstat | 9 files changed, 147 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2007-10-06 Bruno Haible <bruno@clisp.org> + + * modules/open: New file. + * lib/open.c: New file. + * m4/open.m4: New file. + * lib/fchdir.c (open): If the gnulib module 'open' is used, do what + lib/open.c does. + * lib/fcntl.in.h (open): Declare also if replaced by the 'open' module. + * m4/fcntl_h.m4 (gl_FCNTL_MODULE_INDICATOR, gl_FCNTL_H_DEFAULTS): New + macros. + (gl_FCNTL_H): Require gl_FCNTL_H_DEFAULTS. + * modules/fcntl (Makefile.am): Also substitute GNULIB_OPEN and + REPLACE_OPEN. + * doc/functions/open.texi: Mention the 'open' module. + 2007-10-04 Bruno Haible <bruno@clisp.org> * modules/ceill-tests: New file.
--- a/doc/functions/open.texi +++ b/doc/functions/open.texi @@ -4,10 +4,13 @@ POSIX specification: @url{http://www.opengroup.org/susv3xsh/open.html} -Gnulib module: --- +Gnulib module: open Portability problems fixed by Gnulib: @itemize +@item +On Windows platforms (excluding Cygwin), this function does usually not +recognize the @file{/dev/null} filename. @end itemize Portability problems not fixed by Gnulib:
--- a/lib/fchdir.c +++ b/lib/fchdir.c @@ -117,6 +117,10 @@ va_end (arg); } +#if defined GNULIB_OPEN && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__) + if (strcmp (filename, "/dev/null") == 0) + filename = "NUL"; +#endif fd = open (filename, flags, mode); if (fd >= 0) {
--- a/lib/fcntl.in.h +++ b/lib/fcntl.in.h @@ -36,9 +36,9 @@ extern "C" { #endif -#ifdef FCHDIR_REPLACEMENT +#if (@GNULIB_OPEN@ && @REPLACE_OPEN@) || defined FCHDIR_REPLACEMENT # define open rpl_open -extern int open (const char *, int, ...); +extern int open (const char *filename, int flags, ...); #endif #ifdef __cplusplus
new file mode 100644 --- /dev/null +++ b/lib/open.c @@ -0,0 +1,62 @@ +/* Open a descriptor to a file. + Copyright (C) 2007 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 Bruno Haible <bruno@clisp.org>, 2007. */ + +#include <config.h> + +/* Specification. */ +#include <fcntl.h> + +/* If the fchdir replacement is used, open() is defined in fchdir.c. */ +#ifndef FCHDIR_REPLACEMENT + +# include <stdarg.h> +# include <string.h> +# include <sys/types.h> +# include <sys/stat.h> + +int +open (const char *filename, int flags, ...) +# undef open +{ + mode_t mode; + + mode = 0; + if (flags & O_CREAT) + { + va_list arg; + va_start (arg, flags); + + /* If mode_t is narrower than int, use the promoted type (int), + not mode_t. Use sizeof to guess whether mode_t is narrower; + we don't know of any practical counterexamples. */ + mode = (sizeof (mode_t) < sizeof (int) + ? va_arg (arg, int) + : va_arg (arg, mode_t)); + + va_end (arg); + } + +# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ + if (strcmp (filename, "/dev/null") == 0) + filename = "NUL"; +# endif + + return open (filename, flags, mode); +} +#endif
--- a/m4/fcntl_h.m4 +++ b/m4/fcntl_h.m4 @@ -8,6 +8,7 @@ AC_DEFUN([gl_FCNTL_H], [ + AC_REQUIRE([gl_FCNTL_H_DEFAULTS]) AC_CACHE_CHECK([for working fcntl.h], gl_cv_header_working_fcntl_h, [AC_RUN_IFELSE( [AC_LANG_PROGRAM( @@ -77,3 +78,17 @@ FCNTL_H='fcntl.h' AC_SUBST([FCNTL_H]) ]) + +AC_DEFUN([gl_FCNTL_MODULE_INDICATOR], +[ + dnl Use AC_REQUIRE here, so that the default settings are expanded once only. + AC_REQUIRE([gl_FCNTL_H_DEFAULTS]) + GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1 +]) + +AC_DEFUN([gl_FCNTL_H_DEFAULTS], +[ + GNULIB_OPEN=0; AC_SUBST([GNULIB_OPEN]) + dnl Assume proper GNU behavior unless another module says otherwise. + REPLACE_OPEN=0; AC_SUBST([REPLACE_OPEN]) +])
new file mode 100644 --- /dev/null +++ b/m4/open.m4 @@ -0,0 +1,17 @@ +# open.m4 serial 1 +dnl Copyright (C) 2007 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. + +AC_DEFUN([gl_FUNC_OPEN], +[ + AC_REQUIRE([gl_FCNTL_H_DEFAULTS]) + AC_REQUIRE([AC_CANONICAL_HOST]) + case "$host_os" in + mingw* | pw*) + REPLACE_OPEN=1 + AC_LIBOBJ([open]) + ;; + esac +])
--- a/modules/fcntl +++ b/modules/fcntl @@ -22,6 +22,8 @@ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ sed -e 's/@''INCLUDE_NEXT''@/$(INCLUDE_NEXT)/g' \ -e 's|@''NEXT_FCNTL_H''@|$(NEXT_FCNTL_H)|g' \ + -e 's|@''GNULIB_OPEN''@|$(GNULIB_OPEN)|g' \ + -e 's|@''REPLACE_OPEN''@|$(REPLACE_OPEN)|g' \ < $(srcdir)/fcntl.in.h; \ } > $@-t mv $@-t $@
new file mode 100644 --- /dev/null +++ b/modules/open @@ -0,0 +1,26 @@ +Description: +open() function: open a descriptor to a file. + +Files: +lib/open.c +m4/open.m4 + +Depends-on: +fcntl + +configure.ac: +gl_FUNC_OPEN +gl_MODULE_INDICATOR([open]) +gl_FCNTL_MODULE_INDICATOR([open]) + +Makefile.am: + +Include: +<fcntl.h> + +License: +LGPL + +Maintainer: +Bruno Haible +