/bionic/tests/ |
D | stdio_ext_test.cpp | 37 FILE* fp = fopen("/proc/version", "r"); in TEST() local 40 ASSERT_EQ(0U, __fbufsize(fp)); in TEST() 44 fgets(buf, sizeof(buf), fp); in TEST() 45 ASSERT_EQ(1024U, __fbufsize(fp)); in TEST() 47 ASSERT_EQ(0, setvbuf(fp, buf, _IOFBF, 1)); in TEST() 48 ASSERT_EQ(1U, __fbufsize(fp)); in TEST() 50 ASSERT_EQ(0, setvbuf(fp, buf, _IOFBF, 8)); in TEST() 51 ASSERT_EQ(8U, __fbufsize(fp)); in TEST() 53 fclose(fp); in TEST() 57 FILE* fp = fopen("/proc/version", "r"); in TEST() local [all …]
|
D | stdio_test.cpp | 66 FILE* fp; in SetFileTo() local 67 ASSERT_NE(nullptr, fp = fopen(path, "w")); in SetFileTo() 68 ASSERT_NE(EOF, fputs(content, fp)); in SetFileTo() 69 ASSERT_EQ(0, fclose(fp)); in SetFileTo() 73 FILE* fp; in AssertFileIs() local 74 ASSERT_NE(nullptr, fp = fopen(path, "r")); in AssertFileIs() 77 ASSERT_NE(EOF, getline(&line, &length, fp)); in AssertFileIs() 78 ASSERT_EQ(0, fclose(fp)); in AssertFileIs() 83 static void AssertFileIs(FILE* fp, const char* expected, bool is_fmemopen = false) { in AssertFileIs() argument 84 rewind(fp); in AssertFileIs() [all …]
|
D | mntent_test.cpp | 23 FILE* fp = setmntent("/proc/mounts", "r"); in TEST() local 24 ASSERT_TRUE(fp != nullptr); in TEST() 29 while ((me = getmntent(fp)) != nullptr) { in TEST() 34 ASSERT_EQ(1, endmntent(fp)); in TEST() 37 fp = setmntent("/proc/mounts", "r"); in TEST() 38 ASSERT_TRUE(fp != nullptr); in TEST() 43 while (getmntent_r(fp, &entry, buf, sizeof(buf)) != nullptr) { in TEST() 49 ASSERT_EQ(1, endmntent(fp)); in TEST()
|
/bionic/libc/stdio/ |
D | stdio.cpp | 109 static uint64_t __get_file_tag(FILE* fp) { in __get_file_tag() argument 113 if (fp == stdin || fp == stderr || fp == stdout) { in __get_file_tag() 118 reinterpret_cast<uint64_t>(fp)); in __get_file_tag() 126 explicit ScopedFileLock(FILE* fp) : fp_(fp) { in ScopedFileLock() argument 156 static inline void free_fgetln_buffer(FILE* fp) { in free_fgetln_buffer() argument 157 if (__predict_false(fp->_lb._base != nullptr)) { in free_fgetln_buffer() 158 free(fp->_lb._base); in free_fgetln_buffer() 159 fp->_lb._base = nullptr; in free_fgetln_buffer() 167 FILE *fp; in __sfp() local 173 for (fp = g->iobs, n = g->niobs; --n >= 0; fp++) in __sfp() [all …]
|
D | refill.c | 40 lflush(FILE *fp) in lflush() argument 42 if ((fp->_flags & (__SLBF|__SWR)) == (__SLBF|__SWR)) in lflush() 43 return (__sflush_locked(fp)); /* ignored... */ in lflush() 52 __srefill(FILE *fp) in __srefill() argument 54 fp->_r = 0; /* largely a convenience for callers */ in __srefill() 58 if (fp->_flags & __SEOF) in __srefill() 63 if ((fp->_flags & __SRD) == 0) { in __srefill() 64 if ((fp->_flags & __SRW) == 0) { in __srefill() 66 fp->_flags |= __SERR; in __srefill() 70 if (fp->_flags & __SWR) { in __srefill() [all …]
|
D | stdio_ext.cpp | 38 size_t __fbufsize(FILE* fp) { in __fbufsize() argument 39 return fp->_bf._size; in __fbufsize() 42 int __freading(FILE* fp) { in __freading() argument 43 return (fp->_flags & __SRD) != 0; in __freading() 46 int __fwriting(FILE* fp) { in __fwriting() argument 47 return (fp->_flags & __SWR) != 0; in __fwriting() 50 int __freadable(FILE* fp) { in __freadable() argument 51 return (fp->_flags & (__SRD|__SRW)) != 0; in __freadable() 54 int __fwritable(FILE* fp) { in __fwritable() argument 55 return (fp->_flags & (__SWR|__SRW)) != 0; in __fwritable() [all …]
|
D | local.h | 170 #define _EXT(fp) __BIONIC_CAST(reinterpret_cast, struct __sfileext*, (fp)->_ext._base) argument 172 #define _UB(fp) _EXT(fp)->_ub argument 174 #define _FILEEXT_SETUP(fp, fext) \ argument 176 (fp)->_ext._base = __BIONIC_CAST(reinterpret_cast, unsigned char*, fext); \ 177 memset(_EXT(fp), 0, sizeof(struct __sfileext)); \ 178 _EXT(fp)->_caller_handles_locking = true; \ 218 #define cantwrite(fp) ((((fp)->_flags & __SWR) == 0 || (fp)->_bf._base == NULL) && __swsetup(fp)) argument 224 #define HASUB(fp) (_UB(fp)._base != NULL) argument 225 #define FREEUB(fp) \ argument 227 if (_UB(fp)._base != (fp)->_ubuf) free(_UB(fp)._base); \ [all …]
|
D | vfscanf.cpp | 41 int __svfscanf(FILE* fp, const char* fmt0, va_list ap) { in __svfscanf() argument 59 _SET_ORIENTATION(fp, ORIENT_BYTES); in __svfscanf() 67 while ((fp->_r > 0 || __srefill(fp) == 0) && isspace(*fp->_p)) nread++, fp->_r--, fp->_p++; in __svfscanf() 83 if (fp->_r <= 0 && __srefill(fp)) goto input_failure; in __svfscanf() 84 if (*fp->_p != c) goto match_failure; in __svfscanf() 85 fp->_r--, fp->_p++; in __svfscanf() 281 if (fp->_r <= 0 && __srefill(fp)) goto input_failure; in __svfscanf() 288 while (isspace(*fp->_p)) { in __svfscanf() 290 if (--fp->_r > 0) { in __svfscanf() 291 fp->_p++; in __svfscanf() [all …]
|
/bionic/libc/upstream-openbsd/lib/libc/stdio/ |
D | ungetc.c | 47 __submore(FILE *fp) in __submore() argument 52 if (_UB(fp)._base == fp->_ubuf) { in __submore() 58 _UB(fp)._base = p; in __submore() 59 _UB(fp)._size = BUFSIZ; in __submore() 60 p += BUFSIZ - sizeof(fp->_ubuf); in __submore() 61 for (i = sizeof(fp->_ubuf); --i >= 0;) in __submore() 62 p[i] = fp->_ubuf[i]; in __submore() 63 fp->_p = p; in __submore() 66 i = _UB(fp)._size; in __submore() 67 p = reallocarray(_UB(fp)._base, i, 2); in __submore() [all …]
|
D | fgetln.c | 43 __slbexpand(FILE *fp, size_t newsize) in __slbexpand() argument 47 if (fp->_lb._size >= newsize) in __slbexpand() 49 if ((p = recallocarray(fp->_lb._base, fp->_lb._size, newsize, 1)) == NULL) in __slbexpand() 51 fp->_lb._base = p; in __slbexpand() 52 fp->_lb._size = newsize; in __slbexpand() 64 fgetln(FILE *fp, size_t *lenp) in fgetln() argument 71 FLOCKFILE(fp); in fgetln() 72 _SET_ORIENTATION(fp, -1); in fgetln() 75 if (fp->_r <= 0 && __srefill(fp)) in fgetln() 79 if ((p = memchr(fp->_p, '\n', fp->_r)) != NULL) { in fgetln() [all …]
|
D | fvwrite.c | 49 __sfvwrite(FILE *fp, struct __suio *uio) in __sfvwrite() argument 61 if (cantwrite(fp)) in __sfvwrite() 65 #define COPY(n) (void)memcpy(fp->_p, p, n) in __sfvwrite() 78 if (fp->_flags & __SNBF) { in __sfvwrite() 85 w = (*fp->_write)(fp->_cookie, p, MIN(len, INT_MAX)); in __sfvwrite() 91 } else if ((fp->_flags & __SLBF) == 0) { in __sfvwrite() 106 if ((fp->_flags & (__SALC | __SSTR)) == in __sfvwrite() 107 (__SALC | __SSTR) && fp->_w < len) { in __sfvwrite() 108 size_t blen = fp->_p - fp->_bf._base; in __sfvwrite() 115 _base = recallocarray(fp->_bf._base, in __sfvwrite() [all …]
|
D | wsetup.c | 45 __swsetup(FILE *fp) in __swsetup() argument 54 if ((fp->_flags & __SWR) == 0) { in __swsetup() 55 if ((fp->_flags & __SRW) == 0) { in __swsetup() 57 fp->_flags |= __SERR; in __swsetup() 60 if (fp->_flags & __SRD) { in __swsetup() 62 if (HASUB(fp)) in __swsetup() 63 FREEUB(fp); in __swsetup() 64 fp->_flags &= ~(__SRD|__SEOF); in __swsetup() 65 fp->_r = 0; in __swsetup() 66 fp->_p = fp->_bf._base; in __swsetup() [all …]
|
D | setvbuf.c | 44 setvbuf(FILE *fp, char *buf, int mode, size_t size) in setvbuf() argument 65 FLOCKFILE(fp); in setvbuf() 67 (void)__sflush(fp); in setvbuf() 68 if (HASUB(fp)) in setvbuf() 69 FREEUB(fp); in setvbuf() 70 WCIO_FREE(fp); in setvbuf() 71 fp->_r = fp->_lbfsize = 0; in setvbuf() 72 flags = fp->_flags; in setvbuf() 74 free(fp->_bf._base); in setvbuf() 86 flags |= __swhatbuf(fp, &iosize, &ttyflag); in setvbuf() [all …]
|
D | makebuf.c | 49 __smakebuf(FILE *fp) in __smakebuf() argument 56 if (fp->_flags & __SNBF) { in __smakebuf() 57 fp->_bf._base = fp->_p = fp->_nbuf; in __smakebuf() 58 fp->_bf._size = 1; in __smakebuf() 61 flags = __swhatbuf(fp, &size, &couldbetty); in __smakebuf() 63 fp->_flags |= __SNBF; in __smakebuf() 64 fp->_bf._base = fp->_p = fp->_nbuf; in __smakebuf() 65 fp->_bf._size = 1; in __smakebuf() 69 fp->_bf._base = fp->_p = p; in __smakebuf() 70 fp->_bf._size = size; in __smakebuf() [all …]
|
D | fpurge.c | 44 fpurge(FILE *fp) in fpurge() argument 46 FLOCKFILE(fp); in fpurge() 47 if (!fp->_flags) { in fpurge() 48 FUNLOCKFILE(fp); in fpurge() 53 if (HASUB(fp)) in fpurge() 54 FREEUB(fp); in fpurge() 55 WCIO_FREE(fp); in fpurge() 56 fp->_p = fp->_bf._base; in fpurge() 57 fp->_r = 0; in fpurge() 58 fp->_w = fp->_flags & (__SLBF|__SNBF) ? 0 : fp->_bf._size; in fpurge() [all …]
|
D | wbuf.c | 43 __swbuf(int c, FILE *fp) in __swbuf() argument 47 _SET_ORIENTATION(fp, -1); in __swbuf() 55 fp->_w = fp->_lbfsize; in __swbuf() 56 if (cantwrite(fp)) in __swbuf() 69 n = fp->_p - fp->_bf._base; in __swbuf() 70 if (n >= fp->_bf._size) { in __swbuf() 71 if (__sflush(fp)) in __swbuf() 75 fp->_w--; in __swbuf() 76 *fp->_p++ = c; in __swbuf() 77 if (++n == fp->_bf._size || (fp->_flags & __SLBF && c == '\n')) in __swbuf() [all …]
|
D | getdelim.c | 47 int sep, FILE *__restrict fp) in getdelim() argument 53 FLOCKFILE(fp); in getdelim() 64 _SET_ORIENTATION(fp, -1); in getdelim() 68 if (fp->_r <= 0 && __srefill(fp)) { in getdelim() 69 if (__sferror(fp)) in getdelim() 76 p = memchr(fp->_p, sep, fp->_r); in getdelim() 78 len = fp->_r; in getdelim() 80 len = (p - fp->_p) + 1; in getdelim() 113 (void)memcpy((*buf + off), fp->_p, len); in getdelim() 115 fp->_r -= (int)len; in getdelim() [all …]
|
D | fgetwc.c | 38 __fgetwc_unlock(FILE *fp) in __fgetwc_unlock() argument 45 _SET_ORIENTATION(fp, 1); in __fgetwc_unlock() 46 wcio = WCIO_GET(fp); in __fgetwc_unlock() 63 int ch = __sgetc(fp); in __fgetwc_unlock() 72 fp->_flags |= __SERR; in __fgetwc_unlock() 81 fgetwc(FILE *fp) in fgetwc() argument 85 FLOCKFILE(fp); in fgetwc() 86 r = __fgetwc_unlock(fp); in fgetwc() 87 FUNLOCKFILE(fp); in fgetwc()
|
D | ungetwc.c | 38 __ungetwc(wint_t wc, FILE *fp) in __ungetwc() argument 45 _SET_ORIENTATION(fp, 1); in __ungetwc() 52 wcio = WCIO_GET(fp); in __ungetwc() 63 __sclearerr(fp); in __ungetwc() 69 ungetwc(wint_t wc, FILE *fp) in ungetwc() argument 73 FLOCKFILE(fp); in ungetwc() 74 r = __ungetwc(wc, fp); in ungetwc() 75 FUNLOCKFILE(fp); in ungetwc()
|
D | fputwc.c | 40 __fputwc_unlock(wchar_t wc, FILE *fp) in __fputwc_unlock() argument 53 _SET_ORIENTATION(fp, 1); in __fputwc_unlock() 54 wcio = WCIO_GET(fp); in __fputwc_unlock() 65 fp->_flags |= __SERR; in __fputwc_unlock() 70 if (__sfvwrite(fp, &uio)) { in __fputwc_unlock() 78 fputwc(wchar_t wc, FILE *fp) in fputwc() argument 82 FLOCKFILE(fp); in fputwc() 83 r = __fputwc_unlock(wc, fp); in fputwc() 84 FUNLOCKFILE(fp); in fputwc()
|
D | fputws.c | 40 fputws(const wchar_t * __restrict ws, FILE * __restrict fp) in fputws() argument 42 FLOCKFILE(fp); in fputws() 43 _SET_ORIENTATION(fp, 1); in fputws() 46 if (__fputwc_unlock(*ws++, fp) == WEOF) { in fputws() 47 FUNLOCKFILE(fp); in fputws() 52 FUNLOCKFILE(fp); in fputws()
|
D | fgetws.c | 40 fgetws(wchar_t * __restrict ws, int n, FILE * __restrict fp) in fgetws() argument 45 FLOCKFILE(fp); in fgetws() 46 _SET_ORIENTATION(fp, 1); in fgetws() 55 if ((wc = __fgetwc_unlock(fp)) == WEOF && in fgetws() 56 ferror(fp) && errno == EILSEQ) in fgetws() 72 FUNLOCKFILE(fp); in fgetws() 77 FUNLOCKFILE(fp); in fgetws()
|
D | open_memstream.c | 116 FILE *fp; in open_memstream() local 126 if ((fp = __sfp()) == NULL) { in open_memstream() 134 fp->_flags = 0; in open_memstream() 146 fp->_flags = __SWR; in open_memstream() 147 fp->_file = -1; in open_memstream() 148 fp->_cookie = st; in open_memstream() 149 fp->_read = NULL; in open_memstream() 150 fp->_write = memstream_write; in open_memstream() 151 fp->_seek = memstream_seek; in open_memstream() 152 fp->_close = memstream_close; in open_memstream() [all …]
|
D | open_wmemstream.c | 126 FILE *fp; in open_wmemstream() local 136 if ((fp = __sfp()) == NULL) { in open_wmemstream() 144 fp->_flags = 0; in open_wmemstream() 157 fp->_flags = __SWR; in open_wmemstream() 158 fp->_file = -1; in open_wmemstream() 159 fp->_cookie = st; in open_wmemstream() 160 fp->_read = NULL; in open_wmemstream() 161 fp->_write = wmemstream_write; in open_wmemstream() 162 fp->_seek = wmemstream_seek; in open_wmemstream() 163 fp->_close = wmemstream_close; in open_wmemstream() [all …]
|
/bionic/benchmarks/ |
D | stdio_benchmark.cpp | 32 FILE* fp = fopen(tf.path, "we"); in FillFile() local 33 for (size_t i = 0; i < 4096; ++i) fputs(line, fp); in FillFile() 34 fclose(fp); in FillFile() 41 FILE* fp = fopen("/dev/zero", "r+e"); in ReadWriteTest() local 42 __fsetlocking(fp, FSETLOCKING_BYCALLER); in ReadWriteTest() 46 setvbuf(fp, nullptr, _IONBF, 0); in ReadWriteTest() 50 if (f(buf, chunk_size, 1, fp) != 1) { in ReadWriteTest() 57 fclose(fp); in ReadWriteTest() 85 FILE* fp = fopen(tf.path, "re"); in FopenFgetlnFclose() local 86 if (no_locking) __fsetlocking(fp, FSETLOCKING_BYCALLER); in FopenFgetlnFclose() [all …]
|