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

Last change on this file since 4317 was 4317, checked in by Sam Hocevar, 10 years ago

Move some configuration stuff from build-kernel into configure.ac.

File size: 4.3 KB
Line 
1/*
2 *  libcaca       Colour ASCII-Art library
3 *  Copyright (c) 2006 Sam Hocevar <sam@hocevar.net>
4 *                2009 Jean-Yves Lamoureux <jylam@lnxscene.org>
5 *                All Rights Reserved
6 *
7 *  $Id: kernel.h 4154 2009-12-20 13:33:11Z jylam $
8 *
9 *  This library is free software. It comes without any warranty, to
10 *  the extent permitted by applicable law. You can redistribute it
11 *  and/or modify it under the terms of the Do What The Fuck You Want
12 *  To Public License, Version 2, as published by Sam Hocevar. See
13 *  http://sam.zoy.org/wtfpl/COPYING for more details.
14 */
15
16/*
17 *  This file contains replacement functions for the standard C library
18 *  that must be used when building libcaca and libcaca into a kernel.
19 */
20
21#if !defined HAVE_KLIBC_H
22#define HAVE_KLIBC_H
23
24/* Various typedefs -- some are x86-specific */
25#define CUSTOM_INTTYPES
26
27#define outb(port,value) __asm__ __volatile__ ("outb %%al,%%dx"::"d" (port), "a" (value));
28#define outbp(port,value) __asm __volatile__ ("outb %%al,%%dx; jmp 1f; 1:"::"d" (port), "a" (value));
29#define inb(port) ({unsigned char _v; __asm__ __volatile__ ("inb %%dx,%%al" : "=a" (_v) : "d" (port)); _v;      })
30
31
32/* Various defines */
33#define NULL ((void *)0)
34#define EOF (-1)
35#define BUFSIZ 4096
36#define RAND_MAX ((unsigned int)0x8000000)
37#define INT_MAX ((int)0x7fffffff)
38#define M_PI 3.14159265358979323846
39#define __BYTE_ORDER 1
40#define __BIG_ENDIAN 2
41
42typedef unsigned char u8;
43typedef unsigned short u16;
44typedef unsigned int u32;
45typedef unsigned long long u64;
46
47#ifndef size_t
48typedef unsigned int size_t;
49#endif
50typedef struct file
51{
52    void *mem;
53} FILE;
54
55struct timeval
56{
57    int tv_sec;
58    int tv_usec;
59};
60
61struct timezone
62{
63    int tz_minuteswest;
64    int tz_dsttime;
65};
66
67/* stdlib.h functions */
68void *malloc(size_t size);
69void free(void *ptr);
70void *realloc(void *ptr, size_t size);
71char *getenv(const char *name);
72int rand(void);
73int abs(int j);
74void exit(int status);
75void srand(unsigned int s);
76int atexit(void (*function) (void));
77FILE *stdin, *stdout, *stderr;
78
79/* string.h functions */
80void *memset(void *s, int c, size_t n);
81void *memcpy(void *dest, const void *src, size_t n);
82void *memmove(void *dest, const void *src, size_t n);
83size_t strlen(const char *s);
84int strcmp(const char *s1, const char *s2);
85int strcasecmp(const char *s1, const char *s2);
86int memcmp(const void *s1, const void *s2, size_t n);
87char *strdup(const char *s);
88char *strchr(const char *s, int c);
89
90/* stdarg.h functions */
91typedef void *va_list;
92#define va_start(v,a) v = (void *)((uintptr_t)(&a) + sizeof(a))
93#define va_end(v)
94int vsnprintf(char *str, size_t size, const char *format, va_list ap);
95/* va_arg */
96#define args_list char *
97#define _arg_stack_size(type)    (((sizeof(type)-1)/sizeof(int)+1)*sizeof(int))
98#define args_start(ap, fmt) do {    \
99ap = (char *)((unsigned int)&fmt + _arg_stack_size(&fmt));   \
100} while (0)
101#define args_end(ap)
102#define args_next(ap, type) (((type *)(ap+=_arg_stack_size(type)))[-1])
103
104/* stdio.h functions */
105FILE *fopen(const char *path, const char *mode);
106int feof(FILE * stream);
107char *fgets(char *s, int size, FILE * stream);
108size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE * stream);
109int fclose(FILE * fp);
110
111int printf(const char *format, ...);
112
113int fprintf(FILE * stream, const char *format, ...);
114int fflush(FILE * stream);
115int sprintf(char *str, const char *format, ...);
116int sscanf(const char *str, const char *format, ...);
117void itoa(int n, char s[]);
118
119void clearscreen(void);
120
121/* unistd.h functions */
122void usleep(unsigned long usec);
123void sleep(unsigned long sec);
124int getpid(void);
125
126/* time.h functions */
127int gettimeofday(struct timeval *tv, struct timezone *tz);
128int time(void *);
129
130/* math.h functions */
131double cos(double x);
132double sin(double x);
133double sqrt(double x);
134
135/* errno.h functions */
136#define ENOENT   2              /* No such file or directory */
137#define ENOMEM  12              /* Out of memory */
138#define EBUSY   16              /* Device or resource busy */
139#define ENODEV  19              /* No such device */
140#define EINVAL  22              /* Invalid argument */
141#define ENOTTY  25              /* Not a typewriter */
142#define ENOSYS  38              /* Function not implemented */
143extern int errno;
144
145/* arpa/inet.h functions */
146unsigned int htonl(unsigned int hostlong);
147unsigned short htons(unsigned short hostlong);
148
149void print(char *str);
150
151#endif /* HAVE_KLIBC_H */
152
Note: See TracBrowser for help on using the repository browser.