diff options
author | Peter Stromberg <wilfried@cvs.openbsd.org> | 2001-09-21 15:08:17 +0000 |
---|---|---|
committer | Peter Stromberg <wilfried@cvs.openbsd.org> | 2001-09-21 15:08:17 +0000 |
commit | 3010bd9840f459d47f875c7a319a2256a51030c5 (patch) | |
tree | c82796279cb2ce9c9a547d347b5a2ce717dd4f8b | |
parent | 12c27aa21302c48ef1e32638858ebe0a5ce2183c (diff) |
correct fork logic and rewrite for clarity, ok todd@
-rw-r--r-- | usr.bin/mg/fileio.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/usr.bin/mg/fileio.c b/usr.bin/mg/fileio.c index 567684ca869..f348f465117 100644 --- a/usr.bin/mg/fileio.c +++ b/usr.bin/mg/fileio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fileio.c,v 1.19 2001/07/09 07:04:49 deraadt Exp $ */ +/* $OpenBSD: fileio.c,v 1.20 2001/09/21 15:08:16 wilfried Exp $ */ /* * POSIX fileio.c @@ -398,14 +398,16 @@ copy(frname, toname) pid_t pid; int status; - if ((pid = vfork())) { - if (pid == -1) - return -1; + switch ((pid = vfork())) { + case -1: + return -1; + case 0: execl("/bin/cp", "cp", frname, toname, (char *)NULL); _exit(1); /* shouldn't happen */ + default: + waitpid(pid, &status, 0); + return (WIFEXITED(status) && WEXITSTATUS(status) == 0); } - waitpid(pid, &status, 0); - return (WIFEXITED(status) && WEXITSTATUS(status) == 0); } BUFFER * |