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

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

Large source code cleanup, getting rid of spaces, tabs, and svn keywords.

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