diff options
| author | Xavier Del Campo Romero <xavi92@disroot.org> | 2025-11-12 00:37:26 +0100 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi92@disroot.org> | 2025-11-16 22:57:45 +0100 |
| commit | 2ce58c995946f85666e793c4f06efff683e76ae4 (patch) | |
| tree | fbf2658bb0b0f61dadcf4ca27f997eaded78aae5 /src/libc/include | |
| parent | 5ce25ae3b5d8666d373f7d7e336546ce8508c213 (diff) | |
fixesHEADhelloworldmaster
Diffstat (limited to 'src/libc/include')
| -rw-r--r-- | src/libc/include/fcntl.h | 13 | ||||
| -rw-r--r-- | src/libc/include/stdio.h | 17 | ||||
| -rw-r--r-- | src/libc/include/stdlib.h | 38 | ||||
| -rw-r--r-- | src/libc/include/sys/stat.h | 32 | ||||
| -rw-r--r-- | src/libc/include/sys/types.h | 1 | ||||
| -rw-r--r-- | src/libc/include/unistd.h | 14 |
6 files changed, 87 insertions, 28 deletions
diff --git a/src/libc/include/fcntl.h b/src/libc/include/fcntl.h index 282ced8..1edf2fc 100644 --- a/src/libc/include/fcntl.h +++ b/src/libc/include/fcntl.h @@ -19,11 +19,12 @@ #ifndef _FCNTL_H #define _FCNTL_H -enum -{ - O_RDONLY = 1, - O_WRONLY = 1 << 1, - O_RDWR = O_RDONLY | O_WRONLY -}; +#define O_RDONLY 1 +#define O_WRONLY (1 << 1) +#define O_CREAT (1 << 2) +#define O_APPEND (1 << 3) +#define O_RDWR (O_RDONLY | O_WRONLY) + +int open(const char *__path, int __flags, ...); #endif diff --git a/src/libc/include/stdio.h b/src/libc/include/stdio.h index b9c1a38..efa60dd 100644 --- a/src/libc/include/stdio.h +++ b/src/libc/include/stdio.h @@ -19,8 +19,23 @@ #ifndef _STDIO_H #define _STDIO_H -enum {EOF = -1}; +#include <stddef.h> +#define BUFSIZ 128 +#define FOPEN_MAX 8 +#define FILENAME_MAX 128 +#define EOF -1 +#define stdin __stdin +#define stdout __stdout +#define stderr __stderr + +typedef struct __file FILE; +extern FILE *__stdin, *__stdout, *__stderr; + +int fputc(int __c, FILE *__f); +FILE *fopen(const char *__path, const char *__mode); +size_t fwrite(const void *__p, size_t __sz, size_t __nmemb, FILE *__f); +int putc(int __c, FILE *__f); int puts(const char *__s); int putchar(int __c); diff --git a/src/libc/include/stdlib.h b/src/libc/include/stdlib.h index 2704fca..b6e092e 100644 --- a/src/libc/include/stdlib.h +++ b/src/libc/include/stdlib.h @@ -57,10 +57,10 @@ div_t div(int __numerator, int __denominator); #define RESET "\x1b[0m" #define malloc(__n) ({void *__p; \ + int Printf(const char *, ...); \ Printf(GREEN "-> %s:%d (%s)", __FILE__, __LINE__, __func__); \ __p = __malloc(__n); \ Printf(", p=%p" RESET "\n", __p); \ - int Printf(const char *, ...); \ size_t ta_num_free(); \ size_t ta_num_used(); \ size_t ta_num_fresh(); \ @@ -71,13 +71,13 @@ div_t div(int __numerator, int __denominator); __p;}) #define realloc(__p, __n) ({void *__np; \ + int Printf(const char *, ...); \ + size_t ta_num_free(); \ + size_t ta_num_used(); \ + size_t ta_num_fresh(); \ Printf(YELLOW "-> %s:%d (%s)", __FILE__, __LINE__, __func__); \ __np = __realloc(__p, __n); \ Printf(", np=%p" RESET "\n", __np); \ - int Printf(const char *, ...); \ - size_t ta_num_free(); \ -size_t ta_num_used(); \ -size_t ta_num_fresh(); \ Printf("%s: free=%lu, used=%lu, fresh=%lu\n", __func__, \ (unsigned long)ta_num_free(), \ (unsigned long)ta_num_used(), \ @@ -85,13 +85,13 @@ size_t ta_num_fresh(); \ __np;}) #define calloc(__n, __sz) ({void *__p; \ + int Printf(const char *, ...); \ + size_t ta_num_free(); \ + size_t ta_num_used(); \ + size_t ta_num_fresh(); \ Printf(YELLOW "-> %s:%d (%s)", __FILE__, __LINE__, __func__); \ __p = __calloc(__n, __sz); \ Printf(", p=%p" RESET "\n", __p); \ - int Printf(const char *, ...); \ - size_t ta_num_free(); \ -size_t ta_num_used(); \ -size_t ta_num_fresh(); \ Printf("%s: free=%lu, used=%lu, fresh=%lu\n", __func__, \ (unsigned long)ta_num_free(), \ (unsigned long)ta_num_used(), \ @@ -100,18 +100,18 @@ size_t ta_num_fresh(); \ #define free(__p) ({ \ int Printf(const char *, ...); \ + size_t ta_num_free(); \ + size_t ta_num_used(); \ + size_t ta_num_fresh(); \ Printf(RED "<- %s:%d (%s), p=%p" RESET "\n", \ __FILE__, __LINE__, __func__, __p); \ - size_t ta_num_free(); \ - size_t ta_num_used(); \ - size_t ta_num_fresh(); \ - __free(__p);\ - Printf("%s: free=%lu, used=%lu, fresh=%lu\n", \ - __func__, \ - (unsigned long)ta_num_free(), \ - (unsigned long)ta_num_used(), \ - (unsigned long)ta_num_fresh()); \ - }) + __free(__p);\ + Printf("%s: free=%lu, used=%lu, fresh=%lu\n", \ + __func__, \ + (unsigned long)ta_num_free(), \ + (unsigned long)ta_num_used(), \ + (unsigned long)ta_num_fresh()); \ + }) #endif #endif diff --git a/src/libc/include/sys/stat.h b/src/libc/include/sys/stat.h index 08fcf9a..b5ef13d 100644 --- a/src/libc/include/sys/stat.h +++ b/src/libc/include/sys/stat.h @@ -22,6 +22,35 @@ #include <sys/types.h> #include <time.h> +#define S_IRWXU 0700 +#define S_IRUSR 0400 +#define S_IWUSR 0200 +#define S_IXUSR 0100 +#define S_IRWXG 070 +#define S_IRGRP 040 +#define S_IWGRP 020 +#define S_IXGRP 010 +#define S_IRWXO 07 +#define S_IROTH 04 +#define S_IWOTH 02 +#define S_IXOTH 1 + +#define S_IFBLK ((mode_t)1) +#define S_IFCHR ((mode_t)(1 << 1)) +#define S_IFIFO ((mode_t)(1 << 2)) +#define S_IFREG ((mode_t)(1 << 3)) +#define S_IFDIR ((mode_t)(1 << 4)) +#define S_IFLNK ((mode_t)(1 << 5)) +#define S_IFSOCK ((mode_t)(1 << 6)) + +#define S_ISBLK(__m) ((__m) & S_IFBLK) +#define S_ISCHR(__m) ((__m) & S_IFCHR) +#define S_ISDIR(__m) ((__m) & S_IFDIR) +#define S_ISFIFO(__m) ((__m) & S_IFIFO) +#define S_ISREG(__m) ((__m) & S_IFREG) +#define S_ISLNK(__m) ((__m) & S_IFLNK) +#define S_ISSOCK(__m) ((__m) & S_IFSOCK) + struct stat { dev_t st_dev; @@ -37,6 +66,7 @@ struct stat blkcnt_t st_blocks; }; -int mkdir(const char *pathname, mode_t flags); +int mkdir(const char *__pathname, mode_t __flags); +mode_t umask(mode_t __mask); #endif diff --git a/src/libc/include/sys/types.h b/src/libc/include/sys/types.h index 86ca604..fc231f1 100644 --- a/src/libc/include/sys/types.h +++ b/src/libc/include/sys/types.h @@ -22,5 +22,6 @@ typedef unsigned dev_t, mode_t, nlink_t, uid_t, gid_t, blksize_t, blkcnt_t; typedef unsigned long ino_t, off_t; typedef int pid_t; +typedef long ssize_t; #endif diff --git a/src/libc/include/unistd.h b/src/libc/include/unistd.h index ec4fc13..dcf0336 100644 --- a/src/libc/include/unistd.h +++ b/src/libc/include/unistd.h @@ -19,8 +19,20 @@ #ifndef _UNISTD_H #define _UNISTD_H +#include <stddef.h> #include <stdint.h> +#include <sys/types.h> -void *sbrk(intptr_t increment); +enum +{ + STDIN_FILENO, + STDOUT_FILENO, + STDERR_FILENO +}; + +void *sbrk(intptr_t __increment); +ssize_t read(int __fd, void *__buf, size_t __n); +ssize_t write(int __fd, const void *__buf, size_t __n); +int close(int __fd); #endif |
