Merge Samba3 and Samba4 together
[sfrench/samba-autobuild/.git] / source4 / lib / appweb / ejs-2.0 / mpr / 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-2006. 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  */
31
32 /******************************* Documentation ********************************/
33
34 /*
35  *      This header is part of the Mbedthis Portable Runtime and aims to include
36  *      all necessary O/S headers and to unify the constants and declarations 
37  *      required by Mbedthis products. It can be included by C or C++ programs.
38  */
39
40 /******************************************************************************/
41
42 #ifndef _h_MPR_OS_HDRS
43 #define _h_MPR_OS_HDRS 1
44
45 #include        "buildConfig.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        <dirent.h>
70         #include        <dlfcn.h>
71         #include        <fcntl.h>
72         #include        <grp.h> 
73         #include        <errno.h>
74         #include        <libgen.h>
75         #include        <limits.h>
76         #include        <netdb.h>
77         #include        <net/if.h>
78         #include        <netinet/in.h>
79         #include        <netinet/tcp.h>
80         #include        <netinet/ip.h>
81         #include        <pthread.h> 
82         #include        <pwd.h> 
83         #include        <resolv.h>
84         #include        <signal.h>
85         #include        <stdarg.h>
86         #include        <stdio.h>
87         #include        <stdlib.h>
88         #include        <string.h>
89         #include        <syslog.h>
90         #include        <sys/ioctl.h>
91         #include        <sys/stat.h>
92         #include        <sys/param.h>
93         #include        <sys/resource.h>
94         #include        <sys/sem.h>
95         #include        <sys/shm.h>
96         #include        <sys/socket.h>
97         #include        <sys/select.h>
98         #include        <sys/time.h>
99         #include        <sys/times.h>
100         #include        <sys/utsname.h>
101         #include        <sys/wait.h>
102         #include        <unistd.h>
103
104 #if LINUX
105         #include        <stdint.h>
106 #endif
107
108 #if SOLARIS
109         #include        <netinet/in_systm.h>
110 #endif
111
112 #if BLD_FEATURE_FLOATING_POINT
113         #define __USE_ISOC99 1
114         #include        <math.h>
115         #include        <values.h>
116 #endif
117
118 #endif /* LINUX || SOLARIS */
119
120 #if VXWORKS
121         #include        <vxWorks.h>
122         #include        <envLib.h>
123         #include        <sys/types.h>
124         #include        <time.h>
125         #include        <arpa/inet.h>
126         #include        <ctype.h>
127         #include        <dirent.h>
128         #include        <fcntl.h>
129         #include        <errno.h>
130         #include        <limits.h>
131         #include        <loadLib.h>
132         #include        <netdb.h>
133         #include        <net/if.h>
134         #include        <netinet/tcp.h>
135         #include        <netinet/in.h>
136         #include        <netinet/ip.h>
137         #include        <signal.h>
138         #include        <stdarg.h>
139         #include        <stdio.h>
140         #include        <stdlib.h>
141         #include        <string.h>
142         #include        <sysSymTbl.h>
143         #include        <sys/fcntlcom.h>
144         #include        <sys/ioctl.h>
145         #include        <sys/stat.h>
146         #include        <sys/socket.h>
147         #include        <sys/times.h>
148         #include        <sys/wait.h>
149         #include        <unistd.h>
150         #include        <unldLib.h>
151
152         #if BLD_FEATURE_FLOATING_POINT
153         #include        <float.h>
154         #define __USE_ISOC99 1
155         #include        <math.h>
156         #endif
157
158         #include        <sockLib.h>
159         #include        <inetLib.h>
160         #include        <ioLib.h>
161         #include        <pipeDrv.h>
162         #include        <hostLib.h>
163         #include        <netdb.h>
164         #include        <tickLib.h>
165         #include        <taskHookLib.h>
166
167 #endif /* VXWORKS */
168
169 #if MACOSX
170         #include        <time.h>
171         #include        <arpa/inet.h>
172         #include        <ctype.h>
173         #include        <fcntl.h>
174         #include        <grp.h> 
175         #include        <errno.h>
176         #include        <libgen.h>
177         #include        <limits.h>
178         #include        <mach-o/dyld.h>
179         #include        <netdb.h>
180         #include        <net/if.h>
181         #include        <netinet/in_systm.h>
182         #include        <netinet/in.h>
183         #include        <netinet/tcp.h>
184         #include        <netinet/ip.h>
185         #include        <pthread.h> 
186         #include        <pwd.h> 
187         #include        <resolv.h>
188         #include        <signal.h>
189         #include        <stdarg.h>
190         #include        <stdio.h>
191         #include        <stdlib.h>
192         #include        <stdint.h>
193         #include        <string.h>
194         #include        <syslog.h>
195         #include        <sys/ioctl.h>
196         #include        <sys/types.h>
197         #include        <sys/stat.h>
198         #include        <sys/param.h>
199         #include        <sys/resource.h>
200         #include        <sys/sem.h>
201         #include        <sys/shm.h>
202         #include        <sys/socket.h>
203         #include        <sys/select.h>
204         #include        <sys/time.h>
205         #include        <sys/times.h>
206         #include        <sys/types.h>
207         #include        <sys/utsname.h>
208         #include        <sys/wait.h>
209         #include        <unistd.h>
210 #endif /* MACOSX */
211
212 #if WIN
213         /*
214          *      We replace insecure functions with Mbedthis replacements
215          */
216         #define _CRT_SECURE_NO_DEPRECATE 1
217
218         #include        <ctype.h>
219         #include        <conio.h>
220         #include        <direct.h>
221         #include        <errno.h>
222         #include        <fcntl.h>
223         #include        <io.h>
224         #include        <limits.h>
225         #include        <malloc.h>
226         #include        <process.h>
227         #include        <sys/stat.h>
228         #include        <sys/types.h>
229         #include        <stddef.h>
230         #include        <stdio.h>
231         #include        <stdlib.h>
232         #include        <string.h>
233         #include        <stdarg.h>
234         #include        <time.h>
235         #define WIN32_LEAN_AND_MEAN
236         #include        <winsock2.h>
237         #include        <windows.h>
238         #include        <winbase.h>
239         #if BLD_FEATURE_FLOATING_POINT
240         #include        <float.h>
241         #endif
242         #include        <shlobj.h>
243         #include        <shellapi.h>
244         #include        <wincrypt.h>
245
246 #if BLD_DEBUG
247         #include        <crtdbg.h>
248 #endif
249         #include        "mprUnix.h"
250 #endif /* WIN */
251
252 #if BREW
253         #if BLD_FEATURE_FLOATING_POINT
254         #warning "Floating point is not supported on Brew"
255         #endif
256         #if BLD_FEATURE_MULTITHREAD
257         #warning "Multithreading is not supported on Brew"
258         #endif
259
260         #include        "AEEModGen.h"
261         #include        "AEEAppGen.h"
262         #include        "BREWVersion.h"
263
264         #if BREW_MAJ_VER == 2
265                 /*
266                  *      Fix for BREW 2.X
267                  */
268                 #ifdef __GNUC__
269                 #define __inline extern __inline__
270                 #endif
271                 #include        "AEENet.h"
272                 #undef __inline
273         #endif
274
275         #include        "AEE.h"
276         #include        "AEEBitmap.h"
277         #include        "AEEDisp.h"
278         #include        "AEEFile.h"
279         #include        "AEEHeap.h"
280         #include        "AEEImageCtl.h"
281         #include        "AEEMedia.h"
282         #include        "AEEMediaUtil.h"
283         #include        "AEEMimeTypes.h"
284         #include        "AEEStdLib.h"
285         #include        "AEEShell.h"
286         #include        "AEESoundPlayer.h"
287         #include        "AEEText.h"
288         #include        "AEETransform.h"
289         #include        "AEEWeb.h"
290         #if BREW_MAJ_VER >= 3
291         #include        "AEESMS.h"
292         #endif
293         #include        "AEETAPI.h"
294
295 #if 0
296         #include        "AEESound.h"
297         #include        "AEEDb.h"
298         #include        "AEEMenu.h"
299 #endif
300
301 #endif /* BREW */
302
303 /******************************************************************************/
304 /******************************* General Defines ******************************/
305 /******************************************************************************/
306
307 #ifndef MAXINT
308 #if INT_MAX
309         #define MAXINT  INT_MAX
310 #else
311         #define MAXINT  0x7fffffff
312 #endif
313 #endif
314
315 #ifndef BITSPERBYTE
316 #define BITSPERBYTE             (8 * sizeof(char))
317 #endif
318
319 #define BITS(type)              (BITSPERBYTE * (int) sizeof(type))
320
321 #ifndef max
322 #define max(a,b)  (((a) > (b)) ? (a) : (b))
323 #endif
324
325 #ifndef min
326 #define min(a,b)  (((a) < (b)) ? (a) : (b))
327 #endif
328
329 #define MPR_ARRAY_SIZE(type)    (sizeof(type) / sizeof(type[0]))
330
331 #ifndef PRINTF_ATTRIBUTE
332 #if (__GNUC__ >= 3) && !DOXYGEN && BLD_FEATURE_ALLOC_LEAK_TRACK
333 /** Use gcc attribute to check printf fns.  a1 is the 1-based index of
334  * the parameter containing the format, and a2 the index of the first
335  * argument. Note that some gcc 2.x versions don't handle this
336  * properly **/
337 #define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2)))
338 #else
339 #define PRINTF_ATTRIBUTE(a1, a2)
340 #endif
341 #endif
342
343 typedef char    *MprStr;                                        /* Used for dynamic strings */
344
345 #ifdef __cplusplus
346 extern "C" {
347 #else
348 typedef int bool;
349 #endif
350
351 /******************************************************************************/
352 /******************************** Linux Defines *******************************/
353 /******************************************************************************/
354
355 #if LINUX
356         typedef unsigned char uchar;
357
358 #if BLD_FEATURE_INT64
359         __extension__ typedef long long int int64;
360         __extension__ typedef unsigned long long int uint64;
361         #define INT64(x) (x##LL)
362         #define UINT64(x) (x##ULL)
363 #endif
364
365         #define closesocket(x)  close(x)
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               MAXFLOAT
375 #endif
376
377 /*
378  *      For some reason it is removed from fedora pthreads.h and only
379  *      comes in for UNIX96
380  */
381 extern int pthread_mutexattr_gettype (__const pthread_mutexattr_t *__restrict
382                                       __attr, int *__restrict __kind) __THROW;
383 /* Set the mutex kind attribute in *ATTR to KIND (either PTHREAD_MUTEX_NORMAL,
384    PTHREAD_MUTEX_RECURSIVE, PTHREAD_MUTEX_ERRORCHECK, or
385    PTHREAD_MUTEX_DEFAULT).  */
386 extern int pthread_mutexattr_settype (pthread_mutexattr_t *__attr, int __kind)
387      __THROW;
388
389 #endif  /* LINUX  */
390
391 /******************************************************************************/
392 /******************************* VxWorks Defines ******************************/
393 /******************************************************************************/
394
395 #if VXWORKS
396
397         typedef unsigned char uchar;
398         typedef unsigned int uint;
399         typedef unsigned long ulong;
400
401         #define HAVE_SOCKLEN_T
402         typedef int     socklen_t;
403
404 #if BLD_FEATURE_INT64
405         typedef long long int int64;
406         typedef unsigned long long int uint64;
407         #define INT64(x) (x##LL)
408         #define UINT64(x) (x##ULL)
409 #endif
410
411         #define closesocket(x)  close(x)
412         #define getpid()                taskIdSelf()
413         #define MPR_BINARY              ""
414         #define MPR_TEXT                ""
415         #define O_BINARY                0
416         #define O_TEXT                  0
417         #define SOCKET_ERROR    -1
418         #define MPR_DLL_EXT             ".so"
419
420 #if BLD_FEATURE_FLOATING_POINT
421         #define MAX_FLOAT               FLT_MAX
422 #endif
423
424         #undef R_OK
425         #define R_OK    4
426         #undef W_OK
427         #define W_OK    2
428         #undef X_OK
429         #define X_OK    1
430         #undef F_OK
431         #define F_OK    0
432
433         #define MSG_NOSIGNAL 0
434         
435         extern int access(char *path, int mode);
436         extern int sysClkRateGet();
437
438 #endif  /* VXWORKS */
439
440 /******************************************************************************/
441 /******************************** MacOsx Defines ******************************/
442 /******************************************************************************/
443 #if MACOSX
444         typedef unsigned long ulong;
445         typedef unsigned char uchar;
446
447 #if BLD_FEATURE_INT64
448         __extension__ typedef long long int int64;
449         __extension__ typedef unsigned long long int uint64;
450         #define INT64(x) (x##LL)
451         #define UINT64(x) (x##ULL)
452 #endif
453
454         #define closesocket(x)  close(x)
455         #define MPR_BINARY              ""
456         #define MPR_TEXT                ""
457         #define O_BINARY                0
458         #define O_TEXT                  0
459         #define SOCKET_ERROR    -1
460         #define MPR_DLL_EXT             ".dylib"
461         #define MSG_NOSIGNAL    0
462         #define __WALL          0x40000000
463         #define PTHREAD_MUTEX_RECURSIVE_NP  PTHREAD_MUTEX_RECURSIVE
464
465 #if BLD_FEATURE_FLOATING_POINT
466         #define MAX_FLOAT               MAXFLOAT
467 #endif
468
469 #endif /* MACOSX */
470
471 /******************************************************************************/
472 /******************************* Windows Defines ******************************/
473 /******************************************************************************/
474
475 #if WIN
476         typedef unsigned char uchar;
477         typedef unsigned int uint;
478         typedef unsigned long ulong;
479         typedef unsigned short ushort;
480
481 /*
482  *      We always define INT64 types on windows
483  */
484 #if BLD_FEATURE_INT64 || 1
485         typedef __int64 int64;
486         typedef unsigned __int64 uint64;
487         #define INT64(x) (x##i64)
488         #define UINT64(x) (x##Ui64)
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
507         /*
508          *      On windows map X_OK to R_OK
509          */
510         #undef X_OK
511         #define X_OK    4
512         #undef F_OK
513         #define F_OK    0
514         
515         #ifndef EADDRINUSE
516         #define EADDRINUSE              46
517         #endif
518         #ifndef EWOULDBLOCK
519         #define EWOULDBLOCK             EAGAIN
520         #endif
521         #ifndef ENETDOWN
522         #define ENETDOWN                43
523         #endif
524         #ifndef ECONNRESET
525         #define ECONNRESET              44
526         #endif
527         #ifndef ECONNREFUSED
528         #define ECONNREFUSED    45
529         #endif
530
531         #define MSG_NOSIGNAL    0
532         #define MPR_BINARY              "b"
533         #define MPR_TEXT                "t"
534
535 #if BLD_FEATURE_FLOATING_POINT
536         #define MAX_FLOAT               DBL_MAX
537 #endif
538
539 #ifndef FILE_FLAG_FIRST_PIPE_INSTANCE
540 #define FILE_FLAG_FIRST_PIPE_INSTANCE   0x00080000
541 #endif
542
543         #define MPR_DLL_EXT             ".dll"
544 #endif /* WIN */
545
546 /******************************************************************************/
547 /****************************** Solaris Defines *******************************/
548 /******************************************************************************/
549
550 #if SOLARIS
551         typedef unsigned char uchar;
552
553 #if BLD_FEATURE_INT64
554         typedef long long int int64;
555         typedef unsigned long long int uint64;
556         #define INT64(x) (x##LL)
557         #define UINT64(x) (x##ULL)
558 #endif
559
560         #define closesocket(x)  close(x)
561         #define MPR_BINARY              ""
562         #define MPR_TEXT                ""
563         #define O_BINARY                0
564         #define O_TEXT                  0
565         #define SOCKET_ERROR    -1
566         #define MPR_DLL_EXT             ".so"
567         #define MSG_NOSIGNAL    0
568         #define INADDR_NONE             ((in_addr_t) 0xffffffff)
569         #define __WALL  0
570         #define PTHREAD_MUTEX_RECURSIVE_NP  PTHREAD_MUTEX_RECURSIVE
571
572 #if BLD_FEATURE_FLOATING_POINT
573         #define MAX_FLOAT               MAXFLOAT
574 #endif
575
576 #endif /* SOLARIS */
577
578 /******************************************************************************/
579 /********************************* BREW Defines *******************************/
580 /******************************************************************************/
581
582 #if BREW
583         typedef unsigned char uchar;
584         typedef unsigned int uint;
585         typedef unsigned long ulong;
586         typedef unsigned short ushort;
587
588         typedef uint    off_t;
589         typedef long    pid_t;
590
591 #if UNUSED
592         typedef int     uid_t;
593         typedef void    *handle;
594         typedef char    *caddr_t;
595         typedef int             gid_t;
596         typedef ushort  mode_t;
597         typedef void    *siginfo_t;
598
599         #define HAVE_SOCKLEN_T
600         typedef int     socklen_t;
601
602         #ifndef EADDRINUSE
603         #define EADDRINUSE              46
604         #endif
605         #ifndef EWOULDBLOCK
606         #define EWOULDBLOCK             EAGAIN
607         #endif
608         #ifndef ENETDOWN
609         #define ENETDOWN                43
610         #endif
611         #ifndef ECONNRESET
612         #define ECONNRESET              44
613         #endif
614         #ifndef ECONNREFUSED
615         #define ECONNREFUSED    45
616         #endif
617
618         #define MSG_NOSIGNAL    0
619         #define MPR_BINARY              "b"
620         #define MPR_TEXT                "t"
621
622         #define MPR_DLL_EXT             ".dll"
623 #endif
624
625         #define O_RDONLY                0
626         #define O_WRONLY                1
627         #define O_RDWR                  2
628         #define O_CREAT                 0x200
629         #define O_TRUNC                 0x400
630         #define O_BINARY                0
631         #define O_TEXT                  0x20000
632         #define O_EXCL                  0x40000
633         #define O_APPEND                0x80000
634
635         #define R_OK    4
636         #define W_OK    2
637         #define X_OK    1
638         #define F_OK    0
639
640         #define SEEK_SET        0
641         #define SEEK_CUR        1
642         #define SEEK_END        2
643
644 #if UNUSED
645 struct stat {
646         uint    st_size;
647 };
648 #endif
649
650 extern int      getpid();
651 extern int      isalnum(int c);
652 extern int      isalpha(int c);
653 extern int      isdigit(int c);
654 extern int      islower(int c);
655 extern int      isupper(int c);
656 extern int      isspace(int c);
657 extern int      isxdigit(int c);
658
659 extern uint     strlen(const char *str);
660 extern char     *strstr(const char *string, const char *strSet);
661 extern void     *memset(const void *dest, int c, uint count);
662 extern void     exit(int status);
663 extern char     *strpbrk(const char *str, const char *set);
664 extern uint     strspn(const char *str, const char *set);
665 extern int      tolower(int c);
666 extern int      toupper(int c);
667 extern void     *memcpy(void *dest, const void *src, uint count);
668 extern void     *memmove(void *dest, const void *src, uint count);
669
670 extern int      atoi(const char *str);
671 extern void     free(void *ptr);
672 extern void     *malloc(uint size);
673 extern void     *realloc(void *ptr, uint size);
674 extern char     *strcat(char *dest, const char *src);
675 extern char     *strchr(const char *str, int c);
676 extern int      strcmp(const char *s1, const char *s2);
677 extern int      strncmp(const char *s1, const char *s2, uint count);
678 extern char     *strcpy(char *dest, const char *src);
679 extern char     *strncpy(char *dest, const char *src, uint count);
680 extern char     *strrchr(const char *str, int c);
681
682 #undef  printf
683 #define printf DBGPRINTF
684
685 #if BREW_SIMULATOR && BLD_DEBUG
686 extern _CRTIMP int __cdecl _CrtCheckMemory(void);
687 extern _CRTIMP int __cdecl _CrtSetReportHook();
688 #endif
689
690 #endif /* BREW */
691
692 /******************************************************************************/
693 #ifdef __cplusplus
694 }
695 #endif
696
697 #endif /* _h_MPR_OS_HDRS */
698
699 /*
700  * Local variables:
701  * tab-width: 4
702  * c-basic-offset: 4
703  * End:
704  * vim:tw=78
705  * vim600: sw=4 ts=4 fdm=marker
706  * vim<600: sw=4 ts=4
707  */