* cgraph.c (cgraph_node::get_untransformed_body): Pass compressed
[official-gcc.git] / libiberty / rename.c
blobad342ffca65c59479667d11b77ba2ac8e52ee58a
1 /* rename -- rename a file
2 This function is in the public domain. */
4 /*
6 @deftypefn Supplemental int rename (const char *@var{old}, const char *@var{new})
8 Renames a file from @var{old} to @var{new}. If @var{new} already
9 exists, it is removed.
11 @end deftypefn
15 #include "ansidecl.h"
16 #ifdef HAVE_CONFIG_H
17 #include "config.h"
18 #endif
19 #include <errno.h>
20 #ifdef HAVE_UNISTD_H
21 #include <unistd.h>
22 #endif
24 int
25 rename (const char *zfrom, const char *zto)
27 if (link (zfrom, zto) < 0)
29 if (errno != EEXIST)
30 return -1;
31 if (unlink (zto) < 0
32 || link (zfrom, zto) < 0)
33 return -1;
35 return unlink (zfrom);