summaryrefslogtreecommitdiff
path: root/libc/stdio
diff options
context:
space:
mode:
Diffstat (limited to 'libc/stdio')
-rw-r--r--libc/stdio/Makefile17
-rw-r--r--libc/stdio/printf.c54
-rw-r--r--libc/stdio/scanf.c37
3 files changed, 46 insertions, 62 deletions
diff --git a/libc/stdio/Makefile b/libc/stdio/Makefile
index 67ef71ff8..26ab9cfcc 100644
--- a/libc/stdio/Makefile
+++ b/libc/stdio/Makefile
@@ -24,19 +24,6 @@ TOPDIR=../
include $(TOPDIR)Rules.mak
LIBC=$(TOPDIR)libc.a
-PRINTF_FLAGS =
-SCANF_FLAGS =
-
-ifeq ($(HAS_FLOATS),true)
- PRINTF_FLAGS += -DWANT_DOUBLE
- SCANF_FLAGS += -DWANT_DOUBLE
-endif
-
-ifeq ($(HAS_LONG_LONG),true)
- PRINTF_FLAGS += -DWANT_LONG_LONG
- SCANF_FLAGS += -DWANT_LONG_LONG
-endif
-
MSRC=stdio.c
MOBJ=_stdio_init.o \
_alloc_stdio_buffer.o _free_stdio_buffer_of_file.o _free_stdio_stream.o \
@@ -71,11 +58,11 @@ $(MOBJ): $(MSRC)
$(STRIPTOOL) -x -R .note -R .comment $*.o
$(MOBJ2): $(MSRC2)
- $(CC) $(CFLAGS) $(PRINTF_FLAGS) -DL_$* $< -c -o $*.o
+ $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
$(STRIPTOOL) -x -R .note -R .comment $*.o
$(MOBJ3): $(MSRC3)
- $(CC) $(CFLAGS) $(SCANF_FLAGS) -DL_$* $< -c -o $*.o
+ $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
$(STRIPTOOL) -x -R .note -R .comment $*.o
$(COBJS): %.o : %.c
diff --git a/libc/stdio/printf.c b/libc/stdio/printf.c
index ca3ffb772..245a78519 100644
--- a/libc/stdio/printf.c
+++ b/libc/stdio/printf.c
@@ -88,8 +88,8 @@
/* These are now set in the Makefile based on Config. */
/*
-#define WANT_LONG_LONG 0
-#define WANT_DOUBLE 0
+#define __UCLIBC_HAS_LONG_LONG__ 0
+#define __UCLIBC_HAS_FLOATS__ 0
*/
/* 2) An error message is inserted into the stream, an arg of the
@@ -101,7 +101,7 @@
*/
#define WANT_LONG_LONG_ERROR 0
-#define WANT_DOUBLE_ERROR 0
+#define WANT_FLOAT_ERROR 0
/*
* Set to support GNU extension of %m to print string corresponding to errno.
@@ -317,21 +317,21 @@ enum {
/* layout 01234 */
static const char spec[] = "+-#0 ";
-#if WANT_LONG_LONG || WANT_LONG_LONG_ERROR
+#if __UCLIBC_HAS_LONG_LONG__ || WANT_LONG_LONG_ERROR
static const char qual[] = "hlLq";
#else
static const char qual[] = "hl";
#endif
-#if !WANT_LONG_LONG && WANT_LONG_LONG_ERROR
+#if !__UCLIBC_HAS_LONG_LONG__ && WANT_LONG_LONG_ERROR
static const char ll_err[] = "<LONG-LONG>";
#endif
-#if !WANT_DOUBLE && WANT_DOUBLE_ERROR
+#if !__UCLIBC_HAS_FLOATS__ && WANT_FLOAT_ERROR
static const char dbl_err[] = "<DOUBLE>";
#endif
-#if WANT_DOUBLE || WANT_DOUBLE_ERROR
+#if __UCLIBC_HAS_FLOATS__ || WANT_FLOAT_ERROR
/* layout 012345678901234567 */
static const char u_spec[] = "%nbopxXudicsfgGeEaA";
#else
@@ -352,7 +352,7 @@ int vfnprintf(FILE * op, size_t max_size, const char *fmt, va_list ap)
int preci, width;
#define upcase i
int radix, dpoint /*, upcase*/;
-#if WANT_LONG_LONG
+#if __UCLIBC_HAS_LONG_LONG__
char tmp[65];
#else
char tmp[33];
@@ -435,12 +435,12 @@ int vfnprintf(FILE * op, size_t max_size, const char *fmt, va_list ap)
if (*p == *fmt) {
lval = p - qual;
++fmt;
-#if WANT_LONG_LONG || WANT_LONG_LONG_ERROR
+#if __UCLIBC_HAS_LONG_LONG__ || WANT_LONG_LONG_ERROR
if ((*p == 'l') && (*fmt == *p)) {
++lval;
++fmt;
}
-#endif /* WANT_LONG_LONG || WANT_LONG_LONG_ERROR */
+#endif /* __UCLIBC_HAS_LONG_LONG__ || WANT_LONG_LONG_ERROR */
}
}
@@ -470,18 +470,18 @@ int vfnprintf(FILE * op, size_t max_size, const char *fmt, va_list ap)
lval = (sizeof(char *) == sizeof(long));
upcase = 0;
}
-#if WANT_LONG_LONG || WANT_LONG_LONG_ERROR
+#if __UCLIBC_HAS_LONG_LONG__ || WANT_LONG_LONG_ERROR
if (lval >= 2) {
-#if WANT_LONG_LONG
+#if __UCLIBC_HAS_LONG_LONG__
p = __ulltostr(tmp + sizeof(tmp) - 1,
va_arg(ap, unsigned long long),
radix, upcase);
#else
(void) va_arg(ap, unsigned long long); /* cary on */
p = (char *) ll_err;
-#endif /* WANT_LONG_LONG */
+#endif /* __UCLIBC_HAS_LONG_LONG__ */
} else {
-#endif /* WANT_LONG_LONG || WANT_LONG_LONG_ERROR */
+#endif /* __UCLIBC_HAS_LONG_LONG__ || WANT_LONG_LONG_ERROR */
#if UINT_MAX != ULONG_MAX
/* sizeof(unsigned int) != sizeof(unsigned long) */
p = __ultostr(tmp + sizeof(tmp) - 1, (unsigned long)
@@ -495,9 +495,9 @@ int vfnprintf(FILE * op, size_t max_size, const char *fmt, va_list ap)
va_arg(ap, unsigned long),
radix, upcase);
#endif
-#if WANT_LONG_LONG || WANT_LONG_LONG_ERROR
+#if __UCLIBC_HAS_LONG_LONG__ || WANT_LONG_LONG_ERROR
}
-#endif /* WANT_LONG_LONG || WANT_LONG_LONG_ERROR */
+#endif /* __UCLIBC_HAS_LONG_LONG__ || WANT_LONG_LONG_ERROR */
flag[FLAG_PLUS] = '\0'; /* meaningless for unsigned */
if (flag[FLAG_HASH] && (*p != '0')) { /* non-zero */
if (radix == 8) {
@@ -514,17 +514,17 @@ int vfnprintf(FILE * op, size_t max_size, const char *fmt, va_list ap)
}
}
} else if (p-u_spec < 10) { /* signed conversion */
-#if WANT_LONG_LONG || WANT_LONG_LONG_ERROR
+#if __UCLIBC_HAS_LONG_LONG__ || WANT_LONG_LONG_ERROR
if (lval >= 2) {
-#if WANT_LONG_LONG
+#if __UCLIBC_HAS_LONG_LONG__
p = __lltostr(tmp + sizeof(tmp) - 1,
va_arg(ap, long long), 10, 0);
#else
(void) va_arg(ap, long long); /* carry on */
p = (char *) ll_err;
-#endif /* WANT_LONG_LONG */
+#endif /* __UCLIBC_HAS_LONG_LONG__ */
} else {
-#endif /* WANT_LONG_LONG || WANT_LONG_LONG_ERROR */
+#endif /* __UCLIBC_HAS_LONG_LONG__ || WANT_LONG_LONG_ERROR */
#if INT_MAX != LONG_MAX
/* sizeof(int) != sizeof(long) */
p = __ltostr(tmp + sizeof(tmp) - 1, (long)
@@ -536,9 +536,9 @@ int vfnprintf(FILE * op, size_t max_size, const char *fmt, va_list ap)
p = __ltostr(tmp + sizeof(tmp) - 1, (long)
va_arg(ap, long), 10, 0);
#endif
-#if WANT_LONG_LONG || WANT_LONG_LONG_ERROR
+#if __UCLIBC_HAS_LONG_LONG__ || WANT_LONG_LONG_ERROR
}
-#endif /* WANT_LONG_LONG || WANT_LONG_LONG_ERROR */
+#endif /* __UCLIBC_HAS_LONG_LONG__ || WANT_LONG_LONG_ERROR */
} else if (p-u_spec < 12) { /* character or string */
flag[FLAG_PLUS] = '\0';
flag[FLAG_0_PAD] = ' ';
@@ -551,10 +551,10 @@ int vfnprintf(FILE * op, size_t max_size, const char *fmt, va_list ap)
p = "(null)";
}
}
-#if WANT_DOUBLE || WANT_DOUBLE_ERROR
+#if __UCLIBC_HAS_FLOATS__ || WANT_FLOAT_ERROR
} else if (p-u_spec < 27) { /* floating point */
-#endif /* WANT_DOUBLE || WANT_DOUBLE_ERROR */
-#if WANT_DOUBLE
+#endif /* __UCLIBC_HAS_FLOATS__ || WANT_FLOAT_ERROR */
+#if __UCLIBC_HAS_FLOATS__
if (preci < 0) {
preci = 6;
}
@@ -565,11 +565,11 @@ int vfnprintf(FILE * op, size_t max_size, const char *fmt, va_list ap)
: va_arg(ap, double)),
flag, width, preci, *fmt);
goto nextfmt;
-#elif WANT_DOUBLE_ERROR
+#elif WANT_FLOAT_ERROR
(void) ((lval > 1) ? va_arg(ap, long double)
: va_arg(ap, double)); /* carry on */
p = (char *) dbl_err;
-#endif /* WANT_DOUBLE */
+#endif /* __UCLIBC_HAS_FLOATS__ */
}
#if WANT_GNU_ERRNO
diff --git a/libc/stdio/scanf.c b/libc/stdio/scanf.c
index dbb6f8d61..6fd802c73 100644
--- a/libc/stdio/scanf.c
+++ b/libc/stdio/scanf.c
@@ -135,9 +135,15 @@ _strto_ll(const char *str, char **endptr, int base, int uflag);
extern unsigned long
_strto_l(const char *str, char **endptr, int base, int uflag);
-/* #define skip() do{c=getc(fp); if (c<1) goto done;}while(isspace(c))*/
+struct scan_cookie {
+ FILE *fp;
+ int nread;
+ int width;
+ int ungot_char;
+ int ungot_flag;
+};
-#if WANT_LONG_LONG || WANT_LONG_LONG_ERROR
+#if __UCLIBC_HAS_LONG_LONG__
static const char qual[] = "hl" /* "jtz" */ "Lq";
/* char = -2, short = -1, int = 0, long = 1, long long = 2 */
static const char qsz[] = { -1, 1, 2, 2 };
@@ -146,7 +152,8 @@ static const char qual[] = "hl" /* "jtz" */;
static const char qsz[] = { -1, 1, };
#endif
-#if WANT_DOUBLE || WANT_DOUBLE_ERROR
+#if __UCLIBC_HAS_FLOATS__
+static int __strtold(long double *ld, struct scan_cookie *sc);
/*01234567890123456 */
static const char spec[] = "%n[csoupxXidfeEgG";
#else
@@ -155,16 +162,6 @@ static const char spec[] = "%n[csoupxXid";
/* radix[i] <-> spec[i+5] o u p x X i d */
static const char radix[] = { 8, 10, 16, 16, 16, 0, 10 };
-struct scan_cookie {
- FILE *fp;
- int nread;
- int width;
- int ungot_char;
- int ungot_flag;
-};
-
-static int __strtold(long double *ld, struct scan_cookie *sc);
-
static void init_scan_cookie(struct scan_cookie *sc, FILE *fp)
{
sc->fp = fp;
@@ -228,7 +225,7 @@ FILE *fp;
const char *format;
va_list ap;
{
-#if WANT_LONG_LONG
+#if __UCLIBC_HAS_LONG_LONG__
#define STRTO_L_(s,e,b,u) _strto_ll(s,e,b,u)
#define MAX_DIGITS 64
#define UV_TYPE unsigned long long
@@ -239,7 +236,7 @@ va_list ap;
#define UV_TYPE unsigned long
#define V_TYPE long
#endif
-#if WANT_DOUBLE
+#if __UCLIBC_HAS_FLOATS__
long double ld;
#endif
UV_TYPE uv;
@@ -429,7 +426,7 @@ va_list ap;
vp = va_arg(ap, void *);
switch (lval) {
case 2: /* If no long long, treat as long . */
-#if WANT_LONG_LONG
+#if __UCLIBC_HAS_LONG_LONG__
*((unsigned long long *)vp) = uv;
break;
#endif
@@ -437,7 +434,7 @@ va_list ap;
#if ULONG_MAX == UINT_MAX
case 0: /* int and long int are the same */
#endif
-#if WANT_LONG_LONG
+#if __UCLIBC_HAS_LONG_LONG__
if (usflag) {
if (uv > ULONG_MAX) {
uv = ULONG_MAX;
@@ -495,7 +492,7 @@ va_list ap;
}
goto nextfmt;
}
-#if WANT_DOUBLE
+#if __UCLIBC_HAS_FLOATS__
else { /* floating point */
if (sc.width <= 0) {
goto done;
@@ -555,7 +552,7 @@ va_list ap;
}
/*****************************************************************************/
-#if WANT_DOUBLE
+#if __UCLIBC_HAS_FLOATS__
#include <float.h>
@@ -690,5 +687,5 @@ int __strtold(long double *ld, struct scan_cookie *sc)
scan_ungetc(sc);
return 0;
}
-#endif /* WANT_DOUBLE */
+#endif /* __UCLIBC_HAS_FLOATS__ */
#endif