Use switch with fork()
Allows dropping a local variable if the explicit PID is not needed and it makes it clearer what happens. Also, one should always strive for consistency for cases like these.
This commit is contained in:
7
tar.c
7
tar.c
@@ -47,17 +47,16 @@ static char filtermode;
|
||||
static FILE *
|
||||
decomp(FILE *fp)
|
||||
{
|
||||
pid_t pid;
|
||||
int fds[2];
|
||||
|
||||
if (pipe(fds) < 0)
|
||||
eprintf("pipe:");
|
||||
|
||||
pid = fork();
|
||||
if (pid < 0) {
|
||||
switch (fork()) {
|
||||
case -1:
|
||||
weprintf("fork:");
|
||||
_exit(1);
|
||||
} else if (!pid) {
|
||||
case 0:
|
||||
dup2(fileno(fp), 0);
|
||||
dup2(fds[1], 1);
|
||||
close(fds[0]);
|
||||
|
Reference in New Issue
Block a user