/* vi: set sw=4 ts=4: */
-/* printf - format and print data
+/*
+ * printf - format and print data
*
* Copyright 1999 Dave Cinege
* Portions copyright (C) 1990-1996 Free Software Foundation, Inc.
/* 19990508 Busy Boxed! Dave Cinege */
//config:config PRINTF
-//config: bool "printf (3.3 kb)"
+//config: bool "printf (3.8 kb)"
//config: default y
//config: help
//config: printf is used to format and print specified strings.
static void FAST_FUNC conv_strtoull(const char *arg, void *result)
{
+ /* Allow leading '+' - bb_strtoull() by itself does not allow it,
+ * and probably shouldn't (other callers might require purely numeric
+ * inputs to be allowed.
+ */
+ if (arg[0] == '+')
+ arg++;
*(unsigned long long*)result = bb_strtoull(arg, NULL, 0);
/* both coreutils 6.10 and bash 3.2:
* $ printf '%x\n' -2
}
static void FAST_FUNC conv_strtoll(const char *arg, void *result)
{
+ if (arg[0] == '+')
+ arg++;
*(long long*)result = bb_strtoll(arg, NULL, 0);
}
static void FAST_FUNC conv_strtod(const char *arg, void *result)
if (have_width - 1 == have_prec)
have_width = NULL;
+ /* multiconvert sets errno = 0, but %s needs it cleared */
errno = 0;
switch (format[fmt_length - 1]) {
break;
case 'd':
case 'i':
- llv = my_xstrtoll(argument);
+ llv = my_xstrtoll(skip_whitespace(argument));
print_long:
if (!have_width) {
if (!have_prec)
case 'u':
case 'x':
case 'X':
- llv = my_xstrtoull(argument);
+ llv = my_xstrtoull(skip_whitespace(argument));
/* cheat: unsigned long and long have same width, so... */
goto print_long;
case 's':
if (ENABLE_ASH_PRINTF
&& applet_name[0] != 'p'
) {
- bb_error_msg("usage: printf FORMAT [ARGUMENT...]");
+ bb_simple_error_msg("usage: printf FORMAT [ARGUMENT...]");
return 2; /* bash compat */
}
bb_show_usage();