summaryrefslogtreecommitdiffstats
path: root/cpukit/libnetworking/libc/gethostbyht.c
diff options
context:
space:
mode:
Diffstat (limited to 'cpukit/libnetworking/libc/gethostbyht.c')
-rw-r--r--cpukit/libnetworking/libc/gethostbyht.c52
1 files changed, 40 insertions, 12 deletions
diff --git a/cpukit/libnetworking/libc/gethostbyht.c b/cpukit/libnetworking/libc/gethostbyht.c
index 2278e7092b..279514ea89 100644
--- a/cpukit/libnetworking/libc/gethostbyht.c
+++ b/cpukit/libnetworking/libc/gethostbyht.c
@@ -214,17 +214,36 @@ _gethostbyhtaddr(
#ifdef _THREAD_SAFE
-struct hostent* gethostent_r(char* buf, int len)
+int
+gethostent_r(
+ struct hostent *pe,
+ char *buf,
+ size_t len,
+ struct hostent **result,
+ int *h_errnop)
{
char *dest;
- struct hostent* pe=(struct hostent*)buf;
char* last;
char* max=buf+len;
int aliasidx;
int curlen;
-
-
- if (!hostf) return 0;
+ int rv;
+
+ if (pe == NULL || buf == NULL || result == NULL || h_errnop == NULL) {
+ if (h_errnop != NULL) {
+ *h_errnop = NETDB_INTERNAL;
+ }
+ return EINVAL;
+ }
+
+ *result = NULL;
+ *h_errnop = NETDB_INTERNAL;
+ rv = -1;
+
+ if (!hostf) {
+ rv = ENOENT;
+ return rv;
+ }
fseek(hostf,0,SEEK_END);
curlen=ftell(hostf);
fseek(hostf,0,SEEK_SET);
@@ -248,16 +267,22 @@ struct hostent* gethostent_r(char* buf, int len)
last=hostmap+hostlen;
again:
if ((size_t)len<sizeof(struct hostent)+11*sizeof(char*)) goto nospace;
- dest=buf+sizeof(struct hostent);
+ dest=buf;
pe->h_name=0;
pe->h_aliases=(char**)dest; pe->h_aliases[0]=0; dest+=10*sizeof(char*);
pe->h_addr_list=(char**)dest; dest+=2*sizeof(char**);
- if (cur>=last) return 0;
+ if (cur>=last) {
+ rv = ERANGE;
+ return rv;
+ }
if (*cur=='#' || *cur=='\n') goto parseerror;
/* first, the ip number */
pe->h_name=cur;
while (cur<last && !isspace((unsigned char)*cur)) cur++;
- if (cur>=last) return 0;
+ if (cur>=last) {
+ rv = ERANGE;
+ return rv;
+ }
if (*cur=='\n') goto parseerror;
{
char save=*cur;
@@ -301,19 +326,22 @@ again:
pe->h_aliases[aliasidx]=0;
pe->h_name=pe->h_aliases[0];
pe->h_aliases++;
- return pe;
+ *result = pe;
+ *h_errnop = 0;
+ rv = 0;
+ return rv;
parseerror:
while (cur<last && *cur!='\n') cur++;
cur++;
goto again;
nospace:
- errno=ERANGE;
+ rv=ERANGE;
goto __error;
error:
- errno=ENOMEM;
+ rv=ENOMEM;
__error:
if (hostmap!=NULL) free(hostmap);
hostmap=NULL;
- return 0;
+ return rv;
}
#endif