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 */
36 # ifndef HAVE_WINSOCK_H
37 # define HAVE_WINSOCK_H
44 # define tcp_read( s, buf, len ) recv( s, buf, len, 0 )
45 # define tcp_write( s, buf, len ) send( s, buf, len, 0 )
46 # define ioctl( s, c, a ) ioctlsocket( (s), (c), (a) )
47 # define ioctl_t u_long
48 # define AC_SOCKET_INVALID ((unsigned int) ~0)
51 # define tcp_close( s ) (shutdown( s, SD_BOTH ), closesocket( s ))
53 # define tcp_close( s ) closesocket( s )
56 # define EWOULDBLOCK WSAEWOULDBLOCK
57 # define EINPROGRESS WSAEINPROGRESS
58 # define ETIMEDOUT WSAETIMEDOUT
62 # define sock_errno WSAGetLastError()
63 # define sock_errstr gras_wsa_err2string(WSAGetLastError())
65 const char *gras_wsa_err2string(int errcode);
71 # define tcp_read( s, buf, len) read( s, buf, len )
72 # define tcp_write( s, buf, len) write( s, buf, len )
73 # define sock_errno errno
74 # define sock_errstr strerror(errno)
77 # define tcp_close( s ) (shutdown( s, SHUT_RDWR ), close( s ))
79 # define tcp_close( s ) close( s )
81 #endif /* windows or unix ? */
89 #ifdef HAVE_SYS_STAT_H
90 # include <sys/stat.h>
101 #ifdef TIME_WITH_SYS_TIME
102 # include <sys/time.h>
106 # include <sys/time.h>
113 #define sleep _sleep /* else defined in stdlib.h */
120 #ifdef HAVE_UCONTEXT_H
121 # include <ucontext.h>
123 # include "xbt/context_win32.h" /* Manual reimplementation for prehistoric platforms */
126 #endif /* GRAS_PORTABLE_H */