diff options
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/echo.c | 11 | ||||
-rw-r--r-- | coreutils/printf.c | 7 |
2 files changed, 12 insertions, 6 deletions
diff --git a/coreutils/echo.c b/coreutils/echo.c index 36cb6b3..decca09 100644 --- a/coreutils/echo.c +++ b/coreutils/echo.c @@ -46,8 +46,11 @@ int echo_main(int argc UNUSED_PARAM, char **argv) * even if libc receives EBADF on write attempts, it feels determined * to output data no matter what. So it will try later, * and possibly will clobber future output. Not good. */ - if (dup2(1, 1) != 1) - return -1; +// TODO: check fcntl() & O_ACCMODE == O_WRONLY or O_RDWR? + if (fcntl(1, F_GETFL) == -1) + return 1; /* match coreutils 6.10 (sans error msg to stderr) */ + //if (dup2(1, 1) != 1) - old way + // return 1; arg = *++argv; if (!arg) @@ -58,8 +61,8 @@ int echo_main(int argc UNUSED_PARAM, char **argv) char eflag = 0; /* We must check that stdout is not closed. */ - if (dup2(1, 1) != 1) - return -1; + if (fcntl(1, F_GETFL) == -1) + return 1; while (1) { arg = *++argv; diff --git a/coreutils/printf.c b/coreutils/printf.c index 72acbc7..76524f7 100644 --- a/coreutils/printf.c +++ b/coreutils/printf.c @@ -348,8 +348,11 @@ int printf_main(int argc UNUSED_PARAM, char **argv) * even if libc receives EBADF on write attempts, it feels determined * to output data no matter what. So it will try later, * and possibly will clobber future output. Not good. */ - if (dup2(1, 1) != 1) - return -1; +// TODO: check fcntl() & O_ACCMODE == O_WRONLY or O_RDWR? + if (fcntl(1, F_GETFL) == -1) + return 1; /* match coreutils 6.10 (sans error msg to stderr) */ + //if (dup2(1, 1) != 1) - old way + // return 1; /* bash builtin errors out on "printf '-%s-\n' foo", * coreutils-6.9 works. Both work with "printf -- '-%s-\n' foo". |