From f5c05b8c3da2fc70133778daf099b00c5d090ff9 Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Mon, 30 Jul 2007 16:55:05 +0000 Subject: make getnetent.c, md5.c use __uc_malloc --- libc/inet/getnetent.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'libc') diff --git a/libc/inet/getnetent.c b/libc/inet/getnetent.c index d5c25034c..58e679070 100644 --- a/libc/inet/getnetent.c +++ b/libc/inet/getnetent.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -32,14 +33,9 @@ libc_hidden_proto(abort) #include __UCLIBC_MUTEX_STATIC(mylock, PTHREAD_MUTEX_INITIALIZER); - - -#define MAXALIASES 35 static const char NETDB[] = _PATH_NETWORKS; + static FILE *netf = NULL; -static char *line = NULL; -static struct netent net; -static char *net_aliases[MAXALIASES]; int _net_stayopen attribute_hidden; @@ -83,6 +79,22 @@ static char * any(register char *cp, char *match) return ((char *)0); } +#define MAXALIASES 35 +static struct { + char *line; + struct netent net; + char *net_aliases[MAXALIASES]; +} *sp; +#define line (sp->line) +#define net (sp->net) +#define net_aliases (sp->net_aliases) +#define INIT_SP() { \ + if (!sp) { \ + sp = __uc_malloc(sizeof(*sp)); \ + line = NULL; \ + } \ +} + libc_hidden_proto(getnetent) struct netent *getnetent(void) { @@ -90,6 +102,8 @@ struct netent *getnetent(void) register char *cp, **q; struct netent *rv = NULL; + INIT_SP(); + __UCLIBC_MUTEX_LOCK(mylock); if (netf == NULL && (netf = fopen(NETDB, "r" )) == NULL) { goto DONE; -- cgit v1.2.3