libc.h

Commit: 347e967b Author: jokerz Raw Copy
1
/* libc.h - Minimal libc for Pactor64 userspace programs */
2
#ifndef _LIBC_H
3
#define _LIBC_H
4
5
/* Basic types for freestanding userspace */
6
typedef unsigned char       uint8_t;
7
typedef unsigned short      uint16_t;
8
typedef unsigned int        uint32_t;
9
typedef unsigned long       uint64_t;
10
typedef signed char         int8_t;
11
typedef signed short        int16_t;
12
typedef signed int          int32_t;
13
typedef signed long         int64_t;
14
typedef uint64_t size_t;
15
typedef int64_t  ssize_t;
16
17
#define NULL ((void *)0)
18
19
/* GCC built-in va_list for variadic functions */
20
typedef __builtin_va_list va_list;
21
#define va_start(v,l) __builtin_va_start(v,l)
22
#define va_end(v)     __builtin_va_end(v)
23
#define va_arg(v,t)   __builtin_va_arg(v,t)
24
25
/* === System call wrappers === */
26
27
/* write(fd, buf, count) */
28
long write(int fd, const void *buf, unsigned long count);
29
30
/* read(fd, buf, count) */
31
long read(int fd, void *buf, unsigned long count);
32
33
/* exit(status) - does not return */
34
void exit(int status) __attribute__((noreturn));
35
36
/* brk(addr) - set program break */
37
long brk(void *addr);
38
39
/* === String functions === */
40
41
unsigned long strlen(const char *s);
42
int strcmp(const char *s1, const char *s2);
43
int strncmp(const char *s1, const char *s2, unsigned long n);
44
char *strcpy(char *dst, const char *src);
45
char *strncpy(char *dst, const char *src, unsigned long n);
46
void *memset(void *s, int c, unsigned long n);
47
void *memcpy(void *dst, const void *src, unsigned long n);
48
void *memmove(void *dst, const void *src, unsigned long n);
49
50
/* === Memory allocation (bump allocator) === */
51
52
void *malloc(unsigned long size);
53
void free(void *ptr);
54
55
/* === I/O === */
56
57
int puts(const char *s);
58
int putchar(int c);
59
60
/* printf - simplified, supports %d, %s, %x, %c, %u, %% */
61
int printf(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
62
63
/* === Entry point === */
64
/* _start is defined in start.c and calls main() */
65
extern int main(int argc, char **argv);
66
67
#endif /* _LIBC_H */
68