+ char **argv2;
+
+ /* We must check that stdout is not closed.
+ * The reason for this is highly non-obvious.
+ * printf_main is used from shell.
+ * Shell must correctly handle 'printf "%s" foo'
+ * if stdout is closed. With stdio, output gets shoveled into
+ * stdout buffer, and even fflush cannot clear it out. It seems that
+ * 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. */
+// 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".
+ * We will mimic coreutils. */
+ if (argv[1] && argv[1][0] == '-' && argv[1][1] == '-' && !argv[1][2])
+ argv++;
+ if (!argv[1]) {
+ if (ENABLE_ASH_BUILTIN_PRINTF
+ && applet_name[0] != 'p'
+ ) {
+ bb_error_msg("usage: printf FORMAT [ARGUMENT...]");
+ return 2; /* bash compat */
+ }