LibC: add fileno() and fdopen()

fdopen() doesn't currently care about mode and will have same mode
as the underlying file descriptor.
This commit is contained in:
Bananymous 2023-08-17 12:03:59 +03:00
parent 8e4216215e
commit dcd8374b89
1 changed files with 23 additions and 4 deletions

View File

@ -49,8 +49,23 @@ int fclose(FILE* file)
return 0; return 0;
} }
// TODO FILE* fdopen(int fd, const char* mode)
FILE* fdopen(int, const char*); {
// FIXME
(void)mode;
for (int i = 0; i < FOPEN_MAX; i++)
{
if (s_files[i].fd == -1)
{
s_files[i] = { .fd = fd };
return &s_files[i];
}
}
errno = EMFILE;
return nullptr;
}
int feof(FILE* file) int feof(FILE* file)
{ {
@ -144,8 +159,12 @@ char* fgets(char* str, int size, FILE* file)
return str; return str;
} }
// TODO int fileno(FILE* fp)
int fileno(FILE*); {
if (fp == nullptr)
return EBADF;
return fp->fd;
}
// TODO // TODO
void flockfile(FILE*); void flockfile(FILE*);