libc.h (3054B)
1 /* 2 * libc.h - core definitions and function prototypes 3 * Copyright (C) 2026. All rights reserved. 4 */ 5 6 #ifndef LIBC_H 7 #define LIBC_H 8 9 /* base types */ 10 typedef unsigned long size_t; 11 typedef unsigned long ulong_t; 12 typedef long ssize_t; 13 14 #ifndef NULL 15 #define NULL ((void*)0) 16 #endif 17 18 #define stdin 0 19 #define stdout 1 20 #define stderr 2 21 22 #define STDIN_FILENO 0 23 #define STDOUT_FILENO 1 24 #define STDERR_FILENO 2 25 26 struct linux_dirent64 { 27 unsigned long d_ino; 28 long d_off; 29 unsigned short d_reclen; 30 unsigned char d_type; 31 char d_name[]; 32 }; 33 34 #define SIGCHLD 17 35 36 /* open flags */ 37 #define O_RDONLY 00 38 #define O_WRONLY 01 39 #define O_RDWR 02 40 #define O_CREAT 0100 41 #define O_EXCL 0x80 42 #define O_DIRECTORY 0200000 43 44 /* syscall numbers */ 45 #define SYS_read 0 46 #define SYS_write 1 47 #define SYS_open 2 48 #define SYS_close 3 49 #define SYS_mmap 9 50 #define SYS_munmap 11 51 #define SYS_brk 12 52 #define SYS_clone 56 53 #define SYS_execve 59 54 #define SYS_exit 60 55 #define SYS_wait4 61 56 #define SYS_getcwd 79 57 #define SYS_chdir 80 58 #define SYS_mkdir 83 59 #define SYS_rmdir 84 60 #define SYS_unlink 87 61 #define SYS_utime 132 62 #define SYS_mount 165 63 #define SYS_getdents64 217 64 65 /* mmap flags */ 66 #define PROT_READ 0x1 67 #define PROT_WRITE 0x2 68 #define MAP_PRIVATE 0x02 69 #define MAP_ANONYMOUS 0x20 70 #define MAP_FAILED ((void*)-1) 71 72 /* variables */ 73 extern char **environ; 74 75 /* syscall function */ 76 long syscall(long num, ...); 77 78 /* io */ 79 ssize_t read(int fd, void *buf, size_t count); 80 ssize_t write(int fd, const void *buf, size_t count); 81 int open(const char *filename, int flags, int mode); 82 int close(int fd); 83 84 /* proc */ 85 void _exit(int status); 86 void exit(int status); 87 int execve(const char *path, char *const argv[], char *const envp[]); 88 int execvp(const char *file, char *const argv[]); 89 int fork(void); 90 int waitpid(int pid, int *status, int options); 91 92 /* fs */ 93 int mount(const char *src, const char *trg, const char *fstype, ulong_t flags, 94 const void *data); 95 int chdir(const char *path); 96 int mkdir(const char *path, unsigned int mode); 97 int rmdir(const char *path); 98 int unlink(const char *path); 99 char *getcwd(char *buf, size_t size); 100 int getdents64(int fd, struct linux_dirent64 *dirp, unsigned int count); 101 102 /* memory */ 103 void* mmap(void *addr, size_t length, int prot, int flags, int fd, long offset); 104 int munmap(void *addr, size_t length); 105 void* memset(void *s, int c, size_t n); 106 void* memcpy(void *dest, const void *src, size_t n); 107 108 /* alloc */ 109 void* malloc(size_t size); 110 void free(void *ptr); 111 void* calloc(size_t nmemb, size_t size); 112 void* realloc(void *ptr, size_t size); 113 114 /* utime */ 115 struct utimbuf { 116 long actime; 117 long modtime; 118 }; 119 120 int utime(const char *path, const struct utimbuf *times); 121 122 /* string functions */ 123 size_t strlen(const char *str); 124 char *strchr(const char *s, int c); 125 int strcmp(const char *s1, const char *s2); 126 char* strtok(char *str, const char *delim); 127 128 /* errno */ 129 extern int errno; 130 131 #endif /* LIBC_H */