Updated libc

This commit is contained in:
Alex
2022-12-12 00:44:43 +02:00
parent 9ff9b3a319
commit 123ae92e47
17 changed files with 3026 additions and 25 deletions

70
libc/src/std/io.c Normal file
View File

@@ -0,0 +1,70 @@
#include <stdio.h>
#include <stdarg.h>
FILE *stdin;
FILE *stdout;
FILE *stderr;
int fclose(FILE *stream)
{
return 0;
}
int fflush(FILE *stream)
{
return 0;
}
FILE *fopen(const char *filename, const char *mode)
{
return 0;
}
int fprintf(FILE *stream, const char *format, ...)
{
return 0; // sprintf(char *s, const char *format, ...)
}
// int printf(const char *format, ...)
// {
// return 0;
// }
size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
{
return 0;
}
int fseek(FILE *stream, long offset, int whence)
{
return 0;
}
long ftell(FILE *stream)
{
return 0;
}
size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
{
return 0;
}
void setbuf(FILE *stream, char *buf)
{
}
// int vfprintf(FILE *stream, const char *format, va_list arg)
// {
// return 0;
// }
int puts(const char *s)
{
return 0;
}
int putchar(int c)
{
return 0;
}

53
libc/src/std/lib.c Normal file
View File

@@ -0,0 +1,53 @@
#include <stdlib.h>
#include <stddef.h>
#include "../mem/liballoc_1_1.h"
void abort(void)
{
while (1)
;
}
int atexit(void (*function)(void))
{
return 0;
}
void exit(int status)
{
while (1)
;
}
int atoi(const char *nptr)
{
// uint64_t Length = strlen((char *)nptr);
uint64_t Length = 0;
if (nptr)
while (nptr[Length] != '\0')
++Length;
uint64_t OutBuffer = 0;
uint64_t Power = 1;
for (uint64_t i = Length; i > 0; --i)
{
OutBuffer += (nptr[i - 1] - 48) * Power;
Power *= 10;
}
return OutBuffer;
}
char *getenv(const char *name)
{
static char *env = "PATH=/bin";
return env;
}
void *malloc(size_t Size) { return PREFIX(malloc)(Size); }
void *realloc(void *Address, size_t Size) { return PREFIX(realloc)(Address, Size); }
void *calloc(size_t Count, size_t Size) { return PREFIX(calloc)(Count, Size); }
void free(void *Address)
{
PREFIX(free)
(Address);
}