cc12856649e0436d9c7e5ed48a67d8623bd837db
[platform/upstream/bash.git] / lib / sh / rename.c
1 /*
2  * rename - rename a file
3  */
4
5 /* Copyright (C) 1999 Free Software Foundation, Inc.
6
7    This file is part of GNU Bash, the Bourne Again SHell.
8
9    Bash is free software; you can redistribute it and/or modify it
10    under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 2, or (at your option)
12    any later version.
13
14    Bash is distributed in the hope that it will be useful, but WITHOUT
15    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
17    License for more details.
18
19    You should have received a copy of the GNU General Public License
20    along with Bash; see the file COPYING.  If not, write to the Free
21    Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
22
23 #include <config.h>
24
25 #if !defined (HAVE_RENAME)
26
27 #include <bashtypes.h>
28
29 #if defined (HAVE_UNISTD_H)
30 #  include <unistd.h>
31 #endif
32
33 #include <stdc.h>
34
35 int
36 rename (from, to)
37      const char *from, *to;
38 {
39   unlink (to);
40   if (link (from, to) < 0)
41     return (-1);
42   unlink (from);
43   return (0);
44 }
45 #endif /* !HAVE_RENAME */