]>
git.ipfire.org Git - thirdparty/bash.git/blob - lib/sh/rename.c
2 * rename - rename a file
5 /* Copyright (C) 1999 Free Software Foundation, Inc.
7 This file is part of GNU Bash, the Bourne Again SHell.
9 Bash is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 Bash is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with Bash. If not, see <http://www.gnu.org/licenses/>.
25 #if !defined (HAVE_RENAME)
27 #include <bashtypes.h>
28 #include <posixstat.h>
30 #if defined (HAVE_UNISTD_H)
43 const char *from
, *to
;
47 if (stat (from
, &fb
) < 0)
50 if (stat (to
, &tb
) < 0)
57 if (fb
.st_dev
== tb
.st_dev
&& fb
.st_ino
== tb
.st_ino
)
58 return 0; /* same file */
59 if (unlink (to
) < 0 && errno
!= ENOENT
)
63 if (link (from
, to
) < 0)
66 if (unlink (from
) < 0 && errno
!= ENOENT
)
76 #endif /* !HAVE_RENAME */