forked from PoliEcho-holding-org/kern
Made Open() syscall work (badly)
This commit is contained in:
+21
-15
@@ -7,36 +7,42 @@
|
||||
#include <stdint.h>
|
||||
|
||||
// Nobody should have to interface with the internals of this structure
|
||||
typedef struct _iobuf { // 16B
|
||||
char* _ptr; // Virtual address of file base
|
||||
int _offset; // Offset into file; Seek()
|
||||
int _file; // File descriptor
|
||||
int _oflag; // Flags used to open file
|
||||
typedef struct _iobuf { // 24B
|
||||
unsigned char* _ptr; // File buffer base
|
||||
unsigned int _size; // Size of buffer
|
||||
int _offset; // Offset into file
|
||||
unsigned short _flag; // Open flags
|
||||
int _file; // File descriptor
|
||||
|
||||
char __reserved[6];
|
||||
} FILE;
|
||||
|
||||
FILE* stdin;
|
||||
FILE* stdout;
|
||||
FILE* stderr;
|
||||
|
||||
/* Declarations */
|
||||
int printf(const char*, ...);
|
||||
|
||||
/* --- file I/O --- */
|
||||
FILE* fopen(const char* filename, const char* mode) {
|
||||
FILE* stream = malloc(sizeof(FILE));
|
||||
|
||||
int oflag = O_RDWR | O_CREAT | O_BIN; // TODO!
|
||||
|
||||
int fd = open(filename, oflag);
|
||||
if (fd < 0) {
|
||||
printf(""); // TODO: i'd prefer if i didn't need this
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// TODO: Somehow get the open file table
|
||||
FILE* fp = malloc(sizeof(FILE));
|
||||
fp->_file = fd;
|
||||
|
||||
stream->_ptr = NULL; // Idk
|
||||
stream->_file = fd;
|
||||
stream->_oflag = oflag;
|
||||
|
||||
return stream;
|
||||
return fp;
|
||||
}
|
||||
|
||||
int fclose(FILE* stream) {
|
||||
int res = close(stream->_file);
|
||||
free(stream);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -148,7 +154,7 @@ int printf(const char* fmt, ...) {
|
||||
case '%': // Just print '%'
|
||||
buffer[len++] = c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
state = 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user