source: libcaca/trunk/kernel/klibc.h @ 4154

Last change on this file since 4154 was 4154, checked in by Jean-Yves Lamoureux, 10 years ago
  • Total kernel rewrite
  • Property svn:executable set to *
File size: 3.4 KB
Line 
1/* Various typedefs -- some are x86-specific */
2#define CUSTOM_INTTYPES
3
4#define outb(port,value) __asm__ __volatile__ ("outb %%al,%%dx"::"d" (port), "a" (value));
5#define outbp(port,value) __asm __volatile__ ("outb %%al,%%dx; jmp 1f; 1:"::"d" (port), "a" (value));
6#define inb(port) ({unsigned char _v; __asm__ __volatile__ ("inb %%dx,%%al" : "=a" (_v) : "d" (port)); _v;      })
7
8
9/* Various defines */
10#define NULL ((void *)0)
11#define EOF (-1)
12#define BUFSIZ 4096
13#define RAND_MAX ((unsigned int)0x8000000)
14#define INT_MAX ((int)0x7fffffff)
15#define M_PI 3.14159265358979323846
16#define __BYTE_ORDER 1
17#define __BIG_ENDIAN 2
18
19typedef unsigned char       u8;
20typedef unsigned short      u16;
21typedef unsigned int        u32;
22typedef unsigned long int       u64;
23
24#ifndef size_t
25typedef unsigned int size_t;
26#endif
27typedef struct file
28{
29    void *mem;
30} FILE;
31
32struct timeval {
33    int tv_sec;
34    int tv_usec;
35};
36
37struct timezone {
38    int tz_minuteswest;
39    int tz_dsttime;
40};
41
42/* stdlib.h functions */
43void *malloc(size_t size);
44void free(void *ptr);
45void *realloc(void *ptr, size_t size);
46char *getenv(const char *name);
47int rand(void);
48int abs(int j);
49void exit(int status);
50void srand(unsigned int s);
51int atexit(void (*function)(void));
52FILE *stdin, *stdout, *stderr;
53
54/* string.h functions */
55void *memset(void *s, int c, size_t n);
56void *memcpy(void *dest, const void *src, size_t n);
57void *memmove(void *dest, const void *src, size_t n);
58size_t strlen(const char *s);
59int strcmp(const char *s1, const char *s2);
60int strcasecmp(const char *s1, const char *s2);
61int memcmp(const void *s1, const void *s2, size_t n);
62char *strdup(const char *s);
63char *strchr(const char *s, int c);
64
65/* stdarg.h functions */
66typedef void * va_list;
67#define va_start(v,a) v = (void *)((uintptr_t)(&a) + sizeof(a))
68#define va_end(v)
69int vsnprintf(char *str, size_t size, const char *format, va_list ap);
70/* va_arg*/
71#define args_list char *
72#define _arg_stack_size(type)    (((sizeof(type)-1)/sizeof(int)+1)*sizeof(int))
73#define args_start(ap, fmt) do {    \
74ap = (char *)((unsigned int)&fmt + _arg_stack_size(&fmt));   \
75} while (0)
76#define args_end(ap)
77#define args_next(ap, type) (((type *)(ap+=_arg_stack_size(type)))[-1])
78
79/* stdio.h functions */
80FILE *fopen(const char *path, const char *mode);
81int feof(FILE *stream);
82char *fgets(char *s, int size, FILE *stream);
83size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
84int fclose(FILE *fp);
85
86int printf(const char *format, ...);
87
88int fprintf(FILE *stream, const char *format, ...);
89int fflush(FILE *stream);
90int sprintf(char *str, const char *format, ...);
91int sscanf(const char *str, const char *format, ...);
92void itoa(int n, char s[]);
93
94void clearscreen(void);
95
96/* unistd.h functions */
97void usleep(unsigned long usec);
98void sleep(unsigned long sec);
99int getpid(void);
100
101/* time.h functions */
102u64 rdtsc(void);
103int gettimeofday(struct timeval *tv, struct timezone *tz);
104int time(void *);
105
106/* math.h functions */
107double cos(double x);
108double sin(double x);
109double sqrt(double x);
110
111/* errno.h functions */
112#define ENOENT   2 /* No such file or directory */
113#define ENOMEM  12 /* Out of memory */
114#define EBUSY   16 /* Device or resource busy */
115#define ENODEV  19 /* No such device */
116#define EINVAL  22 /* Invalid argument */
117#define ENOTTY  25 /* Not a typewriter */
118#define ENOSYS  38 /* Function not implemented */
119extern int errno;
120
121/* arpa/inet.h functions */
122unsigned int htonl(unsigned int hostlong);
123unsigned short htons(unsigned short hostlong);
124
125void print(char *str);
Note: See TracBrowser for help on using the repository browser.