diff options
author | Christopher Faylor <me@cgf.cx> | 2003-08-31 23:16:34 +0000 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2003-08-31 23:16:34 +0000 |
commit | a3de4e19b48a175c08c4d5b269962330c7d24f71 (patch) | |
tree | a72dbd99943c213584e77fb463b0a3193c12b59d /winsup | |
parent | edf16a29fc6841a30c5cf69bacd7a1e6add77163 (diff) | |
download | newlib-a3de4e19b48a175c08c4d5b269962330c7d24f71.zip newlib-a3de4e19b48a175c08c4d5b269962330c7d24f71.tar.gz newlib-a3de4e19b48a175c08c4d5b269962330c7d24f71.tar.bz2 |
Use dup_ent rather than specific dup_*_ptr functions throughout.
* (gen_ent): Delete.
(dup_ent): Subsume gen_ent functionality.
(dup_host_ptr): Delete.
(dup_proto_ptr): Ditto.
(dup_servent_ptr): Ditto.
* net.cc (gen_ent): Invert sense of null check so that debug output makes
sense.
Diffstat (limited to 'winsup')
-rw-r--r-- | winsup/cygwin/ChangeLog | 14 | ||||
-rw-r--r-- | winsup/cygwin/net.cc | 67 |
2 files changed, 45 insertions, 36 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 7e6091c..3282ccd 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,5 +1,19 @@ 2003-08-31 Christopher Faylor <cgf@redhat.com> + Use dup_ent rather than specific dup_*_ptr functions throughout. + * (gen_ent): Delete. + (dup_ent): Subsume gen_ent functionality. + (dup_host_ptr): Delete. + (dup_proto_ptr): Ditto. + (dup_servent_ptr): Ditto. + +2003-08-31 Christopher Faylor <cgf@redhat.com> + + * net.cc (gen_ent): Invert sense of null check so that debug output + makes sense. + +2003-08-31 Christopher Faylor <cgf@redhat.com> + * net.cc (free_char_list): Delete. (dup_addr_list): Delete. (dup_char_list): Delete. diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc index 84f4380..c8d225bb 100644 --- a/winsup/cygwin/net.cc +++ b/winsup/cygwin/net.cc @@ -396,11 +396,6 @@ strlen_round (const char *s) return DWORD_round (strlen (s) + 1); } -enum struct_type -{ - is_protoent, is_servent, is_hostent -}; - #pragma pack(push,2) struct pservent { @@ -424,6 +419,13 @@ struct unionent }; }; +enum struct_type +{ + is_hostent, is_protoent, is_servent +}; + +static const char *entnames[] = {"host", "proto", "serv"}; + /* Generic "dup a {host,proto,serv}ent structure" function. This is complicated because we need to be able to free the structure at any point and we can't rely on the pointer contents @@ -438,9 +440,18 @@ static void * #else static inline void * #endif -dup_ent (void *src0, struct_type type) +dup_ent (void *old, void *src0, struct_type type) { + if (old) + { + debug_printf ("freeing old %sent structure(%s) %p\n", entnames[type], + ((unionent *) old)->name, old); + free (old); + } + unionent *src = (unionent *) src0; + debug_printf ("duping %sent \"%s\", %p", entnames[type], + src ? src->name : "<null!>", src); /* Find the size of the raw structure minus any character strings, etc. */ int sz, struct_sz; @@ -565,29 +576,10 @@ dup_ent (void *src0, struct_type type) /* Sanity check that we did our bookkeeping correctly. */ assert ((dp - (char *) dst) == sz); } + debug_printf ("duped %sent \"%s\", %p", entnames[type], dst ? dst->name : "<null!>", dst); return dst; } -/* Generic macro to build a dup_{host,proto,serv}ent_ptr function. - The *ent buffers are allocated by dup_ent as contiguous storage. - Frees any previously exiting `old' storage, as well. */ -#define gen_ent(x, p) \ -static x * \ -dup_##x##_ptr (x *old, x *src) \ -{ \ - if (old) \ - { \ - debug_printf ("freeing %s", old->p##_name); \ - free (old); \ - } \ - debug_printf ("%s", src ? "<null!>" : src->p##_name); \ - x *dst = (x *) dup_ent (src, is_##x); \ - debug_printf ("copied %s", dst ? "<null!>" : dst->p##_name); \ - return dst; \ -} \ - -gen_ent (protoent, p) - #ifdef _MT_SAFE #define protoent_buf _reent_winsup ()->_protoent_buf #else @@ -600,7 +592,8 @@ cygwin_getprotobyname (const char *p) { if (check_null_str_errno (p)) return NULL; - protoent_buf = dup_protoent_ptr (protoent_buf, getprotobyname (p)); + protoent_buf = (protoent *) dup_ent (protoent_buf, getprotobyname (p), + is_protoent); if (!protoent_buf) set_winsock_errno (); @@ -612,7 +605,8 @@ cygwin_getprotobyname (const char *p) extern "C" struct protoent * cygwin_getprotobynumber (int number) { - protoent_buf = dup_protoent_ptr (protoent_buf, getprotobynumber (number)); + protoent_buf = (protoent *) dup_ent (protoent_buf, getprotobynumber (number), + is_protoent); if (!protoent_buf) set_winsock_errno (); @@ -942,8 +936,6 @@ cygwin_connect (int fd, const struct sockaddr *name, int namelen) return res; } -gen_ent (servent, s) - #ifdef _MT_SAFE #define servent_buf _reent_winsup ()->_servent_buf #else @@ -960,7 +952,8 @@ cygwin_getservbyname (const char *name, const char *proto) || (proto != NULL && check_null_str_errno (proto))) return NULL; - servent_buf = dup_servent_ptr (servent_buf, getservbyname (name, proto)); + servent_buf = (servent *) dup_ent (servent_buf, getservbyname (name, proto), + is_servent); if (!servent_buf) set_winsock_errno (); @@ -977,7 +970,8 @@ cygwin_getservbyport (int port, const char *proto) if (proto != NULL && check_null_str_errno (proto)) return NULL; - servent_buf = dup_servent_ptr (servent_buf, getservbyport (port, proto)); + servent_buf = (servent *) dup_ent (servent_buf, getservbyport (port, proto), + is_servent); if (!servent_buf) set_winsock_errno (); @@ -1008,8 +1002,6 @@ cygwin_gethostname (char *name, size_t len) return 0; } -gen_ent (hostent, h) - #ifdef _MT_SAFE #define hostent_buf _reent_winsup ()->_hostent_buf #else @@ -1048,7 +1040,8 @@ cygwin_gethostbyname (const char *name) return &tmp; } - hostent_buf = dup_hostent_ptr (hostent_buf, gethostbyname (name)); + hostent_buf = (hostent *) dup_ent (hostent_buf, gethostbyname (name), + is_hostent); if (!hostent_buf) { set_winsock_errno (); @@ -1071,7 +1064,9 @@ cygwin_gethostbyaddr (const char *addr, int len, int type) if (__check_invalid_read_ptr_errno (addr, len)) return NULL; - hostent_buf = dup_hostent_ptr (hostent_buf, gethostbyaddr (addr, len, type)); + hostent_buf = (hostent *) dup_ent (hostent_buf, + gethostbyaddr (addr, len, type), + is_hostent); if (!hostent_buf) { set_winsock_errno (); |