Mercurial > hg > octave-lyh > gnulib-hg
changeset 11972:24ed6ac9fe07
rename: modernize replacement
* modules/rename (Depends-on): Add stdio.
(configure.ac): Declare witness.
* m4/rename.m4 (gl_FUNC_RENAME): Ensure dependency order, and let
stdio take care of replacement.
* m4/stdio_h.m4 (gl_STDIO_H_DEFAULTS): Add new defaults.
* modules/stdio (Makefile.am): Substitute them.
* lib/stdio.in.h (rename): Declare replacement.
* lib/rename.c (includes): Allow cross-compilation to non-windows
machines.
* doc/posix-functions/rename.texi (rename): Improve
documentation.
Signed-off-by: Eric Blake <ebb9@byu.net>
author | Eric Blake <ebb9@byu.net> |
---|---|
date | Mon, 07 Sep 2009 11:27:05 -0600 |
parents | 229df0a197d3 |
children | d71ad7a7711c |
files | ChangeLog doc/posix-functions/rename.texi lib/rename.c lib/stdio.in.h m4/rename.m4 m4/stdio_h.m4 modules/rename modules/stdio |
diffstat | 8 files changed, 73 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,18 @@ 2009-09-07 Eric Blake <ebb9@byu.net> + rename: modernize replacement + * modules/rename (Depends-on): Add stdio. + (configure.ac): Declare witness. + * m4/rename.m4 (gl_FUNC_RENAME): Ensure dependency order, and let + stdio take care of replacement. + * m4/stdio_h.m4 (gl_STDIO_H_DEFAULTS): Add new defaults. + * modules/stdio (Makefile.am): Substitute them. + * lib/stdio.in.h (rename): Declare replacement. + * lib/rename.c (includes): Allow cross-compilation to non-windows + machines. + * doc/posix-functions/rename.texi (rename): Improve + documentation. + stdio: sort witness names * modules/stdio (Makefile.am): Sort replacements. * m4/stdio_h.m4 (gl_STDIO_H_DEFAULTS): Likewise.
--- a/doc/posix-functions/rename.texi +++ b/doc/posix-functions/rename.texi @@ -9,9 +9,9 @@ Portability problems fixed by Gnulib: @itemize @item -This function does not work when the source file name ends in a slash on -some platforms: -SunOS 4.1. +This function does not handle trailing slashes correctly on +some platforms (the full rules for trailing slashes are complex): +SunOS 4.1, mingw. @item This function will not replace an existing destination on some platforms: @@ -23,4 +23,8 @@ This function will not replace a destination that is currently opened by any process: mingw. +@item +This function mistakenly allows names ending in @samp{.} or @samp{..} +on some platforms: +Cygwin 1.5.x. @end itemize
--- a/lib/rename.c +++ b/lib/rename.c @@ -3,7 +3,8 @@ a trailing slash. On mingw, rename fails when the destination exists. - Copyright (C) 2001, 2002, 2003, 2005, 2006, 2009 Free Software Foundation, Inc. + Copyright (C) 2001, 2002, 2003, 2005, 2006, 2009 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 @@ -21,16 +22,20 @@ /* written by Volker Borchert */ #include <config.h> + +#include <stdio.h> + #undef rename -#if RENAME_DEST_EXISTS_BUG -/* This replacement must come first, otherwise when cross - * compiling to Windows we will guess that it has the trailing - * slash bug and entirely miss this one. */ -#include <errno.h> +#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ +/* The mingw rename has problems with trailing slashes; it also + requires use of native Windows calls to allow atomic renames over + existing files. */ -#define WIN32_LEAN_AND_MEAN -#include <windows.h> +# include <errno.h> + +# define WIN32_LEAN_AND_MEAN +# include <windows.h> /* Rename the file SRC to DST. This replacement is necessary on Windows, on which the system rename function will not replace @@ -114,10 +119,10 @@ errno = EPERM; /* ? */ break; -#ifndef ERROR_FILE_TOO_LARGE +# ifndef ERROR_FILE_TOO_LARGE /* This value is documented but not defined in all versions of windows.h. */ -#define ERROR_FILE_TOO_LARGE 223 -#endif +# define ERROR_FILE_TOO_LARGE 223 +# endif case ERROR_FILE_TOO_LARGE: errno = EFBIG; break; @@ -129,13 +134,18 @@ return -1; } -#elif RENAME_TRAILING_SLASH_BUG -#include <stdio.h> -#include <stdlib.h> -#include <string.h> + +#else /* ! W32 platform */ -#include "dirname.h" -#include "xalloc.h" +# if RENAME_DEST_EXISTS_BUG +# error Please report your platform and this message to bug-gnulib@gnu.org. +# elif RENAME_TRAILING_SLASH_BUG +# include <stdio.h> +# include <stdlib.h> +# include <string.h> + +# include "dirname.h" +# include "xalloc.h" /* Rename the file SRC to DST, removing any trailing slashes from SRC. Needed for SunOS 4.1.1_U1. */ @@ -162,4 +172,5 @@ return ret_val; } -#endif /* RENAME_TRAILING_SLASH_BUG */ +# endif /* RENAME_TRAILING_SLASH_BUG */ +#endif /* ! W32 platform */
--- a/lib/stdio.in.h +++ b/lib/stdio.in.h @@ -416,6 +416,20 @@ extern int puts (const char *string); #endif +#if @GNULIB_RENAME@ +# if @REPLACE_RENAME@ +# undef rename +# define rename rpl_rename +extern int rename (const char *old, const char *new); +# endif +#elif defined GNULIB_POSIXCHECK +# undef rename +# define rename(o,n) \ + (GL_LINK_WARNING ("rename is buggy on some platforms - " \ + "use gnulib module rename for more portability"), \ + rename (o, n)) +#endif + #if @GNULIB_SNPRINTF@ # if @REPLACE_SNPRINTF@ # define snprintf rpl_snprintf
--- a/m4/rename.m4 +++ b/m4/rename.m4 @@ -1,4 +1,4 @@ -# serial 14 +# serial 15 # Copyright (C) 2001, 2003, 2005, 2006, 2009 Free Software Foundation, Inc. # This file is free software; the Free Software Foundation @@ -16,7 +16,8 @@ AC_DEFUN([gl_FUNC_RENAME], [ AC_REQUIRE([AC_CANONICAL_HOST]) - AC_CACHE_CHECK([whether rename is broken with a trailing slash], + AC_REQUIRE([gl_STDIO_H_DEFAULTS]) + AC_CACHE_CHECK([whether rename is broken with a trailing slash], gl_cv_func_rename_trailing_slash_bug, [ rm -rf conftest.d1 conftest.d2 @@ -49,8 +50,7 @@ if test $gl_cv_func_rename_trailing_slash_bug = yes || test $gl_cv_func_rename_dest_exists_bug = yes; then AC_LIBOBJ([rename]) - AC_DEFINE([rename], [rpl_rename], - [Define to rpl_rename if the replacement function should be used.]) + REPLACE_RENAME=1 if test $gl_cv_func_rename_trailing_slash_bug = yes; then AC_DEFINE([RENAME_TRAILING_SLASH_BUG], [1], [Define if rename does not work for source file names with a trailing
--- a/m4/stdio_h.m4 +++ b/m4/stdio_h.m4 @@ -67,6 +67,7 @@ GNULIB_PUTC=0; AC_SUBST([GNULIB_PUTC]) GNULIB_PUTCHAR=0; AC_SUBST([GNULIB_PUTCHAR]) GNULIB_PUTS=0; AC_SUBST([GNULIB_PUTS]) + GNULIB_RENAME=0; AC_SUBST([GNULIB_RENAME]) GNULIB_SNPRINTF=0; AC_SUBST([GNULIB_SNPRINTF]) GNULIB_SPRINTF_POSIX=0; AC_SUBST([GNULIB_SPRINTF_POSIX]) GNULIB_STDIO_H_SIGPIPE=0; AC_SUBST([GNULIB_STDIO_H_SIGPIPE]) @@ -106,6 +107,7 @@ REPLACE_PERROR=0; AC_SUBST([REPLACE_PERROR]) REPLACE_POPEN=0; AC_SUBST([REPLACE_POPEN]) REPLACE_PRINTF=0; AC_SUBST([REPLACE_PRINTF]) + REPLACE_RENAME=0; AC_SUBST([REPLACE_RENAME]) REPLACE_SNPRINTF=0; AC_SUBST([REPLACE_SNPRINTF]) REPLACE_SPRINTF=0; AC_SUBST([REPLACE_SPRINTF]) REPLACE_STDIO_WRITE_FUNCS=0; AC_SUBST([REPLACE_STDIO_WRITE_FUNCS])
--- a/modules/rename +++ b/modules/rename @@ -8,9 +8,11 @@ Depends-on: xalloc dirname +stdio configure.ac: gl_FUNC_RENAME +gl_STDIO_MODULE_INDICATOR([rename]) Makefile.am:
--- a/modules/stdio +++ b/modules/stdio @@ -52,6 +52,7 @@ -e 's|@''GNULIB_PUTC''@|$(GNULIB_PUTC)|g' \ -e 's|@''GNULIB_PUTCHAR''@|$(GNULIB_PUTCHAR)|g' \ -e 's|@''GNULIB_PUTS''@|$(GNULIB_PUTS)|g' \ + -e 's|@''GNULIB_RENAME''@|$(GNULIB_RENAME)|g' \ -e 's|@''GNULIB_SNPRINTF''@|$(GNULIB_SNPRINTF)|g' \ -e 's|@''GNULIB_SPRINTF_POSIX''@|$(GNULIB_SPRINTF_POSIX)|g' \ -e 's|@''GNULIB_STDIO_H_SIGPIPE''@|$(GNULIB_STDIO_H_SIGPIPE)|g' \ @@ -88,6 +89,7 @@ -e 's|@''REPLACE_PERROR''@|$(REPLACE_PERROR)|g' \ -e 's|@''REPLACE_POPEN''@|$(REPLACE_POPEN)|g' \ -e 's|@''REPLACE_PRINTF''@|$(REPLACE_PRINTF)|g' \ + -e 's|@''REPLACE_RENAME''@|$(REPLACE_RENAME)|g' \ -e 's|@''REPLACE_SNPRINTF''@|$(REPLACE_SNPRINTF)|g' \ -e 's|@''REPLACE_SPRINTF''@|$(REPLACE_SPRINTF)|g' \ -e 's|@''REPLACE_STDIO_WRITE_FUNCS''@|$(REPLACE_STDIO_WRITE_FUNCS)|g' \