xf86_libc.h revision cf5e38dbd70054aa62bfafc6c4b3c3c263c3d546
/*
* Copyright (c) 1997-2003 by The XFree86 Project, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of the copyright holder(s)
* and author(s) shall not be used in advertising or otherwise to promote
* the sale, use or other dealings in this Software without prior written
* authorization from the copyright holder(s) and author(s).
*/
/*
* This file is an attempt to make developing code for the new loadable module
* architecure simpler. It tries to use macros to hide all libc wrappers so
* that all that is needed to "port" a module to this architecture is to
* include this one header file
*
* Revision history:
*
*
* 0.4 Apr 12 1997 add the ANSI defines
* 0.3 Feb 24 1997 handle getenv
* 0.2 Feb 24 1997 hide few FILE functions
* 0.1 Feb 24 1997 hide the trivial functions mem* str*
*/
#ifndef XF86_LIBC_H
#define XF86_LIBC_H 1
#include <stddef.h>
/*
* The first set of definitions are required both for modules and
*/
/*
* First, the new data types
*
* note: if some pointer is declared "opaque" here, pass it between
* xf86* functions only, and don't rely on it having a whatever internal
* structure, even if some source file might reveal the existence of
* such a structure.
*/
typedef void XF86FILE; /* opaque FILE replacement */
extern XF86FILE* xf86stdout;
extern XF86FILE* xf86stderr;
typedef void XF86fpos_t; /* opaque fpos_t replacement */
/* (divisble by 8) */
typedef void XF86DIR; /* opaque DIR replacement */
/* Note: the following is POSIX! POSIX only requires the d_name member.
* Normal Unix has often a number of other members, but don't rely on that
*/
struct _xf86dirent { /* types in struct dirent/direct: */
};
typedef struct _xf86dirent XF86DIRENT;
typedef unsigned long xf86size_t;
typedef signed long xf86ssize_t;
typedef unsigned long xf86dev_t;
typedef unsigned int xf86mode_t;
typedef unsigned int xf86uid_t;
typedef unsigned int xf86gid_t;
struct xf86stat_s {
};
/* sysv IPC */
typedef int xf86key_t;
#if defined(__ia64__)
#else
typedef int xf86jmp_buf[1024];
#endif
/* for setvbuf */
#define XF86_IONBF 1
#define XF86_IOFBF 2
#define XF86_IOLBF 3
/* for open (XXX not complete) */
#define XF86_O_RDONLY 0x0000
#define XF86_O_WRONLY 0x0001
#define XF86_O_RDWR 0x0002
#define XF86_O_CREAT 0x0200
/* for mmap */
#define XF86_PROT_EXEC 0x0001
#define XF86_PROT_READ 0x0002
#define XF86_PROT_WRITE 0x0004
#define XF86_PROT_NONE 0x0008
#define XF86_MAP_FIXED 0x0001
#define XF86_MAP_SHARED 0x0002
#define XF86_MAP_PRIVATE 0x0004
#define XF86_MAP_32BIT 0x0040
#define XF86_MAP_FAILED ((void *)-1)
/* for fseek */
#define XF86_SEEK_SET 0
#define XF86_SEEK_CUR 1
#define XF86_SEEK_END 2
/* for access */
#define XF86_R_OK 0
#define XF86_W_OK 1
#define XF86_X_OK 2
#define XF86_F_OK 3
/* for chmod */
/* for mknod */
#define XF86_S_IFREG 0010000
#define XF86_S_IFCHR 0020000
#define XF86_S_IFBLK 0040000
#define XF86_S_IFIFO 0100000
/*
* errno values
* They start at 1000 just so they don't match real errnos at all
*/
#define xf86_UNKNOWN 1000
#define xf86_EACCES 1001
#define xf86_EAGAIN 1002
#define xf86_EBADF 1003
#define xf86_EEXIST 1004
#define xf86_EFAULT 1005
#define xf86_EINTR 1006
#define xf86_EINVAL 1007
#define xf86_EISDIR 1008
#define xf86_ELOOP 1009
#define xf86_EMFILE 1010
#define xf86_ENAMETOOLONG 1011
#define xf86_ENFILE 1012
#define xf86_ENOENT 1013
#define xf86_ENOMEM 1014
#define xf86_ENOSPC 1015
#define xf86_ENOTDIR 1016
#define xf86_EPIPE 1017
#define xf86_EROFS 1018
#define xf86_ETXTBSY 1019
#define xf86_ENOTTY 1020
#define xf86_ENOSYS 1021
#define xf86_EBUSY 1022
#define xf86_ENODEV 1023
#define xf86_EIO 1024
#define xf86_ESRCH 1025
#define xf86_ENXIO 1026
#define xf86_E2BIG 1027
#define xf86_ENOEXEC 1028
#define xf86_ECHILD 1029
#define xf86_ENOTBLK 1030
#define xf86_EXDEV 1031
#define xf86_EFBIG 1032
#define xf86_ESPIPE 1033
#define xf86_EMLINK 1034
#define xf86_EDOM 1035
#define xf86_ERANGE 1036
/* sysv IPV */
/* xf86shmget() */
#define XF86IPC_CREAT 01000
#define XF86IPC_EXCL 02000
#define XF86IPC_NOWAIT 04000
#define XF86SHM_R 0400
#define XF86SHM_W 0200
#define XF86IPC_PRIVATE ((xf86key_t)0)
/* xf86shmat() */
/* xf86shmclt() */
#define XF86IPC_RMID 0
/*
* the rest of this file should only be included for code that is supposed
* to go into modules
*/
#if !defined(DONT_DEFINE_WRAPPERS)
#define bsearch(a,b,c,d,e) xf86bsearch(a,b,c,d,e)
#define finite(d) xf86finite(d)
#define printf xf86printf
#define fprintf xf86fprintf
#define fscanf xf86fscanf
#define isalnum(i) xf86isalnum(i)
#define isalpha(i) xf86isalpha(i)
#define iscntrl(i) xf86iscntrl(i)
#define isdigit(i) xf86isdigit(i)
#define isgraph(i) xf86isgraph(i)
#define islower(i) xf86islower(i)
#define isprint(i) xf86isprint(i)
#define ispunct(i) xf86ispunct(i)
#define isspace(i) xf86isspace(i)
#define isupper(i) xf86isupper(i)
#define isxdigit(i) xf86isxdigit(i)
#define malloc(I) xf86malloc(I)
#define random() xf86random()
#define snprintf xf86snprintf
#define sprintf xf86sprintf
#define sscanf xf86sscanf
#define strerror(i) xf86strerror(i)
#define tmpfile() xf86tmpfile()
#define tolower(i) xf86tolower(i)
#define toupper(i) xf86toupper(i)
#define vfprintf(p,f,a) xf86vfprintf(p,f,a)
#define vsnprintf(s,n,f,a) xf86vsnprintf(s,n,f,a)
#define vsprintf(s,f,a) xf86vsprintf(s,f,a)
/* XXX Disable assert as if NDEBUG was defined */
/* Some X headers defined this away too */
#define assert(a) ((void)0)
#define HUGE_VAL xf86HUGE_VAL
/* non-ANSI C functions */
#define geteuid xf86geteuid
#define getegid xf86getegid
#define getpid xf86getpid
#define getpagesize xf86getpagesize
#define shmget(a,b,c) xf86shmget(a,b,c)
#define shmctl(a,b,c) xf86shmctl(a,b,c)
#define S_ISUID XF86_S_ISUID
#define S_ISGID XF86_S_ISGID
#define S_ISVTX XF86_S_ISVTX
#define S_IRUSR XF86_S_IRUSR
#define S_IWUSR XF86_S_IWUSR
#define S_IXUSR XF86_S_IXUSR
#define S_IRGRP XF86_S_IRGRP
#define S_IWGRP XF86_S_IWGRP
#define S_IXGRP XF86_S_IXGRP
#define S_IROTH XF86_S_IROTH
#define S_IWOTH XF86_S_IWOTH
#define S_IXOTH XF86_S_IXOTH
#define S_IFREG XF86_S_IFREG
#define S_IFCHR XF86_S_IFCHR
#define S_IFBLK XF86_S_IFBLK
#define S_IFIFO XF86_S_IFIFO
/* some types */
#define fpos_t XF86fpos_t
#define DIRENT XF86DIRENT
#define size_t xf86size_t
#define ssize_t xf86ssize_t
#define mode_t xf86mode_t
#define stat_t struct xf86stat_s
#define ulong unsigned long
/*
* There should be no need to #undef any of these. If they are already
* defined it is because some illegal header has been included.
*/
/* some vars */
#define stdout xf86stdout
#define stderr xf86stderr
#define SEEK_SET XF86_SEEK_SET
#define SEEK_CUR XF86_SEEK_CUR
#define SEEK_END XF86_SEEK_END
/*
* XXX Basic I/O functions BAD,BAD,BAD!
*/
#if !defined(__DragonFly__)
#endif
#define munmap(a,b) xf86munmap(a,b)
#define access(a,b) xf86access(a,b)
#define O_RDONLY XF86_O_RDONLY
#define O_WRONLY XF86_O_WRONLY
#define O_RDWR XF86_O_RDWR
#define O_CREAT XF86_O_CREAT
#define PROT_EXEC XF86_PROT_EXEC
#define PROT_READ XF86_PROT_READ
#define PROT_WRITE XF86_PROT_WRITE
#define PROT_NONE XF86_PROT_NONE
#define MAP_FIXED XF86_MAP_FIXED
#define MAP_SHARED XF86_MAP_SHARED
#define MAP_PRIVATE XF86_MAP_PRIVATE
#define MAP_FAILED XF86_MAP_FAILED
#define EACCES xf86_EACCES
#define EAGAIN xf86_EAGAIN
#define EBADF xf86_EBADF
#define EEXIST xf86_EEXIST
#define EFAULT xf86_EFAULT
#define EINTR xf86_EINTR
#define EINVAL xf86_EINVAL
#define EISDIR xf86_EISDIR
#define ELOOP xf86_ELOOP
#define EMFILE xf86_EMFILE
#define ENAMETOOLONG xf86_ENAMETOOLONG
#define ENFILE xf86_ENFILE
#define ENOENT xf86_ENOENT
#define ENOMEM xf86_ENOMEM
#define ENOSPC xf86_ENOSPC
#define ENOTDIR xf86_ENOTDIR
#define EPIPE xf86_EPIPE
#define EROFS xf86_EROFS
#define ETXTBSY xf86_ETXTBSY
#define ENOTTY xf86_ENOTTY
#define ENOSYS xf86_ENOSYS
#define EBUSY xf86_EBUSY
#define ENODEV xf86_ENODEV
/* IPC stuff */
#define SHM_RDONLY XF86SHM_RDONLY
#define SHM_RND XF86SHM_RND
#define SHM_REMAP XF86SHM_REMAP
#define IPC_RMID XF86IPC_RMID
#define IPC_CREAT XF86IPC_CREAT
#define IPC_EXCL XF86IPC_EXCL
#define IPC_NOWAIT XF86IPC_NOWAIT
#define IPC_PRIVATE XF86IPC_PRIVATE
/* Some ANSI macros */
#define FILENAME_MAX 1024
# define _FILEDEFED /* Already have FILE defined, don't redefine it */
#endif
#endif /* !DONT_DEFINE_WRAPPERS */
#if (!defined(DONT_DEFINE_WRAPPERS) || defined(DEFINE_SETJMP_WRAPPERS))
#define setjmp(a) xf86setjmp_macro(a)
#define longjmp(a,b) xf86longjmp(a,b)
#define jmp_buf xf86jmp_buf
#endif
#endif /* XF86_LIBC_H */