Skip to content

Commit 3a13e83

Browse files
committed
fix: avoid unnessary perror()
1 parent c9ce395 commit 3a13e83

1 file changed

Lines changed: 0 additions & 13 deletions

File tree

src/exec.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,11 @@ static size_t get_max_pipe_size(void)
3333
{
3434
int fd = open("/proc/sys/fs/pipe-max-size", O_RDONLY);
3535
if (fd < 0) {
36-
perror("open /proc/sys/fs/pipe-max-size");
3736
return 65536; // Default pipe size
3837
}
3938
char buffer[16];
4039
ssize_t bytes_read = read(fd, buffer, sizeof(buffer) - 1);
4140
if (bytes_read < 0) {
42-
perror("read /proc/sys/fs/pipe-max-size");
4341
close(fd);
4442
return 65536; // Default pipe size
4543
}
@@ -80,13 +78,11 @@ char *rurima_fork_execvp_get_stdout_ignore_err(const char *_Nonnull argv[])
8078
// Create a pipe.
8179
int pipefd[2];
8280
if (pipe(pipefd) == -1) {
83-
perror("pipe");
8481
return NULL;
8582
}
8683
// fork(2) and then execvp(3).
8784
int pid = fork();
8885
if (pid == -1) {
89-
perror("fork");
9086
return NULL;
9187
}
9288
if (pid == 0) {
@@ -117,7 +113,6 @@ char *rurima_fork_execvp_get_stdout_ignore_err(const char *_Nonnull argv[])
117113
}
118114
}
119115
if (bytes_read == -1) {
120-
perror("read");
121116
free(output);
122117
close(pipefd[0]);
123118
return NULL;
@@ -143,13 +138,11 @@ char *rurima_fork_execvp_get_stdout(const char *_Nonnull argv[])
143138
// Create a pipe.
144139
int pipefd[2];
145140
if (pipe(pipefd) == -1) {
146-
perror("pipe");
147141
return NULL;
148142
}
149143
// fork(2) and then execvp(3).
150144
int pid = fork();
151145
if (pid == -1) {
152-
perror("fork");
153146
return NULL;
154147
}
155148
if (pid == 0) {
@@ -179,7 +172,6 @@ char *rurima_fork_execvp_get_stdout(const char *_Nonnull argv[])
179172
}
180173
}
181174
if (bytes_read == -1) {
182-
perror("read");
183175
free(output);
184176
close(pipefd[0]);
185177
return NULL;
@@ -252,21 +244,18 @@ char *rurima_fork_execvp_get_stdout_with_input(const char *_Nonnull argv[], cons
252244
// Create a pipe.
253245
int pipefd_in[2];
254246
if (pipe(pipefd_in) == -1) {
255-
perror("pipe");
256247
return NULL;
257248
}
258249
// Set the maximum pipe size.
259250
size_t max_pipe_size = get_max_pipe_size();
260251
fcntl(pipefd_in[1], F_SETPIPE_SZ, max_pipe_size);
261252
int pipefd_out[2];
262253
if (pipe(pipefd_out) == -1) {
263-
perror("pipe");
264254
return NULL;
265255
}
266256
// fork(2) and then execvp(3).
267257
int pid = fork();
268258
if (pid == -1) {
269-
perror("fork");
270259
return NULL;
271260
}
272261
if (pid == 0) {
@@ -295,7 +284,6 @@ char *rurima_fork_execvp_get_stdout_with_input(const char *_Nonnull argv[], cons
295284
close(pipefd_in[0]);
296285
// Write the input to the write end of the input pipe.
297286
if (write(pipefd_in[1], input, strlen(input)) == -1) {
298-
perror("write");
299287
close(pipefd_in[1]);
300288
close(pipefd_out[0]);
301289
return NULL;
@@ -316,7 +304,6 @@ char *rurima_fork_execvp_get_stdout_with_input(const char *_Nonnull argv[], cons
316304
}
317305
}
318306
if (bytes_read == -1) {
319-
perror("read");
320307
free(output);
321308
close(pipefd_out[0]);
322309
return NULL;

0 commit comments

Comments
 (0)