r8397: merged an upstream fix for the expression bug tpot found yesterday
[jelmer/samba4-debian.git] / source / lib / ejs / mprOs.h
1 /*
2  *      @file   mprOs.h
3  *  @brief      Include O/S headers and smooth out per-O/S differences
4  *      @copy   default
5  *      
6  *      Copyright (c) Mbedthis Software LLC, 2003-2005. All Rights Reserved.
7  *      
8  *      This software is distributed under commercial and open source licenses.
9  *      You may use the GPL open source license described below or you may acquire 
10  *      a commercial license from Mbedthis Software. You agree to be fully bound 
11  *      by the terms of either license. Consult the LICENSE.TXT distributed with 
12  *      this software for full details.
13  *      
14  *      This software is open source; you can redistribute it and/or modify it 
15  *      under the terms of the GNU General Public License as published by the 
16  *      Free Software Foundation; either version 2 of the License, or (at your 
17  *      option) any later version. See the GNU General Public License for more 
18  *      details at: http://www.mbedthis.com/downloads/gplLicense.html
19  *      
20  *      This program is distributed WITHOUT ANY WARRANTY; without even the 
21  *      implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
22  *      
23  *      This GPL license does NOT permit incorporating this software into 
24  *      proprietary programs. If you are unable to comply with the GPL, you must
25  *      acquire a commercial license to use this software. Commercial licenses 
26  *      for this software and support services are available from Mbedthis 
27  *      Software at http://www.mbedthis.com 
28  *      
29  *      @end
30  ******************************* Documentation *********************************
31  *
32  *      This header is part of the Mbedthis Portable Runtime and aims to include
33  *      all necessary O/S headers and to unify the constants and declarations
34  *      required by Mbedthis products. It can be included by C or C++ programs.
35  *
36  ********************************************************************************/
37
38 #error foo
39
40 blah blah;
41
42 #ifndef _h_MPR_OS_HDRS
43 #define _h_MPR_OS_HDRS 1
44
45 #include        "lib/ejs/config.h"
46
47 /********************************* CPU Families *********************************/
48 /*
49  *      Porters, add your CPU families here and update configure code.
50  */
51 #define MPR_CPU_UNKNOWN         0
52 #define MPR_CPU_IX86            1
53 #define MPR_CPU_PPC             2
54 #define MPR_CPU_SPARC           3
55 #define MPR_CPU_XSCALE          4
56 #define MPR_CPU_ARM             5
57 #define MPR_CPU_MIPS            6
58 #define MPR_CPU_68K             7
59 #define MPR_CPU_SIMNT           8                       /*      VxWorks NT simulator */
60 #define MPR_CPU_SIMSPARC        9                       /*      VxWorks sparc simulator */
61
62 /********************************* O/S Includes *********************************/
63
64 #if LINUX || SOLARIS
65         #include        <sys/types.h>
66         #include        <time.h>
67         #include        <arpa/inet.h>
68         #include        <ctype.h>
69         #include        <dlfcn.h>
70         #include        <fcntl.h>
71         #include        <grp.h> 
72         #include        <errno.h>
73         #include        <libgen.h>
74         #include        <limits.h>
75         #include        <netdb.h>
76         #include        <net/if.h>
77         #include        <netinet/in.h>
78         #include        <netinet/tcp.h>
79         #include        <netinet/ip.h>
80         #include        <pthread.h> 
81         #include        <pwd.h> 
82         #include        <resolv.h>
83         #include        <signal.h>
84         #include        <stdarg.h>
85         #include        <stdio.h>
86         #include        <stdlib.h>
87         #include        <string.h>
88         #include        <syslog.h>
89         #include        <sys/ioctl.h>
90         #include        <sys/stat.h>
91         #include        <sys/param.h>
92         #include        <sys/resource.h>
93         #include        <sys/sem.h>
94         #include        <sys/shm.h>
95         #include        <sys/socket.h>
96         #include        <sys/select.h>
97         #include        <sys/time.h>
98         #include        <sys/times.h>
99         #include        <sys/utsname.h>
100         #include        <sys/wait.h>
101         #include        <unistd.h>
102
103 #if LINUX
104         #include        <stdint.h>
105 #endif
106
107 #if SOLARIS
108         #include        <netinet/in_systm.h>
109 #endif
110
111 #if BLD_FEATURE_FLOATING_POINT
112         #define __USE_ISOC99 1
113         #include        <math.h>
114         #include        <values.h>
115 #endif
116
117 #endif /* LINUX || SOLARIS */
118
119 #if VXWORKS
120         #include        <vxWorks.h>
121         #include        <envLib.h>
122         #include        <sys/types.h>
123         #include        <time.h>
124         #include        <arpa/inet.h>
125         #include        <ctype.h>
126         #include        <fcntl.h>
127         #include        <errno.h>
128         #include        <limits.h>
129         #include        <loadLib.h>
130         #include        <netdb.h>
131         #include        <net/if.h>
132         #include        <netinet/tcp.h>
133         #include        <netinet/in.h>
134         #include        <netinet/ip.h>
135         #include        <signal.h>
136         #include        <stdarg.h>
137         #include        <stdio.h>
138         #include        <stdlib.h>
139         #include        <string.h>
140         #include        <sysSymTbl.h>
141         #include        <sys/fcntlcom.h>
142         #include        <sys/ioctl.h>
143         #include        <sys/stat.h>
144         #include        <sys/socket.h>
145         #include        <sys/times.h>
146         #include        <sys/wait.h>
147         #include        <unistd.h>
148         #include        <unldLib.h>
149
150         #if BLD_FEATURE_FLOATING_POINT
151         #include        <float.h>
152         #define __USE_ISOC99 1
153         #include        <math.h>
154         #endif
155
156         #include        <sockLib.h>
157         #include        <inetLib.h>
158         #include        <ioLib.h>
159         #include        <pipeDrv.h>
160         #include        <hostLib.h>
161         #include        <netdb.h>
162         #include        <tickLib.h>
163         #include        <taskHookLib.h>
164
165 #endif /* VXWORKS */
166
167 #if MACOSX
168         #include        <time.h>
169         #include        <arpa/inet.h>
170         #include        <ctype.h>
171         #include        <fcntl.h>
172         #include        <grp.h> 
173         #include        <errno.h>
174         #include        <libgen.h>
175         #include        <limits.h>
176         #include        <mach-o/dyld.h>
177         #include        <netdb.h>
178         #include        <net/if.h>
179         #include        <netinet/in_systm.h>
180         #include        <netinet/in.h>
181         #include        <netinet/tcp.h>
182         #include        <netinet/ip.h>
183         #include        <pthread.h> 
184         #include        <pwd.h> 
185         #include        <resolv.h>
186         #include        <signal.h>
187         #include        <stdarg.h>
188         #include        <stdio.h>
189         #include        <stdlib.h>
190         #include        <stdint.h>
191         #include        <string.h>
192         #include        <syslog.h>
193         #include        <sys/ioctl.h>
194         #include        <sys/types.h>
195         #include        <sys/stat.h>
196         #include        <sys/param.h>
197         #include        <sys/resource.h>
198         #include        <sys/sem.h>
199         #include        <sys/shm.h>
200         #include        <sys/socket.h>
201         #include        <sys/select.h>
202         #include        <sys/time.h>
203         #include        <sys/times.h>
204         #include        <sys/types.h>
205         #include        <sys/utsname.h>
206         #include        <sys/wait.h>
207         #include        <unistd.h>
208 #endif /* MACOSX */
209
210 #if WIN
211         #include        <ctype.h>
212         #include        <conio.h>
213         #include        <direct.h>
214         #include        <errno.h>
215         #include        <fcntl.h>
216         #include        <io.h>
217         #include        <limits.h>
218         #include        <malloc.h>
219         #include        <process.h>
220         #include        <sys/stat.h>
221         #include        <sys/types.h>
222         #include        <stddef.h>
223         #include        <stdio.h>
224         #include        <stdlib.h>
225         #include        <string.h>
226         #include        <stdarg.h>
227         #include        <time.h>
228         #define WIN32_LEAN_AND_MEAN
229         #include        <winsock2.h>
230         #include        <windows.h>
231         #include        <winbase.h>
232         #if BLD_FEATURE_FLOATING_POINT
233         #include        <float.h>
234         #endif
235         #include        <shlobj.h>
236         #include        <shellapi.h>
237         #include        <wincrypt.h>
238 #endif /* WIN  */
239
240 #ifdef __cplusplus
241 extern "C" {
242 #endif
243
244 /********************************************************************************/
245 /******************************* General Defines ********************************/
246 /********************************************************************************/
247
248 #define MAXINT                  INT_MAX
249 #define BITS(type)              (BITSPERBYTE * (int) sizeof(type))
250
251 #ifndef max
252 #define max(a,b)  (((a) > (b)) ? (a) : (b))
253 #endif
254
255 #ifndef min
256 #define min(a,b)  (((a) < (b)) ? (a) : (b))
257 #endif
258
259 /*
260  *      Set FD_SETSIZE to the maximum number of files (sockets) that you want to
261  *      support. It is used in select.cpp.
262  *
263  *      #ifdef FD_SETSIZE
264  *              #undef FD_SETSIZE
265  *      #endif
266  *      #define FD_SETSIZE              128
267  */
268
269 typedef char    *MprStr;                                        /* Used for dynamic strings */
270
271 /********************************************************************************/
272 /*******************************/ Linux Defines *********************************/
273 /********************************************************************************/
274
275 #if LINUX
276         typedef unsigned char uchar;
277
278 #if BLD_FEATURE_INT64
279         __extension__ typedef long long int int64;
280         __extension__ typedef unsigned long long int uint64;
281         #define INT64(x) (x##LL)
282 #endif
283
284         #define closesocket(x)  close(x)
285         #define MPR_BINARY              ""
286         #define MPR_TEXT                ""
287         #define O_BINARY                0
288         #define O_TEXT                  0
289         #define SOCKET_ERROR    -1
290         #define MPR_DLL_EXT             ".so"
291
292 #if BLD_FEATURE_FLOATING_POINT
293         #define MAX_FLOAT               MAXFLOAT
294 #endif
295
296         #if BLD_FEATURE_MALLOC
297         /*
298          *      PORTERS: You will need add assembler code for your architecture here
299          *      only if you want to use the fast malloc (BLD_FEATURE_MALLOC)
300          */
301                 #if UNUSED
302                         #define MPR_GET_RETURN(ip)      __builtin_return_address(0)
303                 #else
304                         #if BLD_HOST_CPU_ARCH == MPR_CPU_IX86
305                                 #define MPR_GET_RETURN(ip)      \
306                                         asm("movl 4(%%ebp),%%eax ; movl %%eax,%0" : \
307                                                 "=g" (ip) : \
308                                                 : "eax")
309                         #endif
310 #endif /* UNUSED */
311 #endif /* BLD_FEATURE_MALLOC */
312
313 #if FUTURE
314 /*      #define mprGetHiResTime(x) __asm__ __volatile__ ("rdtsc" : "=A" (x)) */
315 /*      extern char *inet_ntoa_r(const struct in_addr in, char *buffer, int buflen); */
316
317         /* */
318         /*      Atomic functions */
319         /* */
320         typedef struct { volatile int counter; } mprAtomic_t;
321
322         #if BLD_FEATURE_MULTITHREAD
323         #define LOCK "lock ; "
324         #else
325         #define LOCK ""
326         #endif
327
328         static __inline__ void mprAtomicInc(mprAtomic_t* v) {
329                 __asm__ __volatile__(
330                         LOCK "incl %0"
331                         :"=m" (v->counter)
332                         :"m" (v->counter));
333         }
334
335         static __inline__ void mprAtomicDec(mprAtomic_t* v) {
336                 __asm__ __volatile__(
337                         LOCK "decl %0"
338                         :"=m" (v->counter)
339                         :"m" (v->counter));
340         }
341 #endif  /* FUTURE */
342
343 #endif  /* LINUX  */
344
345 /********************************************************************************/
346 /******************************* VxWorks Defines ********************************/
347 /********************************************************************************/
348
349 #if VXWORKS
350
351         typedef unsigned char uchar;
352         typedef unsigned int uint;
353         typedef unsigned long ulong;
354
355         #define HAVE_SOCKLEN_T
356         typedef int     socklen_t;
357
358 #if BLD_FEATURE_INT64
359         typedef long long int int64;
360         typedef unsigned long long int uint64;
361         #define INT64(x) (x##LL)
362 #endif
363
364         #define closesocket(x)  close(x)
365         #define getpid()                taskIdSelf()
366         #define MPR_BINARY              ""
367         #define MPR_TEXT                ""
368         #define O_BINARY                0
369         #define O_TEXT                  0
370         #define SOCKET_ERROR    -1
371         #define MPR_DLL_EXT             ".so"
372
373 #if BLD_FEATURE_FLOATING_POINT
374         #define MAX_FLOAT               FLT_MAX
375 #endif
376
377         #undef R_OK
378         #define R_OK    4
379         #undef W_OK
380         #define W_OK    2
381         #undef X_OK
382         #define X_OK    1
383         #undef F_OK
384         #define F_OK    0
385
386         #define MSG_NOSIGNAL 0
387         
388         extern int access(char *path, int mode);
389         extern int sysClkRateGet();
390
391         #if BLD_FEATURE_MALLOC
392         /*
393          *      PORTERS: You will need add assembler code for your architecture here
394          *      only if you want to use the fast malloc (BLD_FEATURE_MALLOC)
395          */
396                 #if UNUSED
397                         #define MPR_GET_RETURN(ip)      __builtin_return_address(0)
398                 #else
399                         #if BLD_HOST_CPU_ARCH == MPR_CPU_IX86
400                                 #define MPR_GET_RETURN(ip)      \
401                                         asm("movl 4(%%ebp),%%eax ; movl %%eax,%0" : \
402                                                 "=g" (ip) : \
403                                                 : "eax")
404                         #endif
405 #endif /* UNUSED */
406 #endif /* BLD_FEATURE_MALLOC */
407 #endif  /* VXWORKS  */
408
409 /********************************************************************************/
410 /******************************** MacOsx Defines ********************************/
411 /********************************************************************************/
412 #if MACOSX
413         typedef unsigned long ulong;
414         typedef unsigned char uchar;
415
416 #if BLD_FEATURE_INT64
417         __extension__ typedef long long int int64;
418         __extension__ typedef unsigned long long int uint64;
419         #define INT64(x) (x##LL)
420 #endif
421         #define closesocket(x)  close(x)
422         #define MPR_BINARY              ""
423         #define MPR_TEXT                ""
424         #define O_BINARY                0
425         #define O_TEXT                  0
426         #define SOCKET_ERROR    -1
427         #define MPR_DLL_EXT             ".dylib"
428         #define MSG_NOSIGNAL    0
429         #define __WALL          0x40000000
430         #define PTHREAD_MUTEX_RECURSIVE_NP  PTHREAD_MUTEX_RECURSIVE
431
432 #if BLD_FEATURE_FLOATING_POINT
433         #define MAX_FLOAT               MAXFLOAT
434 #endif
435
436         #if MPR_FEATURE_MALLOC
437         /*
438          *      PORTERS: You will need add assembler code for your architecture here
439          *      only if you want to use the fast malloc (MPR_FEATURE_MALLOC)
440          */
441         #define MPR_GET_RETURN(ip)      __builtin_return_address
442         #endif
443
444 #if FUTURE
445 /*      #define mprGetHiResTime(x) __asm__ __volatile__ ("rdtsc" : "=A" (x)) */
446 /*      extern char *inet_ntoa_r(const struct in_addr in, char *buffer, int buflen); */
447
448         /* */
449         /*      Atomic functions */
450         /* */
451         typedef struct { volatile int counter; } mprAtomic_t;
452
453         #if MPR_FEATURE_MULTITHREAD
454         #define LOCK "lock ; "
455         #else
456         #define LOCK ""
457         #endif
458
459         static __inline__ void mprAtomicInc(mprAtomic_t* v) {
460                 __asm__ __volatile__(
461                         LOCK "incl %0"
462                         :"=m" (v->counter)
463                         :"m" (v->counter));
464         }
465
466         static __inline__ void mprAtomicDec(mprAtomic_t* v) {
467                 __asm__ __volatile__(
468                         LOCK "decl %0"
469                         :"=m" (v->counter)
470                         :"m" (v->counter));
471         }
472 #endif
473 #endif /* MACOSX */
474
475 /********************************************************************************/
476 /******************************* Windows Defines ********************************/
477 /********************************************************************************/
478
479 #if WIN
480         typedef unsigned char uchar;
481         typedef unsigned int uint;
482         typedef unsigned long ulong;
483         typedef unsigned short ushort;
484
485 #if BLD_FEATURE_INT64
486         typedef __int64 int64;
487         typedef unsigned __int64 uint64;
488         #define INT64(x) (x##i64)
489 #endif
490
491         typedef int     uid_t;
492         typedef void    *handle;
493         typedef char    *caddr_t;
494         typedef long    pid_t;
495         typedef int             gid_t;
496         typedef ushort  mode_t;
497         typedef void    *siginfo_t;
498
499         #define HAVE_SOCKLEN_T
500         typedef int     socklen_t;
501
502         #undef R_OK
503         #define R_OK    4
504         #undef W_OK
505         #define W_OK    2
506         #undef X_OK
507         #define X_OK    1
508         #undef F_OK
509         #define F_OK    0
510         
511         #ifndef EADDRINUSE
512         #define EADDRINUSE              46
513         #endif
514         #ifndef EWOULDBLOCK
515         #define EWOULDBLOCK             EAGAIN
516         #endif
517         #ifndef ENETDOWN
518         #define ENETDOWN                43
519         #endif
520         #ifndef ECONNRESET
521         #define ECONNRESET              44
522         #endif
523         #ifndef ECONNREFUSED
524         #define ECONNREFUSED    45
525         #endif
526
527         #define MSG_NOSIGNAL    0
528         #define MPR_BINARY              "b"
529         #define MPR_TEXT                "t"
530
531 #if BLD_FEATURE_FLOATING_POINT
532         #define MAX_FLOAT               DBL_MAX
533 #endif
534
535 #ifndef FILE_FLAG_FIRST_PIPE_INSTANCE
536 #define FILE_FLAG_FIRST_PIPE_INSTANCE   0x00080000
537 #endif
538
539         #define access  _access
540         #define close   _close
541         #define fileno  _fileno
542         #define fstat   _fstat
543         #define getpid  _getpid
544         #define open    _open
545         #define putenv  _putenv
546         #define read    _read
547         #define stat    _stat
548         #define umask   _umask
549         #define unlink  _unlink
550         #define write   _write
551         #define strdup  _strdup
552         #define lseek   _lseek
553
554         #define mkdir(a,b)      _mkdir(a)
555         #define rmdir(a)        _rmdir(a)
556
557         #if BLD_FEATURE_MALLOC
558         /*
559          *      PORTERS: You will need add assembler code for your architecture here
560          *      only if you want to use the fast malloc (BLD_FEATURE_MALLOC)
561          */
562         #if MPR_CPU_IX86
563         #define MPR_GET_RETURN(ip) \
564                 __asm { mov     eax, 4[ebp] } \
565                 __asm { mov ip, eax     }
566         #endif
567         #endif
568
569         #define MPR_DLL_EXT             ".dll"
570
571         extern void             srand48(long);
572         extern long             lrand48(void);
573         extern long     ulimit(int, ...);
574         extern long     nap(long);
575         extern uint     sleep(unsigned int secs);
576         extern uid_t    getuid(void);
577         extern uid_t    geteuid(void);
578
579 #endif /* WIN  */
580
581 /********************************************************************************/
582 /*****************************/ Solaris Defines *********************************/
583 /********************************************************************************/
584
585 #if SOLARIS
586         typedef unsigned char uchar;
587
588 #if BLD_FEATURE_INT64
589         typedef long long int int64;
590         typedef unsigned long long int uint64;
591         #define INT64(x) (x##LL)
592 #endif
593
594         #define closesocket(x)  close(x)
595         #define MPR_BINARY              ""
596         #define MPR_TEXT                ""
597         #define O_BINARY                0
598         #define O_TEXT                  0
599         #define SOCKET_ERROR    -1
600         #define MPR_DLL_EXT             ".so"
601         #define MSG_NOSIGNAL    0
602         #define INADDR_NONE             ((in_addr_t) 0xffffffff)
603         #define __WALL  0
604         #define PTHREAD_MUTEX_RECURSIVE_NP  PTHREAD_MUTEX_RECURSIVE
605
606 #if BLD_FEATURE_FLOATING_POINT
607         #define MAX_FLOAT               MAXFLOAT
608 #endif
609
610 #endif /* SOLARIS  */
611
612 /********************************************************************************/
613 #ifdef __cplusplus
614 }
615 #endif
616
617 #endif /* _h_MPR_OS_HDRS  */
618
619 /*
620  * Local variables:
621  * tab-width: 4
622  * c-basic-offset: 4
623  * End:
624  * vim:tw=78
625  * vim600: sw=4 ts=4 fdm=marker
626  * vim<600: sw=4 ts=4
627  */