aboutsummaryrefslogtreecommitdiff
path: root/libc/stdio
Commit message (Collapse)AuthorAgeFilesLines
* Add the missing '--' to shell invocations.Elliott Hughes2021-11-041-1/+1
| | | | | | | | | | | | | | | This came up with POSIX recently. Doesn't seem like it matters since everyone's had this wrong for 40 years, but "meh" --- it's a trivial fix, and it's strictly correct even if nobody needs this, so let's just do it... (Geoff Clare pointed out that my app compat concern "what if someone's relying on this bug to pass flags to the shell?" isn't relevant because while you can indeed do that, you then can't pass a command!) Bug: https://austingroupbugs.net/view.php?id=1440 Test: treehugger Change-Id: I64f6440da55e2dc29d0136ee62007197d2f00d46
* Make fd overflow an abort.Elliott Hughes2021-02-091-14/+9
| | | | | | | | | | | | On LP32, just abort if we're asked to handle an fd that's too big for the `short` field in `struct FILE`. This is unreachable anyway because the ulimit is 32Ki, and this will make issues far more noticeable if we ever do increase that limit (which seems unlikely for LP32 devices). Also rename __finit() to __FILE_init() to match __FILE_close(). Test: treehugger Change-Id: I5db4d6c4529a1f558aff135b4dea071d73666be5
* Fix freopen() where the path is null.Elliott Hughes2021-02-041-37/+41
| | | | | | | | | | | | | | | | | | | | | | | This has been in the standard since C99, but we've never supported it before. It's apparently used by SPIRV-Tools. I tried implementing this the other way (with fcntl(2)) first, but eventually realized that that's more complicated and gives worse results. This implementation assumes that /proc is mounted, but so much of libc relies on that at this point that I don't think there's any realistic case where the fcntl(2) implementation would be preferable, and there are many where it's not. The fact that no-one's mentioned this until now suggests that it's not a heavily used feature anyway. I've also replaced AssertCloseOnExec() with a CloseOnExec() boolean-valued function instead, because it's really annoying getting assertion failures that don't point you at the test line in question, and instead point to some common helper code. Test: treehugger Change-Id: Ia2e53bf2664a4f782581042054ecd492830e2aed
* Fewer copies of ALIGN()/ALIGNBYTES.Elliott Hughes2021-01-111-2/+1
| | | | | | | | Noticed while updating fts.c. Bug: http://b/177003648 Test: treehugger Change-Id: Ic3625c1c3af47c4dafb8ad686bbbddbc82b69b70
* Various coverage improvements.Elliott Hughes2020-08-121-4/+1
| | | | | | | | | | | | | Mostly from extra test cases, but also: * Move the fgets size < 0 assertion into fgets. * Use ELF aliases for strtoq/strtouq rather than duplicating code. * Don't check uname() succeeded, since it can't fail. Test: treehugger Change-Id: I2e6b3b88b0a3eb16bd68be68b9bc9f40d8043291
* Cleanup for #inclusivefixit.Elliott Hughes2020-07-231-2/+2
| | | | | Test: treehugger Change-Id: Iec1af942b5dee37f08ad390afe9fbdb79c47c085
* Changes for #inclusivefixit.Elliott Hughes2020-07-212-3/+3
| | | | | Test: treehugger Change-Id: I7ff0496c5c2792a41781e74634247f55b0548213
* Remove bionic's internal ctype-like inlines.Elliott Hughes2020-02-051-6/+6
| | | | | | Bug: http://b/144165498 Test: treehugger Change-Id: Ifcf352525abc74850053a1a019f90c72e488b71c
* Move bionic_macros.h from private to platform.Josh Gao2020-01-022-2/+2
| | | | | Test: treehugger Change-Id: Ie473914f4c8924c7240b3ac22093a9daf42fc948
* Remove the ___ hack.Elliott Hughes2019-06-191-2/+0
| | | | | | | | | | | | Plain __ for generated syscalls didn't mean it was a hidden symbol, it just meant "please don't use this". We added ___ to signify that a hidden symbol should be generated, but then we added the map files anyway so you now have to explicitly export symbols. Given that, this convention serves no particular purpose so we may as well just use the nicer names have everything look the same. Test: treehugger Change-Id: If424e17a49c36f4be545f5d283c4561a6ea9c7ea
* Revert fwalk/sfp locking to fix concurrent readsRyan Prichard2019-05-043-6/+14
| | | | | | | | | | | | | | | | | | | The locking can fail in a couple of ways: - A concurrent fread from an unbuffered or line-buffered file flushes the output of other line-buffered files, and if _fwalk locks every file, then the fread blocks until other file reads have completed. - __sfp can initialize a file lock while _fwalk is locking/unlocking it. For now, revert to the behavior Bionic had in previous releases. This commit reverts the file locking parts of commit 468efc80da2504f4ae7de8b5e137426d44dda9d7. Bug: http://b/131251441 Bug: http://b/130189834 Test: bionic unit tests Change-Id: I9e20b9cd8ccd14e7962f7308e174f08af72b56c6
* Merge "Typo fix in comment. O_CLOEXEC is e, not x."Treehugger Robot2019-03-261-1/+1
|\
| * Typo fix in comment. O_CLOEXEC is e, not x.Dan Albert2019-03-261-1/+1
| | | | | | | | | | | | Test: None Bug: None Change-Id: I061fe1d3cac6307d878155f1fabdba70da8e9fd5
* | Merge "Fix internal uses of _PATH_BSHELL."Treehugger Robot2019-03-261-1/+2
|\ \
| * | Fix internal uses of _PATH_BSHELL.Elliott Hughes2019-03-251-1/+2
| |/ | | | | | | | | | | | | | | | | | | We regressed on this recently: code under the upstream-* directories has _PATH_BSHELL defined as a call to __bionic_get_shell_path(). In our own code, we may as well just call it directly. Bug: https://issuetracker.google.com/129030706 Test: ran tests Change-Id: Ic2423f521272be95e67f94771772fe8072636ef0
* / popen: stop using _fwalk.Elliott Hughes2019-03-251-8/+0
|/ | | | | | | | | | We don't need this now that popen always uses O_CLOEXEC, and it's unsafe because _fwalk takes a lock. (In <= P, the equivalent code walked the list without a lock in the child.) Bug: http://b/129156634 Test: ran tests Change-Id: Ic9cee7eb59cfc9397f370d1dc47ea3d3326179ca
* Avoid writing to a zero-capacity buffer.Elliott Hughes2019-02-051-1/+3
| | | | | | Bug: http://b/120752721 Test: ran tests Change-Id: I3f03ae204ab5de40fd4402a5562c50ffe51ef998
* Make fclose/pclose distinct.Elliott Hughes2018-10-011-3/+12
| | | | | | | | | | | | | I failed to convince the compiler/linker to just refrain (via factoring out, attribute `noinline`, or meddling with `--icf=none`), but luckily I noticed that we should have CHECK_FP in each function for a better error message, and the distinct error messages keep the two functions apart. (Also add a missing CHECK_FP to `clearerr_unlocked`.) Bug: http://b/116969207 Test: manual with a modified `crasher` Change-Id: Ic122e90e94f7e22f486be57d3dac7137a225d682
* Use strerror_r(3) for the printf family %m.Elliott Hughes2018-09-062-2/+3
| | | | | | | | | | There's TLS space used for unknown errno values, and a call to printf shouldn't clobber that. No-one will ever hit this in real life, but since it's easily fixed... Bug: http://b/112776560 Test: ran tests Change-Id: I8c2437f2e5214e652119791d4e162a197b049d5b
* Add the %m GNU extension to printf/wprintf.Elliott Hughes2018-08-302-0/+17
| | | | | | | | And remove the local hack from syslog(3). Bug: http://b/112776560 Test: ran tests Change-Id: I5807e729a978df26187ea0ee255bba4ca74220c8
* libc: enable -Wimplicit-fallthroughGeorge Burgess IV2018-08-154-19/+22
| | | | | | | | | | libc had some -Wimplicit-fallthrough warnings. They all seem to be benign. We're trying to enable this flag globally, so we need to annotate these breaks here. Bug: 112564944 Test: Builds Change-Id: I5afae694cc4cf26ad1a61e2c8ae91f00cda7c733
* Merge "Make all popen(3) file descriptors O_CLOEXEC."Elliott Hughes2018-08-061-4/+0
|\
| * Make all popen(3) file descriptors O_CLOEXEC.Elliott Hughes2018-08-031-4/+0
| | | | | | | | | | | | | | | | | | | | | | | | POSIX says "The popen() function shall ensure that any streams from previous popen() calls that remain open in the parent process are closed in the new child process". It doesn't appear to disallow all popen(3) file descriptors from being O_CLOEXEC, and it's not obvious why anyone would want them inherited. Let's see if we can make the stricter guarantee... Bug: N/A Test: ran tests Change-Id: I2c85170d730b211637afb8ba10df150ca3237262
* | Modernize codebase by replacing NULL with nullptrYi Kong2018-08-025-71/+71
|/ | | | | | | | Fixes -Wzero-as-null-pointer-constant warning. Test: m Bug: 68236239 Change-Id: I5b4123bc6709641315120a191e36cc57541349b2
* Introduce api to track fd ownership in libc.Josh Gao2018-07-191-1/+20
| | | | | | | | | | | | | Add two functions to allow objects that own a file descriptor to enforce that only they can close their file descriptor. Use them in FILE* and DIR*. Bug: http://b/110100358 Test: bionic_unit_tests Test: aosp/master boots without errors Test: treehugger Change-Id: Iecd6e8b26c62217271e0822dc3d2d7888b091a45
* Reimplement popen(3)/pclose(3).Elliott Hughes2018-07-113-38/+138
| | | | | | | | | | | | | | | | | | | | | | pclose(3) is now an alias for fclose(3). We could add a FORTIFY check that you use pclose(3) if and only if you used popen(3), but there seems little value to that when we can just do the right thing. This patch also adds the missing locking to _fwalk --- we need to lock both the global list of FILE*s and also each FILE* we touch. POSIX says that "The popen() function shall ensure that any streams from previous popen() calls that remain open in the parent process are closed in the new child process", which we implement via _fwalk(fclose) in the child, but we might want to just make *all* popen(3) file descriptors O_CLOEXEC in all cases. Ignore fewer errors in popen(3) failure cases. Improve popen(3) test coverage. Bug: http://b/72470344 Test: ran tests Change-Id: Ic937594bf28ec88b375f7e5825b9c05f500af438
* Call __fortify_fatal if printf sees %n.Elliott Hughes2018-03-074-57/+3
| | | | | | | | | | | | We've ignored %n for a long time, but that's dangerous too because it makes it unclear whether the corresponding pointer argument should be supplied or not. Remove the ambiguity by just rejecting %n outright. Bug: http://b/31832608 Test: ran tests Change-Id: Ic046ad3436a30c6f8f580ea738bdcaeb01c858f8
* clang-format local.h.Elliott Hughes2018-03-011-101/+100
| | | | | | Bug: N/A Test: builds Change-Id: I3b1b238eefc67e6d627dbd6820849522fd7d961b
* Merge stdio/local.h and stdio/wcio.h.Elliott Hughes2018-02-282-83/+32
| | | | | | Bug: N/A Test: ran tests Change-Id: I683a1c45db0b880c73f8d190a46deeeab4cfef6e
* Add __fseterr.Elliott Hughes2018-02-141-0/+4
| | | | | | | | | Trivial, obvious counterpart to the standard ferror(3) and clearerr(3), and lets us build bison out of the box. Bug: http://b/64273806 Test: ran tests Change-Id: I20affabddb71210051165c41e86adfe5ae04f77f
* Switch the rest of our internal headers to #pragma once.Elliott Hughes2018-02-132-8/+2
| | | | | | | | We've been using #pragma once for new internal files, but let's be more bold. Bug: N/A Test: builds Change-Id: I7e2ee2730043bd884f9571cdbd8b524043030c07
* Remove __overloadable/__RENAME_CLANGGeorge Burgess IV2018-02-061-2/+2
| | | | | | | | | | Now that we have a clang that supports transparent overloads, we can kill all of this cruft, and restore our upstream sources to their untouched glory. Woohoo! Bug: 12231437 Test: Built aosp_marlin; no obvious patch-related aosp_mips issues. Change-Id: I520a19d014f12137f80e43f973dccd6711c571cd
* Avoid trademarks.Elliott Hughes2018-02-051-5/+4
| | | | | | | | API levels are generally more useful anyway. Bug: N/A Test: N/A Change-Id: Ie7bd69c3d0223c9bc8ed52c871b1d2d34373e2d0
* Simplify CT_CCL and CT_STRING inner loop.Elliott Hughes2018-01-191-5/+7
| | | | | | | | | Makes no difference to the benchmarks, but does make the code a bit more readable. Bug: http://b/68672236 Test: ran tests, benchmarks Change-Id: I63fa5f78d077c86e4f4f194f2c76ab5510c29109
* Support %mc/%ms/%m[ in sscanf.Elliott Hughes2018-01-191-114/+176
| | | | | | | | Also support the "long" (wchar_t) variants. Bug: http://b/68672236 Test: ran tests Change-Id: I060e98b4d2feb61e12986d9d51e4710b2b1d9724
* Merge "Speed up __sfileext initialization."Elliott Hughes2017-12-213-22/+10
|\
| * Speed up __sfileext initialization.Elliott Hughes2017-12-203-22/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The internal uses don't need to actually initialize a mutex since they'll never escape and don't need locking. It's a small saving, but easy. Before: BM_stdio_scanf_d 465 ns 465 ns 1507891 BM_stdio_scanf_maps 1836 ns 1836 ns 381082 BM_stdio_scanf_maps_baseline 846 ns 845 ns 830881 BM_stdio_scanf_s 419 ns 419 ns 1671979 After: BM_stdio_scanf_d 434 ns 434 ns 1612930 BM_stdio_scanf_maps 1815 ns 1815 ns 386470 BM_stdio_scanf_maps_baseline 875 ns 873 ns 803304 BM_stdio_scanf_s 382 ns 382 ns 1833198 Bug: http://b/70862888 Test: ran tests, benchmarks Change-Id: Ic8822aaca5d8ca1a73390089153d0fe35d91673e
* | Use inline ctype functions for ato*/strto* and scanf.Elliott Hughes2017-12-191-12/+14
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This also let us remove the `unsigned char` casts, since we define our inlines to work for all values. Before: Benchmark Time CPU Iterations ------------------------------------------------------------- BM_inttypes_strtoimax 112 ns 112 ns 6222193 BM_inttypes_strtoumax 104 ns 104 ns 6725010 BM_stdlib_strtol 113 ns 113 ns 6195861 BM_stdlib_strtoll 113 ns 113 ns 6195633 BM_stdlib_strtoul 105 ns 105 ns 6691394 BM_stdlib_strtoull 105 ns 105 ns 6690695 BM_stdio_scanf_d 504 ns 503 ns 1385224 BM_stdio_scanf_maps 1900 ns 1898 ns 369260 BM_stdio_scanf_maps_baseline 1030 ns 1030 ns 678832 BM_stdio_scanf_s 433 ns 432 ns 1619086 After: BM_inttypes_strtoimax 91 ns 91 ns 7718194 BM_inttypes_strtoumax 82 ns 82 ns 8508052 BM_stdlib_strtol 92 ns 92 ns 7674694 BM_stdlib_strtoll 91 ns 91 ns 7639228 BM_stdlib_strtoul 83 ns 82 ns 8500304 BM_stdlib_strtoull 82 ns 82 ns 8504929 BM_stdio_scanf_d 465 ns 465 ns 1507891 BM_stdio_scanf_maps 1836 ns 1836 ns 381082 BM_stdio_scanf_maps_baseline 846 ns 845 ns 830881 BM_stdio_scanf_s 419 ns 419 ns 1671979 Bug: N/A Test: ran tests, benchmarks Change-Id: I44681daf16c4328b060770cf11fc0633157c427f
* More scanf cleanup.Elliott Hughes2017-12-122-160/+40
| | | | | | | | | | | | | | Merge CT_CCL and CT_STRING handling before we add %m. Also fix an accidental scanf/wscanf difference. Add currently-disabled tests for questionable behavior noticed during code review that isn't a regression, but should be fixed later. Bug: http://b/68672236 Bug: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=202240 Test: ran tests Change-Id: I3eec9b7dfce84f63c68426406224822c52551d64
* Add sscanf %[ tests and fix the bug that fell out.Elliott Hughes2017-12-072-28/+43
| | | | | | | | | | | | | Strictly, POSIX says "If a '-' is in the scanlist and is not the first wide character, nor the second where the first wide character is a '^', nor the last wide character, the behavior is implementation-defined", but it seems unreasonable for swscanf to interpret `a-c` differently from sscanf. Make ours behave the same as each other by making swscanf work the same as sscanf. Bug: http://b/68672236 Test: ran tests Change-Id: Ia84805897628d7128e901b468e02504373730e61
* Remove more trivial char/wchar_t printf differences.Elliott Hughes2017-11-132-13/+13
| | | | | | Bug: http://b/67371539 Test: ran tests Change-Id: I899458af92517dc21f874519716fa3f3a0f0e3d6
* Merge "Yet more printf de-duplication."Elliott Hughes2017-11-133-182/+177
|\
| * Yet more printf de-duplication.Elliott Hughes2017-11-103-182/+177
| | | | | | | | | | | | Bug: http://b/67371539 Test: ran tests Change-Id: Iae38055426596919c0de4f5080c99eba95fac3a9
* | Move public scanf functions away from implementation.Elliott Hughes2017-11-103-18/+10
|/ | | | | | Bug: N/A Test: ran tests Change-Id: Ifb8bd91132865f8c6d0b95baf1021af3b3b3c353
* Move shared parts of the two printfs out.Elliott Hughes2017-11-083-1330/+687
| | | | | | Bug: http://b/67371539 Test: ran tests Change-Id: I24eae6a5d2c64ff4fd65c8d508a3709bab5a11c4
* More printf de-duplication.Elliott Hughes2017-11-072-30/+22
| | | | | | | | | | | | Just trivial use of macros. The %s/%ls case in __find_arguments was backwards in the wide copy of the code, but not problematically so because all pointers are the same size anyway. Bug: http://b/67371539 Test: ran tests Change-Id: I8d34915d75ae5425c56c59510a16c328fc481d20
* Allow 32-bit fseeko/fseeko64 SEEK_CUR/SEEK_SET to exceed 2 GiBRyan Prichard2017-11-071-1/+1
| | | | | | | | Bug: http://b/68837650 Test: /data/nativetest/bionic-unit-tests/bionic-unit-tests Test: /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static Test: /data/nativetest64/bionic-unit-tests/bionic-unit-tests Change-Id: I367e0238c31d35f76d8ad89fd0aa27ecfeb7c149
* 10x printf speedup.Elliott Hughes2017-11-032-76/+66
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Android is UTF-8. Don't make everyone pay to convert UTF-8 to ASCII just so we can recognize '%'. With UTF-8 we can just strchr forwards. Before: --------------------------------------------------------------- Benchmark Time CPU Iterations --------------------------------------------------------------- BM_stdio_printf_literal 1290 ns 1290 ns 442554 BM_stdio_printf_s 1204 ns 1204 ns 582446 BM_stdio_printf_d 1206 ns 1206 ns 578311 BM_stdio_printf_1$s 2263 ns 2263 ns 310002 After: --------------------------------------------------------------- Benchmark Time CPU Iterations --------------------------------------------------------------- BM_stdio_printf_literal 178 ns 178 ns 3394001 BM_stdio_printf_s 246 ns 246 ns 2850284 BM_stdio_printf_d 252 ns 252 ns 2778610 BM_stdio_printf_1$s 363 ns 363 ns 1929011 Add missing __find_arguments error checking to the wide variant to match the regular one. Also replace various char/wchar_t differences with the macro. Bug: http://b/67371539 Test: ran tests Change-Id: I18f122009c22699943ab5d666a98ea594a972c40
* More printf de-duplication.Elliott Hughes2017-11-023-25/+22
| | | | | | | | | | | | | | Fix the 'j' (intmax_t/uintmax_t) length qualifier in the wide variant. (With new tests that fail without this fix.) Fix a typo in the wide support for intmax_t*, which isn't testable because %n is disabled on Android (and will be removed in a later cleanup pass). Also move the public vfprintf/vfwprint functions into stdio.cpp. Bug: http://b/67371539 Test: ran tests Change-Id: Ib003599b1e9cb789044a068940b59e447f2cb7cb
* Start de-duplicating the regular and wide printf implementations.Elliott Hughes2017-11-017-243/+191
| | | | | | | | | | | | | | | | | This patch switches to C++ (in anticipation of needing it later), removes a little duplication (via a macro for now), and ensures uniform support for %C/%lc and %S/%ls between regular and wide (with new tests). Since it's so hard to debug problems in printf (as the time I've wasted already today will testify), that's all I want to do in this change. The other 500 lines of diff can wait... (Also merge "floatio.h" into "local.h" now all the users are in forked code.) Bug: http://b/67371539 Test: ran tests Change-Id: I083353d89c32b9302d759ca6967cc6d8a62cd8a5