summaryrefslogtreecommitdiff
path: root/lib/rename.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1999-03-30 04:48:17 +0000
committerJim Meyering <jim@meyering.net>1999-03-30 04:48:17 +0000
commit2080baecff01175f1fa79e9b38d0eecff22b38e8 (patch)
tree467fb87d028770ec2938749a08312658303f25a3 /lib/rename.c
parent69952761e1679f69725e9932143b18c44bb72a9d (diff)
downloadcoreutils-2080baecff01175f1fa79e9b38d0eecff22b38e8.tar.xz
(rename): Use pid_t instead of int; check status
against zero. This is to improve portability.
Diffstat (limited to 'lib/rename.c')
-rw-r--r--lib/rename.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/lib/rename.c b/lib/rename.c
index d649e2e96..8dcd3e514 100644
--- a/lib/rename.c
+++ b/lib/rename.c
@@ -41,7 +41,6 @@ int
rename (char *from, char *to)
{
struct stat from_stats, to_stats;
- int pid, status;
if (stat (from, &from_stats))
return -1;
@@ -74,23 +73,27 @@ rename (char *from, char *to)
if (S_ISDIR (from_stats.st_mode))
{
/* Need a setuid root process to link and unlink directories. */
- pid = fork ();
+ int status;
+ pid_t pid = fork ();
switch (pid)
{
case -1: /* Error. */
- error (1, errno, "cannot fork");
+ return -1; /* errno already set */
case 0: /* Child. */
execl (MVDIR, "mvdir", from, to, (char *) 0);
- error (255, errno, "cannot run `%s'", MVDIR);
+ _exit (1);
default: /* Parent. */
while (wait (&status) != pid)
/* Do nothing. */ ;
- errno = 0; /* mvdir printed the system error message. */
if (status)
- return -1;
+ {
+ /* MVDIR failed. */
+ errno = EIO;
+ return -1;
+ }
}
}
else