Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
f7f0f6db0c53b93575f4b81010145c36a8c9a359
[simgrid.git] / src / portable.h
1 /* $Id$ */
2
3 /* portable -- header loading to write portable code */
4
5 /* Copyright (c) 2004 Martin Quinson. */
6 /* LGPL*/
7
8 #ifndef GRAS_PORTABLE_H
9 #define GRAS_PORTABLE_H
10
11 #include "gras_config.h"
12
13 #include <errno.h>
14 #include <sys/time.h> /* struct timeval */
15 #include <sys/types.h>
16
17 /****
18  **** Networking 
19  ****/
20
21
22 #ifdef HAVE_SYS_SOCKET_H
23 #  include <sys/socket.h>
24 #  include <netinet/in.h>   /* sometimes required for #include <arpa/inet.h> */
25 #  include <netinet/tcp.h>  /* TCP_NODELAY */
26 #  include <netdb.h>        /* getprotobyname() */
27 #  include <arpa/inet.h>    /* inet_ntoa() */
28 # endif
29
30 #ifdef HAVE_WINSOCK2_H
31 #  include <winsock2.h>
32 #  include <ws2tcpip.h>  /* socklen_t, but doubtful */
33 #elif HAVE_WINSOCK_H
34 #  include <winsock.h>
35 #endif
36
37 #ifdef HAVE_WINSOCK_H
38 #       define tcp_read( s, buf, len )  recv( s, buf, len, 0 )
39 #       define tcp_write( s, buf, len ) send( s, buf, len, 0 )
40 #       define ioctl( s, c, a )         ioctlsocket( (s), (c), (a) )
41 #       define ioctl_t                          u_long
42 #       define AC_SOCKET_INVALID        ((unsigned int) ~0)
43
44 #       ifdef SD_BOTH
45 #               define tcp_close( s )   (shutdown( s, SD_BOTH ), closesocket( s ))
46 #       else
47 #               define tcp_close( s )           closesocket( s )
48 #       endif
49
50 #       define EWOULDBLOCK WSAEWOULDBLOCK
51 #       define EINPROGRESS WSAEINPROGRESS
52 #       define ETIMEDOUT   WSAETIMEDOUT
53
54 #       undef  sock_errno
55 #       undef  sock_errstr
56 #       define sock_errno()    WSAGetLastError()
57 #       define sock_errstr(e)  ber_pvt_wsa_err2string(e)
58
59 char *ber_pvt_wsa_err2string(int errcode);
60
61 #       define S_IRGRP 0
62 #       define S_IWGRP 0
63
64 #else
65 #       define tcp_read( s, buf, len)   read( s, buf, len )
66 #       define tcp_write( s, buf, len)  write( s, buf, len )
67
68 #       ifdef SHUT_RDWR
69 #               define tcp_close( s )   (shutdown( s, SHUT_RDWR ), close( s ))
70 #       else
71 #               define tcp_close( s )   close( s )
72 #       endif
73 #endif /* windows or unix ? */
74
75 /****
76  **** File handling
77  ****/
78
79 #include <fcntl.h>
80
81 #ifdef HAVE_SYS_STAT_H
82 #include <sys/stat.h>
83 #endif
84
85 /****
86  **** Time handling
87  ****/
88
89 #if TIME_WITH_SYS_TIME
90 # include <sys/time.h>
91 # include <time.h>
92 #else
93 # if HAVE_SYS_TIME_H
94 #  include <sys/time.h>
95 # else
96 #  include <time.h>
97 # endif
98 #endif
99
100 #ifdef _WIN32
101 #define sleep _sleep /* else defined in stdlib.h */
102 #endif
103
104
105 #endif /* GRAS_PORTABLE_H */