aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-06-01 22:36:39 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-06-01 22:36:39 +0000
commitcd2663f15e74274619dd97dc382bb858ac255872 (patch)
treef86565e574c3488794383b910b9f3fa3ae27df48 /coreutils
parentd78920675f31d6ec87dc883c4edc0f3862b22f6a (diff)
downloadbusybox-w32-cd2663f15e74274619dd97dc382bb858ac255872.tar.gz
busybox-w32-cd2663f15e74274619dd97dc382bb858ac255872.tar.bz2
busybox-w32-cd2663f15e74274619dd97dc382bb858ac255872.zip
ash: optional printf builtin. +25 bytes if off, +35 if on.
by Cristian Ionescu-Idbohrn.
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/Kbuild1
-rw-r--r--coreutils/chown.c1
-rw-r--r--coreutils/printf.c18
3 files changed, 16 insertions, 4 deletions
diff --git a/coreutils/Kbuild b/coreutils/Kbuild
index cb4543912..a5a2d4c26 100644
--- a/coreutils/Kbuild
+++ b/coreutils/Kbuild
@@ -54,6 +54,7 @@ lib-$(CONFIG_NOHUP) += nohup.o
54lib-$(CONFIG_OD) += od.o 54lib-$(CONFIG_OD) += od.o
55lib-$(CONFIG_PRINTENV) += printenv.o 55lib-$(CONFIG_PRINTENV) += printenv.o
56lib-$(CONFIG_PRINTF) += printf.o 56lib-$(CONFIG_PRINTF) += printf.o
57lib-$(CONFIG_ASH_BUILTIN_PRINTF) += printf.o
57lib-$(CONFIG_PWD) += pwd.o 58lib-$(CONFIG_PWD) += pwd.o
58lib-$(CONFIG_READLINK) += readlink.o 59lib-$(CONFIG_READLINK) += readlink.o
59lib-$(CONFIG_REALPATH) += realpath.o 60lib-$(CONFIG_REALPATH) += realpath.o
diff --git a/coreutils/chown.c b/coreutils/chown.c
index eaaefaf29..78377e6a0 100644
--- a/coreutils/chown.c
+++ b/coreutils/chown.c
@@ -61,7 +61,6 @@ static int fileAction(const char *fileName, struct stat *statbuf,
61 return FALSE; 61 return FALSE;
62} 62}
63 63
64int chown_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
65int chown_main(int argc ATTRIBUTE_UNUSED, char **argv) 64int chown_main(int argc ATTRIBUTE_UNUSED, char **argv)
66{ 65{
67 int retval = EXIT_SUCCESS; 66 int retval = EXIT_SUCCESS;
diff --git a/coreutils/printf.c b/coreutils/printf.c
index ebe961564..b7752369c 100644
--- a/coreutils/printf.c
+++ b/coreutils/printf.c
@@ -193,6 +193,7 @@ static char **print_formatted(char *f, char **argv)
193 unsigned direc_length; /* Length of % directive. */ 193 unsigned direc_length; /* Length of % directive. */
194 int field_width; /* Arg to first '*', or -1 if none. */ 194 int field_width; /* Arg to first '*', or -1 if none. */
195 int precision; /* Arg to second '*', or -1 if none. */ 195 int precision; /* Arg to second '*', or -1 if none. */
196 char **saved_argv = argv;
196 197
197 for (; *f; ++f) { 198 for (; *f; ++f) {
198 switch (*f) { 199 switch (*f) {
@@ -264,8 +265,9 @@ static char **print_formatted(char *f, char **argv)
264 precision, ""); 265 precision, "");
265 break; 266 break;
266 case '\\': 267 case '\\':
267 if (*++f == 'c') 268 if (*++f == 'c') {
268 exit(EXIT_SUCCESS); 269 return saved_argv; /* causes main() to exit */
270 }
269 bb_putchar(bb_process_escape_sequence((const char **)&f)); 271 bb_putchar(bb_process_escape_sequence((const char **)&f));
270 f--; 272 f--;
271 break; 273 break;
@@ -277,12 +279,22 @@ static char **print_formatted(char *f, char **argv)
277 return argv; 279 return argv;
278} 280}
279 281
280int printf_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
281int printf_main(int argc ATTRIBUTE_UNUSED, char **argv) 282int printf_main(int argc ATTRIBUTE_UNUSED, char **argv)
282{ 283{
283 char *format; 284 char *format;
284 char **argv2; 285 char **argv2;
285 286
287 /* We must check that stdout is not closed.
288 * The reason for this is highly non-obvious. printf_main is used from shell.
289 * Shell must correctly handle 'printf "%s" foo'
290 * if stdout is closed. With stdio, output gets shoveled into
291 * stdout buffer, and even fflush cannot clear it out. It seems that
292 * even if libc receives EBADF on write attempts, it feels determined
293 * to output data no matter what. So it will try later,
294 * and possibly will clobber future output. Not good. */
295 if (dup2(1, 1) != 1)
296 return -1;
297
286 /* bash builtin errors out on "printf '-%s-\n' foo", 298 /* bash builtin errors out on "printf '-%s-\n' foo",
287 * coreutils-6.9 works. Both work with "printf -- '-%s-\n' foo". 299 * coreutils-6.9 works. Both work with "printf -- '-%s-\n' foo".
288 * We will mimic coreutils. */ 300 * We will mimic coreutils. */