Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add portable.h (headers to include to program in a portable manner, for internal...
[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 #include <errno.h>
17 #include <sys/time.h> /* struct timeval */
18 #include <sys/types.h>
19
20 /****
21  **** Networking 
22  ****/
23
24
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() */
31 # endif
32
33 #ifdef HAVE_WINSOCK2_H
34 #  include <winsock2.h>
35 #  include <ws2tcpip.h>  /* socklen_t, but doubtful */
36 #elif HAVE_WINSOCK_H
37 #  include <winsock.h>
38 #endif
39
40 #ifdef HAVE_WINSOCK_H
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)
46
47 #       ifdef SD_BOTH
48 #               define tcp_close( s )   (shutdown( s, SD_BOTH ), closesocket( s ))
49 #       else
50 #               define tcp_close( s )           closesocket( s )
51 #       endif
52
53 #       define EWOULDBLOCK WSAEWOULDBLOCK
54 #       define EINPROGRESS WSAEINPROGRESS
55 #       define ETIMEDOUT   WSAETIMEDOUT
56
57 #       undef  sock_errno
58 #       undef  sock_errstr
59 #       define sock_errno()    WSAGetLastError()
60 #       define sock_errstr(e)  ber_pvt_wsa_err2string(e)
61
62 char *ber_pvt_wsa_err2string(int errcode);
63
64 #       define S_IRGRP 0
65 #       define S_IWGRP 0
66
67 #else
68 #       define tcp_read( s, buf, len)   read( s, buf, len )
69 #       define tcp_write( s, buf, len)  write( s, buf, len )
70
71 #       ifdef SHUT_RDWR
72 #               define tcp_close( s )   (shutdown( s, SHUT_RDWR ), close( s ))
73 #       else
74 #               define tcp_close( s )   close( s )
75 #       endif
76 #endif /* windows or unix ? */
77
78 /****
79  **** File handling
80  ****/
81
82 #include <fcntl.h>
83
84 #ifdef HAVE_SYS_STAT_H
85 #include <sys/stat.h>
86 #endif
87
88 /****
89  **** Time handling
90  ****/
91
92 #if TIME_WITH_SYS_TIME
93 # include <sys/time.h>
94 # include <time.h>
95 #else
96 # if HAVE_SYS_TIME_H
97 #  include <sys/time.h>
98 # else
99 #  include <time.h>
100 # endif
101 #endif
102
103 #ifdef _WIN32
104 #define sleep _sleep /* else defined in stdlib.h */
105 #endif
106
107
108 #endif /* GRAS_PORTABLE_H */