Update libc

This commit is contained in:
Alex 2023-05-06 05:16:32 +03:00
parent cbbd3d0456
commit 78cfe17749
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD
7 changed files with 90 additions and 29 deletions

View File

@ -16,9 +16,31 @@
*/
#define EOF (-1)
struct _IO_marker
{
struct _IO_marker *_next;
struct _IO_FILE *_sbuf;
int _pos;
};
struct _IO_FILE
{
size_t offset;
int _flags;
char *_IO_read_ptr;
char *_IO_read_end;
char *_IO_read_base;
char *_IO_write_base;
char *_IO_write_ptr;
char *_IO_write_end;
char *_IO_buf_base;
char *_IO_buf_end;
__off_t _offset;
struct _IO_marker *_markers;
struct _IO_FILE *_chain;
int _fileno;
void *KernelPrivate;
};

View File

@ -1,15 +1,15 @@
#ifndef _SYS_STAT_H
#define _SYS_STAT_H
typedef unsigned int _dev_t;
typedef unsigned short _ino_t;
typedef unsigned short _mode_t;
typedef long _off_t;
typedef unsigned int __dev_t;
typedef unsigned short __ino_t;
typedef unsigned short __mode_t;
typedef long __off_t;
#define dev_t _dev_t
#define ino_t _ino_t
#define mode_t _mode_t
#define off_t _off_t
#define dev_t __dev_t
#define ino_t __ino_t
#define mode_t __mode_t
#define off_t __off_t
int mkdir(const char *path, mode_t mode);
int remove(const char *pathname);

View File

@ -2,13 +2,18 @@
extern void __libc_init_array(void);
extern void __libc_fini_array(void);
extern void __libc_init_std(void);
extern void __libc_fini_std(void);
void __libc_init(void)
{
__libc_init_array();
__libc_init_std();
}
void _exit(int Code)
{
__libc_fini_std();
__libc_fini_array();
__asm__ __volatile__("syscall"
:

View File

@ -27,7 +27,7 @@ size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
return 0;
}
return syscall4(_FileRead, (uint64_t)stream->KernelPrivate, stream->offset, (uint64_t)ptr, size * nmemb);
return syscall4(_FileRead, (uint64_t)stream->KernelPrivate, stream->_offset, (uint64_t)ptr, size * nmemb);
}
size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
@ -38,7 +38,7 @@ size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
return 0;
}
return syscall4(_FileWrite, (uint64_t)stream->KernelPrivate, stream->offset, (uint64_t)ptr, size * nmemb);
return syscall4(_FileWrite, (uint64_t)stream->KernelPrivate, stream->_offset, (uint64_t)ptr, size * nmemb);
}
int fclose(FILE *fp)
@ -56,7 +56,7 @@ int fclose(FILE *fp)
off_t fseek(FILE *stream, long offset, int whence)
{
if (stream == NULL)
if (stream == NULL || whence < 0 || whence > 2)
{
errno = EINVAL;
return -1;
@ -65,23 +65,40 @@ off_t fseek(FILE *stream, long offset, int whence)
off_t new_offset = syscall3(_FileSeek, stream->KernelPrivate, offset, whence);
if (IsSyscallError(new_offset))
return -1;
stream->offset = new_offset;
stream->_offset = new_offset;
return new_offset;
}
long ftell(FILE *stream)
{
return stream->offset;
return stream->_offset;
}
int fflush(FILE *stream)
{
return 0;
if (stream == NULL)
{
errno = EINVAL;
return EOF;
}
errno = ENOSYS;
return EOF;
}
int fprintf(FILE *stream, const char *format, ...)
{
return 0; // sprintf(char *s, const char *format, ...)
if (stream == NULL || format == NULL)
{
errno = EINVAL;
return -1;
}
va_list args;
va_start(args, format);
const int ret = vfprintf(stream, format, args);
va_end(args);
return ret;
}
void setbuf(FILE *stream, char *buf)

View File

@ -4,13 +4,17 @@
int fputc(int c, FILE *stream)
{
// FIXME
// if (stream == NULL)
// {
// errno = EBADF;
// return EOF;
// }
return syscall2(_Print, c, 0);
}
int putc(int c, FILE *stream)
{
return syscall2(_Print, c, 0);
}
int putc(int c, FILE *stream) { return fputc(c, stream); }
int fputs(const char *s, FILE *stream)
{
@ -24,12 +28,5 @@ int puts(const char *s)
fputc(s[i], stdout);
}
int putchar(int c)
{
return putc(c, stdout);
}
void perror(const char *s)
{
fputs(s, stderr);
}
int putchar(int c) { return fputc(c, stdout); }
void perror(const char *s) { fputs(s, stderr); }

13
libc/src/std/std_init.c Normal file
View File

@ -0,0 +1,13 @@
#include <stdio.h>
#include "../../../Kernel/syscalls.h"
void __libc_init_std(void)
{
/* FIXME: Temporal workaround */
// int IsCritical = syscall1(_KernelCTL, 6 /* KCTL_IS_CRITICAL */);
}
void __libc_fini_std(void)
{
}

View File

@ -5,36 +5,43 @@
int execl(const char *pathname, const char *arg, ...)
{
errno = ENOSYS;
return -1;
}
int execlp(const char *file, const char *arg, ...)
{
errno = ENOSYS;
return -1;
}
int execle(const char *pathname, const char *arg, ...)
{
errno = ENOSYS;
return -1;
}
int execv(const char *pathname, char *const argv[])
{
errno = ENOSYS;
return -1;
}
int execvp(const char *file, char *const argv[])
{
errno = ENOSYS;
return -1;
}
int execvpe(const char *file, char *const argv[], char *const envp[])
{
errno = ENOSYS;
return -1;
}
int execve(const char *pathname, char *const argv[], char *const envp[])
{
errno = ENOSYS;
return -1;
}