1 /* rename.c -- BSD compatible directory function for System V
2 Copyright (C) 1988, 1990 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
18 #include <sys/types.h>
25 #if !defined(S_ISDIR) && defined(S_IFDIR)
26 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
29 /* Rename file FROM to file TO.
30 Return 0 if successful, -1 if not. */
37 struct stat from_stats
;
40 if (stat (from
, &from_stats
))
43 if (unlink (to
) && errno
!= ENOENT
)
46 if (S_ISDIR (from_stats
.st_mode
))
48 /* Need a setuid root process to link and unlink directories. */
53 error (1, errno
, "cannot fork");
56 execl (MVDIR
, "mvdir", from
, to
, (char *) 0);
57 error (255, errno
, "cannot run `%s'", MVDIR
);
59 default: /* Parent. */
60 while (wait (&status
) != pid
)
63 errno
= 0; /* mvdir printed the system error message. */
72 if (unlink (from
) && errno
!= ENOENT
)