From 7e369c38993cc7cf4063a6cadc8496552abf323d Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Sat, 9 Mar 2013 15:56:30 +0100 Subject: [PATCH] remove mingw32 implementations of {get,end,set}{serv,proto}ent * libguile/win32-socket.h: * libguile/win32-socket.c (getservent, endservent, setservent) (getprotoent, endprotoent, setprotoent): Remove mingw32 wrappers. Their place is in gnulib, if anywhere. --- libguile/net_db.c | 24 +++--- libguile/win32-socket.c | 165 +--------------------------------------- libguile/win32-socket.h | 9 +-- 3 files changed, 11 insertions(+), 187 deletions(-) diff --git a/libguile/net_db.c b/libguile/net_db.c index 8dccb723a..f8007a44d 100644 --- a/libguile/net_db.c +++ b/libguile/net_db.c @@ -55,23 +55,15 @@ #include #include -#ifdef __MINGW32__ -#include "win32-socket.h" -#endif -#if !defined (HAVE_H_ERRNO) && !defined (__MINGW32__) && !defined (__CYGWIN__) -/* h_errno not found in netdb.h, maybe this will help. */ -extern int h_errno; -#endif +#if defined (HAVE_H_ERRNO) +/* Only wrap gethostbyname / gethostbyaddr if h_errno is available. */ -#if defined HAVE_HSTRERROR && !HAVE_DECL_HSTRERROR \ - && !defined __MINGW32__ && !defined __CYGWIN__ +#if defined HAVE_HSTRERROR && !HAVE_DECL_HSTRERROR /* Some OSes, such as Tru64 5.1b, lack a declaration for hstrerror(3). */ extern const char *hstrerror (int); #endif - - SCM_SYMBOL (scm_host_not_found_key, "host-not-found"); SCM_SYMBOL (scm_try_again_key, "try-again"); SCM_SYMBOL (scm_no_recovery_key, "no-recovery"); @@ -200,6 +192,8 @@ SCM_DEFINE (scm_gethost, "gethost", 0, 1, 0, } #undef FUNC_NAME +#endif /* HAVE_H_ERRNO */ + /* In all subsequent getMUMBLE functions, when we're called with no arguments, we're supposed to traverse the tables entry by entry. @@ -263,7 +257,7 @@ SCM_DEFINE (scm_getnet, "getnet", 0, 1, 0, #undef FUNC_NAME #endif -#if defined (HAVE_GETPROTOENT) || defined (__MINGW32__) +#if defined (HAVE_GETPROTOENT) SCM_DEFINE (scm_getproto, "getproto", 0, 1, 0, (SCM protocol), "@deffnx {Scheme Procedure} getprotobyname name\n" @@ -314,7 +308,7 @@ SCM_DEFINE (scm_getproto, "getproto", 0, 1, 0, #undef FUNC_NAME #endif -#if defined (HAVE_GETSERVENT) || defined (__MINGW32__) +#if defined (HAVE_GETSERVENT) static SCM scm_return_entry (struct servent *entry) { @@ -416,7 +410,7 @@ SCM_DEFINE (scm_setnet, "setnet", 0, 1, 0, #undef FUNC_NAME #endif -#if defined (HAVE_SETPROTOENT) && defined (HAVE_ENDPROTOENT) || defined (__MINGW32__) +#if defined (HAVE_SETPROTOENT) && defined (HAVE_ENDPROTOENT) SCM_DEFINE (scm_setproto, "setproto", 0, 1, 0, (SCM stayopen), "If @var{stayopen} is omitted, this is equivalent to @code{endprotoent}.\n" @@ -432,7 +426,7 @@ SCM_DEFINE (scm_setproto, "setproto", 0, 1, 0, #undef FUNC_NAME #endif -#if defined (HAVE_SETSERVENT) && defined (HAVE_ENDSERVENT) || defined (__MINGW32__) +#if defined (HAVE_SETSERVENT) && defined (HAVE_ENDSERVENT) SCM_DEFINE (scm_setserv, "setserv", 0, 1, 0, (SCM stayopen), "If @var{stayopen} is omitted, this is equivalent to @code{endservent}.\n" diff --git a/libguile/win32-socket.c b/libguile/win32-socket.c index 825b4c499..7ffb9611f 100644 --- a/libguile/win32-socket.c +++ b/libguile/win32-socket.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2001, 2006 Free Software Foundation, Inc. +/* Copyright (C) 2001, 2006, 2013 Free Software Foundation, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -441,169 +441,6 @@ scm_i_socket_uncomment (char *line) return end; } -/* The getservent() function reads the next line from the file `/etc/services' - and returns a structure servent containing the broken out fields from the - line. The `/etc/services' file is opened if necessary. */ -struct servent * -getservent (void) -{ - char line[MAX_NAMLEN], *end, *p; - int done = 0, i, n, a; - struct servent *e = NULL; - - /* Ensure a open file. */ - if (scm_i_servent.fd == NULL || feof (scm_i_servent.fd)) - { - setservent (1); - if (scm_i_servent.fd == NULL) - return NULL; - } - - while (!done) - { - /* Get new line. */ - if (fgets (line, MAX_NAMLEN, scm_i_servent.fd) != NULL) - { - end = scm_i_socket_uncomment (line); - - /* Scan the line. */ - if ((i = sscanf (line, "%s %d/%s%n", - scm_i_servent.name, - &scm_i_servent.port, - scm_i_servent.proto, &n)) != 3) - continue; - - /* Scan the remaining aliases. */ - p = line + n; - for (a = 0; a < MAX_ALIASES && p < end && i != -1 && n > 1; - a++, p += n) - i = sscanf (p, "%s%n", scm_i_servent.alias[a], &n); - - /* Prepare the return value. */ - e = &scm_i_servent.ent; - e->s_name = scm_i_servent.name; - e->s_port = htons (scm_i_servent.port); - e->s_proto = scm_i_servent.proto; - e->s_aliases = scm_i_servent.aliases; - scm_i_servent.aliases[a] = NULL; - while (a--) - scm_i_servent.aliases[a] = scm_i_servent.alias[a]; - done = 1; - } - else - break; - } - return done ? e : NULL; -} - -/* The setservent() function opens and rewinds the `/etc/services' file. - This file can be set from outside with an environment variable specifying - the file name. */ -void -setservent (int stayopen) -{ - char *file = NULL; - - endservent (); - if ((file = getenv (ENVIRON_ETC_SERVICES)) != NULL) - strcpy (scm_i_servent.file, file); - else if ((file = scm_i_socket_filename (FILE_ETC_SERVICES)) != NULL) - strcpy (scm_i_servent.file, file); - scm_i_servent.fd = fopen (scm_i_servent.file, "rt"); -} - -/* The endservent() function closes the `/etc/services' file. */ -void -endservent (void) -{ - if (scm_i_servent.fd != NULL) - { - fclose (scm_i_servent.fd); - scm_i_servent.fd = NULL; - } -} - -/* The getprotoent() function reads the next line from the file - `/etc/protocols' and returns a structure protoent containing the broken - out fields from the line. The `/etc/protocols' file is opened if - necessary. */ -struct protoent * -getprotoent (void) -{ - char line[MAX_NAMLEN], *end, *p; - int done = 0, i, n, a; - struct protoent *e = NULL; - - /* Ensure a open file. */ - if (scm_i_protoent.fd == NULL || feof (scm_i_protoent.fd)) - { - setprotoent (1); - if (scm_i_protoent.fd == NULL) - return NULL; - } - - while (!done) - { - /* Get new line. */ - if (fgets (line, MAX_NAMLEN, scm_i_protoent.fd) != NULL) - { - end = scm_i_socket_uncomment (line); - - /* Scan the line. */ - if ((i = sscanf (line, "%s %d%n", - scm_i_protoent.name, - &scm_i_protoent.proto, &n)) != 2) - continue; - - /* Scan the remaining aliases. */ - p = line + n; - for (a = 0; a < MAX_ALIASES && p < end && i != -1 && n > 1; - a++, p += n) - i = sscanf (p, "%s%n", scm_i_protoent.alias[a], &n); - - /* Prepare the return value. */ - e = &scm_i_protoent.ent; - e->p_name = scm_i_protoent.name; - e->p_proto = scm_i_protoent.proto; - e->p_aliases = scm_i_protoent.aliases; - scm_i_protoent.aliases[a] = NULL; - while (a--) - scm_i_protoent.aliases[a] = scm_i_protoent.alias[a]; - done = 1; - } - else - break; - } - return done ? e : NULL; -} - -/* The setprotoent() function opens and rewinds the `/etc/protocols' file. - As in setservent() the user can modify the location of the file using - an environment variable. */ -void -setprotoent (int stayopen) -{ - char *file = NULL; - - endprotoent (); - if ((file = getenv (ENVIRON_ETC_PROTOCOLS)) != NULL) - strcpy (scm_i_protoent.file, file); - else if ((file = scm_i_socket_filename (FILE_ETC_PROTOCOLS)) != NULL) - strcpy (scm_i_protoent.file, file); - scm_i_protoent.fd = fopen (scm_i_protoent.file, "rt"); -} - -/* The endprotoent() function closes `/etc/protocols'. */ -void -endprotoent (void) -{ - if (scm_i_protoent.fd != NULL) - { - fclose (scm_i_protoent.fd); - scm_i_protoent.fd = NULL; - } -} - /* Define both the original and replacement error symbol is possible. Thus the user is able to check symbolic errors after unsuccessful networking function calls. */ diff --git a/libguile/win32-socket.h b/libguile/win32-socket.h index 4ab9b942a..0168c064c 100644 --- a/libguile/win32-socket.h +++ b/libguile/win32-socket.h @@ -3,7 +3,7 @@ #ifndef SCM_WIN32_SOCKET_H #define SCM_WIN32_SOCKET_H -/* Copyright (C) 2001, 2006 Free Software Foundation, Inc. +/* Copyright (C) 2001, 2006, 2013 Free Software Foundation, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -32,11 +32,4 @@ char * scm_i_socket_strerror (int error); void scm_i_init_socket_Win32 (void); char * scm_i_socket_filename (char *file); -struct servent * getservent (void); -void setservent (int stayopen); -void endservent (void); -struct protoent * getprotoent (void); -void setprotoent (int stayopen); -void endprotoent (void); - #endif /* SCM_WIN32_SOCKET_H */