Commit graph

134 commits

Author SHA1 Message Date
Yi Kong
32bc0fcf69 Modernize codebase by replacing NULL with nullptr
Fixes -Wzero-as-null-pointer-constant warning.

Test: m
Bug: 68236239
Change-Id: I5b4123bc6709641315120a191e36cc57541349b2
2018-08-02 18:09:44 -07:00
Josh Gao
f6e5b58260 Introduce api to track fd ownership in libc.
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
2018-07-19 14:28:54 -07:00
Elliott Hughes
468efc80da Reimplement popen(3)/pclose(3).
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
2018-07-11 12:15:26 -07:00
Elliott Hughes
41398d03b7 Call __fortify_fatal if printf sees %n.
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
2018-03-07 13:32:58 -08:00
Elliott Hughes
38e4aefe6c Support %mc/%ms/%m[ in sscanf.
Also support the "long" (wchar_t) variants.

Bug: http://b/68672236
Test: ran tests
Change-Id: I060e98b4d2feb61e12986d9d51e4710b2b1d9724
2018-01-19 14:53:55 -08:00
Elliott Hughes
a7f12944d4 A few more trivial tests.
Based on gaps in the list of functions not referenced by the test
executable.

Bug: N/A
Test: ran tests
Change-Id: I73c238e7cf360f94670c7cd13eb954341c940b7b
2017-12-15 13:55:53 -08:00
Elliott Hughes
bf9cb9e404 More scanf cleanup.
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
2017-12-12 17:10:51 -08:00
Elliott Hughes
0d3ba1f047 Add sscanf %[ tests and fix the bug that fell out.
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
2017-12-07 14:13:57 -08:00
Ryan Prichard
bf54986d19 Allow 32-bit fseeko/fseeko64 SEEK_CUR/SEEK_SET to exceed 2 GiB
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
2017-11-07 15:34:23 -08:00
Elliott Hughes
618303ca4a More printf de-duplication.
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
2017-11-02 16:58:44 -07:00
Elliott Hughes
2f9c8ce38a Start de-duplicating the regular and wide printf implementations.
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
2017-11-01 18:13:36 -07:00
Elliott Hughes
37ad959783 More missing _unlocked <stdio.h> functions.
Also simplify trivial one-liners like perror/puts/fputs, and clean up
fread/fwrite slightly.

Fix perror to match POSIX.

Add basic perror and *_unlocked tests.

Bug: N/A
Test: ran tests
Change-Id: I63f83c8e0c15c3c4096509d17421ac331b6fc23d
2017-10-31 13:23:41 -07:00
Dan Albert
9601f162f4 Expand swprintf tests.
Test: bionic unit tests
Bug: None
Change-Id: I36924c4bdd2fa2c25e50ef7fef5500a365721a05
2017-08-09 14:59:33 -07:00
Elliott Hughes
b15feb7024 Clean up some <stdio.h> constants.
And actually test an assertion rather than just state it in a comment.

Bug: N/A
Test: ran tests
Change-Id: I07699483aca4aac4e089d8b99123cb5bde9b3c63
2017-07-31 17:20:18 -07:00
Elliott Hughes
33a8cb1d1a Use O_APPEND for stdio append mode.
"Although not explicitly required by this volume of POSIX.1-2008, a good
implementation of append (a) mode would cause the O_APPEND flag to be set."

Yeah, about that...

Bug: N/A
Test: ran tests
Change-Id: I23c4bc5c1ebc92e0cb44025d2d313f321f9ffa68
2017-07-25 18:11:23 -07:00
Elliott Hughes
3a4c45499e Replace fmemopen.
A new implementation starting from the FreeBSD fmemopen rather than the
OpenBSD one we used to use.

The tests were arrived at by translating each sentence in
http://pubs.opengroup.org/onlinepubs/9699919799/functions/fmemopen.html,
plus http://man7.org/linux/man-pages/man3/fmemopen.3.html for historical
GNU bugs.

Bug: http://b/31304889
Test: ran tests
Change-Id: Id8b168c9ecde638e9cdedbc3b8a0982fc83c7048
2017-07-24 10:48:42 -07:00
Josh Gao
2f06e10280 Improve fmemopen tests.
Tag fmemopen_NULL as a known failure, and make it reliably fail by
memsetting the buffer we read to.

Bug: http://b/33251022
Test: bionic-unit-tests/bionic-unit-tests64 on bullhead
Test: bionic-unit-tests-glibc --gtest_filter="*memopen*"
Change-Id: I381783282359851c9de47146dafbb5a291960c2a
2017-01-11 13:00:15 -08:00
Josh Gao
b36efa4343 Fix instances of '#if __LP64__'.
Triggers -Wundef, which is on in -Weverything.

Bug: http://b/31496165
Change-Id: Ib06107073f7dd1d584c19c222d0430da9d35630b
2016-09-15 14:21:28 -07:00
Elliott Hughes
7f0849fd11 Fix sscanf/wcstod parsing of NaNs.
The parsefloat routines -- which let us pass NaNs and infinities on to
strto(f|d|ld) -- come from NetBSD.

Also fix LP64's strtold to return a NaN, and fix all the architectures
to return quiet NaNs.

Also fix wcstof/wcstod/wcstold to use parsefloat so they support hex
floats.

Lots of new tests.

Bug: http://b/31101647
Change-Id: Id7d46ac2d8acb8770b5e8c445e87cfabfde6f111
2016-09-07 15:01:54 -07:00
Elliott Hughes
fb3873d4db Fortify vsnprintf in more cases.
Bug: http://b/30445072
Change-Id: I1893890f0e3b56533eef053eda1bd96a0b9a5119
2016-08-10 11:50:12 -07:00
Elliott Hughes
d1f25a7eb1 Reimplement remove(3) without the lstat(2).
This assumes that it's more likely we're unlinking a file than a directory,
though even if that's not true, as long as a failed unlink(2) is cheaper
than a successful lstat(2) -- which seems likely since there's no data to
copy -- we still win.

Change-Id: I0210e9cd3d31b8cf1813c55c810262ef327382ed
2016-08-05 15:53:03 -07:00
Elliott Hughes
70715da453 More stdio one-liners.
This actually turns up a bug in fmemopen, so I guess that's what I'll
look at next...

Change-Id: I2971ecd1b5a3a3c7f43c22d985f88e389af89e97
2016-08-01 18:06:38 -07:00
Elliott Hughes
20788aec00 Add ctermid.
Change-Id: I7c7c815c2725df222932db923632c8b6419741ab
2016-06-09 15:16:32 -07:00
Elliott Hughes
8200e55d94 Add a test for a possible overflow in *printf.
It turns out we don't have any bugs here, but glibc does. Found while
chasing down a toybox failure I saw on the host, but we may as well
add the test in case we ever screw up here in future.

Change-Id: Ib8dd227ed3b742dc4dab8c09dc08e6ea9a35c807
2016-02-05 21:57:37 -08:00
Elliott Hughes
43f7c87565 Add a test for snprintf on a PTHREAD_STACK_MIN-sized stack.
This is a common thing for people to want to do, snprintf requires
a lot of stack for itself, and PTHREAD_STACK_MIN should be usable
for realistic code.

Change-Id: Ib09cfb4e0beec1c69ee0944c3ea4c5d03a94c491
2016-02-05 11:18:41 -08:00
Elliott Hughes
f226ee59e0 Add fopen64/freopen64/tmpfile64 aliases.
Our fopen/freopen/tmpfile are already always O_LARGEFILE, but let's add
the aliases for _LARGEFILE_SOURCE compatibility.

Bug: http://b/24807045
Change-Id: I5d99b3ef3c9f27ce70f13313f6a92e96c7f21f80
2016-02-03 11:24:28 -08:00
Elliott Hughes
e4fa6e9cc7 Expose ftello64.
Also add the missing test that would have caught this.

Bug: http://b/24807045
Change-Id: I756a4d825595b52396b15898e3f717156fd1ba2f
2016-02-02 22:39:15 -08:00
Elliott Hughes
955426ef79 Fix a sign extension bug in stdio.
This also lets us test the EOVERFLOW behavior, which pointed out that the
fgetpos/fsetpos return on failure has always been wrong...

Bug: http://b/24807045
Change-Id: I35273eb07c8c9155af858adb27569983397580b6
2016-01-26 18:25:52 -08:00
Elliott Hughes
03e65eb03b Implement funopen64.
Bug: http://b/24807045
Change-Id: I161920978161389be34b707cc6ce8e05f760d552
2016-01-26 14:45:13 -08:00
Elliott Hughes
9677fab88c Support _FILE_OFFSET_BITS=64 for most of <stdio.h>.
This doesn't address funopen, but does add fgetpos/fsetpos/fseeko/ftello.

Bug: http://b/24807045
Change-Id: Ibff6f00df5fb699c8e8f13b91a75caf024540b73
2016-01-26 09:14:41 -08:00
Elliott Hughes
71288cbfdf Add another stdio test.
This test didn't catch anything, but it does ensure that we exercise
the "lots of files" case.

Bug: http://b/26747402
Change-Id: I6c51c6436029572a49190d509f131eb93b808652
2016-01-22 19:22:44 -08:00
Elliott Hughes
2704bd1340 Simplify fseek/ftell.
Another step towards _FILE_OFFSET_BITS=64 support.

Bug: http://b/24807045
Change-Id: I00b83c81a7b108176c4d9437bc32611f73b7e967
2016-01-21 10:34:35 -08:00
Elliott Hughes
923f165b29 Make FILE*s less usable after fclose(3).
BSD doesn't invalidate the fd stored in struct FILE, which can make
it possible (via fileno(3), for example), to perform operations on
an fd you didn't intend to (rather than just failing with EBADF).

Fixing this makes the code slightly simpler anyway, and might help
catch bad code before it ships.

Bug: http://stackoverflow.com/questions/10816837/fclose-works-differently-on-android-and-linux
Change-Id: I9db74584038229499197a2695c70b58ed0372a87
2016-01-19 15:46:05 -08:00
Christopher Ferris
13f26a7b2b Add method to run fortified versions of funcs.
Add a way to turn fortify off for the files that test fortify functions.

This method involves simply compiling the same file with fortify off and
changing the test name slightly.

It's not very pretty, and it assumes that only these few files test
functions that can be fortified.

Bug: 15195631
Change-Id: Iba9db1d508b7d28a1d6968019cb70fe08864827b
2016-01-13 17:13:21 -08:00
Elliott Hughes
8ab433df13 Fix stdio read after EOF behavior.
Bug: https://code.google.com/p/android/issues/detail?id=184847
Change-Id: Ia20ce94007c2a09649f0763b1dc7ba959f2f618d
2015-10-09 17:57:26 -07:00
Elliott Hughes
694fd2d880 Add a test for getdelim(3) on a directory.
Apparently uClibc has a bug here. We don't, but let's keep it that way.

Bug: http://landley.net/notes.html#21-03-2015
Change-Id: If406df963db9bee47921d7a1c116ebcab08d96bf
2015-04-05 10:51:56 -07:00
Christopher Ferris
cc9ca1051d Fix fread returning bad data.
Bug: 19172514
Change-Id: I05016577858a02aca7d14e75e6ec28abc925037c
2015-02-27 18:22:45 -08:00
Elliott Hughes
e6bb5a2776 Fix optimized fread.
gcov does writes after reads on the same stream, but the bulk read optimization
was clobbering the FILE _flags, causing fwrite to fail.

Bug: 19129055
Change-Id: I9650cb7de4bb173a706b502406266ed0d2b654d7
2015-01-24 12:35:41 -08:00
Elliott Hughes
0ed7e08cda Fix the stdio.fread_EOF test.
Another sizeof/strlen screwup caused by trying to be too clever. Use
std::string instead.

Also fix all the ASSERT_STREQ calls in this file that had the arguments
the right^Wwrong way round. If I ever see Kent Beck...

Change-Id: I47a1bdfee99cf4e7bed9b398f3158a308fbcf1e8
2015-01-22 15:28:48 -08:00
Elliott Hughes
bcb378d643 Fix fread_EOF test name.
Change-Id: I53a7f1428fd27c0b2a5c80f2e8af4845d17f5b4b
2015-01-22 14:18:35 -08:00
Elliott Hughes
75b99387dd Optimized fread.
This makes us competitive with glibc for fully-buffered and unbuffered reads,
except in single-threaded situations where glibc avoids locking, but since
we're never really single-threaded anyway, that isn't a priority.

Bug: 18593728
Change-Id: Ib776bfba422ccf46209581fc0dc54f3567645b8f
2015-01-20 15:59:17 -08:00
Elliott Hughes
1b18aff9ba Fix nan output in the printf family.
Bug: https://code.google.com/p/android/issues/detail?id=82452
Change-Id: I51f226c8b033de6e81baeea5e6db3de6ed196f73
2014-12-20 18:53:08 -08:00
Elliott Hughes
20841a137b Avoid pathological behavior in OpenBSD's fread.
Bug: https://code.google.com/p/android/issues/detail?id=81155
Bug: 18556607
Change-Id: Idc60976b79610e2202cc42dc393dcb4ca6c42e05
2014-12-02 14:22:02 -08:00
Yabin Cui
5ca4a9e2da implement missing seekdir and telldir
Bug: 18266863
Change-Id: I189ee949d4f7ccee099f3341e349cd969d25480f
2014-11-07 10:20:32 -08:00
Elliott Hughes
6a03abcfd2 Ensure we initialize stdin/stdout/stderr's recursive mutexes.
Bug: 18208568
Change-Id: I9da16ce0f9375bc363d1d02be706d73fd3b1e150
2014-11-03 12:32:17 -08:00
Elliott Hughes
31165edf57 CLOEXEC support in fdopen, freopen, and mkostemp/mkostemps.
Change-Id: I74ea88e0d4973d6ab3c57da7d8bb643c31592b14
2014-09-23 18:21:52 -07:00
Wally Yau
a40fdbd565 call uselocale() before freelocale() to make sure that g_local_key has a valid locale.
For tests that call uselocale(), the locale is stored in the
g_userlocale_key thread-specific key. If freelocale() is called later,
then g_uselocal_key points to a deleted pointer. CTS eventually calls
vfprintf to print the result, which calls MB_CUR_MAX and MB_CUR_MAX
accesses the deleted locale stored in g_uselocale_key, causing unpredictable
errors.

Fixed the tests by calling uselocale() with the old locale before
calling freelocale.

(cherry-pick of 8a46cf0fcf82b8c76e05be7e066ec854f974603a.)

Bug: 17299565
Change-Id: I87efa2a9b16999a11d587f68d3aeedcbe6ac8a2c
2014-08-27 10:26:49 -07:00
Elliott Hughes
6b841db2ba Add POSIX-2008 fmemopen, open_memstream, and open_wmemstream.
Bug: 17164505
Change-Id: I59e28a08ff8b6ab632230b11a5807cfd5278aeb5
2014-08-20 17:03:46 -07:00
Dan Albert
1aec7c1a35 Proper MB_CUR_MAX.
Previously this was hard coded to 4. This is only the case for UTF-8
locales.

As a side effect, this properly reports C.UTF-8 as the default locale
instead of C.

Change-Id: I7c73cc8fe6ffac61d211cd5f75287e36de06f4fc
2014-07-30 17:09:46 -07:00
Dan Albert
8e613cf342 Remove declaration for putw(3)/getw(3).
These were both removed from POSIX 2004, and we don't define an
implementation for getw(3). Keep the definition of put(3) on LP32 for
binary compatibility.

Bug: 13935372
Change-Id: Iba384b45093ac6d2d7c2d81f7980cd7701dd6f56
2014-06-11 14:41:45 -07:00
Elliott Hughes
69f05d291d Fix the printf family for non-ASCII.
The bug here turned out to be that we hadn't increased the constant
corresponding to the maximum number of bytes in a character to match
our new implementation, so any character requiring more than a byte
in UTF-8 would break our printf family.

Bug: 15439554
Change-Id: I693e5e6eb11c640b5886e848502908ec5fff53b1
2014-06-05 23:19:15 -07:00
Christopher Ferris
9e01ea63a7 Fix dprintf test.
Change-Id: Ied783d545b6a35a70a158249f3957a9d00971627
2014-05-29 13:17:40 -07:00
Calin Juravle
6afb2a9a97 Add dprintf test
Change-Id: I0fe1b4d45c1312cf01deed6ce5db032d5513e908
2014-05-22 11:47:47 +01:00
Calin Juravle
9b95ea936a Document a known test issue in stdio_test.cpp.
Bug: 13077905
Change-Id: Iab7fc7be0737c732e26cc07ecd7884b3087b51bb
2014-05-15 10:34:06 +01:00
Elliott Hughes
c9244bdac1 Add tests for fprintf behavior when the underlying fd is bad.
Bug: 7229520
Change-Id: Ie878e0c13fdcda7b9131fa56208b84ed88125be7
2014-05-14 13:31:35 -07:00
Elliott Hughes
e77f38f14a Add a unit test for already-fixed printf -0.0 formatting.
This was fixed by the upgrade to upstream head.

Bug: 5084292
Change-Id: Ia3bda1c0bbe38f428e22213b8bdbdf1a16caccf2
2014-05-14 12:39:12 -07:00
Elliott Hughes
063525c61d Consistently use #if defined(__BIONIC__) in tests.
I've also switched some tests to be positive rather than negative,
because !defined is slightly harder to reason about and there are
only two cases: bionic and glibc.

Change-Id: I8d3ac40420ca5aead3e88c69cf293f267273c8ef
2014-05-13 11:19:57 -07:00
Calin Juravle
03e4ebee8d Add fpos_t tests.
Bug: 13077905

Change-Id: I86bb0ee95660f69f9971231c6f828a3a067d1ac8
2014-05-13 00:39:08 +01:00
Elliott Hughes
20f8aec897 Fix use-after-free errors in stdio_test.
fclose(3) frees the passed-in FILE*. We should close(2) the underlying fd,
not fclose(3) the stream, if we want to test what happens with a stream
we can't read from.

Bug: 14466691
Change-Id: I99fed5904b0266b9c6ae05d0b9cf2e926446c064
2014-05-12 15:15:37 -07:00
Elliott Hughes
ad534985ec Merge "Disable %n in printf and vfwprintf." 2014-05-05 21:49:22 +00:00
Elliott Hughes
e2341d08fa Disable %n in printf and vfwprintf.
Bug: 14492135
Change-Id: If190bede29e5f68a65043ddbe8e878c660933d03
2014-05-05 14:43:17 -07:00
Elliott Hughes
53b24382f5 Switch to current upstream OpenBSD wsetup.c.
Change-Id: I2c1123f3e1d3c4af7fd7bf354e763934a39b78c0
2014-05-05 14:31:20 -07:00
Elliott Hughes
0549371bd7 Upgrade to current vfprintf.
This gets us various bug fixes and missing C99 functionality.

Bug: https://code.google.com/p/android/issues/detail?id=64886
Change-Id: Ie9f8ac569e9b5eec1e4a1faacfe2c21662eaf895
2014-04-17 17:30:03 -07:00
Elliott Hughes
4bd97cee28 Switch to gdtoa.
This gives us a real strtold for LP64 and fixes various LP64
bugs.

Bug: 13563801
Change-Id: I277858d718ee746e136b6b6308a495ba50dfa488
2014-04-16 15:15:52 -07:00
Elliott Hughes
7823f320b1 Extra tests for printf of NaN and Inf.
Change-Id: I61fc655d9777a03aabf38f6ebd047fe275386f05
2014-04-14 12:11:28 -07:00
Alexander Ivchenko
edd7c2ec25 Fix the printf issue for 64 bits. The following case:
printf("%1$s %1$s\n", "test");

would print garbage instead of the second "test". The problem is __find_arguments
and the patch is a backport of two patches from OpenBSD that fix the issue:

Author: tedu <tedu@cvs.openbsd.org>
Date:   Sat Apr 29 23:00:24 2006 +0000

    check mmap for failure.  the helper functions using it return -1, but
    callers do not yet check since printf() for example is not documented
    to return an error.
    some formatting cleanups.
    mostly ok deraadt millert

Author: millert <millert@cvs.openbsd.org>
Date:   Fri May 16 14:28:54 2008 +0000

    C99 says that for each va_copy() there must be a matching va_end().
    Replace the non-portable hackery in __find_arguments() with a union.
    From FreeBSD.

Change-Id: I6ea392ce6fcf4a319ae6a67ec58cc52fe7cbe534
Signed-off-by: Alexander Ivchenko <alexander.ivchenko@intel.com>
2014-04-02 18:30:55 +04:00
Christopher Ferris
f171b34cf0 Use the float/double assert macros.
The normal ASSERT_EQ macros don't work quite right for float/double values,
and result in false failures. Use the correct macros instead.

Bug: 13511379
Change-Id: Ic2feee7f3d3569f57b6453b8fa95222846c625cd
2014-03-17 16:40:26 -07:00
Elliott Hughes
603332fc4c Upgrade to current upstream scanf implementation.
Also add a basic test.

Change-Id: Icc0e68a5716b9579244f6eb8bac1ab5a24eda85a
2014-03-12 17:10:41 -07:00
Christopher Ferris
f04935c85e Make sure that the same tests are on all platforms.
In order to be able to generate a list of tests for cts, the same set of
tests must exist across all platforms. This CL adds empty tests where a
test was conditionally compiled out.

This CL creates a single library libBionicTests that includes all of
the tests found in bionic-unit-tests-static.

Also fix a few missing include files in some test files.

Tested by running and compiling the tests for every platform and
verifying the same number of tests are on each platform.

Change-Id: I9989d4bfebb0f9c409a0ce7e87169299eac605a2
2014-02-06 20:12:21 -08:00
Elliott Hughes
6ad8f76f1f Don't abort in stdio.getdelim_invalid and stdio.getline_invalid.
Change-Id: Ie1aefed732f4bea77887bddd1be9a0578e247aa3
2013-12-19 14:56:17 -08:00
Christopher Ferris
cbd85b9cc1 Modify tests for another glibc difference.
It turns out that when passing a closed file to getdelim or getline, the
functions in glibc will properly return a failure, but errno might not be
set. Skip the errno check except on bionic.

Change-Id: I8d625f15303d4c2d42e8d28491ea8a368aea4d32
2013-11-15 16:09:44 -08:00
Christopher Ferris
13613137bc Fix up failing glibc tests.
There is a known bug running clone with the CLONE_VM flag, so for host
create an empty test.

Change the expected output of the stdio test for a glibc difference.

Change the pause test to use ScopedSignalHandler to setup/restore the SIGALRM
handler.

After this, running bionic-unit-tests-glibc passes for all tests.

Bug: 11389824

Change-Id: Ib304eae4164115835a54991dfdca5821ecc3db5e
2013-10-29 14:55:11 -07:00
Elliott Hughes
925753aa11 Fix some test assumptions that are wrong for __LP64__.
Change-Id: Ic79cd5858ceb611640a76bd03f3da4925d3150d9
2013-10-18 13:17:18 -07:00
Stephen Hines
6c7b3cb056 Fix clang warnings in bionic.
This fixes a few diverse issues that clang warns on in bionic. First,
it specifies the appropriate converted types for format specifiers.
The "h" and "hh" modifiers specify that the user is passing a short or
char respectively. We were passing int deliberately in both cases and
relying on the compiler to implicitly downcast to the smaller type.
We also remove the non-standard "d" suffix from our double-precision
floating point constant. This is an extension for gcc that clang does
not implement. The third fix is to mark the c1 variable as unused,
since it truly is neither read nor written.

Change-Id: I4793352b9d3e58f1f4cac9e7581ef4b2a70b43c7
2013-10-11 16:20:08 -07:00
Elliott Hughes
7248a2d4d0 Add a unit test for %n.
Change-Id: I9335e089d66c98d34577f5e1d1a54b8f507b94f6
2013-09-24 18:01:33 -07:00
Elliott Hughes
1d13c64d78 Fix %hhd formats in the printf family.
Found by adapting the simple unit tests for libc logging to test
snprintf too. Fix taken from upstream OpenBSD without updating
the rest of stdio.

Change-Id: Ie339a8e9393a36080147aae4d6665118e5d93647
2013-09-23 16:02:39 -07:00
Elliott Hughes
6b05c8e280 Start moving to current FreeBSD stdio.
This only touches the easy stuff.

Change-Id: Iecee57f1681dba5c56bff59f0e9a89811a71f0ca
2013-04-11 13:55:01 -07:00
Elliott Hughes
b6e22482d4 Let bionic use the correct definition of ssize_t.
Bug: 8253769
Change-Id: I50c7cc20828fc089b83580e039ce9153a6c5a8cc
2013-03-08 15:28:52 -08:00
Elliott Hughes
6b3f49a537 Upgrade to current NetBSD popen/pclose.
This gets us back to using vfork now our ARM vfork assembler stub is
fixed, and adds the missing thread safety for the 'pidlist'.

Bug: 5335385
Change-Id: Ib08bfa65b2cb9fa695717aae629ea14816bf988d
2013-03-06 16:20:55 -08:00
Elliott Hughes
e255642dc1 Avoid changing the C++ ABI with ssize_t.
Bug: 8253769
Change-Id: Ia325003ed6e59da553e2bdde7c43515bc191b8ba
2013-02-28 10:51:31 -08:00
Thorsten Glaser
c641cafbc3 use architecture-specific ssize_t definition
after change 32822 was rejected, this is the more light-weight
version of the fix: libc/include/sys/types.h already - via
libc/kernel/common/linux/posix_types.h - includes a definition
of __kernel_ssize_t from libc/kernel/arch-*/asm/posix_types.h
which is architecture-specific, toolchain-agnostic and also
gets rid of the gcc -Wformat warning (which it issues correctly,
since this i̲s̲ indeed a bug in bionic)

Change-Id: Ie4503ab16628bc25815a836d07556f665e9795c7
2013-02-19 14:12:55 -08:00
Elliott Hughes
5e3fc43dde Fix __pthread_clone on ARM to set errno on failure.
MIPS and x86 appear to have been correct already.

(Also fix unit tests that ASSERT_EQ with errno so that the
arguments are in the retarded junit order.)

Bug: 3461078
Change-Id: I2418ea98927b56e15b4ba9cfec97f5e7094c6291
2013-02-11 16:39:10 -08:00
Irina Tirdea
eac9eb462e Add getdelim(3) and getline(3) to bionic
Some userspace programs (e.g. perf) need getline.

Changes:
() add getdelim.c, getline.c from NetBSD (http://netbsd.org/) under the
NetBSD Foundation's (TNF) license ("2 clause" Berkeley-style license).
() add stub for reentrant.h header that is needed by getdelim.c
() add tests for getdelim(3) and getline(3).
() update NOTICE file.

Change-Id: I22ed82dd5904b9d7a3695535c04f502be3c27c5d
Signed-off-by: Irina Tirdea <irina.tirdea@intel.com>
2012-09-27 11:38:57 -07:00
Elliott Hughes
91875dcd6e Fix tmpfile(3).
This could be better, but at least now it works.

Change-Id: I88b7cf3f7ce8e5fa0b3fe678b7d1679a68ffffc9
2012-09-26 12:02:17 -07:00