From f7eeb033da7df55ded207f5cda0e6257b2ae0167 Mon Sep 17 00:00:00 2001 From: prnmxfqg4 Date: Mon, 4 Jul 2022 21:03:14 +0800 Subject: [PATCH] ADD file via upload --- mylib.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 mylib.c diff --git a/mylib.c b/mylib.c new file mode 100644 index 0000000..667fc31 --- /dev/null +++ b/mylib.c @@ -0,0 +1,65 @@ +#define __LIBRARY__ +#include +#include +#include +#include + +#define EINVAL 4 + +extern char ** environ; +#define __environ environ + +char * ___strtok; +volatile int errno; + +_syscall1(int,setup,void *,BIOS) + +volatile void exit(int exit_code) +{ + __asm__("int $0x80"::"a" (__NR_exit),"b" (exit_code)); + while(1); /* to avoid warning of compiler */ +} + +extern char _end; +void * ___brk_addr = &_end; + +int brk(void * end_data_segment) +{ + long __res; + __asm__ volatile ("int $0x80" + : "=a" (__res) + : "0" (__NR_brk),"b" ((long)(end_data_segment))); + if (__res >= 0) { + ___brk_addr = end_data_segment; + return (int) __res; + } + errno = -__res; + return -1; +} + +void * sbrk(ptrdiff_t increment) +{ + char *oldbrk; + + if (increment == 0) + return ___brk_addr; + + oldbrk = ___brk_addr; + if (brk(oldbrk + increment) < 0) + return (char *) -1; + + return oldbrk; +} + +/* Return the value of the environment variable NAME. */ +char * getenv(register const char *name) +{ + register const size_t len = strlen(name); + register char **ep; + + for (ep = __environ; *ep != NULL; ++ep) + if (!strncmp(*ep, name, len) && (*ep)[len] == '=') + return &(*ep)[len + 1]; + + return NULL; +}