[BusyBox] watch: dup2 [PATCH]
Shaun Jackman
sjackman at gmail.com
Wed Jun 29 16:07:31 UTC 2005
This patch replaces a close/dup call with dup2, which could reduce
code size by a couple bytes.
Cheers,
Shaun
2005-06-29 Shaun Jackman <sjackman at gmail.com>
* coreutils/watch.c (watch_main): Use dup2 instead of close/dup.
--- coreutils/watch.c
+++ coreutils/watch.c
@@ -84,7 +84,7 @@
header[len] = 0;
/* thanks to lye, who showed me how to redirect stdin/stdout */
- old_stdout = dup(1);
+ old_stdout = dup(STDOUT_FILENO);
while (1) {
time(&t);
@@ -98,8 +98,7 @@
sleep(period);
} else if (0 == pid) {
//child
- close(1);
- dup(old_stdout);
+ dup2(old_stdout, STDOUT_FILENO);
run_applet_by_name(*watched_argv, argc, watched_argv);
execvp(*watched_argv, watched_argv);
bb_perror_msg_and_die(*watched_argv);
More information about the busybox
mailing list