changeset 10170:1dffc8b2fca7

use rename module from gnulib
author John W. Eaton <jwe@octave.org>
date Thu, 21 Jan 2010 02:07:24 -0500
parents 06bd6e57f889
children 22400682d3aa
files ChangeLog bootstrap.conf liboctave/ChangeLog liboctave/Makefile.am liboctave/file-ops.cc liboctave/lo-cutils.c liboctave/lo-utils.h liboctave/rename.c
diffstat 8 files changed, 22 insertions(+), 118 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Jan 21 01:49:36 2010 -0500
+++ b/ChangeLog	Thu Jan 21 02:07:24 2010 -0500
@@ -1,3 +1,7 @@
+2010-01-21  John W. Eaton  <jwe@octave.org>
+
+	* bootstrap.conf (gnulib_modules): Include rename in the list.
+
 2010-01-21  John W. Eaton  <jwe@octave.org>
 
 	* bootstrap.conf (gnulib_modules): Include rmdir in the list.
--- a/bootstrap.conf	Thu Jan 21 01:49:36 2010 -0500
+++ b/bootstrap.conf	Thu Jan 21 02:07:24 2010 -0500
@@ -27,6 +27,7 @@
   lstat
   mkdir
   mkfifo
+  rename
   rmdir
   stat
   strftime
--- a/liboctave/ChangeLog	Thu Jan 21 01:49:36 2010 -0500
+++ b/liboctave/ChangeLog	Thu Jan 21 02:07:24 2010 -0500
@@ -1,3 +1,11 @@
+2010-01-21  John W. Eaton  <jwe@octave.org>
+
+	* lo-cutils.c (octave_rename): New funtion.
+	* lo-utils.h: Provide decl.
+	* file-ops.cc (file_ops::rename): Call octave_rename.
+	* Makefile.am (LIBOCTAVE_C_SOURCES): Remove rename.c from the list.
+	* rename.c: Delete.
+
 2010-01-21  John W. Eaton  <jwe@octave.org>
 
 	* lo-cutils.c (octave_rmdir): New function.
--- a/liboctave/Makefile.am	Thu Jan 21 01:49:36 2010 -0500
+++ b/liboctave/Makefile.am	Thu Jan 21 02:07:24 2010 -0500
@@ -463,7 +463,6 @@
   randgamma.c \
   randmtzig.c \
   randpoisson.c \
-  rename.c \
   strptime.c \
   tempnam.c \
   tempname.c
--- a/liboctave/file-ops.cc	Thu Jan 21 01:49:36 2010 -0500
+++ b/liboctave/file-ops.cc	Thu Jan 21 02:07:24 2010 -0500
@@ -260,17 +260,13 @@
 
   msg = std::string ();
 
-#if defined (HAVE_RENAME)
-  status = ::rename (from.c_str (), to.c_str ());
+  status = octave_rename (from.c_str (), to.c_str ());
 
   if (status < 0)
     {
       using namespace std;
       msg = ::strerror (errno);
     }
-#else
-  msg = NOT_SUPPORTED ("rename");
-#endif
 
   return status;
 }
--- a/liboctave/lo-cutils.c	Thu Jan 21 01:49:36 2010 -0500
+++ b/liboctave/lo-cutils.c	Thu Jan 21 02:07:24 2010 -0500
@@ -98,6 +98,12 @@
 }
 
 OCTAVE_API int
+octave_rename (const char *from, const char *to)
+{
+  return rename (from, to);
+}
+
+OCTAVE_API int
 octave_strcasecmp (const char *s1, const char *s2)
 {
   return strcasecmp (s1, s2);
--- a/liboctave/lo-utils.h	Thu Jan 21 01:49:36 2010 -0500
+++ b/liboctave/lo-utils.h	Thu Jan 21 02:07:24 2010 -0500
@@ -56,6 +56,8 @@
 
 extern "C" OCTAVE_API int octave_rmdir (const char *name);
 
+extern "C" OCTAVE_API int octave_rename (const char *from, const char *to);
+
 extern "C" OCTAVE_API char *oct_strptime (const char *buf, const char *format,
 			       struct tm *tm);
 
--- a/liboctave/rename.c	Thu Jan 21 01:49:36 2010 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,112 +0,0 @@
-/* rename.c -- BSD compatible directory function for System V
-   Copyright (C) 1988, 1990 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 of the License, 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.  */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#ifndef HAVE_RENAME
-
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-#include <sys/stat.h>
-#include <errno.h>
-#ifndef errno
-extern int errno;
-#endif
-
-#ifdef STAT_MACROS_BROKEN
-#undef S_ISDIR
-#endif /* STAT_MACROS_BROKEN.  */
-
-#if !defined(S_ISDIR) && defined(S_IFDIR)
-#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
-#endif
-
-#include "safe-stat.h"
-
-/* Rename file FROM to file TO.
-   Return 0 if successful, -1 if not. */
-
-int
-rename (from, to)
-     char *from;
-     char *to;
-{
-  struct stat from_stats, to_stats;
-  int pid, status;
-
-  if (SAFE_STAT (from, &from_stats))
-    return -1;
-
-  /* Be careful not to unlink `from' if it happens to be equal to `to' or
-     (on filesystems that silently truncate filenames after 14 characters)
-     if `from' and `to' share the significant characters. */
-  if (SAFE_STAT (to, &to_stats))
-    {
-      if (errno != ENOENT)
-        return -1;
-    }
-  else
-    {
-      if ((from_stats.st_dev == to_stats.st_dev)
-          && (from_stats.st_ino == to_stats.st_dev))
-        /* `from' and `to' designate the same file on that filesystem. */
-        return 0;
-
-      if (unlink (to) && errno != ENOENT)
-        return -1;
-    }
-
-  if (S_ISDIR (from_stats.st_mode))
-    {
-      /* Need a setuid root process to link and unlink directories. */
-      pid = fork ();
-      switch (pid)
-	{
-	case -1:		/* Error. */
-	  error (1, errno, "cannot fork");
-
-	case 0:			/* Child. */
-	  execl (MVDIR, "mvdir", from, to, (char *) 0);
-	  error (255, errno, "cannot run `%s'", MVDIR);
-
-	default:		/* Parent. */
-	  while (wait (&status) != pid)
-	    /* Do nothing. */ ;
-
-	  errno = 0;		/* mvdir printed the system error message. */
-	  if (status)
-	    return -1;
-	}
-    }
-  else
-    {
-      if (link (from, to))
-	return -1;
-      if (unlink (from) && errno != ENOENT)
-	{
-	  unlink (to);
-	  return -1;
-	}
-    }
-  return 0;
-}
-
-#endif