Added LGPL standard comment, and copyright notices where necessary.
[wine] / include / wine / port.h
1 /*
2  * Wine porting definitions
3  *
4  * Copyright 1996 Alexandre Julliard
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #ifndef __WINE_WINE_PORT_H
22 #define __WINE_WINE_PORT_H
23
24 #ifndef __WINE_CONFIG_H  
25 # error You must include config.h to use this header  
26 #endif  
27
28 #define _GNU_SOURCE  /* for pread/pwrite */
29 #include <fcntl.h>
30 #include <sys/types.h>
31 #include <sys/time.h>
32 #include <sys/stat.h>
33 #include <unistd.h>
34
35 /* Types */
36
37 #ifndef HAVE_GETRLIMIT
38 #define RLIMIT_STACK 3
39 typedef int rlim_t;
40 struct rlimit
41 {
42     rlim_t rlim_cur;
43     rlim_t rlim_max;
44 };
45 int getrlimit (int resource, struct rlimit *rlim);
46 #endif /* HAVE_GETRLIMIT */
47
48 #if !defined(HAVE_GETNETBYADDR) && !defined(HAVE_GETNETBYNAME)
49 struct netent {
50   char         *n_name;
51   char        **n_aliases;
52   int           n_addrtype;
53   unsigned long n_net;
54 };
55 #endif /* !defined(HAVE_GETNETBYADDR) && !defined(HAVE_GETNETBYNAME) */
56
57 #if !defined(HAVE_GETPROTOBYNAME) && !defined(HAVE_GETPROTOBYNUMBER)
58 struct  protoent {
59   char  *p_name;
60   char **p_aliases;
61   int    p_proto;
62 };
63 #endif /* !defined(HAVE_GETPROTOBYNAME) && !defined(HAVE_GETPROTOBYNUMBER) */
64
65 #ifndef HAVE_STATFS
66 # ifdef __BEOS__
67 #  define STATFS_HAS_BFREE
68 struct statfs {
69   long   f_bsize;  /* block_size */
70   long   f_blocks; /* total_blocks */
71   long   f_bfree;  /* free_blocks */
72 };
73 # else /* defined(__BEOS__) */
74 struct statfs;
75 # endif /* defined(__BEOS__) */
76 #endif /* !defined(HAVE_STATFS) */
77
78 /* Functions */
79
80 #if !defined(HAVE_CLONE) && defined(linux)
81 int clone(int (*fn)(void *arg), void *stack, int flags, void *arg);
82 #endif /* !defined(HAVE_CLONE) && defined(linux) */
83
84 #ifndef HAVE_GETNETBYADDR
85 struct netent *getnetbyaddr(unsigned long net, int type);
86 #endif /* defined(HAVE_GETNETBYNAME) */
87
88 #ifndef HAVE_GETNETBYNAME
89 struct netent *getnetbyname(const char *name);
90 #endif /* defined(HAVE_GETNETBYNAME) */
91
92 #ifndef HAVE_GETPROTOBYNAME
93 struct protoent *getprotobyname(const char *name);
94 #endif /* !defined(HAVE_GETPROTOBYNAME) */
95
96 #ifndef HAVE_GETPROTOBYNUMBER
97 struct protoent *getprotobynumber(int proto);
98 #endif /* !defined(HAVE_GETPROTOBYNUMBER) */
99
100 #ifndef HAVE_GETSERVBYPORT
101 struct servent *getservbyport(int port, const char *proto);
102 #endif /* !defined(HAVE_GETSERVBYPORT) */
103
104 #ifndef HAVE_GETSOCKOPT
105 int getsockopt(int socket, int level, int option_name, void *option_value, size_t *option_len);
106 #endif /* !defined(HAVE_GETSOCKOPT) */
107
108 #ifndef HAVE_MEMMOVE
109 void *memmove(void *dest, const void *src, unsigned int len);
110 #endif /* !defined(HAVE_MEMMOVE) */
111
112 #ifndef HAVE_GETPAGESIZE
113 size_t getpagesize(void);
114 #endif  /* HAVE_GETPAGESIZE */
115
116 #ifndef HAVE_INET_NETWORK
117 unsigned long inet_network(const char *cp);
118 #endif /* !defined(HAVE_INET_NETWORK) */
119
120 #ifndef HAVE_SETTIMEOFDAY
121 int settimeofday(struct timeval *tp, void *reserved);
122 #endif /* !defined(HAVE_SETTIMEOFDAY) */
123
124 #ifndef HAVE_STATFS
125 int statfs(const char *name, struct statfs *info);
126 #endif /* !defined(HAVE_STATFS) */
127
128 #ifndef HAVE_STRNCASECMP
129 int strncasecmp(const char *str1, const char *str2, size_t n);
130 #endif /* !defined(HAVE_STRNCASECMP) */
131
132 #ifndef HAVE_OPENPTY
133 struct termios;
134 struct winsize;
135 int openpty(int *master, int *slave, char *name, struct termios *term, struct winsize *winsize);
136 #endif  /* HAVE_OPENPTY */
137
138 #ifndef HAVE_STRERROR
139 const char *strerror(int err);
140 #endif /* !defined(HAVE_STRERROR) */
141
142 #ifndef HAVE_STRCASECMP
143 int strcasecmp(const char *str1, const char *str2);
144 #endif /* !defined(HAVE_STRCASECMP) */
145
146 #ifndef HAVE_USLEEP
147 int usleep (unsigned int useconds);
148 #endif /* !defined(HAVE_USLEEP) */
149
150 #ifndef HAVE_LSTAT
151 int lstat(const char *file_name, struct stat *buf);
152 #endif /* HAVE_LSTAT */
153
154 #ifndef HAVE_PREAD
155 ssize_t pread( int fd, void *buf, size_t count, off_t offset );
156 #endif /* HAVE_PREAD */
157
158 #ifndef HAVE_PWRITE
159 ssize_t pwrite( int fd, const void *buf, size_t count, off_t offset );
160 #endif /* HAVE_PWRITE */
161
162 #ifndef S_ISLNK
163 #define S_ISLNK(mod) (0)
164 #endif /* S_ISLNK */
165
166 /* So we open files in 64 bit access mode on Linux */
167 #ifndef O_LARGEFILE
168 # define O_LARGEFILE 0
169 #endif
170
171 extern void *wine_dlopen( const char *filename, int flag, char *error, int errorsize );
172 extern void *wine_dlsym( void *handle, const char *symbol, char *error, int errorsize );
173 extern int wine_dlclose( void *handle, char *error, int errorsize );
174
175 #ifdef HAVE_DLFCN_H
176 #include <dlfcn.h>
177 #else
178 #define RTLD_LAZY       0x001
179 #define RTLD_NOW        0x002
180 #define RTLD_GLOBAL     0x100
181 #endif
182
183
184 /* Macros to access unaligned or wrong-endian WORDs and DWORDs. */
185
186 #define PUT_WORD(ptr, w)  (*(WORD *)(ptr) = (w))
187 #define GET_WORD(ptr)     (*(WORD *)(ptr))
188 #define PUT_DWORD(ptr, d) (*(DWORD *)(ptr) = (d))
189 #define GET_DWORD(ptr)    (*(DWORD *)(ptr))
190
191 #define PUT_LE_WORD(ptr, w) \
192         do { ((BYTE *)(ptr))[0] = LOBYTE(w); \
193              ((BYTE *)(ptr))[1] = HIBYTE(w); } while (0)
194 #define GET_LE_WORD(ptr) \
195         MAKEWORD( ((BYTE *)(ptr))[0], \
196                   ((BYTE *)(ptr))[1] )
197 #define PUT_LE_DWORD(ptr, d) \
198         do { PUT_LE_WORD(&((WORD *)(ptr))[0], LOWORD(d)); \
199              PUT_LE_WORD(&((WORD *)(ptr))[1], HIWORD(d)); } while (0)
200 #define GET_LE_DWORD(ptr) \
201         ((DWORD)MAKELONG( GET_LE_WORD(&((WORD *)(ptr))[0]), \
202                           GET_LE_WORD(&((WORD *)(ptr))[1]) ))
203
204 #define PUT_BE_WORD(ptr, w) \
205         do { ((BYTE *)(ptr))[1] = LOBYTE(w); \
206              ((BYTE *)(ptr))[0] = HIBYTE(w); } while (0)
207 #define GET_BE_WORD(ptr) \
208         MAKEWORD( ((BYTE *)(ptr))[1], \
209                   ((BYTE *)(ptr))[0] )
210 #define PUT_BE_DWORD(ptr, d) \
211         do { PUT_BE_WORD(&((WORD *)(ptr))[1], LOWORD(d)); \
212              PUT_BE_WORD(&((WORD *)(ptr))[0], HIWORD(d)); } while (0)
213 #define GET_BE_DWORD(ptr) \
214         ((DWORD)MAKELONG( GET_BE_WORD(&((WORD *)(ptr))[1]), \
215                           GET_BE_WORD(&((WORD *)(ptr))[0]) ))
216
217 #if defined(ALLOW_UNALIGNED_ACCESS)
218 #define PUT_UA_WORD(ptr, w)  PUT_WORD(ptr, w)
219 #define GET_UA_WORD(ptr)     GET_WORD(ptr)
220 #define PUT_UA_DWORD(ptr, d) PUT_DWORD(ptr, d)
221 #define GET_UA_DWORD(ptr)    GET_DWORD(ptr)
222 #elif defined(WORDS_BIGENDIAN)
223 #define PUT_UA_WORD(ptr, w)  PUT_BE_WORD(ptr, w)
224 #define GET_UA_WORD(ptr)     GET_BE_WORD(ptr)
225 #define PUT_UA_DWORD(ptr, d) PUT_BE_DWORD(ptr, d)
226 #define GET_UA_DWORD(ptr)    GET_BE_DWORD(ptr)
227 #else
228 #define PUT_UA_WORD(ptr, w)  PUT_LE_WORD(ptr, w)
229 #define GET_UA_WORD(ptr)     GET_LE_WORD(ptr)
230 #define PUT_UA_DWORD(ptr, d) PUT_LE_DWORD(ptr, d)
231 #define GET_UA_DWORD(ptr)    GET_LE_DWORD(ptr)
232 #endif
233
234 #endif /* !defined(__WINE_WINE_PORT_H) */