rename: modernize replacement upstream/20090908+c5c46dc
authorEric Blake <ebb9@byu.net>
Mon, 7 Sep 2009 17:27:05 +0000 (11:27 -0600)
committerEric Blake <ebb9@byu.net>
Mon, 7 Sep 2009 17:27:05 +0000 (11:27 -0600)
* 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>
ChangeLog
doc/posix-functions/rename.texi
lib/rename.c
lib/stdio.in.h
m4/rename.m4
m4/stdio_h.m4
modules/rename
modules/stdio

index e3af685..0b9e3a0 100644 (file)
--- 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.
index aa7287a..84a03ab 100644 (file)
@@ -9,9 +9,9 @@ Gnulib module: rename
 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 @@ Portability problems not fixed by Gnulib:
 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
index b27fd91..5cd4dee 100644 (file)
@@ -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
 /* 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.  */
+
+# include <errno.h>
 
-#define WIN32_LEAN_AND_MEAN
-#include <windows.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 @@ rpl_rename (char const *src, char const *dst)
       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 @@ rpl_rename (char const *src, char const *dst)
 
   return -1;
 }
-#elif RENAME_TRAILING_SLASH_BUG
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
 
-#include "dirname.h"
-#include "xalloc.h"
+#else /* ! W32 platform */
+
+# 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 @@ rpl_rename (char const *src, char const *dst)
 
   return ret_val;
 }
-#endif /* RENAME_TRAILING_SLASH_BUG */
+# endif /* RENAME_TRAILING_SLASH_BUG */
+#endif /* ! W32 platform */
index 495baca..27cd305 100644 (file)
@@ -416,6 +416,20 @@ extern int putchar (int c);
 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
index 0592fcb..2e43a87 100644 (file)
@@ -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 @@ dnl
 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 @@ AC_DEFUN([gl_FUNC_RENAME],
   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
index 8314f58..ac5e20a 100644 (file)
@@ -67,6 +67,7 @@ AC_DEFUN([gl_STDIO_H_DEFAULTS],
   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 @@ AC_DEFUN([gl_STDIO_H_DEFAULTS],
   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])
index 9eaea93..8d2a968 100644 (file)
@@ -8,9 +8,11 @@ m4/rename.m4
 Depends-on:
 xalloc
 dirname
+stdio
 
 configure.ac:
 gl_FUNC_RENAME
+gl_STDIO_MODULE_INDICATOR([rename])
 
 Makefile.am:
 
index 9f95fd3..eb58269 100644 (file)
@@ -52,6 +52,7 @@ stdio.h: stdio.in.h
              -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 @@ stdio.h: stdio.in.h
              -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' \