From c2fbeebd174072c86adcd9ff58406979479a886c Mon Sep 17 00:00:00 2001 From: Sebastian Schmelzer Date: Thu, 21 Jun 2012 16:05:14 +0200 Subject: commit suggested changes from #860 --- toolchain/uClibc/uClibc-0.9.33.2-scanf.patch | 163 +++++++++++++++++++++++++++ toolchain/uClibc/uClibc-0.9.33.config | 2 +- toolchain/uClibc/uclibc.mk | 10 +- 3 files changed, 169 insertions(+), 6 deletions(-) create mode 100644 toolchain/uClibc/uClibc-0.9.33.2-scanf.patch (limited to 'toolchain') diff --git a/toolchain/uClibc/uClibc-0.9.33.2-scanf.patch b/toolchain/uClibc/uClibc-0.9.33.2-scanf.patch new file mode 100644 index 000000000..5b779db86 --- /dev/null +++ b/toolchain/uClibc/uClibc-0.9.33.2-scanf.patch @@ -0,0 +1,163 @@ +From 8cfb43de636faa401634340d1a18404844f9ba5a Mon Sep 17 00:00:00 2001 +From: Mike Frysinger +Date: Sun, 06 May 2012 07:50:44 +0000 +Subject: stdio: implement assignment-allocation "m" character + +The latest POSIX spec introduces a "m" character to allocate buffers for +the user when using scanf type functions. This is like the old glibc "a" +flag, but now standardized. With packages starting to use these, we need +to implement it. + +for example: + char *s; + sscanf("foo", "%ms", &s); + printf("%s\n", s); + free(s); +This will automatically allocate storage for "s", read in "foo" to it, +and then display it. + +I'm not terribly familiar with the stdio layer, so this could be wrong. +But it seems to work for me. + +Signed-off-by: Mike Frysinger +--- +(limited to 'libc/stdio/_scanf.c') + +diff --git a/libc/stdio/_scanf.c b/libc/stdio/_scanf.c +index f38e72b..952853c 100644 +--- a/libc/stdio/_scanf.c ++++ b/libc/stdio/_scanf.c +@@ -77,14 +77,6 @@ + #include + #endif /* __UCLIBC_HAS_FLOATS__ */ + +-#ifdef __UCLIBC_HAS_SCANF_GLIBC_A_FLAG__ +-#ifdef L_vfscanf +-/* only emit this once */ +-#warning Forcing undef of __UCLIBC_HAS_SCANF_GLIBC_A_FLAG__ until implemented! +-#endif +-#undef __UCLIBC_HAS_SCANF_GLIBC_A_FLAG__ +-#endif +- + #undef __STDIO_HAS_VSSCANF + #if defined(__STDIO_BUFFERS) || !defined(__UCLIBC_HAS_WCHAR__) || defined(__UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__) + #define __STDIO_HAS_VSSCANF 1 +@@ -433,8 +425,9 @@ libc_hidden_def(vswscanf) + + + /* float layout 0123456789012345678901 repeat n for "l[" */ +-#define SPEC_CHARS "npxXoudifFeEgGaACSncs[" +-/* npxXoudif eEgG CS cs[ */ ++#define SPEC_CHARS "npxXoudifFeEgGaACSnmcs[" ++/* npxXoudif eEgG CS cs[ */ ++/* NOTE: the 'm' flag must come before any convs that support it */ + + /* NOTE: Ordering is important! In particular, CONV_LEFTBRACKET + * must immediately precede CONV_c. */ +@@ -444,7 +437,7 @@ enum { + CONV_p, + CONV_x, CONV_X, CONV_o, CONV_u, CONV_d, CONV_i, + CONV_f, CONV_F, CONV_e, CONV_E, CONV_g, CONV_G, CONV_a, CONV_A, +- CONV_C, CONV_S, CONV_LEFTBRACKET, CONV_c, CONV_s, CONV_leftbracket, ++ CONV_C, CONV_S, CONV_LEFTBRACKET, CONV_m, CONV_c, CONV_s, CONV_leftbracket, + CONV_percent, CONV_whitespace /* not in SPEC_* and no flags */ + }; + +@@ -474,7 +467,7 @@ enum { + FLAG_SURPRESS = 0x10, /* MUST BE 1ST!! See DO_FLAGS. */ + FLAG_THOUSANDS = 0x20, + FLAG_I18N = 0x40, /* only works for d, i, u */ +- FLAG_MALLOC = 0x80, /* only works for s, S, and [ (and l[)*/ ++ FLAG_MALLOC = 0x80, /* only works for c, s, S, and [ (and l[)*/ + }; + + +@@ -491,7 +484,7 @@ enum { + /* fFeEgGaA */ (0x0c|FLAG_SURPRESS|FLAG_THOUSANDS|FLAG_I18N), \ + /* C */ ( 0|FLAG_SURPRESS), \ + /* S and l[ */ ( 0|FLAG_SURPRESS|FLAG_MALLOC), \ +- /* c */ (0x04|FLAG_SURPRESS), \ ++ /* c */ (0x04|FLAG_SURPRESS|FLAG_MALLOC), \ + /* s and [ */ (0x04|FLAG_SURPRESS|FLAG_MALLOC), \ + } + +@@ -904,17 +897,17 @@ int attribute_hidden __psfs_parse_spec(register psfs_t *psfs) + if (*psfs->fmt == *p) { + int p_m_spec_chars = p - spec_chars; + +-#ifdef __UCLIBC_HAS_SCANF_GLIBC_A_FLAG__ +-#error implement gnu a flag +- if ((*p == 'a') +- && ((psfs->fmt[1] == '[') || ((psfs->fmt[1]|0x20) == 's')) +- ) { /* Assumes ascii for 's' and 'S' test. */ +- psfs->flags |= FLAG_MALLOC; ++ if (*p == 'm' && ++ (psfs->fmt[1] == '[' || psfs->fmt[1] == 'c' || ++ /* Assumes ascii for 's' and 'S' test. */ ++ (psfs->fmt[1] | 0x20) == 's')) ++ { ++ if (psfs->store) ++ psfs->flags |= FLAG_MALLOC; + ++psfs->fmt; + ++p; +- continue; /* The related conversions follow 'a'. */ ++ continue; /* The related conversions follow 'm'. */ + } +-#endif /* __UCLIBC_HAS_SCANF_GLIBC_A_FLAG__ */ + + for (p = spec_ranges; p_m_spec_chars > *p ; ++p) {} + if (((psfs->dataargtype >> 8) | psfs->flags) +@@ -1265,12 +1258,6 @@ int VFSCANF (FILE *__restrict fp, const Wchar *__restrict format, va_list arg) + while (*wf && __isascii(*wf) && (b < buf + sizeof(buf) - 1)) { + *b++ = *wf++; + } +-#ifdef __UCLIBC_HAS_SCANF_GLIBC_A_FLAG__ +-#error this is wrong... we need to ched in __psfs_parse_spec instead since this checks last char in buffer and conversion my have stopped before it. +- if ((*b == 'a') && ((*wf == '[') || ((*wf|0x20) == 's'))) { +- goto DONE; /* Spec was excessively long. */ +- } +-#endif /* __UCLIBC_HAS_SCANF_GLIBC_A_FLAG__ */ + *b = 0; + if (b == buf) { /* Bad conversion specifier! */ + goto DONE; +@@ -1390,13 +1377,36 @@ int VFSCANF (FILE *__restrict fp, const Wchar *__restrict format, va_list arg) + } + + if (psfs.conv_num == CONV_s) { ++ /* We might have to handle the allocation ourselves */ ++ int len; ++ /* With 'm', we actually got a pointer to a pointer */ ++ unsigned char **ptr = (void *)b; ++ ++ i = 0; ++ if (psfs.flags & FLAG_MALLOC) { ++ len = 0; ++ b = NULL; ++ } else ++ len = -1; ++ + /* Yes, believe it or not, a %s conversion can store nuls. */ + while ((__scan_getc(&sc) >= 0) && !isspace(sc.cc)) { + zero_conversions = 0; +- *b = sc.cc; +- b += psfs.store; ++ if (i == len) { ++ /* Pick a size that won't trigger a lot of ++ * mallocs early on ... */ ++ len += 256; ++ b = realloc(b, len + 1); ++ } ++ b[i] = sc.cc; ++ i += psfs.store; + fail = 0; + } ++ ++ if (psfs.flags & FLAG_MALLOC) ++ *ptr = b; ++ /* The code below takes care of terminating NUL */ ++ b += i; + } else { + #ifdef __UCLIBC_HAS_WCHAR__ + assert((psfs.conv_num == CONV_LEFTBRACKET) || \ +-- +cgit v0.9.0.1-2-gef13 diff --git a/toolchain/uClibc/uClibc-0.9.33.config b/toolchain/uClibc/uClibc-0.9.33.config index eb39df6ed..5f3815d5c 100644 --- a/toolchain/uClibc/uClibc-0.9.33.config +++ b/toolchain/uClibc/uClibc-0.9.33.config @@ -238,7 +238,7 @@ UCLIBC_HAS_UTMPX=y # # Library Installation Options # -RUNTIME_PREFIX="/" +RUNTIME_PREFIX="/openslx/" DEVEL_PREFIX="/usr/" MULTILIB_DIR="lib" HARDWIRED_ABSPATH=y diff --git a/toolchain/uClibc/uclibc.mk b/toolchain/uClibc/uclibc.mk index 07281351b..0df0ffb08 100644 --- a/toolchain/uClibc/uclibc.mk +++ b/toolchain/uClibc/uclibc.mk @@ -106,7 +106,7 @@ $(UCLIBC_DIR)/.oldconfig: $(UCLIBC_DIR)/.patched $(UCLIBC_CONFIG_FILE) -e 's,^TARGET_ARCH=".*",TARGET_ARCH=\"$(UCLIBC_TARGET_ARCH)\",g' \ -e 's,^KERNEL_SOURCE=.*,KERNEL_SOURCE=\"$(LINUX_HEADERS_DIR)\",g' \ -e 's,^KERNEL_HEADERS=.*,KERNEL_HEADERS=\"$(LINUX_HEADERS_DIR)/include\",g' \ - -e 's,^RUNTIME_PREFIX=.*,RUNTIME_PREFIX=\"/\",g' \ + -e 's,^RUNTIME_PREFIX=.*,RUNTIME_PREFIX=\"/openslx/\",g' \ -e 's,^DEVEL_PREFIX=.*,DEVEL_PREFIX=\"/usr/\",g' \ -e 's,^SHARED_LIB_LOADER_PREFIX=.*,SHARED_LIB_LOADER_PREFIX=\"/lib\",g' \ $(UCLIBC_DIR)/.oldconfig @@ -433,7 +433,7 @@ $(UCLIBC_DIR)/lib/libc.a: $(UCLIBC_DIR)/.configured $(gcc_intermediate) $(LIBFLO ARCH="$(UCLIBC_TARGET_ARCH)" \ PREFIX= \ DEVEL_PREFIX=/ \ - RUNTIME_PREFIX=/ \ + RUNTIME_PREFIX=/openslx/ \ CROSS_COMPILE="$(TARGET_CROSS)" \ UCLIB_EXTRA_CFLAGS="$(TARGET_ABI)" \ HOSTCC="$(HOSTCC)" \ @@ -458,7 +458,7 @@ $(STAGING_DIR)/usr/lib/libc.a: $(UCLIBC_DIR)/lib/libc.a ARCH="$(UCLIBC_TARGET_ARCH)" \ PREFIX=$(STAGING_DIR) \ DEVEL_PREFIX=/usr/ \ - RUNTIME_PREFIX=/ \ + RUNTIME_PREFIX=/openslx/ \ CROSS_COMPILE="$(TARGET_CROSS)" \ UCLIB_EXTRA_CFLAGS="$(TARGET_ABI)" \ install_runtime install_dev @@ -489,7 +489,7 @@ $(TARGET_DIR)/lib/libc.so.0: $(STAGING_DIR)/usr/lib/libc.a ARCH="$(UCLIBC_TARGET_ARCH)" \ PREFIX=$(TARGET_DIR) \ DEVEL_PREFIX=/usr/ \ - RUNTIME_PREFIX=/ \ + RUNTIME_PREFIX=/openslx/ \ CROSS_COMPILE="$(TARGET_CROSS)" \ UCLIB_EXTRA_CFLAGS="$(TARGET_ABI)" \ install_runtime @@ -573,7 +573,7 @@ $(TARGET_DIR)/usr/lib/libc.a: $(STAGING_DIR)/usr/lib/libc.a ARCH="$(UCLIBC_TARGET_ARCH)" \ PREFIX=$(TARGET_DIR) \ DEVEL_PREFIX=/usr/ \ - RUNTIME_PREFIX=/ \ + RUNTIME_PREFIX=/openslx/ \ install_dev # Install the kernel headers to the target dir if necessary if [ ! -f $(TARGET_DIR)/usr/include/linux/version.h ]; then \ -- cgit v1.2.3-55-g7522