Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
missing files
[simgrid.git] / src / portable.h
1 /* $Id$ */
2
3 /* portable -- header loading to write portable code                         */
4 /* loads much more stuff than sysdep.h since the latter is in public interface*/
5
6 /* Copyright (c) 2004 Martin Quinson. All rights reserved.                   */
7
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. */
10
11 #ifndef GRAS_PORTABLE_H
12 #define GRAS_PORTABLE_H
13
14 #include "gras_config.h"
15
16 #ifdef HAVE_ERRNO_H
17 #  include <errno.h>
18 #endif
19
20 #ifdef HAVE_UNISTD_H
21 #  include <unistd.h>
22 #endif
23
24 /****
25  **** Networking 
26  ****/
27
28
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() */
35 # endif
36
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
42 #  endif
43 #elif HAVE_WINSOCK_H
44 #  include <winsock.h>
45 #endif
46
47 #ifdef 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)
53
54 #       ifdef SD_BOTH
55 #               define tcp_close( s )   (shutdown( s, SD_BOTH ), closesocket( s ))
56 #       else
57 #               define tcp_close( s )           closesocket( s )
58 #       endif
59
60 #       define EWOULDBLOCK WSAEWOULDBLOCK
61 #       define EINPROGRESS WSAEINPROGRESS
62 #       define ETIMEDOUT   WSAETIMEDOUT
63
64 #       undef  sock_errno
65 #       undef  sock_errstr
66 #       define sock_errno      WSAGetLastError()
67 #       define sock_errstr     gras_wsa_err2string(WSAGetLastError())
68
69 const char *gras_wsa_err2string(int errcode);
70
71 #       define S_IRGRP 0
72 #       define S_IWGRP 0
73
74 #else
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)
79
80 #       ifdef SHUT_RDWR
81 #               define tcp_close( s )   (shutdown( s, SHUT_RDWR ), close( s ))
82 #       else
83 #               define tcp_close( s )   close( s )
84 #       endif
85 #endif /* windows or unix ? */
86
87 /****
88  **** File handling
89  ****/
90
91 #include <fcntl.h>
92
93 #ifdef HAVE_SYS_STAT_H
94 #  include <sys/stat.h>
95 #endif
96
97 #ifndef O_BINARY
98 #  define O_BINARY 0
99 #endif
100
101 /****
102  **** Time handling
103  ****/
104
105 #ifdef TIME_WITH_SYS_TIME
106 # include <sys/time.h>
107 # include <time.h>
108 #else
109 # if HAVE_SYS_TIME_H
110 #  include <sys/time.h>
111 # else
112 #  include <time.h>
113 # endif
114 #endif
115
116 #ifdef _WIN32
117 #define sleep _sleep /* else defined in stdlib.h */
118 #endif
119
120 /****
121  **** Contexts
122  ****/
123
124 #ifdef HAVE_UCONTEXT_H
125 #  include <ucontext.h>
126 #else
127 #  include "xbt/context_win32.h" /* Manual reimplementation for prehistoric platforms */
128 #endif
129
130
131 #endif /* GRAS_PORTABLE_H */