From c50d27fa8b1f62ebf9853a641dcf38a90ed33d38 Mon Sep 17 00:00:00 2001 From: Austin Foxley Date: Fri, 1 Oct 2010 16:06:23 -0700 Subject: sparc: pipe.S return value of pipe on success is supposed to be 0 Signed-off-by: Austin Foxley --- libc/sysdeps/linux/sparc/pipe.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libc/sysdeps/linux/sparc/pipe.S b/libc/sysdeps/linux/sparc/pipe.S index 76a5b9617..94913d486 100644 --- a/libc/sysdeps/linux/sparc/pipe.S +++ b/libc/sysdeps/linux/sparc/pipe.S @@ -49,7 +49,7 @@ pipe: st %o0,[%i0] st %o1,[%i0+4] ret - restore %o0,%g0,%o0 + restore %g0,%g0,%o0 .Lerror: call HIDDEN_JUMPTARGET(__errno_location) -- cgit v1.2.3 From 54187ed0f082d145955a932f67259668dd038f65 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Thu, 14 Oct 2010 06:35:04 +0000 Subject: config parser: do not assume that realloc return same pointer We need to update the parser->line pointer on realloc and do not initialize the token array til after the potensial realloc in bb_get_chunk_with_continuation(). While here, also replace a realloc() with malloc() where pointer always is NULL. Signed-off-by: Natanael Copa Signed-off-by: Bernhard Reutner-Fischer --- libc/misc/internals/parse_config.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/libc/misc/internals/parse_config.c b/libc/misc/internals/parse_config.c index 8fa324e10..6734f35f4 100644 --- a/libc/misc/internals/parse_config.c +++ b/libc/misc/internals/parse_config.c @@ -78,6 +78,7 @@ static off_t bb_get_chunk_with_continuation(parser_t* parsr) parsr->line_len += PAGE_SIZE; parsr->data = realloc(parsr->data, parsr->data_len + parsr->line_len); + parsr->line = parsr->data + parsr->data_len; } } return pos; @@ -186,23 +187,21 @@ again: parser->line_len = 81; if (parser->data_len == 0) parser->data_len += 1 + ntokens * sizeof(char *); - parser->data = realloc(parser->data, - parser->data_len + parser->line_len); + parser->data = malloc(parser->data_len + parser->line_len); if (parser->data == NULL) return 0; parser->allocated |= 1; } /* else { assert(parser->data_len > 0); } */ if (parser->line == NULL) parser->line = parser->data + parser->data_len; - if (*tokens == NULL) - *tokens = (char **) parser->data; - memset(*tokens, 0, sizeof(*tokens[0]) * ntokens); /*config_free_data(parser);*/ /* Read one line (handling continuations with backslash) */ len = bb_get_chunk_with_continuation(parser); if (len == -1) return 0; + *tokens = (char **) parser->data; + memset(*tokens, 0, sizeof(*tokens[0]) * ntokens); line = parser->line; /* Skip multiple token-delimiters in the start of line? */ -- cgit v1.2.3 From 5cb23c3c734fad8fcfcd09eef34f666f04a0af5e Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Thu, 14 Oct 2010 06:35:05 +0000 Subject: getservice: getservent_r must return ERANGE when buffer is too small This fixes issue introduced by 72e1a1ce186c39f07282398e2af9eb0253e60f15 This should also fix the following testcase to exit with error rather than cause an endless loop. int main(void) { if (getservbyname("non-existing", "udp") == NULL) err(1, "getservbyname"); return 0; } Reported by Pirmin Walthert http://lists.uclibc.org/pipermail/uclibc/2010-August/044277.html Signed-off-by: Natanael Copa Signed-off-by: Bernhard Reutner-Fischer --- libc/inet/getservice.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libc/inet/getservice.c b/libc/inet/getservice.c index 47d26a262..c38ff80ac 100644 --- a/libc/inet/getservice.c +++ b/libc/inet/getservice.c @@ -69,7 +69,7 @@ int getservent_r(struct servent *result_buf, char **serv_aliases; char **tok = NULL; const size_t aliaslen = sizeof(*serv_aliases) * MAXALIASES; - int ret = ENOENT; + int ret = ERANGE; *result = NULL; if (buflen < aliaslen @@ -77,7 +77,7 @@ int getservent_r(struct servent *result_buf, goto DONE_NOUNLOCK; __UCLIBC_MUTEX_LOCK(mylock); - + ret = ENOENT; if (servp == NULL) setservent(serv_stayopen); if (servp == NULL) @@ -88,7 +88,6 @@ int getservent_r(struct servent *result_buf, servp->line_len = buflen - aliaslen; /* [[:space:]]/[[:space:]][] */ if (!config_read(servp, &tok, MAXALIASES, 3, "# \t/", PARSE_NORMAL)) { - ret = ERANGE; goto DONE; } result_buf->s_name = *(tok++); -- cgit v1.2.3 From c7c7ea92be00a9b5b48d1243bb75d32390263159 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Thu, 14 Oct 2010 06:35:06 +0000 Subject: config parser: always initialize line pointer We must always initialize line pointer since data pointer might have changed due to a realloc (in getserv.c for example). Signed-off-by: Natanael Copa Signed-off-by: Bernhard Reutner-Fischer --- libc/misc/internals/parse_config.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libc/misc/internals/parse_config.c b/libc/misc/internals/parse_config.c index 6734f35f4..6d3b6f4a0 100644 --- a/libc/misc/internals/parse_config.c +++ b/libc/misc/internals/parse_config.c @@ -192,8 +192,7 @@ again: return 0; parser->allocated |= 1; } /* else { assert(parser->data_len > 0); } */ - if (parser->line == NULL) - parser->line = parser->data + parser->data_len; + parser->line = parser->data + parser->data_len; /*config_free_data(parser);*/ /* Read one line (handling continuations with backslash) */ -- cgit v1.2.3 From 6e74339e7d762857579169068b060a4fd3f345c4 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Thu, 14 Oct 2010 06:35:07 +0000 Subject: parse_config: discard rest of incomplete line If line is longer then size of given buffer and buffer is not allocated by the config parser itself, then discard rest of line. Signed-off-by: Natanael Copa Signed-off-by: Bernhard Reutner-Fischer --- libc/misc/internals/parse_config.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libc/misc/internals/parse_config.c b/libc/misc/internals/parse_config.c index 6d3b6f4a0..c17d25553 100644 --- a/libc/misc/internals/parse_config.c +++ b/libc/misc/internals/parse_config.c @@ -79,6 +79,13 @@ static off_t bb_get_chunk_with_continuation(parser_t* parsr) parsr->data = realloc(parsr->data, parsr->data_len + parsr->line_len); parsr->line = parsr->data + parsr->data_len; + } else { + /* discard rest of line if not enough space in buffer */ + int c; + do { + c = fgetc(parsr->fp); + } while (c != EOF && c != '\n'); + break; } } return pos; -- cgit v1.2.3 From 2631ae8aab71c350273fa2d7a787bfcbff258029 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Thu, 14 Oct 2010 06:35:08 +0000 Subject: getservice: fix handling of long lines Don't try to be smart by dynamically realloc buffersize as it doesn't work. Instead, be simple and allocate a buffer big enough. This fixes a memory leak when calling getserv{ent,byname,byport} multiple times. To save memory we reduce number of max aliases. We seldomly will need more than 1 anyways. While here, fix segfault that happened if there were too many aliases. Signed-off-by: Natanael Copa Signed-off-by: Bernhard Reutner-Fischer --- libc/inet/getservice.c | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/libc/inet/getservice.c b/libc/inet/getservice.c index c38ff80ac..183099f5c 100644 --- a/libc/inet/getservice.c +++ b/libc/inet/getservice.c @@ -28,9 +28,11 @@ aliases: case sensitive optional space or tab separated list of other names #include __UCLIBC_MUTEX_STATIC(mylock, PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP); -#define MAXALIASES 35 -#define BUFSZ (80) /* one line */ -#define SBUFSIZE (BUFSZ + 1 + (sizeof(char *) * MAXALIASES)) +#define MINTOKENS 3 +#define MAXALIASES 8 /* we seldomly need more than 1 alias */ +#define MAXTOKENS (MINTOKENS + MAXALIASES + 1) +#define BUFSZ (255) /* one line */ +#define SBUFSIZE (BUFSZ + 1 + (sizeof(char *) * MAXTOKENS)) static parser_t *servp = NULL; static struct servent serve; @@ -65,10 +67,8 @@ libc_hidden_def(endservent) int getservent_r(struct servent *result_buf, char *buf, size_t buflen, struct servent **result) { - char **alias; - char **serv_aliases; char **tok = NULL; - const size_t aliaslen = sizeof(*serv_aliases) * MAXALIASES; + const size_t aliaslen = sizeof(char *) * MAXTOKENS; int ret = ERANGE; *result = NULL; @@ -87,13 +87,13 @@ int getservent_r(struct servent *result_buf, servp->data_len = aliaslen; servp->line_len = buflen - aliaslen; /* [[:space:]]/[[:space:]][] */ - if (!config_read(servp, &tok, MAXALIASES, 3, "# \t/", PARSE_NORMAL)) { + if (!config_read(servp, &tok, MAXTOKENS - 1, MINTOKENS, "# \t/", PARSE_NORMAL)) { goto DONE; } result_buf->s_name = *(tok++); result_buf->s_port = htons((u_short) atoi(*(tok++))); result_buf->s_proto = *(tok++); - result_buf->s_aliases = alias = serv_aliases = tok; + result_buf->s_aliases = tok; *result = result_buf; ret = 0; DONE: @@ -106,9 +106,8 @@ libc_hidden_def(getservent_r) static void __initbuf(void) { - if (servbuf) - servbuf_sz += BUFSZ; - servbuf = realloc(servbuf, servbuf_sz); + if (!servbuf) + servbuf = malloc(SBUFSIZE); if (!servbuf) abort(); } @@ -117,9 +116,8 @@ struct servent *getservent(void) { struct servent *result; - do { - __initbuf(); - } while (getservent_r(&serve, servbuf, servbuf_sz, &result) == ERANGE); + __initbuf(); + getservent_r(&serve, servbuf, servbuf_sz, &result); return result; } @@ -154,10 +152,8 @@ struct servent *getservbyname(const char *name, const char *proto) { struct servent *result; - do { - __initbuf(); - } while (getservbyname_r(name, proto, &serve, servbuf, servbuf_sz, &result) - == ERANGE); + __initbuf(); + getservbyname_r(name, proto, &serve, servbuf, servbuf_sz, &result); return result; } @@ -187,10 +183,8 @@ struct servent *getservbyport(int port, const char *proto) { struct servent *result; - do { - __initbuf(); - } while (getservbyport_r(port, proto, &serve, servbuf, servbuf_sz, &result) - == ERANGE); + __initbuf(); + getservbyport_r(port, proto, &serve, servbuf, servbuf_sz, &result); return result; } libc_hidden_def(getservbyport) -- cgit v1.2.3 From 3dc83600855e3754a9046495751758624ac5bfb7 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Thu, 14 Oct 2010 06:35:09 +0000 Subject: getnet: simplify alias handling and reduce MAXALIASES Reduce MAXALIASES to something lower. There will probably never be need for more than 1 alias but we allow a few extra. While here we alos fix segfault when there are too many aliases. Signed-off-by: Natanael Copa Signed-off-by: Bernhard Reutner-Fischer --- libc/inet/getnet.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/libc/inet/getnet.c b/libc/inet/getnet.c index c604b63d3..9049f97af 100644 --- a/libc/inet/getnet.c +++ b/libc/inet/getnet.c @@ -27,9 +27,11 @@ aliases: case sensitive optional space or tab separated list of other names #include __UCLIBC_MUTEX_STATIC(mylock, PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP); -#define MAXALIASES 35 -#define BUFSZ (80) /* one line */ -#define SBUFSIZE (BUFSZ + 1 + (sizeof(char *) * MAXALIASES)) +#define MINTOKENS 2 +#define MAXALIASES 8 +#define MAXTOKENS (MINTOKENS + MAXALIASES + 1) +#define BUFSZ (255) /* one line */ +#define SBUFSIZE (BUFSZ + 1 + (sizeof(char *) * MAXTOKENS)) static parser_t *netp = NULL; static struct netent nete; @@ -65,10 +67,8 @@ int getnetent_r(struct netent *result_buf, int *h_errnop ) { - char **alias, *cp = NULL; - char **net_aliases; char **tok = NULL; - const size_t aliaslen = sizeof(*net_aliases) * MAXALIASES; + const size_t aliaslen = sizeof(char *) * MAXTOKENS; int ret = ERANGE; *result = NULL; @@ -86,7 +86,7 @@ int getnetent_r(struct netent *result_buf, netp->data_len = aliaslen; netp->line_len = buflen - aliaslen; /* [[:space:]][[:space:]][] */ - if (!config_read(netp, &tok, 3, 2, "# \t/", PARSE_NORMAL)) { + if (!config_read(netp, &tok, MAXTOKENS-1, MINTOKENS, "# \t/", PARSE_NORMAL)) { goto DONE; } result_buf->n_name = *(tok++); @@ -110,16 +110,7 @@ int getnetent_r(struct netent *result_buf, sa4_to_uint32(addri->ai_addr); freeaddrinfo(addri); } - result_buf->n_aliases = alias = net_aliases = tok; - cp = *alias; - while (cp && *cp) { - if (alias < &net_aliases[MAXALIASES - 1]) - *alias++ = cp; - cp = strpbrk(cp, " \t"); - if (cp != NULL) - *cp++ = '\0'; - } - *alias = NULL; + result_buf->n_aliases = tok; *result = result_buf; ret = 0; DONE: -- cgit v1.2.3 From 7b74c6bab0fc39325a5b9a978a3d8ab73009e5d3 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Thu, 14 Oct 2010 06:35:10 +0000 Subject: getproto: increase line buffer size, simlify and fix alias handling We increase line buffer size, reduce MAXALIASES and make sure we don't segfault when there are too manuy aliases in /etc/protocols. Signed-off-by: Natanael Copa Signed-off-by: Bernhard Reutner-Fischer --- libc/inet/getproto.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/libc/inet/getproto.c b/libc/inet/getproto.c index bcf507bda..c59da7e66 100644 --- a/libc/inet/getproto.c +++ b/libc/inet/getproto.c @@ -27,9 +27,11 @@ aliases: case sensitive optional space or tab separated list of other names #include __UCLIBC_MUTEX_STATIC(mylock, PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP); -#define MAXALIASES 35 -#define BUFSZ (80) /* one line */ -#define SBUFSIZE (BUFSZ + 1 + (sizeof(char *) * MAXALIASES)) +#define MINTOKENS 2 +#define MAXALIASES 8 /* will probably never be more than one */ +#define MAXTOKENS (MINTOKENS + MAXALIASES + 1) +#define BUFSZ (255) /* one line */ +#define SBUFSIZE (BUFSZ + 1 + (sizeof(char *) * MAXTOKENS)) static parser_t *protop = NULL; static struct protoent protoe; @@ -63,10 +65,8 @@ libc_hidden_def(endprotoent) int getprotoent_r(struct protoent *result_buf, char *buf, size_t buflen, struct protoent **result) { - char **alias, *cp = NULL; - char **proto_aliases; char **tok = NULL; - const size_t aliaslen = sizeof(*proto_aliases) * MAXALIASES; + const size_t aliaslen = sizeof(char *) * MAXTOKENS; int ret = ERANGE; *result = NULL; @@ -85,21 +85,12 @@ int getprotoent_r(struct protoent *result_buf, protop->data_len = aliaslen; protop->line_len = buflen - aliaslen; /* [[:space:]][[:space:]][] */ - if (!config_read(protop, &tok, 3, 2, "# \t/", PARSE_NORMAL)) { + if (!config_read(protop, &tok, MAXTOKENS - 1, MINTOKENS, "# \t/", PARSE_NORMAL)) { goto DONE; } result_buf->p_name = *(tok++); result_buf->p_proto = atoi(*(tok++)); - result_buf->p_aliases = alias = proto_aliases = tok; - cp = *alias; - while (cp && *cp) { - if (alias < &proto_aliases[MAXALIASES - 1]) - *alias++ = cp; - cp = strpbrk(cp, " \t"); - if (cp != NULL) - *cp++ = '\0'; - } - *alias = NULL; + result_buf->p_aliases = tok; *result = result_buf; ret = 0; DONE: -- cgit v1.2.3 From 7add20c8200f9fb02743cd1b24b15b6201294fbf Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 19 Oct 2010 14:07:51 +0200 Subject: vfprintf.c: de-obfuscate if(with nested assignments). no logic changes God knows this file is hard to read as-is, some readability improvement is in order. Signed-off-by: Denys Vlasenko --- libc/stdio/_vfprintf.c | 63 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 25 deletions(-) diff --git a/libc/stdio/_vfprintf.c b/libc/stdio/_vfprintf.c index 6fa8ecb8d..ac3edfdf1 100644 --- a/libc/stdio/_vfprintf.c +++ b/libc/stdio/_vfprintf.c @@ -328,7 +328,7 @@ enum { /* q:long_long Z:(s)size_t */ \ 'h', 'l', 'L', 'j', 'z', 't', 'q', 'Z', 0, \ 2, 4, 8, IMS, SS, PDS, 8, SS, 0, /* TODO -- fix!!! */\ - 1, 8 \ + 1, 8 \ } /**********************************************************************/ @@ -550,7 +550,8 @@ int attribute_hidden _ppfs_init(register ppfs_t *ppfs, const char *fmt0) while (*fmt) { if ((*fmt == '%') && (*++fmt != '%')) { ppfs->fmtpos = fmt; /* back up to the '%' */ - if ((r = _ppfs_parsespec(ppfs)) < 0) { + r = _ppfs_parsespec(ppfs); + if (r < 0) { return -1; } fmt = ppfs->fmtpos; /* update to one past end of spec */ @@ -587,7 +588,8 @@ void attribute_hidden _ppfs_prepargs(register ppfs_t *ppfs, va_list arg) va_copy(ppfs->arg, arg); #ifdef NL_ARGMAX - if ((i = ppfs->maxposarg) > 0) { /* init for positional args */ + i = ppfs->maxposarg; /* init for positional args */ + if (i > 0) { ppfs->num_data_args = i; ppfs->info.width = ppfs->info.prec = ppfs->maxposarg = 0; _ppfs_setargs(ppfs); @@ -859,15 +861,15 @@ int attribute_hidden _ppfs_parsespec(ppfs_t *ppfs) * While there a legal specifiers that won't, the all involve duplicate * flags or outrageous field widths/precisions. */ width = dpoint = 0; - if ((flags = ppfs->info._flags & FLAG_WIDESTREAM) == 0) { + flags = ppfs->info._flags & FLAG_WIDESTREAM; + if (flags == 0) { fmt = ppfs->fmtpos; } else { fmt = buf + 1; i = 0; do { - if ((buf[i] = (char) (((wchar_t *) ppfs->fmtpos)[i-1])) - != (((wchar_t *) ppfs->fmtpos)[i-1]) - ) { + buf[i] = (char) (((wchar_t *) ppfs->fmtpos)[i-1]); + if (buf[i] != (((wchar_t *) ppfs->fmtpos)[i-1])) { return -1; } } while (buf[i++] && (i < sizeof(buf))); @@ -908,7 +910,8 @@ int attribute_hidden _ppfs_parsespec(ppfs_t *ppfs) if (maxposarg == 0) { return -1; } - if ((argnumber[2] = i) > maxposarg) { + argnumber[2] = i; + if (argnumber[2] > maxposarg) { maxposarg = i; } /* Now fall through to check flags. */ @@ -1091,7 +1094,8 @@ int attribute_hidden _ppfs_parsespec(ppfs_t *ppfs) ? (ppfs->argnumber[i] = argnumber[i]) : argnumber[2] + (i-2)); if (n > maxposarg) { - if ((maxposarg = n) > NL_ARGMAX) { + maxposarg = n; + if (maxposarg > NL_ARGMAX) { return -1; } } @@ -1112,7 +1116,8 @@ int attribute_hidden _ppfs_parsespec(ppfs_t *ppfs) #endif /* NL_ARGMAX */ #ifdef __UCLIBC_HAS_WCHAR__ - if ((flags = ppfs->info._flags & FLAG_WIDESTREAM) == 0) { + flags = ppfs->info._flags & FLAG_WIDESTREAM; + if (flags == 0) { ppfs->fmtpos = ++fmt; } else { ppfs->fmtpos = (const char *) (((const wchar_t *)(ppfs->fmtpos)) @@ -1202,8 +1207,10 @@ static size_t _fp_out_narrow(FILE *fp, intptr_t type, intptr_t len, intptr_t buf if (type & 0x80) { /* Some type of padding needed. */ int buflen = strlen((const char *) buf); - if ((len -= buflen) > 0) { - if ((r = _charpad(fp, (type & 0x7f), len)) != len) { + len -= buflen; + if (len > 0) { + r = _charpad(fp, (type & 0x7f), len); + if (r != len) { return r; } } @@ -1274,8 +1281,10 @@ static size_t _fp_out_wide(FILE *fp, intptr_t type, intptr_t len, intptr_t buf) if (type & 0x80) { /* Some type of padding needed */ int buflen = strlen(s); - if ((len -= buflen) > 0) { - if ((r = _charpad(fp, (type & 0x7f), len)) != len) { + len -= buflen; + if (len > 0) { + r = _charpad(fp, (type & 0x7f), len); + if (r != len) { return r; } } @@ -1366,7 +1375,8 @@ static int _ppwfs_init(register ppfs_t *ppfs, const wchar_t *fmt0) while (*fmt) { if ((*fmt == '%') && (*++fmt != '%')) { ppfs->fmtpos = (const char *) fmt; /* back up to the '%' */ - if ((r = _ppfs_parsespec(ppfs)) < 0) { + r = _ppfs_parsespec(ppfs); + if (r < 0) { return -1; } fmt = (const wchar_t *) ppfs->fmtpos; /* update to one past end of spec */ @@ -1419,7 +1429,7 @@ static int _do_one_spec(FILE * __restrict stream, static const char spec_base[] = SPEC_BASE; #ifdef L__vfprintf_internal static const char prefix[] = "+\0-\0 \0000x\0000X"; - /* 0 2 4 6 9 11*/ + /* 0 2 4 6 9 11*/ #else /* L__vfprintf_internal */ static const wchar_t prefix[] = L"+\0-\0 \0000x\0000X"; #endif /* L__vfprintf_internal */ @@ -1514,7 +1524,8 @@ static int _do_one_spec(FILE * __restrict stream, #warning CONSIDER: Should we ignore these flags if stub locale? What about custom specs? #endif #endif /* __UCLIBC_MJN3_ONLY__ */ - if ((base = spec_base[(int)(ppfs->conv_num - CONV_p)]) == 10) { + base = spec_base[(int)(ppfs->conv_num - CONV_p)]; + if (base == 10) { if (PRINT_INFO_FLAG_VAL(&(ppfs->info),group)) { alphacase = __UIM_GROUP; } @@ -1620,7 +1631,8 @@ static int _do_one_spec(FILE * __restrict stream, #ifdef __UCLIBC_HAS_WCHAR__ mbstate.__mask = 0; /* Initialize the mbstate. */ if (ppfs->conv_num == CONV_S) { /* wide string */ - if (!(ws = *((const wchar_t **) *argptr))) { + ws = *((const wchar_t **) *argptr); + if (!ws) { goto NULL_STRING; } /* We use an awful uClibc-specific hack here, passing @@ -1628,12 +1640,12 @@ static int _do_one_spec(FILE * __restrict stream, * uClibc's wcsrtombs that we want a "restricted" length * such that the mbs fits in a buffer of the specified * size with no partial conversions. */ - if ((slen = wcsrtombs((char *) &ws, &ws, /* Use awful hack! */ - ((ppfs->info.prec >= 0) - ? ppfs->info.prec - : SIZE_MAX), &mbstate)) - == ((size_t)-1) - ) { + slen = wcsrtombs((char *) &ws, &ws, /* Use awful hack! */ + ((ppfs->info.prec >= 0) + ? ppfs->info.prec + : SIZE_MAX), + &mbstate); + if (slen == ((size_t)-1)) { return -1; /* EILSEQ */ } } else { /* wide char */ @@ -1881,7 +1893,8 @@ int VFPRINTF_internal (FILE * __restrict stream, /* TODO: _do_one_spec needs to know what the output funcs are!!! */ ppfs.fmtpos = (const char *)(++format); /* TODO: check -- should only fail on stream error */ - if ( (r = _do_one_spec(stream, &ppfs, &count)) < 0) { + r = _do_one_spec(stream, &ppfs, &count); + if (r < 0) { count = -1; break; } -- cgit v1.2.3 From 7da684a4613809f430ed6f157f059c35c782da9e Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 19 Oct 2010 14:37:40 +0200 Subject: vfprintf.c: remove endif comments which clog up the source. no code changes Example: --ppfs->maxposarg; Verified with objdump that no code is changed Signed-off-by: Denys Vlasenko --- libc/stdio/_vfprintf.c | 271 ++++++++++++++++++++++++------------------------- 1 file changed, 135 insertions(+), 136 deletions(-) diff --git a/libc/stdio/_vfprintf.c b/libc/stdio/_vfprintf.c index ac3edfdf1..721efe2f7 100644 --- a/libc/stdio/_vfprintf.c +++ b/libc/stdio/_vfprintf.c @@ -104,13 +104,13 @@ #include #ifdef __UCLIBC_HAS_THREADS__ -#include -#include -#endif /* __UCLIBC_HAS_THREADS__ */ +# include +# include +#endif #ifdef __UCLIBC_HAS_WCHAR__ -#include -#endif /* __UCLIBC_HAS_WCHAR__ */ +# include +#endif #include #include @@ -136,24 +136,24 @@ /**********************************************************************/ #if defined(__UCLIBC__) && !defined(__UCLIBC_HAS_FLOATS__) -#undef __STDIO_PRINTF_FLOAT +# undef __STDIO_PRINTF_FLOAT #endif #ifdef __BCC__ -#undef __STDIO_PRINTF_FLOAT +# undef __STDIO_PRINTF_FLOAT #endif #ifdef __STDIO_PRINTF_FLOAT -#include -#include -#else /* __STDIO_PRINTF_FLOAT */ -#undef L__fpmaxtostr -#endif /* __STDIO_PRINTF_FLOAT */ +# include +# include +#else +# undef L__fpmaxtostr +#endif #undef __STDIO_HAS_VSNPRINTF #if defined(__STDIO_BUFFERS) || defined(__USE_OLD_VFPRINTF__) || defined(__UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__) -#define __STDIO_HAS_VSNPRINTF 1 +# define __STDIO_HAS_VSNPRINTF 1 #endif /**********************************************************************/ @@ -162,40 +162,36 @@ /* #define __UCLIBC_HAS_GLIBC_CUSTOM_PRINTF__ */ #ifdef __UCLIBC_MJN3_ONLY__ -#ifdef L_register_printf_function +# ifdef L_register_printf_function /* emit only once */ -#warning WISHLIST: Make MAX_USER_SPEC configurable? -#warning WISHLIST: Make MAX_ARGS_PER_SPEC configurable? +# warning WISHLIST: Make MAX_USER_SPEC configurable? +# warning WISHLIST: Make MAX_ARGS_PER_SPEC configurable? +# endif #endif -#endif /* __UCLIBC_MJN3_ONLY__ */ #ifdef __UCLIBC_HAS_GLIBC_CUSTOM_PRINTF__ - -#define MAX_USER_SPEC 10 -#define MAX_ARGS_PER_SPEC 5 - -#else /* __UCLIBC_HAS_GLIBC_CUSTOM_PRINTF__ */ - -#undef MAX_USER_SPEC -#define MAX_ARGS_PER_SPEC 1 - -#endif /* __UCLIBC_HAS_GLIBC_CUSTOM_PRINTF__ */ +# define MAX_USER_SPEC 10 +# define MAX_ARGS_PER_SPEC 5 +#else +# undef MAX_USER_SPEC +# define MAX_ARGS_PER_SPEC 1 +#endif #if MAX_ARGS_PER_SPEC < 1 -#error MAX_ARGS_PER_SPEC < 1! -#undef MAX_ARGS_PER_SPEC -#define MAX_ARGS_PER_SPEC 1 +# error MAX_ARGS_PER_SPEC < 1! +# undef MAX_ARGS_PER_SPEC +# define MAX_ARGS_PER_SPEC 1 #endif #if defined(NL_ARGMAX) && (NL_ARGMAX < 9) -#error NL_ARGMAX < 9! +# error NL_ARGMAX < 9! #endif #if defined(NL_ARGMAX) && (NL_ARGMAX >= (MAX_ARGS_PER_SPEC + 2)) -#define MAX_ARGS NL_ARGMAX +# define MAX_ARGS NL_ARGMAX #else /* N for spec itself, plus 1 each for width and precision */ -#define MAX_ARGS (MAX_ARGS_PER_SPEC + 2) +# define MAX_ARGS (MAX_ARGS_PER_SPEC + 2) #endif /**********************************************************************/ @@ -207,20 +203,20 @@ extern printf_function _custom_printf_handler[MAX_USER_SPEC] attribute_hidden; extern printf_arginfo_function *_custom_printf_arginfo[MAX_USER_SPEC] attribute_hidden; extern char *_custom_printf_spec attribute_hidden; -#endif /* __UCLIBC_HAS_GLIBC_CUSTOM_PRINTF__ */ +#endif /**********************************************************************/ #define SPEC_FLAGS " +0-#'I" enum { - FLAG_SPACE = 0x01, - FLAG_PLUS = 0x02, /* must be 2 * FLAG_SPACE */ - FLAG_ZERO = 0x04, - FLAG_MINUS = 0x08, /* must be 2 * FLAG_ZERO */ - FLAG_HASH = 0x10, - FLAG_THOUSANDS = 0x20, - FLAG_I18N = 0x40, /* only works for d, i, u */ - FLAG_WIDESTREAM = 0x80 + FLAG_SPACE = 0x01, + FLAG_PLUS = 0x02, /* must be 2 * FLAG_SPACE */ + FLAG_ZERO = 0x04, + FLAG_MINUS = 0x08, /* must be 2 * FLAG_ZERO */ + FLAG_HASH = 0x10, + FLAG_THOUSANDS = 0x20, + FLAG_I18N = 0x40, /* only works for d, i, u */ + FLAG_WIDESTREAM = 0x80 }; /**********************************************************************/ @@ -240,10 +236,10 @@ enum { }; /* p x X o u d i */ -#define SPEC_BASE { 16, 16, 16, 8, 10, 10, 10 } +#define SPEC_BASE { 16, 16, 16, 8, 10, 10, 10 } -#define SPEC_RANGES { CONV_n, CONV_p, CONV_i, CONV_A, \ - CONV_C, CONV_S, CONV_c, CONV_s, CONV_custom0 } +#define SPEC_RANGES { CONV_n, CONV_p, CONV_i, CONV_A, \ + CONV_C, CONV_S, CONV_c, CONV_s, CONV_custom0 } #define SPEC_OR_MASK { \ /* n */ (PA_FLAG_PTR|PA_INT), \ @@ -284,43 +280,43 @@ enum { /* #endif */ #ifdef PDS -#error PDS already defined! +# error PDS already defined! #endif #ifdef SS -#error SS already defined! +# error SS already defined! #endif #ifdef IMS -#error IMS already defined! +# error IMS already defined! #endif #if PTRDIFF_MAX == INT_MAX -#define PDS 0 +# define PDS 0 #elif PTRDIFF_MAX == LONG_MAX -#define PDS 4 +# define PDS 4 #elif defined(LLONG_MAX) && (PTRDIFF_MAX == LLONG_MAX) -#define PDS 8 +# define PDS 8 #else -#error fix QUAL_CHARS ptrdiff_t entry 't'! +# error fix QUAL_CHARS ptrdiff_t entry 't'! #endif #if SIZE_MAX == UINT_MAX -#define SS 0 +# define SS 0 #elif SIZE_MAX == ULONG_MAX -#define SS 4 +# define SS 4 #elif defined(LLONG_MAX) && (SIZE_MAX == ULLONG_MAX) -#define SS 8 +# define SS 8 #else -#error fix QUAL_CHARS size_t entries 'z', 'Z'! +# error fix QUAL_CHARS size_t entries 'z', 'Z'! #endif #if INTMAX_MAX == INT_MAX -#define IMS 0 +# define IMS 0 #elif INTMAX_MAX == LONG_MAX -#define IMS 4 +# define IMS 4 #elif defined(LLONG_MAX) && (INTMAX_MAX == LLONG_MAX) -#define IMS 8 +# define IMS 8 #else -#error fix QUAL_CHARS intmax_t entry 'j'! +# error fix QUAL_CHARS intmax_t entry 'j'! #endif #define QUAL_CHARS { \ @@ -334,45 +330,46 @@ enum { /**********************************************************************/ #ifdef __STDIO_VA_ARG_PTR -#ifdef __BCC__ -#define __va_arg_ptr(ap,type) (((type *)(ap += sizeof(type))) - 1) -#endif +# ifdef __BCC__ +# define __va_arg_ptr(ap,type) (((type *)(ap += sizeof(type))) - 1) +# endif -#if 1 -#ifdef __GNUC__ +# if 1 +# ifdef __GNUC__ /* TODO -- need other than for 386 as well! */ -#ifndef __va_rounded_size -#define __va_rounded_size(TYPE) \ - (((sizeof (TYPE) + sizeof (int) - 1) / sizeof (int)) * sizeof (int)) -#endif -#define __va_arg_ptr(AP, TYPE) \ - (AP = (va_list) ((char *) (AP) + __va_rounded_size (TYPE)), \ - ((void *) ((char *) (AP) - __va_rounded_size (TYPE)))) -#endif -#endif +# ifndef __va_rounded_size +# define __va_rounded_size(TYPE) \ + (((sizeof (TYPE) + sizeof (int) - 1) / sizeof (int)) * sizeof (int)) +# endif +# define __va_arg_ptr(AP, TYPE) \ + (AP = (va_list) ((char *) (AP) + __va_rounded_size (TYPE)), \ + ((void *) ((char *) (AP) - __va_rounded_size (TYPE))) \ + ) +# endif +# endif #endif /* __STDIO_VA_ARG_PTR */ #ifdef __va_arg_ptr -#define GET_VA_ARG(AP,F,TYPE,ARGS) (*(AP) = __va_arg_ptr(ARGS,TYPE)) -#define GET_ARG_VALUE(AP,F,TYPE) (*((TYPE *)(*(AP)))) +# define GET_VA_ARG(AP,F,TYPE,ARGS) (*(AP) = __va_arg_ptr(ARGS,TYPE)) +# define GET_ARG_VALUE(AP,F,TYPE) (*((TYPE *)(*(AP)))) #else typedef union { wchar_t wc; unsigned int u; unsigned long ul; -#ifdef ULLONG_MAX +# ifdef ULLONG_MAX unsigned long long ull; -#endif -#ifdef __STDIO_PRINTF_FLOAT +# endif +# ifdef __STDIO_PRINTF_FLOAT double d; long double ld; -#endif /* __STDIO_PRINTF_FLOAT */ +# endif void *p; } argvalue_t; -#define GET_VA_ARG(AU,F,TYPE,ARGS) (AU->F = va_arg(ARGS,TYPE)) -#define GET_ARG_VALUE(AU,F,TYPE) ((TYPE)((AU)->F)) +# define GET_VA_ARG(AU,F,TYPE,ARGS) (AU->F = va_arg(ARGS,TYPE)) +# define GET_ARG_VALUE(AU,F,TYPE) ((TYPE)((AU)->F)) #endif typedef struct { @@ -380,7 +377,7 @@ typedef struct { struct printf_info info; #ifdef NL_ARGMAX int maxposarg; /* > 0 if args are positional, 0 if not, -1 if unknown */ -#endif /* NL_ARGMAX */ +#endif int num_data_args; /* TODO: use sentinal??? */ unsigned int conv_num; unsigned char argnumber[4]; /* width | prec | 1st data | unused */ @@ -436,7 +433,8 @@ size_t parse_printf_format(register const char *template, if (_ppfs_init(&ppfs, template) >= 0) { #ifdef NL_ARGMAX - if (ppfs.maxposarg > 0) { /* Using positional args. */ + if (ppfs.maxposarg > 0) { + /* Using positional args. */ count = ppfs.maxposarg; if (n > count) { n = count; @@ -444,8 +442,10 @@ size_t parse_printf_format(register const char *template, for (i = 0 ; i < n ; i++) { *argtypes++ = ppfs.argtype[i]; } - } else { /* Not using positional args. */ -#endif /* NL_ARGMAX */ + } else +#endif + { + /* Not using positional args. */ while (*template) { if ((*template == '%') && (*++template != '%')) { ppfs.fmtpos = template; @@ -478,9 +478,7 @@ size_t parse_printf_format(register const char *template, ++template; } } -#ifdef NL_ARGMAX } -#endif /* NL_ARGMAX */ } return count; @@ -498,10 +496,10 @@ int attribute_hidden _ppfs_init(register ppfs_t *ppfs, const char *fmt0) memset(ppfs, 0, sizeof(ppfs_t)); /* TODO: nonportable???? */ #ifdef NL_ARGMAX --ppfs->maxposarg; /* set to -1 */ -#endif /* NL_ARGMAX */ +#endif ppfs->fmtpos = fmt0; #ifdef __UCLIBC_MJN3_ONLY__ -#warning TODO: Make checking of the format string in C locale an option. +# warning TODO: Make checking of the format string in C locale an option. #endif #ifdef __UCLIBC_HAS_LOCALE__ /* To support old programs, don't check mb validity if in C locale. */ @@ -595,7 +593,7 @@ void attribute_hidden _ppfs_prepargs(register ppfs_t *ppfs, va_list arg) _ppfs_setargs(ppfs); ppfs->maxposarg = i; } -#endif /* NL_ARGMAX */ +#endif } #endif /**********************************************************************/ @@ -612,7 +610,7 @@ void attribute_hidden _ppfs_setargs(register ppfs_t *ppfs) #ifdef NL_ARGMAX if (ppfs->maxposarg == 0) { /* initing for or no pos args */ -#endif /* NL_ARGMAX */ +#endif if (ppfs->info.width == INT_MIN) { ppfs->info.width = #ifdef __va_arg_ptr @@ -745,7 +743,7 @@ static const short int type_codes[] = { /* PA_FLOAT, */ PA_DOUBLE, PA_DOUBLE|PA_FLAG_LONG_DOUBLE, -#endif /* __STDIO_PRINTF_FLOAT */ +#endif }; static const unsigned char type_sizes[] = { @@ -768,7 +766,7 @@ static const unsigned char type_sizes[] = { /* PROMOTED_SIZE_OF(float), */ PROMOTED_SIZE_OF(double), PROMOTED_SIZE_OF(long double), -#endif /* __STDIO_PRINTF_FLOAT */ +#endif }; static int _promoted_size(int argtype) @@ -827,7 +825,7 @@ int attribute_hidden _ppfs_parsespec(ppfs_t *ppfs) int dpoint; #ifdef NL_ARGMAX int maxposarg; -#endif /* NL_ARGMAX */ +#endif int p_m_spec_chars; int n; int argtype[MAX_ARGS_PER_SPEC+2]; @@ -840,7 +838,7 @@ int attribute_hidden _ppfs_parsespec(ppfs_t *ppfs) static const char qual_chars[] = QUAL_CHARS; #ifdef __UCLIBC_HAS_WCHAR__ char buf[32]; -#endif /* __UCLIBC_HAS_WCHAR__ */ +#endif /* WIDE note: we can test against '%' here since we don't allow */ /* WIDE note: other mappings of '%' in the wide char set. */ @@ -851,7 +849,7 @@ int attribute_hidden _ppfs_parsespec(ppfs_t *ppfs) argtype[1] = __PA_NOARG; #ifdef NL_ARGMAX maxposarg = ppfs->maxposarg; -#endif /* NL_ARGMAX */ +#endif #ifdef __UCLIBC_HAS_WCHAR__ /* This is somewhat lame, but saves a lot of code. If we're dealing with @@ -878,7 +876,7 @@ int attribute_hidden _ppfs_parsespec(ppfs_t *ppfs) #else /* __UCLIBC_HAS_WCHAR__ */ width = flags = dpoint = 0; fmt = ppfs->fmtpos; -#endif /* __UCLIBC_HAS_WCHAR__ */ +#endif assert(fmt[-1] == '%'); assert(fmt[0] != '%'); @@ -917,16 +915,16 @@ int attribute_hidden _ppfs_parsespec(ppfs_t *ppfs) /* Now fall through to check flags. */ } else { if (maxposarg > 0) { -#ifdef __UCLIBC_HAS_PRINTF_M_SPEC__ -#ifdef __UCLIBC_MJN3_ONLY__ -#warning TODO: Support prec and width for %m when positional args used +# ifdef __UCLIBC_HAS_PRINTF_M_SPEC__ +# ifdef __UCLIBC_MJN3_ONLY__ +# warning TODO: Support prec and width for %m when positional args used /* Actually, positional arg processing will fail in general * for specifiers that don't require an arg. */ -#endif /* __UCLIBC_MJN3_ONLY__ */ +# endif if (*fmt == 'm') { goto PREC_WIDTH; } -#endif /* __UCLIBC_HAS_PRINTF_M_SPEC__ */ +# endif /* __UCLIBC_HAS_PRINTF_M_SPEC__ */ return -1; } maxposarg = 0; /* Possible redundant store, but cuts size. */ @@ -985,7 +983,7 @@ int attribute_hidden _ppfs_parsespec(ppfs_t *ppfs) } argnumber[-dpoint] = i; } else -#endif /* NL_ARGMAX */ +#endif if (++p != fmt) { /* Not using pos args but digits followed *. */ return -1; @@ -1105,15 +1103,16 @@ int attribute_hidden _ppfs_parsespec(ppfs_t *ppfs) ppfs->argtype[n] = argtype[i]; } } while (++i < ppfs->num_data_args + 2); - } else { + } else #endif /* NL_ARGMAX */ + { ppfs->argnumber[2] = 1; memcpy(ppfs->argtype, argtype + 2, ppfs->num_data_args * sizeof(int)); -#ifdef NL_ARGMAX } +#ifdef NL_ARGMAX ppfs->maxposarg = maxposarg; -#endif /* NL_ARGMAX */ +#endif #ifdef __UCLIBC_HAS_WCHAR__ flags = ppfs->info._flags & FLAG_WIDESTREAM; @@ -1125,7 +1124,7 @@ int attribute_hidden _ppfs_parsespec(ppfs_t *ppfs) } #else /* __UCLIBC_HAS_WCHAR__ */ ppfs->fmtpos = ++fmt; -#endif /* __UCLIBC_HAS_WCHAR__ */ +#endif return ppfs->num_data_args + 2; } @@ -1296,13 +1295,13 @@ static size_t _fp_out_wide(FILE *fp, intptr_t type, intptr_t len, intptr_t buf) do { #ifdef __LOCALE_C_ONLY wbuf[i] = s[i]; -#else /* __LOCALE_C_ONLY */ +#else -#ifdef __UCLIBC_HAS_GLIBC_DIGIT_GROUPING__ +# ifdef __UCLIBC_HAS_GLIBC_DIGIT_GROUPING__ if (s[i] == ',') { wbuf[i] = __UCLIBC_CURLOCALE->thousands_sep_wc; } else -#endif /* __UCLIBC_HAS_GLIBC_DIGIT_GROUPING__ */ +# endif if (s[i] == '.') { wbuf[i] = __UCLIBC_CURLOCALE->decimal_point_wc; } else { @@ -1329,7 +1328,7 @@ static int _ppwfs_init(register ppfs_t *ppfs, const wchar_t *fmt0) memset(ppfs, 0, sizeof(ppfs_t)); /* TODO: nonportable???? */ #ifdef NL_ARGMAX --ppfs->maxposarg; /* set to -1 */ -#endif /* NL_ARGMAX */ +#endif ppfs->fmtpos = (const char *) fmt0; ppfs->info._flags = FLAG_WIDESTREAM; @@ -1430,9 +1429,9 @@ static int _do_one_spec(FILE * __restrict stream, #ifdef L__vfprintf_internal static const char prefix[] = "+\0-\0 \0000x\0000X"; /* 0 2 4 6 9 11*/ -#else /* L__vfprintf_internal */ +#else static const wchar_t prefix[] = L"+\0-\0 \0000x\0000X"; -#endif /* L__vfprintf_internal */ +#endif enum { PREFIX_PLUS = 0, PREFIX_MINUS = 2, @@ -1451,7 +1450,7 @@ static int _do_one_spec(FILE * __restrict stream, #ifdef __UCLIBC_HAS_WCHAR__ const wchar_t *ws = NULL; mbstate_t mbstate; -#endif /* __UCLIBC_HAS_WCHAR__ */ +#endif size_t slen; #ifdef L__vfprintf_internal #define SLEN slen @@ -1467,7 +1466,7 @@ static int _do_one_spec(FILE * __restrict stream, char padchar = ' '; #ifdef __UCLIBC_MJN3_ONLY__ #warning TODO: Determine appropriate buf size. -#endif /* __UCLIBC_MJN3_ONLY__ */ +#endif /* TODO: buf needs to be big enough for any possible error return strings * and also for any locale-grouped long long integer strings generated. * This should be large enough for any of the current archs/locales, but @@ -1487,21 +1486,21 @@ static int _do_one_spec(FILE * __restrict stream, /* Deal with the argptr vs argvalue issue. */ #ifdef __va_arg_ptr argptr = (const void * const *) ppfs->argptr; -#ifdef NL_ARGMAX +# ifdef NL_ARGMAX if (ppfs->maxposarg > 0) { /* Using positional args... */ argptr += ppfs->argnumber[2] - 1; } -#endif /* NL_ARGMAX */ +# endif #else /* Need to build a local copy... */ { register argvalue_t *p = ppfs->argvalue; int i; -#ifdef NL_ARGMAX +# ifdef NL_ARGMAX if (ppfs->maxposarg > 0) { /* Using positional args... */ p += ppfs->argnumber[2] - 1; } -#endif /* NL_ARGMAX */ +# endif for (i = 0 ; i < ppfs->num_data_args ; i++ ) { argptr[i] = (void *) p++; } @@ -1523,7 +1522,7 @@ static int _do_one_spec(FILE * __restrict stream, #ifdef L__vfprintf_internal #warning CONSIDER: Should we ignore these flags if stub locale? What about custom specs? #endif -#endif /* __UCLIBC_MJN3_ONLY__ */ +#endif base = spec_base[(int)(ppfs->conv_num - CONV_p)]; if (base == 10) { if (PRINT_INFO_FLAG_VAL(&(ppfs->info),group)) { @@ -1552,7 +1551,7 @@ static int _do_one_spec(FILE * __restrict stream, #ifdef L__vfprintf_internal #warning CONSIDER: If using outdigits and/or grouping, how should we interpret precision? #endif -#endif /* __UCLIBC_MJN3_ONLY__ */ +#endif s = _uintmaxtostr(buf + sizeof(buf) - 1, (uintmax_t) _load_inttype(ppfs->conv_num == CONV_p ? PA_FLAG_LONG : *argtype & __PA_INTMASK, @@ -1624,7 +1623,7 @@ static int _do_one_spec(FILE * __restrict stream, return 0; #else /* __STDIO_PRINTF_FLOAT */ return -1; /* TODO -- try to continue? */ -#endif /* __STDIO_PRINTF_FLOAT */ +#endif } else if (ppfs->conv_num <= CONV_S) { /* wide char or string */ #ifdef L__vfprintf_internal @@ -1658,7 +1657,7 @@ static int _do_one_spec(FILE * __restrict stream, } #else /* __UCLIBC_HAS_WCHAR__ */ return -1; -#endif /* __UCLIBC_HAS_WCHAR__ */ +#endif } else if (ppfs->conv_num <= CONV_s) { /* char or string */ if (ppfs->conv_num == CONV_s) { /* string */ s = *((char **) (*argptr)); @@ -1704,7 +1703,7 @@ static int _do_one_spec(FILE * __restrict stream, if (ppfs->conv_num == CONV_s) { /* string */ #ifdef __UCLIBC_MJN3_ONLY__ #warning TODO: Fix %s for _vfwprintf_internal... output upto illegal sequence? -#endif /* __UCLIBC_MJN3_ONLY__ */ +#endif s = *((char **) (*argptr)); if (s) { #ifdef __UCLIBC_HAS_PRINTF_M_SPEC__ @@ -1771,7 +1770,7 @@ static int _do_one_spec(FILE * __restrict stream, #ifdef L__vfprintf_internal #warning CONSIDER: If using outdigits and/or grouping, how should we pad? #endif -#endif /* __UCLIBC_MJN3_ONLY__ */ +#endif { size_t t; @@ -1802,7 +1801,7 @@ static int _do_one_spec(FILE * __restrict stream, #ifdef L__vfprintf_internal -#ifdef __UCLIBC_HAS_WCHAR__ +# ifdef __UCLIBC_HAS_WCHAR__ if (!ws) { assert(s); if (_outnstr(stream, s, slen) != slen) { @@ -1814,18 +1813,18 @@ static int _do_one_spec(FILE * __restrict stream, while (slen) { t = (slen <= sizeof(buf)) ? slen : sizeof(buf); t = wcsrtombs(buf, &ws, t, &mbstate); - assert (t != ((size_t)(-1))); + assert(t != ((size_t)(-1))); if (_outnstr(stream, buf, t) != t) { return -1; } slen -= t; } } -#else /* __UCLIBC_HAS_WCHAR__ */ +# else /* __UCLIBC_HAS_WCHAR__ */ if (_outnstr(stream, (const unsigned char *) s, slen) != slen) { return -1; } -#endif /* __UCLIBC_HAS_WCHAR__ */ +# endif #else /* L__vfprintf_internal */ @@ -1930,13 +1929,13 @@ int VFPRINTF_internal (FILE * __restrict stream, * is using __stdio_fwrite (TODO: do the same for wide functions). */ #ifdef L_vfprintf -#define VFPRINTF vfprintf -#define VFPRINTF_internal _vfprintf_internal -#define FMT_TYPE char +# define VFPRINTF vfprintf +# define VFPRINTF_internal _vfprintf_internal +# define FMT_TYPE char #else -#define VFPRINTF vfwprintf -#define VFPRINTF_internal _vfwprintf_internal -#define FMT_TYPE wchar_t +# define VFPRINTF vfwprintf +# define VFPRINTF_internal _vfwprintf_internal +# define FMT_TYPE wchar_t #endif libc_hidden_proto(VFPRINTF) -- cgit v1.2.3 From 984e74b6df47fe33622a06e6995324f706b8f936 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 19 Oct 2010 14:46:05 +0200 Subject: _vfprintf.c: de-obfuscate badly twisted fragment. no code changes. objdump confirms that I did not mess it up. Signed-off-by: Denys Vlasenko --- libc/stdio/_vfprintf.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/libc/stdio/_vfprintf.c b/libc/stdio/_vfprintf.c index 721efe2f7..8c5e0e76c 100644 --- a/libc/stdio/_vfprintf.c +++ b/libc/stdio/_vfprintf.c @@ -1059,16 +1059,14 @@ int attribute_hidden _ppfs_parsespec(ppfs_t *ppfs) } #endif #ifdef __UCLIBC_HAS_GLIBC_CUSTOM_PRINTF__ - /* Handle custom arg -- WARNING -- overwrites p!!! */ ppfs->conv_num = CONV_custom0; p = _custom_printf_spec; do { if (*p == *fmt) { - if ((ppfs->num_data_args - = ((*_custom_printf_arginfo[(int)(p-_custom_printf_spec)]) - (&(ppfs->info), MAX_ARGS_PER_SPEC, argtype+2))) - > MAX_ARGS_PER_SPEC) { + printf_arginfo_function *fp = _custom_printf_arginfo[(int)(p - _custom_printf_spec)]; + ppfs->num_data_args = fp(&(ppfs->info), MAX_ARGS_PER_SPEC, argtype + 2); + if (ppfs->num_data_args > MAX_ARGS_PER_SPEC) { break; /* Error -- too many args! */ } goto DONE; -- cgit v1.2.3 From 71dcf8f4401b27f2b7446601a6d0dbcddc0aa8b4 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 19 Oct 2010 15:07:00 +0200 Subject: vfprintf.c: reduce a chunk of #ifdef forest and remove one goto inside it No code changes according to objdump. Signed-off-by: Denys Vlasenko --- libc/stdio/_vfprintf.c | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/libc/stdio/_vfprintf.c b/libc/stdio/_vfprintf.c index 8c5e0e76c..3b007084d 100644 --- a/libc/stdio/_vfprintf.c +++ b/libc/stdio/_vfprintf.c @@ -1055,31 +1055,30 @@ int attribute_hidden _ppfs_parsespec(ppfs_t *ppfs) if (*fmt == 'm') { ppfs->conv_num = CONV_m; ppfs->num_data_args = 0; - goto DONE; - } + } else #endif -#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_PRINTF__ - /* Handle custom arg -- WARNING -- overwrites p!!! */ - ppfs->conv_num = CONV_custom0; - p = _custom_printf_spec; - do { - if (*p == *fmt) { - printf_arginfo_function *fp = _custom_printf_arginfo[(int)(p - _custom_printf_spec)]; - ppfs->num_data_args = fp(&(ppfs->info), MAX_ARGS_PER_SPEC, argtype + 2); - if (ppfs->num_data_args > MAX_ARGS_PER_SPEC) { - break; /* Error -- too many args! */ + { +#ifndef __UCLIBC_HAS_GLIBC_CUSTOM_PRINTF__ + return -1; /* Error */ +#else + /* Handle custom arg -- WARNING -- overwrites p!!! */ + ppfs->conv_num = CONV_custom0; + p = _custom_printf_spec; + while (1) { + if (*p == *fmt) { + printf_arginfo_function *fp = _custom_printf_arginfo[(int)(p - _custom_printf_spec)]; + ppfs->num_data_args = fp(&(ppfs->info), MAX_ARGS_PER_SPEC, argtype + 2); + if (ppfs->num_data_args > MAX_ARGS_PER_SPEC) { + return -1; /* Error -- too many args! */ + } + break; } - goto DONE; + if (++p >= (_custom_printf_spec + MAX_USER_SPEC)) + return -1; /* Error */ } - } while (++p < (_custom_printf_spec + MAX_USER_SPEC)); -#endif /* __UCLIBC_HAS_GLIBC_CUSTOM_PRINTF__ */ - /* Otherwise error. */ - return -1; - } - -#if defined(__UCLIBC_HAS_GLIBC_CUSTOM_PRINTF__) || defined(__UCLIBC_HAS_PRINTF_M_SPEC__) - DONE: #endif + } + } #ifdef NL_ARGMAX if (maxposarg > 0) { -- cgit v1.2.3 From c403e32526bc99e886d58a09e11a4f3043af8040 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 21 Oct 2010 18:19:35 +0200 Subject: sleep: code shrink Use less stack by using same "sigset_t set" object for new and saved signal set, remove redundant clearing of set, and do not save/restore errno around sigprocmask(SIG_SETMASK) - it never changes it. While at it, improve comments and make code style consistent across sleep.c file. text data bss dec hex filename - 242 0 0 242 f2 libc/unistd/sleep.o + 197 0 0 197 c5 libc/unistd/sleep.o Signed-off-by: Denys Vlasenko --- libc/unistd/sleep.c | 47 +++++++++++++++++++++-------------------------- libc/unistd/usleep.c | 14 +++++++------- 2 files changed, 28 insertions(+), 33 deletions(-) diff --git a/libc/unistd/sleep.c b/libc/unistd/sleep.c index b0031f022..d844d5b11 100644 --- a/libc/unistd/sleep.c +++ b/libc/unistd/sleep.c @@ -49,50 +49,45 @@ unsigned int sleep (unsigned int sec) unsigned int sleep (unsigned int seconds) { struct timespec ts = { .tv_sec = (long int) seconds, .tv_nsec = 0 }; - sigset_t set, oset; + sigset_t set; unsigned int result; /* This is not necessary but some buggy programs depend on this. */ - if (seconds == 0) - { + if (seconds == 0) { # ifdef CANCELLATION_P - CANCELLATION_P (THREAD_SELF); + CANCELLATION_P (THREAD_SELF); # endif - return 0; - } + return 0; + } /* Linux will wake up the system call, nanosleep, when SIGCHLD arrives even if SIGCHLD is ignored. We have to deal with it in libc. We block SIGCHLD first. */ __sigemptyset (&set); __sigaddset (&set, SIGCHLD); - sigprocmask (SIG_BLOCK, &set, &oset); /* can't fail */ + sigprocmask (SIG_BLOCK, &set, &set); /* never fails */ - /* If SIGCHLD is already blocked, we don't have to do anything. */ - if (!__sigismember (&oset, SIGCHLD)) - { - int saved_errno; + /* If SIGCHLD was already blocked, no need to check SIG_IGN. Else... */ + if (!__sigismember (&set, SIGCHLD)) { struct sigaction oact; - __sigemptyset (&set); - __sigaddset (&set, SIGCHLD); - + /* Is SIGCHLD set to SIG_IGN? */ sigaction (SIGCHLD, NULL, &oact); /* never fails */ + if (oact.sa_handler == SIG_IGN) { + //int saved_errno; - if (oact.sa_handler == SIG_IGN) - { - /* We should leave SIGCHLD blocked. */ + /* Yes, run nanosleep with SIGCHLD blocked. */ result = nanosleep (&ts, &ts); - saved_errno = errno; - /* Restore the original signal mask. */ - sigprocmask (SIG_SETMASK, &oset, NULL); - __set_errno (saved_errno); - } - else - { - /* We should unblock SIGCHLD. Restore the original signal mask. */ - sigprocmask (SIG_SETMASK, &oset, NULL); + /* Unblock SIGCHLD by restoring signal mask. */ + /* this sigprocmask call never fails, thus never updates errno, + and therefore we don't need to save/restore it. */ + //saved_errno = errno; + sigprocmask (SIG_SETMASK, &set, NULL); + //__set_errno (saved_errno); + } else { + /* No workaround needed, unblock SIGCHLD by restoring signal mask. */ + sigprocmask (SIG_SETMASK, &set, NULL); result = nanosleep (&ts, &ts); } } diff --git a/libc/unistd/usleep.c b/libc/unistd/usleep.c index 61ddb900a..8d01703ec 100644 --- a/libc/unistd/usleep.c +++ b/libc/unistd/usleep.c @@ -14,19 +14,19 @@ int usleep (__useconds_t usec) { - const struct timespec ts = { - .tv_sec = (long int) (usec / 1000000), - .tv_nsec = (long int) (usec % 1000000) * 1000ul - }; - return(nanosleep(&ts, NULL)); + const struct timespec ts = { + .tv_sec = (long int) (usec / 1000000), + .tv_nsec = (long int) (usec % 1000000) * 1000ul + }; + return nanosleep(&ts, NULL); } #else /* __UCLIBC_HAS_REALTIME__ */ int usleep (__useconds_t usec) { struct timeval tv; - tv.tv_sec = 0; - tv.tv_usec = usec; + tv.tv_sec = (long int) (usec / 1000000); + tv.tv_usec = (long int) (usec % 1000000); return select(0, NULL, NULL, NULL, &tv); } #endif /* __UCLIBC_HAS_REALTIME__ */ -- cgit v1.2.3 From 5e8d3975e2cb45df16038e2a99c74abfb252d44a Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 22 Oct 2010 13:48:57 +0200 Subject: sleep: remove commented-out code. no code changes It can be easily reconstructed, since it's obvious Signed-off-by: Denys Vlasenko --- libc/unistd/sleep.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libc/unistd/sleep.c b/libc/unistd/sleep.c index d844d5b11..55e646380 100644 --- a/libc/unistd/sleep.c +++ b/libc/unistd/sleep.c @@ -74,17 +74,13 @@ unsigned int sleep (unsigned int seconds) /* Is SIGCHLD set to SIG_IGN? */ sigaction (SIGCHLD, NULL, &oact); /* never fails */ if (oact.sa_handler == SIG_IGN) { - //int saved_errno; - /* Yes, run nanosleep with SIGCHLD blocked. */ result = nanosleep (&ts, &ts); /* Unblock SIGCHLD by restoring signal mask. */ /* this sigprocmask call never fails, thus never updates errno, and therefore we don't need to save/restore it. */ - //saved_errno = errno; sigprocmask (SIG_SETMASK, &set, NULL); - //__set_errno (saved_errno); } else { /* No workaround needed, unblock SIGCHLD by restoring signal mask. */ sigprocmask (SIG_SETMASK, &set, NULL); -- cgit v1.2.3 From f53db356f53686cb0e4ddb25946b8cff9e82453d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Ter=C3=A4s?= Date: Fri, 22 Oct 2010 13:58:13 +0200 Subject: libm/x86: use call instead of jump for wrappers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GCC can emit prologue/epilogue code for the functions in various different cases: - frame pointers - PIC build (to load ebx for indirect calls/jumps) - forced stack smashing protection If we used jump in such cases, we'd corrupt the call stack and crash. Signed-off-by: Timo Teräs Signed-off-by: Denys Vlasenko --- libm/ldouble_wrappers.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/libm/ldouble_wrappers.c b/libm/ldouble_wrappers.c index bf7ae15f0..f78a97a05 100644 --- a/libm/ldouble_wrappers.c +++ b/libm/ldouble_wrappers.c @@ -61,6 +61,10 @@ long long func##l(long double x) \ * a long double or returning a double). So we can simply jump to func. * Using __GI_func in jump to make optimized intra-library jump. * gcc will still generate a useless "ret" after asm. Oh well... + * + * Update: we do need to use call (instead of tail jump) as gcc can create + * stack frame, and push/modify/pop ebx during PIC build. + * TODO: add conditionals to use tail jump if possible? */ # define WRAPPER1(func) \ long double func##l(long double x) \ @@ -69,7 +73,7 @@ long double func##l(long double x) \ __asm__ ( \ " fldt %1\n" \ " fstpl %1\n" \ - " jmp " __stringify(__GI_##func) "\n" \ + " call " __stringify(__GI_##func) "\n" \ : "=t" (st_top) \ : "m" (x) \ ); \ @@ -82,7 +86,7 @@ int func##l(long double x) \ __asm__ ( \ " fldt %1\n" \ " fstpl %1\n" \ - " jmp " __stringify(__GI_##func) "\n" \ + " call " __stringify(__GI_##func) "\n" \ : "=a" (ret) \ : "m" (x) \ ); \ @@ -95,7 +99,7 @@ long func##l(long double x) \ __asm__ ( \ " fldt %1\n" \ " fstpl %1\n" \ - " jmp " __stringify(__GI_##func) "\n" \ + " call " __stringify(__GI_##func) "\n" \ : "=a" (ret) \ : "m" (x) \ ); \ @@ -108,7 +112,7 @@ long long func##l(long double x) \ __asm__ ( \ " fldt %1\n" \ " fstpl %1\n" \ - " jmp " __stringify(__GI_##func) "\n" \ + " call " __stringify(__GI_##func) "\n" \ : "=A" (ret) \ : "m" (x) \ ); \ -- cgit v1.2.3 From 62fb840ea00d9d10446959d290d93a45065220f4 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 22 Oct 2010 15:22:40 +0200 Subject: sleep: check "SIGCHLD is SIG_IGN'ed" first. Saves two syscalls in common case text data bss dec hex filename - 197 0 0 197 c5 libc/unistd/sleep.o + 168 0 0 168 a8 libc/unistd/sleep.o Signed-off-by: Denys Vlasenko --- libc/unistd/sleep.c | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/libc/unistd/sleep.c b/libc/unistd/sleep.c index 55e646380..481e635a2 100644 --- a/libc/unistd/sleep.c +++ b/libc/unistd/sleep.c @@ -50,6 +50,7 @@ unsigned int sleep (unsigned int seconds) { struct timespec ts = { .tv_sec = (long int) seconds, .tv_nsec = 0 }; sigset_t set; + struct sigaction oact; unsigned int result; /* This is not necessary but some buggy programs depend on this. */ @@ -62,33 +63,28 @@ unsigned int sleep (unsigned int seconds) /* Linux will wake up the system call, nanosleep, when SIGCHLD arrives even if SIGCHLD is ignored. We have to deal with it - in libc. We block SIGCHLD first. */ + in libc. */ + __sigemptyset (&set); __sigaddset (&set, SIGCHLD); - sigprocmask (SIG_BLOCK, &set, &set); /* never fails */ - /* If SIGCHLD was already blocked, no need to check SIG_IGN. Else... */ + /* Is SIGCHLD set to SIG_IGN? */ + sigaction (SIGCHLD, NULL, &oact); /* never fails */ + if (oact.sa_handler == SIG_IGN) { + /* Yes. Block SIGCHLD, save old mask. */ + sigprocmask (SIG_BLOCK, &set, &set); /* never fails */ + } + + /* Run nanosleep, with SIGCHLD blocked if SIGCHLD is SIG_IGNed. */ + result = nanosleep (&ts, &ts); + if (!__sigismember (&set, SIGCHLD)) { - struct sigaction oact; - - /* Is SIGCHLD set to SIG_IGN? */ - sigaction (SIGCHLD, NULL, &oact); /* never fails */ - if (oact.sa_handler == SIG_IGN) { - /* Yes, run nanosleep with SIGCHLD blocked. */ - result = nanosleep (&ts, &ts); - - /* Unblock SIGCHLD by restoring signal mask. */ - /* this sigprocmask call never fails, thus never updates errno, - and therefore we don't need to save/restore it. */ - sigprocmask (SIG_SETMASK, &set, NULL); - } else { - /* No workaround needed, unblock SIGCHLD by restoring signal mask. */ - sigprocmask (SIG_SETMASK, &set, NULL); - result = nanosleep (&ts, &ts); - } + /* We did block SIGCHLD, and old mask had no SIGCHLD bit. + IOW: we need to unblock SIGCHLD now. Do it. */ + /* this sigprocmask call never fails, thus never updates errno, + and therefore we don't need to save/restore it. */ + sigprocmask (SIG_SETMASK, &set, NULL); /* never fails */ } - else - result = nanosleep (&ts, &ts); if (result != 0) /* Round remaining time. */ -- cgit v1.2.3 From 251a3c19cb4bba47fcd38c697b3d7679b3edb137 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 22 Oct 2010 15:24:13 +0200 Subject: sleep: employ __USE_EXTERN_INLINES (with necessary fixes) __USE_EXTERN_INLINES was unused and had bit-rotted, had to fix it when it didn't work as intended at first. text data bss dec hex filename - 168 0 0 168 a8 libc/unistd/sleep.o + 146 0 0 146 92 libc/unistd/sleep.o Signed-off-by: Denys Vlasenko --- libc/signal/sigsetops.c | 2 +- libc/sysdeps/linux/common/bits/sigset.h | 14 ++++++++++---- libc/unistd/sleep.c | 7 ++++++- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/libc/signal/sigsetops.c b/libc/signal/sigsetops.c index c47a87b0e..e39d32f99 100644 --- a/libc/signal/sigsetops.c +++ b/libc/signal/sigsetops.c @@ -3,7 +3,7 @@ #include -#define _EXTERN_INLINE +#define __PROVIDE_OUT_OF_LINE_SIGSETFN #ifndef __USE_EXTERN_INLINES # define __USE_EXTERN_INLINES 1 #endif diff --git a/libc/sysdeps/linux/common/bits/sigset.h b/libc/sysdeps/linux/common/bits/sigset.h index 2f67a4ebf..7c2ce0ebe 100644 --- a/libc/sysdeps/linux/common/bits/sigset.h +++ b/libc/sysdeps/linux/common/bits/sigset.h @@ -53,10 +53,6 @@ typedef struct { #if !defined _SIGSET_H_fns && defined _SIGNAL_H # define _SIGSET_H_fns 1 -# ifndef _EXTERN_INLINE -# define _EXTERN_INLINE extern __inline -# endif - /* Return a mask that includes the bit for SIG only. */ /* Unsigned cast ensures shift/mask insns are used. */ # define __sigmask(sig) \ @@ -156,14 +152,24 @@ typedef struct { /* These functions needn't check for a bogus signal number -- error checking is done in the non __ versions. */ +# if !defined __USE_EXTERN_INLINES || defined __PROVIDE_OUT_OF_LINE_SIGSETFN extern int __sigismember (__const __sigset_t *, int); libc_hidden_proto(__sigismember) extern int __sigaddset (__sigset_t *, int); libc_hidden_proto(__sigaddset) extern int __sigdelset (__sigset_t *, int); libc_hidden_proto(__sigdelset) +# endif # ifdef __USE_EXTERN_INLINES +# undef _EXTERN_INLINE +# ifdef __PROVIDE_OUT_OF_LINE_SIGSETFN +# define _EXTERN_INLINE +# else /* normal case */ + /* dropped extern below: otherwise every module with __USE_EXTERN_INLINES + * will have its own copy of out-of line function emitted. */ +# define _EXTERN_INLINE /*extern*/ __always_inline +# endif # define __SIGSETFN(NAME, BODY, CONST) \ _EXTERN_INLINE int \ NAME (CONST __sigset_t *__set, int __sig) \ diff --git a/libc/unistd/sleep.c b/libc/unistd/sleep.c index 481e635a2..438f5e282 100644 --- a/libc/unistd/sleep.c +++ b/libc/unistd/sleep.c @@ -20,8 +20,13 @@ #include #include -#include #include +/* Want fast and small __sigemptyset/__sigaddset/__sigismember: */ +/* TODO: make them available (to everybody) without this hack */ +#ifndef __USE_EXTERN_INLINES +# define __USE_EXTERN_INLINES 1 +#endif +#include -- cgit v1.2.3 From e9b9c97c33c52e9eafaf6bf6d682e43ecfa3aea7 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 22 Oct 2010 15:46:04 +0200 Subject: sleep: tiny code shrink ...or rather, it WILL BE code shrink when gcc become clever enough to not emit a second, useless XORing of ebx: 31 db xor %ebx,%ebx 85 c0 test %eax,%eax 74 11 je 73 <__GI_sleep+0x73> 31 db xor %ebx,%ebx <=== ?! Signed-off-by: Denys Vlasenko --- libc/unistd/sleep.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libc/unistd/sleep.c b/libc/unistd/sleep.c index 438f5e282..6a237e3f9 100644 --- a/libc/unistd/sleep.c +++ b/libc/unistd/sleep.c @@ -82,6 +82,10 @@ unsigned int sleep (unsigned int seconds) /* Run nanosleep, with SIGCHLD blocked if SIGCHLD is SIG_IGNed. */ result = nanosleep (&ts, &ts); + if (result != 0) { + /* Got EINTR. Return remaining time. */ + result = (unsigned int) ts.tv_sec + (ts.tv_nsec >= 500000000L); + } if (!__sigismember (&set, SIGCHLD)) { /* We did block SIGCHLD, and old mask had no SIGCHLD bit. @@ -91,10 +95,6 @@ unsigned int sleep (unsigned int seconds) sigprocmask (SIG_SETMASK, &set, NULL); /* never fails */ } - if (result != 0) - /* Round remaining time. */ - result = (unsigned int) ts.tv_sec + (ts.tv_nsec >= 500000000L); - return result; } #endif -- cgit v1.2.3 From 4bbf7dfe44bb83391b12ac94ca478df71fcf3dd7 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 22 Oct 2010 16:52:41 +0200 Subject: remove superfluous libc_hidden_proto(memcpy) and #include Signed-off-by: Denys Vlasenko --- libc/sysdeps/linux/common/__rt_sigtimedwait.c | 4 ---- libc/sysdeps/linux/common/__rt_sigwaitinfo.c | 4 ---- 2 files changed, 8 deletions(-) diff --git a/libc/sysdeps/linux/common/__rt_sigtimedwait.c b/libc/sysdeps/linux/common/__rt_sigtimedwait.c index 79b94adef..a7ab8fb61 100644 --- a/libc/sysdeps/linux/common/__rt_sigtimedwait.c +++ b/libc/sysdeps/linux/common/__rt_sigtimedwait.c @@ -12,11 +12,7 @@ #include #include -libc_hidden_proto(memcpy) - #ifdef __NR_rt_sigtimedwait -#include -libc_hidden_proto(memcpy) # ifdef __UCLIBC_HAS_THREADS_NATIVE__ # include diff --git a/libc/sysdeps/linux/common/__rt_sigwaitinfo.c b/libc/sysdeps/linux/common/__rt_sigwaitinfo.c index c8953bfbc..92a11c9b6 100644 --- a/libc/sysdeps/linux/common/__rt_sigwaitinfo.c +++ b/libc/sysdeps/linux/common/__rt_sigwaitinfo.c @@ -12,12 +12,8 @@ #include #include -libc_hidden_proto(memcpy) - #ifdef __NR_rt_sigtimedwait -#include - # ifdef __UCLIBC_HAS_THREADS_NATIVE__ # include -- cgit v1.2.3 From 162cfaea20d807f0ae329efe39292a9b22593b41 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 22 Oct 2010 17:01:05 +0200 Subject: *: inline constant __sig{add,del}set and __sigismember text data bss dec hex filename - 318 4 0 322 142 libc/pwd_grp/lckpwdf.o + 312 4 0 316 13c libc/pwd_grp/lckpwdf.o - 166 0 1 167 a7 libc/stdlib/abort.o + 157 0 1 158 9e libc/stdlib/abort.o - 42 0 0 42 2a libc/sysdeps/linux/common/pause.o + 27 0 0 27 1b libc/sysdeps/linux/common/pause.o Signed-off-by: Denys Vlasenko --- libc/signal/sigsetops.c | 3 ++ libc/stdlib/system.c | 5 ++-- libc/sysdeps/linux/common/bits/sigset.h | 35 +++++++++++++++++++++- libc/sysdeps/linux/common/pause.c | 2 +- libc/unistd/sleep.c | 8 +---- .../nptl/sysdeps/unix/sysv/linux/timer_routines.c | 2 +- 6 files changed, 43 insertions(+), 12 deletions(-) diff --git a/libc/signal/sigsetops.c b/libc/signal/sigsetops.c index e39d32f99..fa5fe6acf 100644 --- a/libc/signal/sigsetops.c +++ b/libc/signal/sigsetops.c @@ -12,6 +12,9 @@ /* Since we massaged signal.h into emitting non-inline function * definitions, we need to finish PLT avoidance trick: */ +#undef __sigismember +#undef __sigaddset +#undef __sigdelset libc_hidden_def(__sigismember) libc_hidden_def(__sigaddset) libc_hidden_def(__sigdelset) diff --git a/libc/stdlib/system.c b/libc/stdlib/system.c index acd86761d..59f5cc9c6 100644 --- a/libc/stdlib/system.c +++ b/libc/stdlib/system.c @@ -126,9 +126,10 @@ do_system (const char *line) struct sigaction sa; sigset_t omask; + memset(&sa,