aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/echo.c11
-rw-r--r--coreutils/printf.c7
2 files changed, 12 insertions, 6 deletions
diff --git a/coreutils/echo.c b/coreutils/echo.c
index 36cb6b3af..decca095f 100644
--- a/coreutils/echo.c
+++ b/coreutils/echo.c
@@ -46,8 +46,11 @@ int echo_main(int argc UNUSED_PARAM, char **argv)
46 * even if libc receives EBADF on write attempts, it feels determined 46 * even if libc receives EBADF on write attempts, it feels determined
47 * to output data no matter what. So it will try later, 47 * to output data no matter what. So it will try later,
48 * and possibly will clobber future output. Not good. */ 48 * and possibly will clobber future output. Not good. */
49 if (dup2(1, 1) != 1) 49// TODO: check fcntl() & O_ACCMODE == O_WRONLY or O_RDWR?
50 return -1; 50 if (fcntl(1, F_GETFL) == -1)
51 return 1; /* match coreutils 6.10 (sans error msg to stderr) */
52 //if (dup2(1, 1) != 1) - old way
53 // return 1;
51 54
52 arg = *++argv; 55 arg = *++argv;
53 if (!arg) 56 if (!arg)
@@ -58,8 +61,8 @@ int echo_main(int argc UNUSED_PARAM, char **argv)
58 char eflag = 0; 61 char eflag = 0;
59 62
60 /* We must check that stdout is not closed. */ 63 /* We must check that stdout is not closed. */
61 if (dup2(1, 1) != 1) 64 if (fcntl(1, F_GETFL) == -1)
62 return -1; 65 return 1;
63 66
64 while (1) { 67 while (1) {
65 arg = *++argv; 68 arg = *++argv;
diff --git a/coreutils/printf.c b/coreutils/printf.c
index 72acbc751..76524f706 100644
--- a/coreutils/printf.c
+++ b/coreutils/printf.c
@@ -348,8 +348,11 @@ int printf_main(int argc UNUSED_PARAM, char **argv)
348 * even if libc receives EBADF on write attempts, it feels determined 348 * even if libc receives EBADF on write attempts, it feels determined
349 * to output data no matter what. So it will try later, 349 * to output data no matter what. So it will try later,
350 * and possibly will clobber future output. Not good. */ 350 * and possibly will clobber future output. Not good. */
351 if (dup2(1, 1) != 1) 351// TODO: check fcntl() & O_ACCMODE == O_WRONLY or O_RDWR?
352 return -1; 352 if (fcntl(1, F_GETFL) == -1)
353 return 1; /* match coreutils 6.10 (sans error msg to stderr) */
354 //if (dup2(1, 1) != 1) - old way
355 // return 1;
353 356
354 /* bash builtin errors out on "printf '-%s-\n' foo", 357 /* bash builtin errors out on "printf '-%s-\n' foo",
355 * coreutils-6.9 works. Both work with "printf -- '-%s-\n' foo". 358 * coreutils-6.9 works. Both work with "printf -- '-%s-\n' foo".