libc: Implement freopen()
This commit is contained in:
parent
f3af3e252b
commit
aa90e4a8d9
@ -42,6 +42,9 @@ extern "C"
|
|||||||
/* Returns a new file associated with the file descriptor fd. */
|
/* Returns a new file associated with the file descriptor fd. */
|
||||||
FILE* fdopen(int fd, const char* mode);
|
FILE* fdopen(int fd, const char* mode);
|
||||||
|
|
||||||
|
/* Opens the file specified by pathname and points the file handle stream to it. */
|
||||||
|
FILE* freopen(const char* pathname, const char* mode, FILE* stream);
|
||||||
|
|
||||||
/* Returns the file descriptor associated with the file stream. */
|
/* Returns the file descriptor associated with the file stream. */
|
||||||
int fileno(FILE* stream);
|
int fileno(FILE* stream);
|
||||||
|
|
||||||
|
@ -51,6 +51,20 @@ extern "C"
|
|||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FILE* freopen(const char* pathname, const char* mode,
|
||||||
|
FILE* stream) // FIXME: If pathname is NULL, open the original file with the new mode.
|
||||||
|
{
|
||||||
|
int fd = open(pathname, O_RDWR); // FIXME: Use the mode string.
|
||||||
|
if (fd < 0) { return 0; }
|
||||||
|
|
||||||
|
fflush(stream); // To make it future-proof.
|
||||||
|
fclose(stream);
|
||||||
|
|
||||||
|
stream->f_fd = fd;
|
||||||
|
clearerr(stream);
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
|
||||||
int fileno(FILE* stream)
|
int fileno(FILE* stream)
|
||||||
{
|
{
|
||||||
return stream->f_fd;
|
return stream->f_fd;
|
||||||
|
Loading…
Reference in New Issue
Block a user