diff options
author | Jeff Johnston <jjohnstn@redhat.com> | 2007-09-18 19:32:43 +0000 |
---|---|---|
committer | Jeff Johnston <jjohnstn@redhat.com> | 2007-09-18 19:32:43 +0000 |
commit | 3908c985922d653fa47775dfbf5d2d29ff7c4fa0 (patch) | |
tree | bf5fac0245666188665bcb55719e2000e288ab3f /newlib | |
parent | 4090f565a839d8e846cf9c6249a5ebbfd8ad9790 (diff) | |
download | newlib-3908c985922d653fa47775dfbf5d2d29ff7c4fa0.zip newlib-3908c985922d653fa47775dfbf5d2d29ff7c4fa0.tar.gz newlib-3908c985922d653fa47775dfbf5d2d29ff7c4fa0.tar.bz2 |
2007-09-18 Jeff Johnston <jjohnstn@redhat.com>
* libc/reent/renamer.c: New file.
* libc/reent/Makefile.am: Add new file.
* libc/reent/Makefile.in: Regenerated.
* libc/stdio/rename.c: Break out _rename_r code into reent/renamer.c
and add check for rename syscall.
Diffstat (limited to 'newlib')
-rw-r--r-- | newlib/ChangeLog | 8 | ||||
-rw-r--r-- | newlib/libc/reent/Makefile.am | 2 | ||||
-rw-r--r-- | newlib/libc/reent/Makefile.in | 21 | ||||
-rw-r--r-- | newlib/libc/reent/renamer.c | 74 | ||||
-rw-r--r-- | newlib/libc/stdio/rename.c | 34 |
5 files changed, 99 insertions, 40 deletions
diff --git a/newlib/ChangeLog b/newlib/ChangeLog index f35dc5d..a8251b8 100644 --- a/newlib/ChangeLog +++ b/newlib/ChangeLog @@ -1,3 +1,11 @@ +2007-09-18 Jeff Johnston <jjohnstn@redhat.com> + + * libc/reent/renamer.c: New file. + * libc/reent/Makefile.am: Add new file. + * libc/reent/Makefile.in: Regenerated. + * libc/stdio/rename.c: Break out _rename_r code into reent/renamer.c + and add check for rename syscall. + 2007-09-17 Eric Blake <ebb9@byu.net> Obey POSIX on printf("%.s", (char*)NULL). diff --git a/newlib/libc/reent/Makefile.am b/newlib/libc/reent/Makefile.am index 37a334f..b695e29 100644 --- a/newlib/libc/reent/Makefile.am +++ b/newlib/libc/reent/Makefile.am @@ -41,6 +41,7 @@ GENERAL_SOURCES = \ lseekr.c \ openr.c \ readr.c \ + renamer.c \ signalr.c \ signgam.c \ sbrkr.c \ @@ -75,6 +76,7 @@ CHEWOUT_FILES = \ lseekr.def \ openr.def \ readr.def \ + renamer.def \ signalr.def \ sbrkr.def \ statr.def \ diff --git a/newlib/libc/reent/Makefile.in b/newlib/libc/reent/Makefile.in index d8019cc..270184e 100644 --- a/newlib/libc/reent/Makefile.in +++ b/newlib/libc/reent/Makefile.in @@ -60,10 +60,11 @@ am__objects_1 = lib_a-closer.$(OBJEXT) lib_a-reent.$(OBJEXT) \ lib_a-fstatr.$(OBJEXT) lib_a-getreent.$(OBJEXT) \ lib_a-gettimeofdayr.$(OBJEXT) lib_a-linkr.$(OBJEXT) \ lib_a-lseekr.$(OBJEXT) lib_a-openr.$(OBJEXT) \ - lib_a-readr.$(OBJEXT) lib_a-signalr.$(OBJEXT) \ - lib_a-signgam.$(OBJEXT) lib_a-sbrkr.$(OBJEXT) \ - lib_a-statr.$(OBJEXT) lib_a-timesr.$(OBJEXT) \ - lib_a-unlinkr.$(OBJEXT) lib_a-writer.$(OBJEXT) + lib_a-readr.$(OBJEXT) lib_a-renamer.$(OBJEXT) \ + lib_a-signalr.$(OBJEXT) lib_a-signgam.$(OBJEXT) \ + lib_a-sbrkr.$(OBJEXT) lib_a-statr.$(OBJEXT) \ + lib_a-timesr.$(OBJEXT) lib_a-unlinkr.$(OBJEXT) \ + lib_a-writer.$(OBJEXT) @HAVE_STDIO64_DIR_TRUE@am__objects_2 = lib_a-fstat64r.$(OBJEXT) \ @HAVE_STDIO64_DIR_TRUE@ lib_a-lseek64r.$(OBJEXT) \ @HAVE_STDIO64_DIR_TRUE@ lib_a-open64r.$(OBJEXT) @@ -81,8 +82,8 @@ LTLIBRARIES = $(noinst_LTLIBRARIES) libreent_la_LIBADD = am__objects_6 = closer.lo reent.lo impure.lo fcntlr.lo fstatr.lo \ getreent.lo gettimeofdayr.lo linkr.lo lseekr.lo openr.lo \ - readr.lo signalr.lo signgam.lo sbrkr.lo statr.lo timesr.lo \ - unlinkr.lo writer.lo + readr.lo renamer.lo signalr.lo signgam.lo sbrkr.lo statr.lo \ + timesr.lo unlinkr.lo writer.lo @HAVE_STDIO64_DIR_TRUE@am__objects_7 = fstat64r.lo lseek64r.lo \ @HAVE_STDIO64_DIR_TRUE@ open64r.lo am__objects_8 = $(am__objects_7) @@ -298,6 +299,7 @@ GENERAL_SOURCES = \ lseekr.c \ openr.c \ readr.c \ + renamer.c \ signalr.c \ signgam.c \ sbrkr.c \ @@ -325,6 +327,7 @@ CHEWOUT_FILES = \ lseekr.def \ openr.def \ readr.def \ + renamer.def \ signalr.def \ sbrkr.def \ statr.def \ @@ -470,6 +473,12 @@ lib_a-readr.o: readr.c lib_a-readr.obj: readr.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-readr.obj `if test -f 'readr.c'; then $(CYGPATH_W) 'readr.c'; else $(CYGPATH_W) '$(srcdir)/readr.c'; fi` +lib_a-renamer.o: renamer.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-renamer.o `test -f 'renamer.c' || echo '$(srcdir)/'`renamer.c + +lib_a-renamer.obj: renamer.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-renamer.obj `if test -f 'renamer.c'; then $(CYGPATH_W) 'renamer.c'; else $(CYGPATH_W) '$(srcdir)/renamer.c'; fi` + lib_a-signalr.o: signalr.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-signalr.o `test -f 'signalr.c' || echo '$(srcdir)/'`signalr.c diff --git a/newlib/libc/reent/renamer.c b/newlib/libc/reent/renamer.c new file mode 100644 index 0000000..0467ae9 --- /dev/null +++ b/newlib/libc/reent/renamer.c @@ -0,0 +1,74 @@ +/* Reentrant version of rename system call. */ + +#include <reent.h> +#include <unistd.h> +#include <sys/stat.h> +#include <_syslist.h> + +/* Some targets provides their own versions of these functions. Those + targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS. */ + +#ifdef _REENT_ONLY +#ifndef REENTRANT_SYSCALLS_PROVIDED +#define REENTRANT_SYSCALLS_PROVIDED +#endif +#endif + +#ifndef REENTRANT_SYSCALLS_PROVIDED + +/* We use the errno variable used by the system dependent layer. */ +#undef errno +extern int errno; + +/* +FUNCTION + <<_rename_r>>---Reentrant version of rename + +INDEX + _rename_r + +ANSI_SYNOPSIS + #include <reent.h> + int _rename_r(struct _reent *<[ptr]>, + int <[fd]>, int <[cmd]>, <[arg]>); + +TRAD_SYNOPSIS + #include <reent.h> + int _rename_r(<[ptr]>, <[fd]>, <[cmd]>, <[arg]>) + struct _reent *<[ptr]>; + int <[fd]>; + int <[cmd]>; + int <[arg]>; + +DESCRIPTION + This is a reentrant version of <<rename>>. It + takes a pointer to the global data block, which holds + <<errno>>. +*/ + +int +_DEFUN (_rename_r, (ptr, old, new), + struct _reent *ptr _AND + _CONST char *old _AND + _CONST char *new) +{ + int ret = 0; + +#ifdef HAVE_RENAME + errno = 0; + if ((ret = _rename (old, new)) == -1 && errno != 0) + ptr->_errno = errno; +#else + if (_link_r (ptr, old, new) == -1) + return -1; + + if (_unlink_r (ptr, old) == -1) + { + /* ??? Should we unlink new? (rhetorical question) */ + return -1; + } +#endif + return ret; +} + +#endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */ diff --git a/newlib/libc/stdio/rename.c b/newlib/libc/stdio/rename.c index 4fa8e39..6eb1f7d 100644 --- a/newlib/libc/stdio/rename.c +++ b/newlib/libc/stdio/rename.c @@ -21,27 +21,17 @@ FUNCTION INDEX rename -INDEX - _rename_r ANSI_SYNOPSIS #include <stdio.h> int rename(const char *<[old]>, const char *<[new]>); - int _rename_r(struct _reent *<[reent]>, - const char *<[old]>, const char *<[new]>); - TRAD_SYNOPSIS #include <stdio.h> int rename(<[old]>, <[new]>) char *<[old]>; char *<[new]>; - int _rename_r(<[reent]>, <[old]>, <[new]>) - struct _reent *<[reent]>; - char *<[old]>; - char *<[new]>; - DESCRIPTION Use <<rename>> to establish a new name (the string at <[new]>) for a file now known by the string at <[old]>. After a successful @@ -50,9 +40,6 @@ file now known by the string at <[old]>. After a successful If <<rename>> fails, the file named <<*<[old]>>> is unaffected. The conditions for failure depend on the host operating system. -The alternate function <<_rename_r>> is a reentrant version. The -extra argument <[reent]> is a pointer to a reentrancy structure. - RETURNS The result is either <<0>> (when successful) or <<-1>> (when the file could not be renamed). @@ -70,27 +57,6 @@ Supporting OS subroutines required: <<link>>, <<unlink>>, or <<rename>>. #include <stdio.h> #include <sys/unistd.h> -int -_DEFUN(_rename_r, (ptr, old, new), - struct _reent *ptr _AND - _CONST char *old _AND - _CONST char *new) -{ -#ifdef HAVE_RENAME - return _rename (old,new); -#else - if (_link_r (ptr, old, new) == -1) - return -1; - - if (_unlink_r (ptr, old) == -1) - { - /* ??? Should we unlink new? (rhetorical question) */ - return -1; - } -#endif - return 0; -} - #ifndef _REENT_ONLY int |