]> git.ipfire.org Git - thirdparty/gcc.git/blame - libiberty/rename.c
* config/microblaze/microblaze.c (microblaze_expand_block_move): Treat
[thirdparty/gcc.git] / libiberty / rename.c
CommitLineData
28e9041c 1/* rename -- rename a file
2 This function is in the public domain. */
3
614a23c6 4/*
5
6@deftypefn Supplemental int rename (const char *@var{old}, const char *@var{new})
7
8Renames a file from @var{old} to @var{new}. If @var{new} already
9exists, it is removed.
10
11@end deftypefn
12
13*/
28e9041c 14
ca3ccdf6 15#include "ansidecl.h"
a1d4f79a 16#ifdef HAVE_CONFIG_H
17#include "config.h"
18#endif
28e9041c 19#include <errno.h>
a1d4f79a 20#ifdef HAVE_UNISTD_H
21#include <unistd.h>
22#endif
28e9041c 23
24int
f8d9d6a0 25rename (const char *zfrom, const char *zto)
28e9041c 26{
27 if (link (zfrom, zto) < 0)
28 {
29 if (errno != EEXIST)
30 return -1;
31 if (unlink (zto) < 0
32 || link (zfrom, zto) < 0)
33 return -1;
34 }
35 return unlink (zfrom);
36}