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"
29 #ifdef HAVE_SYS_SOCKET_H
30 # include <sys/socket.h>
31 # include <netinet/in.h> /* sometimes required for #include <arpa/inet.h> */
32 # include <netinet/tcp.h> /* TCP_NODELAY */
33 # include <netdb.h> /* getprotobyname() */
34 # include <arpa/inet.h> /* inet_ntoa() */
37 #ifdef HAVE_WINSOCK2_H
38 # include <winsock2.h>
39 # include <ws2tcpip.h> /* socklen_t, but doubtful */
40 # ifndef HAVE_WINSOCK_H
41 # define HAVE_WINSOCK_H
48 # define tcp_read( s, buf, len ) recv( s, buf, len, 0 )
49 # define tcp_write( s, buf, len ) send( s, buf, len, 0 )
50 # define ioctl( s, c, a ) ioctlsocket( (s), (c), (a) )
51 # define ioctl_t u_long
52 # define AC_SOCKET_INVALID ((unsigned int) ~0)
55 # define tcp_close( s ) (shutdown( s, SD_BOTH ), closesocket( s ))
57 # define tcp_close( s ) closesocket( s )
60 # define EWOULDBLOCK WSAEWOULDBLOCK
61 # define EINPROGRESS WSAEINPROGRESS
62 # define ETIMEDOUT WSAETIMEDOUT
66 # define sock_errno WSAGetLastError()
67 # define sock_errstr gras_wsa_err2string(WSAGetLastError())
69 const char *gras_wsa_err2string(int errcode);
75 # define tcp_read( s, buf, len) read( s, buf, len )
76 # define tcp_write( s, buf, len) write( s, buf, len )
77 # define sock_errno errno
78 # define sock_errstr strerror(errno)
81 # define tcp_close( s ) (shutdown( s, SHUT_RDWR ), close( s ))
83 # define tcp_close( s ) close( s )
85 #endif /* windows or unix ? */
93 #ifdef HAVE_SYS_STAT_H
94 # include <sys/stat.h>
105 #ifdef TIME_WITH_SYS_TIME
106 # include <sys/time.h>
110 # include <sys/time.h>
117 #define sleep _sleep /* else defined in stdlib.h */
124 #ifdef HAVE_UCONTEXT_H
125 # include <ucontext.h>
127 # include "xbt/context_win32.h" /* Manual reimplementation for prehistoric platforms */
131 #endif /* GRAS_PORTABLE_H */