summaryrefslogtreecommitdiff
path: root/libc/inet/getservice.c
diff options
context:
space:
mode:
authorCarmelo Amoroso <carmelo.amoroso@st.com>2010-11-28 21:09:47 +0100
committerCarmelo Amoroso <carmelo.amoroso@st.com>2010-11-28 21:09:47 +0100
commit57f6cce72c889f2e7b342e87a565a064320a6ee2 (patch)
tree5466406472918d3adb63398f5fb9ea1511a5e73f /libc/inet/getservice.c
parent4ec89b87bc0eea8d9ca6b50564d12eeb3b1b0119 (diff)
parent5dea871ac73ef4608022c058b50adc946917f9b9 (diff)
Merge commit 'origin/master' into prelink
Conflicts: ldso/include/dl-hash.h Signed-off-by: Carmelo Amoroso <carmelo.amoroso@st.com>
Diffstat (limited to 'libc/inet/getservice.c')
-rw-r--r--libc/inet/getservice.c43
1 files changed, 18 insertions, 25 deletions
diff --git a/libc/inet/getservice.c b/libc/inet/getservice.c
index 47d26a262..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 <bits/uClibc_mutex.h>
__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,11 +67,9 @@ 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;
- int ret = ENOENT;
+ const size_t aliaslen = sizeof(char *) * MAXTOKENS;
+ 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)
@@ -87,14 +87,13 @@ int getservent_r(struct servent *result_buf,
servp->data_len = aliaslen;
servp->line_len = buflen - aliaslen;
/* <name>[[:space:]]<port>/<proto>[[:space:]][<aliases>] */
- if (!config_read(servp, &tok, MAXALIASES, 3, "# \t/", PARSE_NORMAL)) {
- ret = ERANGE;
+ 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:
@@ -107,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();
}
@@ -118,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;
}
@@ -155,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;
}
@@ -188,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)