[Apcupsd-commits] apcupsd/src/lib gethostname.c, NONE, 1.1.2.1 Makefile, 1.1.2.2, 1.1.2.3
Brought to you by:
adk0212
From: Adam K. <ad...@us...> - 2009-10-28 00:24:41
|
Update of /cvsroot/apcupsd/apcupsd/src/lib In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv6314/src/lib Modified Files: Tag: Branch-3_14 Makefile Added Files: Tag: Branch-3_14 gethostname.c Log Message: Switch SnmpEngine to thread-safe resolver, gethostbyname_r() Index: Makefile =================================================================== RCS file: /cvsroot/apcupsd/apcupsd/src/lib/Makefile,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -d -r1.1.2.2 -r1.1.2.3 --- Makefile 20 Sep 2009 19:41:26 -0000 1.1.2.2 +++ Makefile 28 Oct 2009 00:24:28 -0000 1.1.2.3 @@ -3,7 +3,7 @@ SRCS = apcconfig.c apcerror.c apcevents.c apcexec.c \ apcfile.c apclibnis.c apclock.c apclog.c apcsignal.c \ - apcstatus.c asys.c newups.c md5.c statmgr.cpp \ + apcstatus.c asys.c newups.c md5.c statmgr.cpp gethostname.c \ amutex.cpp astring.cpp autil.cpp atimer.cpp athread.cpp \ $(LIBEXTRAOBJ:.o=.c) --- NEW FILE: gethostname.c --- #include "apc.h" #ifdef HAVE_FUNC_GETHOSTBYNAME_R_6 struct hostent * gethostname_re (const char *host,struct hostent *hostbuf,char **tmphstbuf,size_t *hstbuflen) { struct hostent *hp; int herr,res; if (*hstbuflen == 0) { *hstbuflen = 1024; *tmphstbuf = (char *)malloc (*hstbuflen); } while (( res = gethostbyname_r(host,hostbuf,*tmphstbuf,*hstbuflen,&hp,&herr)) && (errno == ERANGE)) { /* Enlarge the buffer. */ *hstbuflen *= 2; *tmphstbuf = (char *)realloc (*tmphstbuf,*hstbuflen); } if (res) return NULL; return hp; } #endif #ifdef HAVE_FUNC_GETHOSTBYNAME_R_5 struct hostent * gethostname_re (const char *host,struct hostent *hostbuf,char **tmphstbuf,size_t *hstbuflen) { struct hostent *hp; int herr; if (*hstbuflen == 0) { *hstbuflen = 1024; *tmphstbuf = (char *)malloc (*hstbuflen); } while ((NULL == ( hp = gethostbyname_r(host,hostbuf,*tmphstbuf,*hstbuflen,&herr))) && (errno == ERANGE)) { /* Enlarge the buffer. */ *hstbuflen *= 2; *tmphstbuf = (char *)realloc (*tmphstbuf,*hstbuflen); } return hp; } #endif #ifdef HAVE_FUNC_GETHOSTBYNAME_R_3 struct hostent * gethostname_re (const char *host,struct hostent *hostbuf,char **tmphstbuf,size_t *hstbuflen) { if (*hstbuflen == 0) { *hstbuflen = sizeof(struct hostent_data); *tmphstbuf = (char *)malloc (*hstbuflen); } else if (*hstbuflen < sizeof(struct hostent_data)) { *hstbuflen = sizeof(struct hostent_data); *tmphstbuf = (char *)realloc(*tmphstbuf, *hstbuflen); } memset((void *)(*tmphstbuf),0,*hstbuflen); if (0 != gethostbyname_r(host,hostbuf,(struct hostent_data *)*tmphstbuf)) return NULL; return hostbuf; } #endif #ifdef HAVE_FUNC_GETHOSTBYNAME_R_0 struct hostent * gethostname_re (const char *host,struct hostent *hostbuf,char **tmphstbuf,size_t *hstbuflen) { return gethostbyname(host); } #endif |