From: Tulio A M Mendes Date: Fri, 3 Apr 2026 19:53:14 +0000 (-0300) Subject: feat(ulibc): add missing fdopen() and fileno() to stdio X-Git-Url: https://projects.tadryanom.me/?a=commitdiff_plain;h=d434ac978ca3605e7cca310e555aef92e46e020c;p=AdrOS.git feat(ulibc): add missing fdopen() and fileno() to stdio Add POSIX fdopen() and fileno() implementations required by popen/pclose and other stdio operations: - fdopen(): wraps an existing file descriptor into a FILE* - fileno(): returns the file descriptor from a FILE* --- diff --git a/user/ulibc/src/stdio.c b/user/ulibc/src/stdio.c index 1a3e030b..257ed12a 100644 --- a/user/ulibc/src/stdio.c +++ b/user/ulibc/src/stdio.c @@ -518,6 +518,25 @@ ssize_t getline(char** lineptr, size_t* n, FILE* stream) { return getdelim(lineptr, n, '\n', stream); } +FILE* fdopen(int fd, const char* mode) { + if (fd < 0 || !mode) return (FILE*)0; + FILE* fp = (FILE*)malloc(sizeof(FILE)); + if (!fp) return (FILE*)0; + fp->fd = fd; + fp->flags = 0; + fp->buf_pos = 0; + fp->buf_len = 0; + if (mode[0] == 'r') fp->flags |= _STDIO_READ; + if (mode[0] == 'w' || mode[0] == 'a') fp->flags |= _STDIO_WRITE; + if (mode[1] == '+') fp->flags |= _STDIO_READ | _STDIO_WRITE; + return fp; +} + +int fileno(FILE* fp) { + if (!fp) return -1; + return fp->fd; +} + FILE* popen(const char* command, const char* type) { int fds[2]; extern int pipe(int[2]);