From a525821bc76f67a72ec06524421de2191f97dd23 Mon Sep 17 00:00:00 2001 From: Chris Toshok Date: Tue, 24 Apr 2001 07:09:06 +0000 Subject: remove prototype for e_gethostbyname_init. 2001-04-24 Chris Toshok * e-host-utils.h: remove prototype for e_gethostbyname_init. * e-host-utils.c (e_gethostbyname_r): don't dynamically allocate anything - store everything in the buffer that's passed in. Also, stop using EMutex. Switch to a static GMutex (so we can initialize it without having e_gethostbyname_init). (e_gethostbyname_init): removed. svn path=/trunk/; revision=9535 --- e-util/ChangeLog | 10 +++++++ e-util/e-host-utils.c | 72 +++++++++++++++++++++++---------------------------- e-util/e-host-utils.h | 2 -- 3 files changed, 43 insertions(+), 41 deletions(-) diff --git a/e-util/ChangeLog b/e-util/ChangeLog index 27ee510d5a..adabec2e9d 100644 --- a/e-util/ChangeLog +++ b/e-util/ChangeLog @@ -1,3 +1,13 @@ +2001-04-24 Chris Toshok + + * e-host-utils.h: remove prototype for e_gethostbyname_init. + + * e-host-utils.c (e_gethostbyname_r): don't dynamically allocate + anything - store everything in the buffer that's passed in. Also, + stop using EMutex. Switch to a static GMutex (so we can + initialize it without having e_gethostbyname_init). + (e_gethostbyname_init): removed. + 2001-04-23 Jon Trowbridge * e-html-utils.c (e_text_to_html_full): Removed attempts to use diff --git a/e-util/e-host-utils.c b/e-util/e-host-utils.c index 1223b60193..238674ddcc 100644 --- a/e-util/e-host-utils.c +++ b/e-util/e-host-utils.c @@ -23,27 +23,13 @@ #include #include -#include "e-msgport.h" #include "e-host-utils.h" #include #include #include #include -#ifndef HAVE_GETHOSTBYNAME_R -static EMutex *gethost_mutex = NULL; -#endif - -void -e_gethostbyname_init () -{ -#ifndef HAVE_GETHOSTBYNAME_R - if (gethost_mutex) - return; - - gethost_mutex = e_mutex_new (E_MUTEX_SIMPLE); -#endif -} +G_LOCK_DEFINE_STATIC (gethost_mutex); int e_gethostbyname_r (const char *name, struct hostent *host, @@ -63,17 +49,12 @@ e_gethostbyname_r (const char *name, struct hostent *host, int req_length; int num_aliases = 0, num_addrs = 0; - if (!gethost_mutex) { - g_warning ("mutex wasn't initialized - you must call e_gethostbyname_init before e_gethostbyname_r\n"); - return -1; - } - - e_mutex_lock (gethost_mutex); + G_LOCK (gethost_mutex); h = gethostbyname (name); if (!h) { - e_mutex_unlock (gethost_mutex); + G_UNLOCK (gethost_mutex); return -1; } @@ -82,58 +63,71 @@ e_gethostbyname_r (const char *name, struct hostent *host, if (h->h_aliases) { for (i = 0; h->h_aliases[i]; i ++) req_length += strlen (h->h_aliases[i]) + 1; - num_aliases = i + 1; + num_aliases = i; } if (h->h_addr_list) { for (i = 0; h->h_addr_list[i]; i ++) req_length += h->h_length; - num_addrs = i + 1; + num_addrs = i; } + req_length += sizeof (char*) * (num_aliases + 1); + req_length += sizeof (char*) * (num_addrs + 1); + req_length += strlen (h->h_name) + 1; + if (buflen < req_length) { *herr = ERANGE; - e_mutex_unlock (gethost_mutex); + G_UNLOCK (gethost_mutex); return -1; } - if (num_aliases) - host->h_aliases = malloc (sizeof (char*) * num_aliases); + /* we store the alias/addr pointers in the buffer - figure out + their addresses here. */ + p = buf; + if (num_aliases) { + host->h_aliases = (char**)p; + p += sizeof (char*) * (num_aliases + 1); + } else host->h_aliases = NULL; - if (num_addrs) - host->h_addr_list = malloc (sizeof (char*) * num_addrs); + if (num_addrs) { + host->h_addr_list = (char**)p; + p += sizeof(char*) * (num_addrs + 1); + } else host->h_addr_list = NULL; - host->h_name = strdup (h->h_name); + /* copy the host name into the buffer */ + host->h_name = p; + strcpy (p, h->h_name); + p += strlen (h->h_name) + 1; host->h_addrtype = h->h_addrtype; host->h_length = h->h_length; /* copy the aliases/addresses into the buffer, and assign the pointers into the hostent */ - *buf = 0; - p = buf; + *p = 0; if (num_aliases) { - for (i = 0; h->h_aliases[i]; i ++) { - strcpy (buf, h->h_aliases[i]); + for (i = 0; i < num_aliases; i ++) { + strcpy (p, h->h_aliases[i]); host->h_aliases[i] = p; p += strlen (h->h_aliases[i]); } - host->h_aliases[num_aliases - 1] = NULL; + host->h_aliases[num_aliases] = NULL; } if (num_addrs) { - for (i = 0; h->h_addr_list[i]; i ++) { - memcpy (buf, h->h_addr_list[i], h->h_length); + for (i = 0; i < num_addrs; i ++) { + memcpy (p, h->h_addr_list[i], h->h_length); host->h_addr_list[i] = p; p += h->h_length; } - host->h_addr_list[num_addrs - 1] = NULL; + host->h_addr_list[num_addrs] = NULL; } *herr = h_errno; - e_mutex_unlock (gethost_mutex); + G_UNLOCK (gethost_mutex); return 0; #endif diff --git a/e-util/e-host-utils.h b/e-util/e-host-utils.h index b111d05942..0935ef85be 100644 --- a/e-util/e-host-utils.h +++ b/e-util/e-host-utils.h @@ -27,8 +27,6 @@ #include #include -void e_gethostbyname_init (void); - /* gethostbyname_r implementation that works for systems without a native gethostbyname_r. if you use this, you must make sure to *only* use this - it can't even coexist with naked calls to -- cgit v1.2.3