1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 16:18:12 +00:00

LibC: Remove a bunch of pointless rc temporaries in stdio.cpp

This commit is contained in:
Andreas Kling 2021-09-09 14:25:35 +02:00
parent f1ce43bdbf
commit 16105091ba

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2020, Sergey Bugaev <bugaevc@serenityos.org> * Copyright (c) 2020, Sergey Bugaev <bugaevc@serenityos.org>
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
@ -1174,8 +1174,7 @@ FILE* popen(const char* command, const char* type)
int pipe_fds[2]; int pipe_fds[2];
int rc = pipe(pipe_fds); if (pipe(pipe_fds) < 0) {
if (rc < 0) {
ScopedValueRollback rollback(errno); ScopedValueRollback rollback(errno);
perror("pipe"); perror("pipe");
return nullptr; return nullptr;
@ -1190,16 +1189,14 @@ FILE* popen(const char* command, const char* type)
return nullptr; return nullptr;
} else if (child_pid == 0) { } else if (child_pid == 0) {
if (*type == 'r') { if (*type == 'r') {
int rc = dup2(pipe_fds[1], STDOUT_FILENO); if (dup2(pipe_fds[1], STDOUT_FILENO) < 0) {
if (rc < 0) {
perror("dup2"); perror("dup2");
exit(1); exit(1);
} }
close(pipe_fds[0]); close(pipe_fds[0]);
close(pipe_fds[1]); close(pipe_fds[1]);
} else if (*type == 'w') { } else if (*type == 'w') {
int rc = dup2(pipe_fds[0], STDIN_FILENO); if (dup2(pipe_fds[0], STDIN_FILENO) < 0) {
if (rc < 0) {
perror("dup2"); perror("dup2");
exit(1); exit(1);
} }
@ -1207,8 +1204,7 @@ FILE* popen(const char* command, const char* type)
close(pipe_fds[1]); close(pipe_fds[1]);
} }
int rc = execl("/bin/sh", "sh", "-c", command, nullptr); if (execl("/bin/sh", "sh", "-c", command, nullptr) < 0)
if (rc < 0)
perror("execl"); perror("execl");
exit(1); exit(1);
} }
@ -1232,19 +1228,17 @@ int pclose(FILE* stream)
VERIFY(stream->popen_child() != 0); VERIFY(stream->popen_child() != 0);
int wstatus = 0; int wstatus = 0;
int rc = waitpid(stream->popen_child(), &wstatus, 0); if (waitpid(stream->popen_child(), &wstatus, 0) < 0)
if (rc < 0) return -1;
return rc;
return wstatus; return wstatus;
} }
int remove(const char* pathname) int remove(const char* pathname)
{ {
int rc = unlink(pathname); if (unlink(pathname) < 0 && errno == EISDIR)
if (rc < 0 && errno == EISDIR)
return rmdir(pathname); return rmdir(pathname);
return rc; return 0;
} }
int scanf(const char* fmt, ...) int scanf(const char* fmt, ...)