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

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

Fix the source code to reduce testsuite errors.

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