Compare commits
No commits in common. "be9026442e4bef148ba8894b9ab8ea4d6159dcf3" and "52944ba5d8890f7b812258bea975007ddbc2e87d" have entirely different histories.
be9026442e
...
52944ba5d8
@ -32,9 +32,6 @@ extern "C"
|
|||||||
/* Opens the file specified by pathname. Returns the file handle on success, or NULL on error. */
|
/* Opens the file specified by pathname. Returns the file handle on success, or NULL on error. */
|
||||||
FILE* fopen(const char* pathname, const char* mode);
|
FILE* fopen(const char* pathname, const char* mode);
|
||||||
|
|
||||||
/* Returns a new file associated with the file descriptor fd. */
|
|
||||||
FILE* fdopen(int fd, const char* mode);
|
|
||||||
|
|
||||||
/* Writes formatted output according to the string format to the file stream. */
|
/* Writes formatted output according to the string format to the file stream. */
|
||||||
int fprintf(FILE* stream, const char* format, ...);
|
int fprintf(FILE* stream, const char* format, ...);
|
||||||
|
|
||||||
|
@ -40,19 +40,6 @@ extern "C"
|
|||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE* fdopen(int fd, const char*)
|
|
||||||
{
|
|
||||||
if (fd < 0) // FIXME: Also check if the mode string is compatible with how fd was opened.
|
|
||||||
{
|
|
||||||
errno = EBADF;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
FILE* stream = (FILE*)malloc(sizeof(FILE));
|
|
||||||
stream->f_fd = fd;
|
|
||||||
clearerr(stream);
|
|
||||||
return stream;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t fread(void* buf, size_t size, size_t nmemb, FILE* stream)
|
size_t fread(void* buf, size_t size, size_t nmemb, FILE* stream)
|
||||||
{
|
{
|
||||||
ssize_t status = read(stream->f_fd, buf, size * nmemb);
|
ssize_t status = read(stream->f_fd, buf, size * nmemb);
|
||||||
|
@ -6,22 +6,13 @@
|
|||||||
|
|
||||||
extern "C" void initialize_libc()
|
extern "C" void initialize_libc()
|
||||||
{
|
{
|
||||||
if (lseek(0, 0, SEEK_CUR) < 0)
|
close(0); // If it was already open, close it
|
||||||
{
|
close(1); // If it was already open, close it
|
||||||
if (errno == EBADF) stdout = fopen("/dev/console", "rw");
|
errno = 0; // If it was not open. the kernel will throw us EBADF. Let's ignore that, since we don't care.
|
||||||
else
|
stderr = fopen("/dev/console", "rw");
|
||||||
exit(errno);
|
|
||||||
if (!stdout) exit(errno);
|
|
||||||
errno = 0;
|
|
||||||
}
|
|
||||||
else { stdout = fdopen(0, "rw"); }
|
|
||||||
if (lseek(1, 0, SEEK_CUR) < 0)
|
|
||||||
{
|
|
||||||
if (errno == EBADF) stderr = fopen("/dev/console", "rw");
|
|
||||||
else
|
|
||||||
exit(errno);
|
|
||||||
if (!stderr) exit(errno);
|
if (!stderr) exit(errno);
|
||||||
errno = 0;
|
stdout = fopen("/dev/console", "rw");
|
||||||
}
|
if (!stdout) exit(errno);
|
||||||
else { stderr = fdopen(1, "rw"); }
|
clearerr(stderr);
|
||||||
|
clearerr(stdout);
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user