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 random() xf86random()
364 #define realloc(vp,I) xf86realloc(vp,I)
366 #define remove(ccp) xf86remove(ccp)
368 #define rename(ccp1,ccp2) xf86rename(ccp1,ccp2)
370 #define rewind(FP) xf86rewind(FP)
372 #define setbuf(FP,cp) xf86setbuf(FP,cp)
374 #define setvbuf(FP,cp,i,I) xf86setvbuf(FP,cp,i,I)
376 #define sin(d) xf86sin(d)
378 #define snprintf xf86snprintf
380 #define sprintf xf86sprintf
382 #define sqrt(d) xf86sqrt(d)
384 #define sscanf xf86sscanf
386 #define strcat(cp,ccp) xf86strcat(cp,ccp)
388 #define strcmp(ccp1,ccp2) xf86strcmp(ccp1,ccp2)
390 #define strcasecmp(ccp1,ccp2) xf86strcasecmp(ccp1,ccp2)
392 #define strcpy(cp,ccp) xf86strcpy(cp,ccp)
394 #define strcspn(ccp1,ccp2) xf86strcspn(ccp1,ccp2)
396 #define strerror(i) xf86strerror(i)
398 #define strlcat(cp,ccp,I) xf86strlcat(cp,ccp,I)
400 #define strlcpy(cp,ccp,I) xf86strlcpy(cp,ccp,I)
402 #define strlen(ccp) xf86strlen(ccp)
404 #define strncmp(ccp1,ccp2,I) xf86strncmp(ccp1,ccp2,I)
406 #define strncasecmp(ccp1,ccp2,I) xf86strncasecmp(ccp1,ccp2,I)
408 #define strncpy(cp,ccp,I) xf86strncpy(cp,ccp,I)
410 #define strpbrk(ccp1,ccp2) xf86strpbrk(ccp1,ccp2)
412 #define strchr(ccp,i) xf86strchr(ccp,i)
414 #define strrchr(ccp,i) xf86strrchr(ccp,i)
416 #define strspn(ccp1,ccp2) xf86strspn(ccp1,ccp2)
418 #define strstr(ccp1,ccp2) xf86strstr(ccp1,ccp2)
420 #define strtod(ccp,cpp) xf86strtod(ccp,cpp)
422 #define strtok(cp,ccp) xf86strtok(cp,ccp)
424 #define strtol(ccp,cpp,i) xf86strtol(ccp,cpp,i)
426 #define strtoul(ccp,cpp,i) xf86strtoul(ccp,cpp,i)
428 #define tan(d) xf86tan(d)
430 #define tmpfile() xf86tmpfile()
432 #define tolower(i) xf86tolower(i)
434 #define toupper(i) xf86toupper(i)
436 #define ungetc(i,FP) xf86ungetc(i,FP)
438 #define vfprintf(p,f,a) xf86vfprintf(p,f,a)
440 #define vsnprintf(s,n,f,a) xf86vsnprintf(s,n,f,a)
442 #define vsprintf(s,f,a) xf86vsprintf(s,f,a)
443 /* XXX Disable assert as if NDEBUG was defined */
444 /* Some X headers defined this away too */
446 #define assert(a) ((void)0)
448 #define HUGE_VAL xf86HUGE_VAL
451 #define hypot(x,y) xf86hypot(x,y)
454 #define qsort(b, n, s, f) xf86qsort(b, n, s, f)
456 /* non-ANSI C functions */
458 #define opendir(cp) xf86opendir(cp)
460 #define closedir(DP) xf86closedir(DP)
462 #define readdir(DP) xf86readdir(DP)
464 #define rewinddir(DP) xf86rewinddir(DP)
466 #define bcopy(vp,cvp,I) xf86memmove(cvp,vp,I)
468 #define ffs(i) xf86ffs(i)
470 #define strdup(ccp) xf86strdup(ccp)
472 #define bzero(vp,ui) xf86bzero(vp,ui)
474 #define execl xf86execl
476 #define chmod(a,b) xf86chmod(a,b)
478 #define chown(a,b,c) xf86chown(a,b,c)
480 #define geteuid xf86geteuid
482 #define getegid xf86getegid
484 #define getpid xf86getpid
486 #define mknod(a,b,c) xf86mknod(a,b,c)
488 #define sleep(a) xf86sleep(a)
490 #define mkdir(a,b) xf86mkdir(a,b)
492 #define getpagesize xf86getpagesize
494 #define shmget(a,b,c) xf86shmget(a,b,c)
496 #define shmat(a,b,c) xf86shmat(a,b,c)
498 #define shmdt(a) xf86shmdt(a)
500 #define shmctl(a,b,c) xf86shmctl(a,b,c)
503 #define S_ISUID XF86_S_ISUID
505 #define S_ISGID XF86_S_ISGID
507 #define S_ISVTX XF86_S_ISVTX
509 #define S_IRUSR XF86_S_IRUSR
511 #define S_IWUSR XF86_S_IWUSR
513 #define S_IXUSR XF86_S_IXUSR
515 #define S_IRGRP XF86_S_IRGRP
517 #define S_IWGRP XF86_S_IWGRP
519 #define S_IXGRP XF86_S_IXGRP
521 #define S_IROTH XF86_S_IROTH
523 #define S_IWOTH XF86_S_IWOTH
525 #define S_IXOTH XF86_S_IXOTH
527 #define S_IFREG XF86_S_IFREG
529 #define S_IFCHR XF86_S_IFCHR
531 #define S_IFBLK XF86_S_IFBLK
533 #define S_IFIFO XF86_S_IFIFO
537 #define FILE XF86FILE
539 #define fpos_t XF86fpos_t
543 #define DIRENT XF86DIRENT
545 #define size_t xf86size_t
547 #define ssize_t xf86ssize_t
549 #define dev_t xf86dev_t
551 #define mode_t xf86mode_t
553 #define uid_t xf86uid_t
555 #define gid_t xf86gid_t
557 #define stat_t struct xf86stat
560 #define ulong unsigned long
563 * There should be no need to #undef any of these. If they are already
564 * defined it is because some illegal header has been included.
569 #define stdin xf86stdin
571 #define stdout xf86stdout
573 #define stderr xf86stderr
576 #define SEEK_SET XF86_SEEK_SET
578 #define SEEK_CUR XF86_SEEK_CUR
580 #define SEEK_END XF86_SEEK_END
583 * XXX Basic I/O functions BAD,BAD,BAD!
585 #define open xf86open
586 #define close(a) xf86close(a)
587 #define lseek(a,b,c) xf86lseek(a,b,c)
588 #if !defined(__DragonFly__)
589 #define ioctl(a,b,c) xf86ioctl(a,b,c)
591 #define read(a,b,c) xf86read(a,b,c)
592 #define write(a,b,c) xf86write(a,b,c)
593 #define mmap(a,b,c,d,e,f) xf86mmap(a,b,c,d,e,f)
594 #define munmap(a,b) xf86munmap(a,b)
595 #define stat(a,b) xf86stat(a,b)
596 #define fstat(a,b) xf86fstat(a,b)
597 #define access(a,b) xf86access(a,b)
599 #define O_RDONLY XF86_O_RDONLY
601 #define O_WRONLY XF86_O_WRONLY
603 #define O_RDWR XF86_O_RDWR
605 #define O_CREAT XF86_O_CREAT
607 #define PROT_EXEC XF86_PROT_EXEC
609 #define PROT_READ XF86_PROT_READ
611 #define PROT_WRITE XF86_PROT_WRITE
613 #define PROT_NONE XF86_PROT_NONE
615 #define MAP_FIXED XF86_MAP_FIXED
617 #define MAP_SHARED XF86_MAP_SHARED
619 #define MAP_PRIVATE XF86_MAP_PRIVATE
621 #define MAP_FAILED XF86_MAP_FAILED
623 #define R_OK XF86_R_OK
625 #define W_OK XF86_W_OK
627 #define X_OK XF86_X_OK
629 #define F_OK XF86_F_OK
631 #define errno xf86errno
633 #define putchar(i) xf86fputc(i, xf86stdout)
635 #define puts(s) xf86fputs(s, xf86stdout)
638 #define EACCES xf86_EACCES
640 #define EAGAIN xf86_EAGAIN
642 #define EBADF xf86_EBADF
644 #define EEXIST xf86_EEXIST
646 #define EFAULT xf86_EFAULT
648 #define EINTR xf86_EINTR
650 #define EINVAL xf86_EINVAL
652 #define EISDIR xf86_EISDIR
654 #define ELOOP xf86_ELOOP
656 #define EMFILE xf86_EMFILE
658 #define ENAMETOOLONG xf86_ENAMETOOLONG
660 #define ENFILE xf86_ENFILE
662 #define ENOENT xf86_ENOENT
664 #define ENOMEM xf86_ENOMEM
666 #define ENOSPC xf86_ENOSPC
668 #define ENOTDIR xf86_ENOTDIR
670 #define EPIPE xf86_EPIPE
672 #define EROFS xf86_EROFS
674 #define ETXTBSY xf86_ETXTBSY
676 #define ENOTTY xf86_ENOTTY
678 #define ENOSYS xf86_ENOSYS
680 #define EBUSY xf86_EBUSY
682 #define ENODEV xf86_ENODEV
688 #define SHM_RDONLY XF86SHM_RDONLY
690 #define SHM_RND XF86SHM_RND
692 #define SHM_REMAP XF86SHM_REMAP
694 #define IPC_RMID XF86IPC_RMID
696 #define IPC_CREAT XF86IPC_CREAT
698 #define IPC_EXCL XF86IPC_EXCL
700 #define IPC_NOWAIT XF86IPC_NOWAIT
702 #define SHM_R XF86SHM_R
704 #define SHM_W XF86SHM_W
706 #define IPC_PRIVATE XF86IPC_PRIVATE
708 /* Some ANSI macros */
710 #define FILENAME_MAX 1024
712 #if (defined(sun) && defined(__SVR4))
713 # define _FILEDEFED /* Already have FILE defined, don't redefine it */
716 #endif /* XFree86LOADER && !DONT_DEFINE_WRAPPERS */
718 #if defined(XFree86LOADER) && \
719 (!defined(DONT_DEFINE_WRAPPERS) || defined(DEFINE_SETJMP_WRAPPERS))
721 #define setjmp(a) xf86setjmp_macro(a)
723 #define longjmp(a,b) xf86longjmp(a,b)
725 #define jmp_buf xf86jmp_buf
728 #endif /* XF86_LIBC_H */