mirror of
https://github.com/Fennix-Project/Userspace.git
synced 2025-05-25 22:14:28 +00:00
Fix std file operations
This commit is contained in:
parent
f740c1e736
commit
1000a57531
@ -8,10 +8,14 @@
|
||||
#define SEEK_CUR 1
|
||||
#define SEEK_END 2
|
||||
|
||||
typedef struct
|
||||
struct _IO_FILE
|
||||
{
|
||||
int unused;
|
||||
} FILE;
|
||||
size_t offset;
|
||||
|
||||
void *KernelPrivate;
|
||||
};
|
||||
|
||||
typedef struct _IO_FILE FILE;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
@ -22,15 +26,15 @@ extern "C"
|
||||
extern FILE *stdout;
|
||||
extern FILE *stderr;
|
||||
|
||||
int fclose(FILE *stream);
|
||||
int fflush(FILE *stream);
|
||||
FILE *fopen(const char *filename, const char *mode);
|
||||
int fprintf(FILE *stream, const char *format, ...);
|
||||
int printf(const char *format, ...);
|
||||
size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
|
||||
size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
|
||||
int fseek(FILE *stream, long offset, int whence);
|
||||
long ftell(FILE *stream);
|
||||
size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
|
||||
int fclose(FILE *fp);
|
||||
int fflush(FILE *stream);
|
||||
int fprintf(FILE *stream, const char *format, ...);
|
||||
int printf(const char *format, ...);
|
||||
void setbuf(FILE *stream, char *buf);
|
||||
int vfprintf(FILE *stream, const char *format, va_list arg);
|
||||
int vsscanf(const char *s, const char *format, va_list arg);
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <sys/syscalls.h>
|
||||
|
||||
@ -6,9 +7,52 @@ FILE *stdin;
|
||||
FILE *stdout;
|
||||
FILE *stderr;
|
||||
|
||||
int fclose(FILE *stream)
|
||||
FILE *fopen(const char *filename, const char *mode)
|
||||
{
|
||||
return 0;
|
||||
FILE *FilePtr = malloc(sizeof(FILE));
|
||||
FilePtr->KernelPrivate = (void *)syscall2(_FileOpen, (uint64_t)filename, (uint64_t)mode);
|
||||
return FilePtr;
|
||||
}
|
||||
|
||||
size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
|
||||
{
|
||||
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)
|
||||
{
|
||||
return syscall4(_FileWrite, (uint64_t)stream->KernelPrivate, stream->offset, (uint64_t)ptr, size * nmemb);
|
||||
}
|
||||
|
||||
int fseek(FILE *stream, long offset, int whence)
|
||||
{
|
||||
switch (whence)
|
||||
{
|
||||
case SEEK_SET:
|
||||
stream->offset = offset;
|
||||
break;
|
||||
case SEEK_CUR:
|
||||
stream->offset += offset;
|
||||
break;
|
||||
case SEEK_END:
|
||||
// stream->offset = syscall1(_FileLength, (uint64_t)File->KernelPrivate) + offset;
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
return stream->offset;
|
||||
}
|
||||
|
||||
long ftell(FILE *stream)
|
||||
{
|
||||
return stream->offset;
|
||||
}
|
||||
|
||||
int fclose(FILE *fp)
|
||||
{
|
||||
void *KP = fp->KernelPrivate;
|
||||
free(fp);
|
||||
return syscall1(_FileClose, (uint64_t)KP);
|
||||
}
|
||||
|
||||
int fflush(FILE *stream)
|
||||
@ -16,11 +60,6 @@ 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, ...)
|
||||
@ -31,26 +70,6 @@ int fprintf(FILE *stream, 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)
|
||||
{
|
||||
}
|
||||
@ -72,30 +91,3 @@ int sscanf(const char *s, const char *format, ...)
|
||||
va_end(args);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int fputc(int c, FILE *stream)
|
||||
{
|
||||
syscall1(_Print, c);
|
||||
}
|
||||
|
||||
int putc(int c, FILE *stream)
|
||||
{
|
||||
syscall1(_Print, c);
|
||||
}
|
||||
|
||||
int fputs(const char *s, FILE *stream)
|
||||
{
|
||||
for (int i = 0; s[i] != '\0'; i++)
|
||||
fputc(s[i], stream);
|
||||
}
|
||||
|
||||
int putchar(int c)
|
||||
{
|
||||
syscall1(_Print, c);
|
||||
}
|
||||
|
||||
int puts(const char *s)
|
||||
{
|
||||
for (int i = 0; s[i] != '\0'; i++)
|
||||
fputc(s[i], stdout);
|
||||
}
|
30
libc/src/std/io/put.c
Normal file
30
libc/src/std/io/put.c
Normal file
@ -0,0 +1,30 @@
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <sys/syscalls.h>
|
||||
|
||||
int fputc(int c, FILE *stream)
|
||||
{
|
||||
syscall1(_Print, c);
|
||||
}
|
||||
|
||||
int putc(int c, FILE *stream)
|
||||
{
|
||||
syscall1(_Print, c);
|
||||
}
|
||||
|
||||
int fputs(const char *s, FILE *stream)
|
||||
{
|
||||
for (int i = 0; s[i] != '\0'; i++)
|
||||
fputc(s[i], stream);
|
||||
}
|
||||
|
||||
int putchar(int c)
|
||||
{
|
||||
syscall1(_Print, c);
|
||||
}
|
||||
|
||||
int puts(const char *s)
|
||||
{
|
||||
for (int i = 0; s[i] != '\0'; i++)
|
||||
fputc(s[i], stdout);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user