fixes for host gcc 4.6.1
[zpugcc/jano.git] / toolchain / gcc / newlib / libc / stdio / rename.c
blob19a6afdd3873c50b7c55ec08deabc1d41a54e5f2
1 /*
2 FUNCTION
3 <<rename>>---rename a file
5 INDEX
6 rename
7 INDEX
8 _rename_r
10 ANSI_SYNOPSIS
11 #include <stdio.h>
12 int rename(const char *<[old]>, const char *<[new]>);
14 int _rename_r(void *<[reent]>,
15 const char *<[old]>, const char *<[new]>);
17 TRAD_SYNOPSIS
18 #include <stdio.h>
19 int rename(<[old]>, <[new]>)
20 char *<[old]>;
21 char *<[new]>;
23 int _rename_r(<[reent]>, <[old]>, <[new]>)
24 char *<[reent]>;
25 char *<[old]>;
26 char *<[new]>;
28 DESCRIPTION
29 Use <<rename>> to establish a new name (the string at <[new]>) for a
30 file now known by the string at <[old]>. After a successful
31 <<rename>>, the file is no longer accessible by the string at <[old]>.
33 If <<rename>> fails, the file named <<*<[old]>>> is unaffected. The
34 conditions for failure depend on the host operating system.
36 The alternate function <<_rename_r>> is a reentrant version. The
37 extra argument <[reent]> is a pointer to a reentrancy structure.
39 RETURNS
40 The result is either <<0>> (when successful) or <<-1>> (when the file
41 could not be renamed).
43 PORTABILITY
44 ANSI C requires <<rename>>, but only specifies that the result on
45 failure be nonzero. The effects of using the name of an existing file
46 as <<*<[new]>>> may vary from one implementation to another.
48 Supporting OS subroutines required: <<link>>, <<unlink>>, or <<rename>>.
51 #include <stdio.h>
52 #include <sys/unistd.h>
53 #include <reent.h>
55 int
56 _rename_r (ptr, old, new)
57 struct _reent *ptr;
58 _CONST char *old;
59 _CONST char *new;
61 #ifdef HAVE_RENAME
62 return _rename (old,new);
63 #else
64 if (_link_r (ptr, old, new) == -1)
65 return -1;
67 if (_unlink_r (ptr, old) == -1)
69 /* ??? Should we unlink new? (rhetorical question) */
70 return -1;
72 #endif
73 return 0;
76 #ifndef _REENT_ONLY
78 int
79 rename (old, new)
80 _CONST char *old;
81 _CONST char *new;
83 return _rename_r (_REENT, old, new);
86 #endif