summaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2005-08-18 01:16:25 +0000
committerMike Frysinger <vapier@gentoo.org>2005-08-18 01:16:25 +0000
commit93cfbb84b1a61bf081e5afb0410bf80c5a0a2f36 (patch)
tree4959fe1e42046b86a0cef635f0e64039e572841d /libc
parent231572ebb54a32649de68cb579c1cc0546896288 (diff)
rework some of the code to shrink size
Diffstat (limited to 'libc')
-rw-r--r--libc/inet/rpc/getrpcent.c35
1 files changed, 19 insertions, 16 deletions
diff --git a/libc/inet/rpc/getrpcent.c b/libc/inet/rpc/getrpcent.c
index ac693e21a..5e86cb9c8 100644
--- a/libc/inet/rpc/getrpcent.c
+++ b/libc/inet/rpc/getrpcent.c
@@ -128,17 +128,26 @@ void endrpcent()
if (d == NULL)
return;
- if (d->current && !d->stayopen) {
+ if (d->stayopen)
+ return;
+ if (d->current) {
free(d->current);
d->current = NULL;
}
- if (d->rpcf && !d->stayopen) {
+ if (d->rpcf) {
fclose(d->rpcf);
d->rpcf = NULL;
}
}
-static struct rpcent *interpret(const char *val, int len);
+static struct rpcent *interpret(struct rpcdata *);
+
+static struct rpcent *__get_next_rpcent(struct rpcdata *d)
+{
+ if (fgets(d->line, BUFSIZ, d->rpcf) == NULL)
+ return NULL;
+ return interpret(d);
+}
struct rpcent *getrpcent()
{
@@ -148,9 +157,7 @@ struct rpcent *getrpcent()
return NULL;
if (d->rpcf == NULL && (d->rpcf = fopen(RPCDB, "r")) == NULL)
return NULL;
- if (fgets(d->line, BUFSIZ, d->rpcf) == NULL)
- return NULL;
- return interpret(d->line, strlen(d->line));
+ return __get_next_rpcent(d);
}
#ifdef __linux__
@@ -170,37 +177,33 @@ static char *firstwhite(char *s)
}
#endif
-static struct rpcent *interpret(const char *val, int len)
+static struct rpcent *interpret(register struct rpcdata *d)
{
- register struct rpcdata *d = _rpcdata();
char *p;
register char *cp, **q;
- if (d == NULL)
- return NULL;
- strncpy(d->line, val, len);
p = d->line;
- d->line[len] = '\n';
+ d->line[strlen(p)-1] = '\n';
if (*p == '#')
- return (getrpcent());
+ return __get_next_rpcent(d);
cp = index(p, '#');
if (cp == NULL) {
cp = index(p, '\n');
if (cp == NULL)
- return (getrpcent());
+ return __get_next_rpcent(d);
}
*cp = '\0';
#ifdef __linux__
if ((cp = firstwhite(p)))
*cp++ = 0;
else
- return (getrpcent());
+ return __get_next_rpcent(d);
#else
cp = index(p, ' ');
if (cp == NULL) {
cp = index(p, '\t');
if (cp == NULL)
- return (getrpcent());
+ return __get_next_rpcent(d);
}
*cp++ = '\0';
#endif