From cceaf069c7d203d63de6e8ca95e1d93ec32e7e0e Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Fri, 29 Jul 2016 16:31:52 -0700 Subject: More stdio cleanup. Time to get back to cleaning up stdio, so start with a bunch of easy one-liners... Change-Id: I8df5fdc72500a89b977bfaa6c64c3639198d4e3e --- libc/stdio/stdio.cpp | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) (limited to 'libc/stdio/stdio.cpp') diff --git a/libc/stdio/stdio.cpp b/libc/stdio/stdio.cpp index 3aabbe23c..d218ee6d7 100644 --- a/libc/stdio/stdio.cpp +++ b/libc/stdio/stdio.cpp @@ -388,11 +388,47 @@ int fclose(FILE* fp) { return r; } +int fileno_unlocked(FILE* fp) { + int fd = fp->_file; + if (fd == -1) { + errno = EBADF; + return -1; + } + return fd; +} + int fileno(FILE* fp) { ScopedFileLock sfl(fp); return fileno_unlocked(fp); } +void clearerr_unlocked(FILE* fp) { + return __sclearerr(fp); +} + +void clearerr(FILE* fp) { + ScopedFileLock sfl(fp); + clearerr_unlocked(fp); +} + +int feof_unlocked(FILE* fp) { + return __sfeof(fp); +} + +int feof(FILE* fp) { + ScopedFileLock sfl(fp); + return feof_unlocked(fp); +} + +int ferror_unlocked(FILE* fp) { + return __sferror(fp); +} + +int ferror(FILE* fp) { + ScopedFileLock sfl(fp); + return ferror_unlocked(fp); +} + int __sread(void* cookie, char* buf, int n) { FILE* fp = reinterpret_cast(cookie); return TEMP_FAILURE_RETRY(read(fp->_file, buf, n)); @@ -603,3 +639,65 @@ FILE* funopen64(const void* cookie, char* ctermid(char* s) { return s ? strcpy(s, _PATH_TTY) : const_cast(_PATH_TTY); } + +int fgetc(FILE* fp) { + return getc(fp); +} + +int fputc(int c, FILE* fp) { + return putc(c, fp); +} + +ssize_t getline(char** buf, size_t* len, FILE* fp) { + return getdelim(buf, len, '\n', fp); +} + +wint_t getwc(FILE* fp) { + return fgetwc(fp); +} + +wint_t getwchar() { + return fgetwc(stdin); +} + +wint_t putwc(wchar_t wc, FILE* fp) { + return fputwc(wc, fp); +} + +wint_t putwchar(wchar_t wc) { + return fputwc(wc, stdout); +} + +void rewind(FILE* fp) { + ScopedFileLock sfl(fp); + fseek(fp, 0, SEEK_SET); + clearerr_unlocked(fp); +} + +void setbuf(FILE* fp, char* buf) { + setbuffer(fp, buf, BUFSIZ); +} + +void setbuffer(FILE* fp, char* buf, int size) { + setvbuf(fp, buf, buf ? _IOFBF : _IONBF, size); +} + +int setlinebuf(FILE* fp) { + return setvbuf(fp, nullptr, _IOLBF, 0); +} + +int vprintf(const char* fmt, va_list ap) { + return vfprintf(stdout, fmt, ap); +} + +int vscanf(const char* fmt, va_list ap) { + return vfscanf(stdin, fmt, ap); +} + +int vwprintf(const wchar_t* fmt, va_list ap) { + return vfwprintf(stdout, fmt, ap); +} + +int vwscanf(const wchar_t* fmt, va_list ap) { + return vfwscanf(stdin, fmt, ap); +} -- cgit v1.2.3