# HG changeset patch # User John W. Eaton # Date 1264057644 18000 # Node ID 1dffc8b2fca75e9776717cd6dbe689e4d6e91aec # Parent 06bd6e57f889697df6de6d90795466ae2bd63f28 use rename module from gnulib diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-01-21 John W. Eaton + + * bootstrap.conf (gnulib_modules): Include rename in the list. + 2010-01-21 John W. Eaton * bootstrap.conf (gnulib_modules): Include rmdir in the list. diff --git a/bootstrap.conf b/bootstrap.conf --- a/bootstrap.conf +++ b/bootstrap.conf @@ -27,6 +27,7 @@ lstat mkdir mkfifo + rename rmdir stat strftime diff --git a/liboctave/ChangeLog b/liboctave/ChangeLog --- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,11 @@ +2010-01-21 John W. Eaton + + * 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 * lo-cutils.c (octave_rmdir): New function. diff --git a/liboctave/Makefile.am b/liboctave/Makefile.am --- a/liboctave/Makefile.am +++ b/liboctave/Makefile.am @@ -463,7 +463,6 @@ randgamma.c \ randmtzig.c \ randpoisson.c \ - rename.c \ strptime.c \ tempnam.c \ tempname.c diff --git a/liboctave/file-ops.cc b/liboctave/file-ops.cc --- a/liboctave/file-ops.cc +++ b/liboctave/file-ops.cc @@ -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; } diff --git a/liboctave/lo-cutils.c b/liboctave/lo-cutils.c --- a/liboctave/lo-cutils.c +++ b/liboctave/lo-cutils.c @@ -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); diff --git a/liboctave/lo-utils.h b/liboctave/lo-utils.h --- a/liboctave/lo-utils.h +++ b/liboctave/lo-utils.h @@ -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); diff --git a/liboctave/rename.c b/liboctave/rename.c deleted file mode 100644 --- a/liboctave/rename.c +++ /dev/null @@ -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 -#endif - -#ifndef HAVE_RENAME - -#ifdef HAVE_SYS_TYPES_H -#include -#endif -#include -#include -#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