mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 22:27:42 +00:00
LibC: A whole bunch of compat work towards porting Lynx.
This commit is contained in:
parent
48590a0e51
commit
2c3cf22bc9
10 changed files with 125 additions and 5 deletions
|
@ -351,8 +351,20 @@ void perror(const char* s)
|
|||
|
||||
FILE* fopen(const char* pathname, const char* mode)
|
||||
{
|
||||
assert(!strcmp(mode, "r") || !strcmp(mode, "rb"));
|
||||
int fd = open(pathname, O_RDONLY);
|
||||
int flags = 0;
|
||||
if (!strcmp(mode, "r") || !strcmp(mode, "rb"))
|
||||
flags = O_RDONLY;
|
||||
else if (!strcmp(mode, "r+") || !strcmp(mode, "rb+"))
|
||||
flags = O_RDWR;
|
||||
else if (!strcmp(mode, "w") || !strcmp(mode, "wb"))
|
||||
flags = O_WRONLY | O_CREAT | O_TRUNC;
|
||||
else if (!strcmp(mode, "w+") || !strcmp(mode, "wb+"))
|
||||
flags = O_RDWR | O_CREAT | O_TRUNC;
|
||||
else {
|
||||
fprintf(stderr, "FIXME(LibC): fopen('%s', '%s')\n", pathname, mode);
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
int fd = open(pathname, flags, 0666);
|
||||
if (fd < 0)
|
||||
return nullptr;
|
||||
return make_FILE(fd);
|
||||
|
@ -368,7 +380,7 @@ FILE* freopen(const char* pathname, const char* mode, FILE* stream)
|
|||
|
||||
FILE* fdopen(int fd, const char* mode)
|
||||
{
|
||||
assert(!strcmp(mode, "r") || !strcmp(mode, "rb"));
|
||||
// FIXME: Verify that the mode matches how fd is already open.
|
||||
if (fd < 0)
|
||||
return nullptr;
|
||||
return make_FILE(fd);
|
||||
|
@ -404,5 +416,13 @@ int pclose(FILE*)
|
|||
assert(false);
|
||||
}
|
||||
|
||||
int remove(const char* pathname)
|
||||
{
|
||||
int rc = unlink(pathname);
|
||||
if (rc < 0 && errno != EISDIR)
|
||||
return -1;
|
||||
return rmdir(pathname);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue