libdali  1.6
 All Classes Files Functions Variables Typedefs Macros Pages
portable.h
Go to the documentation of this file.
1 /***********************************************************************/
24 #ifndef PORTABLE_H
25 #define PORTABLE_H 1
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 
32  /* Portability to the XScale (ARM) architecture
33  * requires a packed attribute in certain places
34  * but this only works with GCC for now.
35  */
36 
37 #if defined (__GNUC__)
38  #define DLP_PACKED __attribute__ ((packed))
39 #else
40  #define DLP_PACKED
41 #endif
42 
43  /* Make some guesses about the system libraries based
44  * on the architecture. Currently the assumptions are:
45  * Linux => glibc2 (DLP_GLIBC2)
46  * Sun => Solaris (DLP_SOLARIS)
47  * BSD => BSD libraries, including Apple Mac OS X (DLP_BSD)
48  * WIN32 => WIN32 and Windows Sockets 2 (DLP_WIN32)
49  */
50 
51 #if defined(__linux__) || defined(__linux)
52  #define DLP_GLIBC2 1
53 
54  #include <stdlib.h>
55  #include <unistd.h>
56  #include <stdarg.h>
57  #include <inttypes.h>
58  #include <sys/socket.h>
59  #include <netinet/in.h>
60  #include <netdb.h>
61  #include <sys/time.h>
62  #include <sys/utsname.h>
63  #include <sys/types.h>
64  #include <pwd.h>
65 
66 #elif defined(__sun__) || defined(__sun)
67  #define DLP_SOLARIS 1
68 
69  #include <stdlib.h>
70  #include <unistd.h>
71  #include <stdarg.h>
72  #include <inttypes.h>
73  #include <errno.h>
74  #include <sys/types.h>
75  #include <sys/socket.h>
76  #include <netinet/in.h>
77  #include <netdb.h>
78  #include <sys/time.h>
79  #include <sys/utsname.h>
80  #include <sys/types.h>
81  #include <pwd.h>
82 
83 #elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
84  #define DLP_BSD 1
85 
86  #include <stdlib.h>
87  #include <stdio.h>
88  #include <unistd.h>
89  #include <stdarg.h>
90  #include <inttypes.h>
91  #include <sys/socket.h>
92  #include <netinet/in.h>
93  #include <netdb.h>
94  #include <sys/time.h>
95  #include <sys/utsname.h>
96  #include <sys/types.h>
97  #include <string.h>
98  #include <ctype.h>
99  #include <pwd.h>
100 
101 #elif defined(WIN32)
102  #define DLP_WIN32 1
103 
104  #include <windows.h>
105  #include <stdarg.h>
106  #include <winsock.h>
107  #include <stdio.h>
108  #include <io.h>
109  #include <process.h>
110 
111  #define snprintf _snprintf
112  #define vsnprintf _vsnprintf
113  #define strncasecmp _strnicmp
114 
115  typedef signed char int8_t;
116  typedef unsigned char uint8_t;
117  typedef signed short int int16_t;
118  typedef unsigned short int uint16_t;
119  typedef signed int int32_t;
120  typedef unsigned int uint32_t;
121  typedef signed __int64 int64_t;
122  typedef unsigned __int64 uint64_t;
123 
124 #else
125  typedef signed char int8_t;
126  typedef unsigned char uint8_t;
127  typedef signed short int int16_t;
128  typedef unsigned short int uint16_t;
129  typedef signed int int32_t;
130  typedef unsigned int uint32_t;
131  typedef signed long long int64_t;
132  typedef unsigned long long uint64_t;
133 
134 #endif
135 
136 extern int dlp_sockstartup (void);
137 extern int dlp_sockconnect (int socket, struct sockaddr * inetaddr, int addrlen);
138 extern int dlp_sockclose (int socket);
139 extern int dlp_sockblock (int socket);
140 extern int dlp_socknoblock (int socket);
141 extern int dlp_noblockcheck (void);
142 extern int dlp_setsocktimeo (int socket, int timeout);
143 extern int dlp_setioalarm (int timeout);
144 extern int dlp_getaddrinfo (char * nodename, char * nodeport,
145  struct sockaddr * addr, size_t * addrlen);
146 extern int dlp_openfile (const char *filename, char perm);
147 extern const char *dlp_strerror (void);
148 extern int64_t dlp_time (void);
149 extern void dlp_usleep (unsigned long int useconds);
150 extern int dlp_genclientid (char *progname, char *clientid, size_t maxsize);
151 
152 #ifdef __cplusplus
153 }
154 #endif
155 
156 #endif /* PORTABLE_H */