diff options
author | Andreas Baumann <abaumann@yahoo.com> | 2009-04-01 15:48:39 +0200 |
---|---|---|
committer | Andreas Baumann <abaumann@yahoo.com> | 2009-04-01 15:48:39 +0200 |
commit | 8caf15e38c6c1a803c110028b0d8a10d6fece776 (patch) | |
tree | dcc3b99e2e716ce17172b94c2f7adc5ca3d522eb /include | |
parent | dde2d0138dd3d6d603b476f7e5f50aff2270251e (diff) | |
download | wolfbones-8caf15e38c6c1a803c110028b0d8a10d6fece776.tar.gz wolfbones-8caf15e38c6c1a803c110028b0d8a10d6fece776.tar.bz2 |
removed extern in function prototypes; added gai_strerror_r and a test, cleanup in netdb.h and netdb.c
Diffstat (limited to 'include')
-rw-r--r-- | include/wolf/port/gettext.h | 8 | ||||
-rw-r--r-- | include/wolf/port/netdb.h | 82 | ||||
-rw-r--r-- | include/wolf/port/stdio.h | 4 | ||||
-rw-r--r-- | include/wolf/port/stdlib.h | 2 | ||||
-rw-r--r-- | include/wolf/port/string.h | 16 |
5 files changed, 97 insertions, 15 deletions
diff --git a/include/wolf/port/gettext.h b/include/wolf/port/gettext.h index 3d45d7e..3d4a4f9 100644 --- a/include/wolf/port/gettext.h +++ b/include/wolf/port/gettext.h @@ -48,10 +48,10 @@ */ #if defined __GNUC__ #if defined GETTEXT_NEEDS_FORMAT_ARG -extern char *gettext( const char *__msgid ) __attribute__ ( ( format_arg ( 1 ) ) ); -extern char *libintl_gettext( const char *__msgid ) __attribute__ ( ( format_arg ( 1 ) ) ); -extern char *dgettext( const char *__domainname, const char *__msgid ) __attribute__ ( ( format_arg ( 2 ) ) ); -extern char *libintl_dgettext( const char *__domainname, const char *__msgid ) __attribute__ ( ( format_arg ( 2 ) ) ); +char *gettext( const char *__msgid ) __attribute__ ( ( format_arg ( 1 ) ) ); +char *libintl_gettext( const char *__msgid ) __attribute__ ( ( format_arg ( 1 ) ) ); +char *dgettext( const char *__domainname, const char *__msgid ) __attribute__ ( ( format_arg ( 2 ) ) ); +char *libintl_dgettext( const char *__domainname, const char *__msgid ) __attribute__ ( ( format_arg ( 2 ) ) ); #endif #endif diff --git a/include/wolf/port/netdb.h b/include/wolf/port/netdb.h index 99abf73..28aa679 100644 --- a/include/wolf/port/netdb.h +++ b/include/wolf/port/netdb.h @@ -29,6 +29,14 @@ * @author Andreas Baumann <abaumann@yahoo.com> */ +/* + * Based on ideas found in: + * - Postgres src/port/getaddrinfo.c + * Copyright (c) 2003-2008, PostgreSQL Global Development Group + * - Unix Stevens Network Programming + * libgai implementation in unpv12e + */ + #include "port/sys.h" #ifdef FREEBSD @@ -84,6 +92,80 @@ #define NI_MAXSERV 32 #endif +#if !defined HAVE_GETADDRINFO || defined TEST_GETADDRINFO + +#include <sys/types.h> /* for size_t */ +#include <sys/socket.h> /* for AF_UNSPEC */ +#include <arpa/inet.h> /* for TCPPROTO and others */ + +/* for errors returned by getaddrinfo */ +#if !defined EAI_NONAME +#define EAI_NONAME -2 /**< NAME or SERVICE is unknown */ +#define EAI_AGAIN -3 /**< temporary failure in name resolution */ +#define EAI_FAIL -4 /**< non-recoverable failure in name resultion */ +#define EAI_FAMILY -6 /**< socket family not supported */ +#define EAI_MEMORY -10 /**< memory allocation failure */ +#endif + +/* for ai_flags */ +#if !defined AI_PASSIVE +#define AI_PASSIVE 1 /**< socket is intended for bind() + listen() */ +#define AI_CANONNAME 2 /**< return canonical name */ +#define AI_NUMERICHOST 4 /**< don't use name resolution */ +#endif + +/* for flags in getnameinfo */ +#if !defined NI_NUMERICHOST +#define NI_NUMERICHOST 1 /**< don't try to look up hostname. */ +#define NI_NUMERICSERV 2 /**< don't convert port number to name. */ +#endif + +struct wolf_port_addrinfo +{ + int ai_flags; + int ai_family; + int ai_socktype; + int ai_protocol; + size_t ai_addrlen; + struct sockaddr *ai_addr; + char *ai_canonname; + struct wolf_port_addrinfo *ai_next; +}; + +int wolf_port_getaddrinfo( const char *host_name, + const char *service_name, + const struct wolf_port_addrinfo *hints, + struct wolf_port_addrinfo **result ); +void wolf_port_freeaddrinfo( struct wolf_port_addrinfo *result ); + +int wolf_port_getnameinfo( const struct sockaddr *sa, socklen_t salen, + char *host, size_t hostlen, + char *serv, size_t servlen, + int flags ); + +const char *wolf_port_gai_strerror( int errcode ); + +#if !defined HAVE_GETADDRINFO +#define addrinfo wolf_port_addrinfo +#define getaddrinfo( host_name, service_name, hints, result ) wolf_port_getaddrinfo( host_name, service_name, hints, result ) +#define freeaddrinfo( result ) wolf_port_freeaddrinfo( result ) +#define getnameinfo( sa, salen, host, hostlen, serv, servlen, flags ) wolf_port_getnameinfo( sa, salen, host, hostlen, serv, servlen, flags ) +#define gai_strerror( errcode ) wolf_port_gai_strerror( errcode ) +#endif + +#endif /* !defined HAVE_GETADDRINFO || defined TEST_GETADDRINFO */ + +/* gai_strerror is not thread-safe. Some platforms (like AIX 6.1) started to + * introduce a thread-safe version gai_strerror_r + */ +#if !defined HAVE_GAI_STRERROR_R || defined TEST_GAI_STRERROR_R +int wolf_port_gai_strerror_r( int errcode, char *buf, size_t buflen ); +#if !defined HAVE_GAI_STRERROR_R +#define gai_strerror_r( errcode, buf, buflen ) wolf_port_gai_strerror_r( errcode, buf, buflen ) +#endif /* !defined HAVE_GAI_STRERROR_R */ + +#endif /* !defined HAVE_GAI_STRERROR_R || defined TEST_GAI_STRERROR_R */ + /** @} */ /* @addtogroup wolf_port */ #endif /* ifndef WOLF_NETDB_H */ diff --git a/include/wolf/port/stdio.h b/include/wolf/port/stdio.h index d195f6d..1a2fc75 100644 --- a/include/wolf/port/stdio.h +++ b/include/wolf/port/stdio.h @@ -62,7 +62,7 @@ #include <sys/types.h> /* for size_t */ #if !defined HAVE_SNPRINTF || defined WOLF_TEST_SNPRINTF -extern int rpl_snprintf( char *str, size_t size, const char *format, ... ); +int rpl_snprintf( char *str, size_t size, const char *format, ... ); #endif /* !defined HAVE_SNPRINTF || defined TEST_SNPRINTF */ #if !defined HAVE_SNPRINTF /* TODO: with variadic macros, we can define a much better macro here! */ @@ -70,7 +70,7 @@ extern int rpl_snprintf( char *str, size_t size, const char *format, ... ); #endif /* !defined HAVE_SNPRINTF */ #if !defined HAVE_VSNPRINTF || defined WOLF_TEST_VSNPRINTF -extern int rpl_vsnprintf( char *str, size_t size, const char *format, va_list args ); +int rpl_vsnprintf( char *str, size_t size, const char *format, va_list args ); #endif /* !defined HAVE_VSNPRINTF || defined TEST_VSNPRINTF */ #if !defined HAVE_VSNPRINTF #define vsnprintf( str, size, format, ap ) rpl_vsnprintf( str, size, format, ap ) diff --git a/include/wolf/port/stdlib.h b/include/wolf/port/stdlib.h index 37e1931..c8afeb8 100644 --- a/include/wolf/port/stdlib.h +++ b/include/wolf/port/stdlib.h @@ -34,7 +34,7 @@ #include <stdlib.h> #if !defined HAVE_ITOA || defined TEST_ITOA -extern char *wolf_port_itoa( int value, char *string, int radix ); +char *wolf_port_itoa( int value, char *string, int radix ); #endif /* !defined HAVE_ITOA || defined TEST_ITOA */ #if !defined HAVE_ITOA #define itoa( value, string, radix ) wolf_port_itoa( value, string, radix ) diff --git a/include/wolf/port/string.h b/include/wolf/port/string.h index 7875701..0f17083 100644 --- a/include/wolf/port/string.h +++ b/include/wolf/port/string.h @@ -46,52 +46,52 @@ #endif #if !defined HAVE_STRDUP || defined TEST_STRDUP -extern char *wolf_port_strdup( const char *s ); +char *wolf_port_strdup( const char *s ); #endif #if !defined HAVE_STRDUP #define strdup wolf_port_strdup #endif #if !defined HAVE_STRERROR_R || defined TEST_STRERROR_R -extern int wolf_port_strerror_r( int num, char *buf, size_t buflen ); +int wolf_port_strerror_r( int num, char *buf, size_t buflen ); #endif #if !defined HAVE_STRERROR_R #define strerror_r( errnum, buf, buflen ) wolf_port_strerror_r( errnum, buf, buflen ) #endif #if !defined HAVE_STRCASECMP || defined TEST_STRCASECMP -extern int wolf_port_strcasecmp( const char *s1, const char *s2 ); +int wolf_port_strcasecmp( const char *s1, const char *s2 ); #endif #if !defined HAVE_STRCASECMP #define strcasecmp( s1, s2 ) wolf_port_strcasecmp( s1, s2 ) #endif #if !defined HAVE_STRNCASECMP || defined TEST_STRNCASECMP -extern int wolf_port_strncasecmp( const char *s1, const char *s2, size_t n ); +int wolf_port_strncasecmp( const char *s1, const char *s2, size_t n ); #endif #if !defined HAVE_STRNCASECMP #define strncasecmp( s1, s2, n ) wolf_port_strncasecmp( s1, s2, n ) #endif #if !defined HAVE_STRLCPY || defined TEST_STRLCPY -extern size_t wolf_port_strlcpy( char *d, const char *s, size_t bufsize ); +size_t wolf_port_strlcpy( char *d, const char *s, size_t bufsize ); #endif #if !defined HAVE_STRLCPY #define strlcpy( d, s, bufsize ) wolf_port_strlcpy( d, s, bufsize ) #else #if defined MUST_DEFINE_STRLCPY_PROTOTYPE -extern size_t strlcpy( char *d, const char *s, size_t bufsize ); +size_t strlcpy( char *d, const char *s, size_t bufsize ); #endif #endif #if !defined HAVE_STRLCAT || defined TEST_STRLCAT -extern size_t wolf_port_strlcat( char *d, const char *s, size_t bufsize ); +size_t wolf_port_strlcat( char *d, const char *s, size_t bufsize ); #endif #if !defined HAVE_STRLCAT #define strlcat( d, s, bufsize ) wolf_port_strlcat( d, s, bufsize ) #else #if defined MUST_DEFINE_STRLCAT_PROTOTYPE -extern size_t strlcat( char *d, const char *s, size_t bufsize ); +size_t strlcat( char *d, const char *s, size_t bufsize ); #endif #endif |