3 /* portable -- header loading to write portable code */
4 /* loads much more stuff than sysdep.h since the latter is in public interface*/
6 /* Copyright (c) 2004 Martin Quinson. All rights reserved. */
8 /* This program is free software; you can redistribute it and/or modify it
9 * under the terms of the license (GNU LGPL) which comes with this package. */
11 #ifndef GRAS_PORTABLE_H
12 #define GRAS_PORTABLE_H
14 #include "gras_config.h"
17 #include <sys/time.h> /* struct timeval */
18 #include <sys/types.h>
25 #ifdef HAVE_SYS_SOCKET_H
26 # include <sys/socket.h>
27 # include <netinet/in.h> /* sometimes required for #include <arpa/inet.h> */
28 # include <netinet/tcp.h> /* TCP_NODELAY */
29 # include <netdb.h> /* getprotobyname() */
30 # include <arpa/inet.h> /* inet_ntoa() */
33 #ifdef HAVE_WINSOCK2_H
34 # include <winsock2.h>
35 # include <ws2tcpip.h> /* socklen_t, but doubtful */
41 # define tcp_read( s, buf, len ) recv( s, buf, len, 0 )
42 # define tcp_write( s, buf, len ) send( s, buf, len, 0 )
43 # define ioctl( s, c, a ) ioctlsocket( (s), (c), (a) )
44 # define ioctl_t u_long
45 # define AC_SOCKET_INVALID ((unsigned int) ~0)
48 # define tcp_close( s ) (shutdown( s, SD_BOTH ), closesocket( s ))
50 # define tcp_close( s ) closesocket( s )
53 # define EWOULDBLOCK WSAEWOULDBLOCK
54 # define EINPROGRESS WSAEINPROGRESS
55 # define ETIMEDOUT WSAETIMEDOUT
59 # define sock_errno() WSAGetLastError()
60 # define sock_errstr(e) ber_pvt_wsa_err2string(e)
62 char *ber_pvt_wsa_err2string(int errcode);
68 # define tcp_read( s, buf, len) read( s, buf, len )
69 # define tcp_write( s, buf, len) write( s, buf, len )
72 # define tcp_close( s ) (shutdown( s, SHUT_RDWR ), close( s ))
74 # define tcp_close( s ) close( s )
76 #endif /* windows or unix ? */
84 #ifdef HAVE_SYS_STAT_H
92 #if TIME_WITH_SYS_TIME
93 # include <sys/time.h>
97 # include <sys/time.h>
104 #define sleep _sleep /* else defined in stdlib.h */
108 #endif /* GRAS_PORTABLE_H */