1
/* $XdotOrg: xserver/xorg/hw/xfree86/os-support/xf86_libc.h,v 1.9 2005/08/24 11:18:31 daniels Exp $ */
2
/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/xf86_libc.h,v 3.63 2003/12/08 21:46:55 alanh Exp $ */
4
* Copyright (c) 1997-2003 by The XFree86 Project, Inc.
6
* Permission is hereby granted, free of charge, to any person obtaining a
7
* copy of this software and associated documentation files (the "Software"),
8
* to deal in the Software without restriction, including without limitation
9
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
10
* and/or sell copies of the Software, and to permit persons to whom the
11
* Software is furnished to do so, subject to the following conditions:
13
* The above copyright notice and this permission notice shall be included in
14
* all copies or substantial portions of the Software.
16
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
* OTHER DEALINGS IN THE SOFTWARE.
24
* Except as contained in this notice, the name of the copyright holder(s)
25
* and author(s) shall not be used in advertising or otherwise to promote
26
* the sale, use or other dealings in this Software without prior written
27
* authorization from the copyright holder(s) and author(s).
31
* This file is an attempt to make developing code for the new loadable module
32
* architecure simpler. It tries to use macros to hide all libc wrappers so
33
* that all that is needed to "port" a module to this architecture is to
34
* include this one header file
39
* 0.4 Apr 12 1997 add the ANSI defines
40
* 0.3 Feb 24 1997 handle getenv
41
* 0.2 Feb 24 1997 hide few FILE functions
42
* 0.1 Feb 24 1997 hide the trivial functions mem* str*
48
#include <X11/Xfuncs.h>
52
* The first set of definitions are required both for modules and
56
#if defined(XFree86LOADER) || defined(NEED_XF86_TYPES)
59
* First, the new data types
61
* note: if some pointer is declared "opaque" here, pass it between
62
* xf86* functions only, and don't rely on it having a whatever internal
63
* structure, even if some source file might reveal the existence of
66
typedef void XF86FILE; /* opaque FILE replacement */
67
extern XF86FILE* xf86stdin;
68
extern XF86FILE* xf86stdout;
69
extern XF86FILE* xf86stderr;
71
typedef void XF86fpos_t; /* opaque fpos_t replacement */
73
#define _XF86NAMELEN 263 /* enough for a larger filename */
75
typedef void XF86DIR; /* opaque DIR replacement */
77
/* Note: the following is POSIX! POSIX only requires the d_name member.
78
* Normal Unix has often a number of other members, but don't rely on that
80
struct _xf86dirent { /* types in struct dirent/direct: */
81
char d_name[_XF86NAMELEN+1]; /* char [MAXNAMLEN]; might be smaller or unaligned */
83
typedef struct _xf86dirent XF86DIRENT;
85
typedef unsigned long xf86size_t;
86
typedef signed long xf86ssize_t;
87
typedef unsigned long xf86dev_t;
88
typedef unsigned int xf86mode_t;
89
typedef unsigned int xf86uid_t;
90
typedef unsigned int xf86gid_t;
93
xf86dev_t st_rdev; /* This is incomplete, and makes assumptions */
97
typedef int xf86key_t;
100
#if defined(__ia64__)
101
typedef int xf86jmp_buf[1024] __attribute__ ((aligned (16))); /* guarantees 128-bit alignment! */
103
typedef int xf86jmp_buf[1024];
111
/* for open (XXX not complete) */
112
#define XF86_O_RDONLY 0x0000
113
#define XF86_O_WRONLY 0x0001
114
#define XF86_O_RDWR 0x0002
115
#define XF86_O_CREAT 0x0200
118
#define XF86_PROT_EXEC 0x0001
119
#define XF86_PROT_READ 0x0002
120
#define XF86_PROT_WRITE 0x0004
121
#define XF86_PROT_NONE 0x0008
122
#define XF86_MAP_FIXED 0x0001
123
#define XF86_MAP_SHARED 0x0002
124
#define XF86_MAP_PRIVATE 0x0004
125
#define XF86_MAP_32BIT 0x0040
126
#define XF86_MAP_FAILED ((void *)-1)
129
#define XF86_SEEK_SET 0
130
#define XF86_SEEK_CUR 1
131
#define XF86_SEEK_END 2
140
#define XF86_S_ISUID 04000 /* set user ID on execution */
141
#define XF86_S_ISGID 02000 /* set group ID on execution */
142
#define XF86_S_ISVTX 01000 /* sticky bit */
143
#define XF86_S_IRUSR 00400 /* read by owner */
144
#define XF86_S_IWUSR 00200 /* write by owner */
145
#define XF86_S_IXUSR 00100 /* execute/search by owner */
146
#define XF86_S_IRGRP 00040 /* read by group */
147
#define XF86_S_IWGRP 00020 /* write by group */
148
#define XF86_S_IXGRP 00010 /* execute/search by group */
149
#define XF86_S_IROTH 00004 /* read by others */
150
#define XF86_S_IWOTH 00002 /* write by others */
151
#define XF86_S_IXOTH 00001 /* execute/search by others */
154
#define XF86_S_IFREG 0010000
155
#define XF86_S_IFCHR 0020000
156
#define XF86_S_IFBLK 0040000
157
#define XF86_S_IFIFO 0100000
161
* They start at 1000 just so they don't match real errnos at all
163
#define xf86_UNKNOWN 1000
164
#define xf86_EACCES 1001
165
#define xf86_EAGAIN 1002
166
#define xf86_EBADF 1003
167
#define xf86_EEXIST 1004
168
#define xf86_EFAULT 1005
169
#define xf86_EINTR 1006
170
#define xf86_EINVAL 1007
171
#define xf86_EISDIR 1008
172
#define xf86_ELOOP 1009
173
#define xf86_EMFILE 1010
174
#define xf86_ENAMETOOLONG 1011
175
#define xf86_ENFILE 1012
176
#define xf86_ENOENT 1013
177
#define xf86_ENOMEM 1014
178
#define xf86_ENOSPC 1015
179
#define xf86_ENOTDIR 1016
180
#define xf86_EPIPE 1017
181
#define xf86_EROFS 1018
182
#define xf86_ETXTBSY 1019
183
#define xf86_ENOTTY 1020
184
#define xf86_ENOSYS 1021
185
#define xf86_EBUSY 1022
186
#define xf86_ENODEV 1023
187
#define xf86_EIO 1024
189
#define xf86_ESRCH 1025
190
#define xf86_ENXIO 1026
191
#define xf86_E2BIG 1027
192
#define xf86_ENOEXEC 1028
193
#define xf86_ECHILD 1029
194
#define xf86_ENOTBLK 1030
195
#define xf86_EXDEV 1031
196
#define xf86_EFBIG 1032
197
#define xf86_ESPIPE 1033
198
#define xf86_EMLINK 1034
199
#define xf86_EDOM 1035
200
#define xf86_ERANGE 1036
205
#define XF86IPC_CREAT 01000
206
#define XF86IPC_EXCL 02000
207
#define XF86IPC_NOWAIT 04000
208
#define XF86SHM_R 0400
209
#define XF86SHM_W 0200
210
#define XF86IPC_PRIVATE ((xf86key_t)0)
212
#define XF86SHM_RDONLY 010000 /* attach read-only else read-write */
213
#define XF86SHM_RND 020000 /* round attach address to SHMLBA */
214
#define XF86SHM_REMAP 040000 /* take-over region on attach */
216
#define XF86IPC_RMID 0
218
#endif /* defined(XFree86LOADER) || defined(NEED_XF86_TYPES) */
221
* the rest of this file should only be included for code that is supposed
225
#if defined(XFree86LOADER) && !defined(DONT_DEFINE_WRAPPERS)
228
#define abort() xf86abort()
230
#define abs(i) xf86abs(i)
232
#define acos(d) xf86acos(d)
234
#define asin(d) xf86asin(d)
236
#define atan(d) xf86atan(d)
238
#define atan2(d1,d2) xf86atan2(d1,d2)
240
#define atof(ccp) xf86atof(ccp)
242
#define atoi(ccp) xf86atoi(ccp)
244
#define atol(ccp) xf86atol(ccp)
246
#define bsearch(a,b,c,d,e) xf86bsearch(a,b,c,d,e)
248
#define ceil(d) xf86ceil(d)
250
#define calloc(I1,I2) xf86calloc(I1,I2)
252
#define clearerr(FP) xf86clearerr(FP)
254
#define cos(d) xf86cos(d)
256
#define exit(i) xf86exit(i)
258
#define exp(d) xf86exp(d)
260
#define fabs(d) xf86fabs(d)
262
#define fclose(FP) xf86fclose(FP)
264
#define feof(FP) xf86feof(FP)
266
#define ferror(FP) xf86ferror(FP)
268
#define fflush(FP) xf86fflush(FP)
270
#define fgetc(FP) xf86fgetc(FP)
272
#define getc(FP) xf86getc(FP)
274
#define fgetpos(FP,fpp) xf86fgetpos(FP,fpp)
276
#define fgets(cp,i,FP) xf86fgets(cp,i,FP)
278
#define finite(d) xf86finite(d)
280
#define floor(d) xf86floor(d)
282
#define fmod(d1,d2) xf86fmod(d1,d2)
284
#define fopen(ccp1,ccp2) xf86fopen(ccp1,ccp2)
286
#define printf xf86printf
288
#define fprintf xf86fprintf
290
#define fputc(i,FP) xf86fputc(i,FP)
292
#define fputs(ccp,FP) xf86fputs(ccp,FP)
294
#define fread(vp,I1,I2,FP) xf86fread(vp,I1,I2,FP)
296
#define free(vp) xf86free(vp)
298
#define freopen(ccp1,ccp2,FP) xf86freopen(ccp1,ccp2,FP)
300
#define frexp(x,exp) xf86frexp(x,exp)
302
#define fscanf xf86fscanf
304
#define fseek(FP,l,i) xf86fseek(FP,l,i)
306
#define fsetpos(FP,cfpp) xf86fsetpos(FP,cfpp)
308
#define ftell(FP) xf86ftell(FP)
310
#define fwrite(cvp,I1,I2,FP) xf86fwrite(cvp,I1,I2,FP)
312
#define getenv(ccp) xf86getenv(ccp)
314
#define isalnum(i) xf86isalnum(i)
316
#define isalpha(i) xf86isalpha(i)
318
#define iscntrl(i) xf86iscntrl(i)
320
#define isdigit(i) xf86isdigit(i)
322
#define isgraph(i) xf86isgraph(i)
324
#define islower(i) xf86islower(i)
326
#define isprint(i) xf86isprint(i)
328
#define ispunct(i) xf86ispunct(i)
330
#define isspace(i) xf86isspace(i)
332
#define isupper(i) xf86isupper(i)
334
#define isxdigit(i) xf86isxdigit(i)
336
#define labs(l) xf86labs(l)
338
#define ldexp(x, exp) xf86ldexp(x, exp)
340
#define log(d) xf86log(d)
342
#define log10(d) xf86log10(d)
344
#define malloc(I) xf86malloc(I)
346
#define memchr(cvp,i,I) xf86memchr(cvp,i,I)
348
#define memcmp(cvp1,cvp2,I) xf86memcmp(cvp1,cvp2,I)
350
#define memcpy(vp,cvp,I) xf86memcpy(vp,cvp,I)
352
#define memmove(vp,cvp,I) xf86memmove(vp,cvp,I)
354
#define memset(vp,int,I) xf86memset(vp,int,I)
356
#define modf(d,dp) xf86modf(d,dp)
358
#define perror(ccp) xf86perror(ccp)
360
#define pow(d1,d2) xf86pow(d1,d2)
362
#define realloc(vp,I) xf86realloc(vp,I)
364
#define remove(ccp) xf86remove(ccp)
366
#define rename(ccp1,ccp2) xf86rename(ccp1,ccp2)
368
#define rewind(FP) xf86rewind(FP)
370
#define setbuf(FP,cp) xf86setbuf(FP,cp)
372
#define setvbuf(FP,cp,i,I) xf86setvbuf(FP,cp,i,I)
374
#define sin(d) xf86sin(d)
376
#define snprintf xf86snprintf
378
#define sprintf xf86sprintf
380
#define sqrt(d) xf86sqrt(d)
382
#define sscanf xf86sscanf
384
#define strcat(cp,ccp) xf86strcat(cp,ccp)
386
#define strcmp(ccp1,ccp2) xf86strcmp(ccp1,ccp2)
388
#define strcasecmp(ccp1,ccp2) xf86strcasecmp(ccp1,ccp2)
390
#define strcpy(cp,ccp) xf86strcpy(cp,ccp)
392
#define strcspn(ccp1,ccp2) xf86strcspn(ccp1,ccp2)
394
#define strerror(i) xf86strerror(i)
396
#define strlcat(cp,ccp,I) xf86strlcat(cp,ccp,I)
398
#define strlcpy(cp,ccp,I) xf86strlcpy(cp,ccp,I)
400
#define strlen(ccp) xf86strlen(ccp)
402
#define strncmp(ccp1,ccp2,I) xf86strncmp(ccp1,ccp2,I)
404
#define strncasecmp(ccp1,ccp2,I) xf86strncasecmp(ccp1,ccp2,I)
406
#define strncpy(cp,ccp,I) xf86strncpy(cp,ccp,I)
408
#define strpbrk(ccp1,ccp2) xf86strpbrk(ccp1,ccp2)
410
#define strchr(ccp,i) xf86strchr(ccp,i)
412
#define strrchr(ccp,i) xf86strrchr(ccp,i)
414
#define strspn(ccp1,ccp2) xf86strspn(ccp1,ccp2)
416
#define strstr(ccp1,ccp2) xf86strstr(ccp1,ccp2)
418
#define strtod(ccp,cpp) xf86strtod(ccp,cpp)
420
#define strtok(cp,ccp) xf86strtok(cp,ccp)
422
#define strtol(ccp,cpp,i) xf86strtol(ccp,cpp,i)
424
#define strtoul(ccp,cpp,i) xf86strtoul(ccp,cpp,i)
426
#define tan(d) xf86tan(d)
428
#define tmpfile() xf86tmpfile()
430
#define tolower(i) xf86tolower(i)
432
#define toupper(i) xf86toupper(i)
434
#define ungetc(i,FP) xf86ungetc(i,FP)
436
#define vfprintf(p,f,a) xf86vfprintf(p,f,a)
438
#define vsnprintf(s,n,f,a) xf86vsnprintf(s,n,f,a)
440
#define vsprintf(s,f,a) xf86vsprintf(s,f,a)
441
/* XXX Disable assert as if NDEBUG was defined */
442
/* Some X headers defined this away too */
444
#define assert(a) ((void)0)
446
#define HUGE_VAL xf86HUGE_VAL
449
#define hypot(x,y) xf86hypot(x,y)
452
#define qsort(b, n, s, f) xf86qsort(b, n, s, f)
454
/* non-ANSI C functions */
456
#define opendir(cp) xf86opendir(cp)
458
#define closedir(DP) xf86closedir(DP)
460
#define readdir(DP) xf86readdir(DP)
462
#define rewinddir(DP) xf86rewinddir(DP)
464
#define bcopy(vp,cvp,I) xf86memmove(cvp,vp,I)
466
#define ffs(i) xf86ffs(i)
468
#define strdup(ccp) xf86strdup(ccp)
470
#define bzero(vp,ui) xf86bzero(vp,ui)
472
#define execl xf86execl
474
#define chmod(a,b) xf86chmod(a,b)
476
#define chown(a,b,c) xf86chown(a,b,c)
478
#define geteuid xf86geteuid
480
#define getegid xf86getegid
482
#define getpid xf86getpid
484
#define mknod(a,b,c) xf86mknod(a,b,c)
486
#define sleep(a) xf86sleep(a)
488
#define mkdir(a,b) xf86mkdir(a,b)
490
#define getpagesize xf86getpagesize
492
#define shmget(a,b,c) xf86shmget(a,b,c)
494
#define shmat(a,b,c) xf86shmat(a,b,c)
496
#define shmdt(a) xf86shmdt(a)
498
#define shmctl(a,b,c) xf86shmctl(a,b,c)
501
#define S_ISUID XF86_S_ISUID
503
#define S_ISGID XF86_S_ISGID
505
#define S_ISVTX XF86_S_ISVTX
507
#define S_IRUSR XF86_S_IRUSR
509
#define S_IWUSR XF86_S_IWUSR
511
#define S_IXUSR XF86_S_IXUSR
513
#define S_IRGRP XF86_S_IRGRP
515
#define S_IWGRP XF86_S_IWGRP
517
#define S_IXGRP XF86_S_IXGRP
519
#define S_IROTH XF86_S_IROTH
521
#define S_IWOTH XF86_S_IWOTH
523
#define S_IXOTH XF86_S_IXOTH
525
#define S_IFREG XF86_S_IFREG
527
#define S_IFCHR XF86_S_IFCHR
529
#define S_IFBLK XF86_S_IFBLK
531
#define S_IFIFO XF86_S_IFIFO
535
#define FILE XF86FILE
537
#define fpos_t XF86fpos_t
541
#define DIRENT XF86DIRENT
543
#define size_t xf86size_t
545
#define ssize_t xf86ssize_t
547
#define dev_t xf86dev_t
549
#define mode_t xf86mode_t
551
#define uid_t xf86uid_t
553
#define gid_t xf86gid_t
555
#define stat_t struct xf86stat
558
#define ulong unsigned long
561
* There should be no need to #undef any of these. If they are already
562
* defined it is because some illegal header has been included.
567
#define stdin xf86stdin
569
#define stdout xf86stdout
571
#define stderr xf86stderr
574
#define SEEK_SET XF86_SEEK_SET
576
#define SEEK_CUR XF86_SEEK_CUR
578
#define SEEK_END XF86_SEEK_END
581
* XXX Basic I/O functions BAD,BAD,BAD!
583
#define open xf86open
584
#define close(a) xf86close(a)
585
#define lseek(a,b,c) xf86lseek(a,b,c)
586
#if !defined(__DragonFly__)
587
#define ioctl(a,b,c) xf86ioctl(a,b,c)
589
#define read(a,b,c) xf86read(a,b,c)
590
#define write(a,b,c) xf86write(a,b,c)
591
#define mmap(a,b,c,d,e,f) xf86mmap(a,b,c,d,e,f)
592
#define munmap(a,b) xf86munmap(a,b)
593
#define stat(a,b) xf86stat(a,b)
594
#define fstat(a,b) xf86fstat(a,b)
595
#define access(a,b) xf86access(a,b)
597
#define O_RDONLY XF86_O_RDONLY
599
#define O_WRONLY XF86_O_WRONLY
601
#define O_RDWR XF86_O_RDWR
603
#define O_CREAT XF86_O_CREAT
605
#define PROT_EXEC XF86_PROT_EXEC
607
#define PROT_READ XF86_PROT_READ
609
#define PROT_WRITE XF86_PROT_WRITE
611
#define PROT_NONE XF86_PROT_NONE
613
#define MAP_FIXED XF86_MAP_FIXED
615
#define MAP_SHARED XF86_MAP_SHARED
617
#define MAP_PRIVATE XF86_MAP_PRIVATE
619
#define MAP_FAILED XF86_MAP_FAILED
621
#define R_OK XF86_R_OK
623
#define W_OK XF86_W_OK
625
#define X_OK XF86_X_OK
627
#define F_OK XF86_F_OK
629
#define errno xf86errno
631
#define putchar(i) xf86fputc(i, xf86stdout)
633
#define puts(s) xf86fputs(s, xf86stdout)
636
#define EACCES xf86_EACCES
638
#define EAGAIN xf86_EAGAIN
640
#define EBADF xf86_EBADF
642
#define EEXIST xf86_EEXIST
644
#define EFAULT xf86_EFAULT
646
#define EINTR xf86_EINTR
648
#define EINVAL xf86_EINVAL
650
#define EISDIR xf86_EISDIR
652
#define ELOOP xf86_ELOOP
654
#define EMFILE xf86_EMFILE
656
#define ENAMETOOLONG xf86_ENAMETOOLONG
658
#define ENFILE xf86_ENFILE
660
#define ENOENT xf86_ENOENT
662
#define ENOMEM xf86_ENOMEM
664
#define ENOSPC xf86_ENOSPC
666
#define ENOTDIR xf86_ENOTDIR
668
#define EPIPE xf86_EPIPE
670
#define EROFS xf86_EROFS
672
#define ETXTBSY xf86_ETXTBSY
674
#define ENOTTY xf86_ENOTTY
676
#define ENOSYS xf86_ENOSYS
678
#define EBUSY xf86_EBUSY
680
#define ENODEV xf86_ENODEV
686
#define SHM_RDONLY XF86SHM_RDONLY
688
#define SHM_RND XF86SHM_RND
690
#define SHM_REMAP XF86SHM_REMAP
692
#define IPC_RMID XF86IPC_RMID
694
#define IPC_CREAT XF86IPC_CREAT
696
#define IPC_EXCL XF86IPC_EXCL
698
#define IPC_NOWAIT XF86IPC_NOWAIT
700
#define SHM_R XF86SHM_R
702
#define SHM_W XF86SHM_W
704
#define IPC_PRIVATE XF86IPC_PRIVATE
706
/* Some ANSI macros */
708
#define FILENAME_MAX 1024
710
#if (defined(sun) && defined(__SVR4))
711
# define _FILEDEFED /* Already have FILE defined, don't redefine it */
714
#endif /* XFree86LOADER && !DONT_DEFINE_WRAPPERS */
716
#if defined(XFree86LOADER) && \
717
(!defined(DONT_DEFINE_WRAPPERS) || defined(DEFINE_SETJMP_WRAPPERS))
719
#define setjmp(a) xf86setjmp_macro(a)
721
#define longjmp(a,b) xf86longjmp(a,b)
723
#define jmp_buf xf86jmp_buf
726
#endif /* XF86_LIBC_H */