path: root/base
AgeCommit message (Collapse)Author
2015-11-02Merge "Make Join support string delimiters"Casey Dahlin
2015-11-02Make Join support string delimitersCasey Dahlin
We've needed this several times in the past. Change-Id: I7324e8083fe2ff1aa0bf392a8c124fc2f3bb26e2 Test: Full android build Signed-off-by: Casey Dahlin <>
2015-11-02Fix ParseInt/ParseUint to handle explicit "0x" hex.Elliott Hughes
Also improve fastboot error reporting around max-download-size. Change-Id: Ic3aec9460de01e5264a2803a0a6be3706d73026b
2015-10-20Fix lseek argument order.Elliott Hughes
Change-Id: I12feed2de8a4e0782f90609254a3e2ec66d7d98e
2015-09-21base logging: fix errno restoring, severity conditionality, dangling ifsSpencer Low
Fix LOG() to properly save and restore errno. Test this properly. Only do logging if severity is >= the minimum. Fix dangling if statements in CHECK(), CHECK_STR{EQ,NE}(). Test this properly. Fix base logging tests on Windows. All libbase_tests now pass on Windows. Change place to lock, so the lock can protect logging of all data in LogMessage. Change-Id: I7ff531c67ae10a99ef0a2bbfe279aa77282d5ae9 Signed-off-by: Spencer Low <>
2015-09-11libbase_test: get it building for WindowsSpencer Low
Add to whitelist. For some reason, when compiling, parseint_test.cpp would encounter errors like the following: host cross C++: host_cross_libbase_test <= system/core/base/parseint_test.cpp In file included from external/gtest/include/gtest/gtest.h:1929:0, from system/core/base/parseint_test.cpp:19: system/core/base/parseint_test.cpp: In member function ‘virtual void parseint_signed_smoke_Test::TestBody()’: external/gtest/include/gtest/internal/gtest-internal.h:133:55: error: converting ‘false’ to pointer type for argument 1 of ‘char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)’ [-Werror=conversion-null] (sizeof(::testing::internal::IsNullLiteralHelper(x)) == 1) ^ external/gtest/include/gtest/gtest_pred_impl.h:77:52: note: in definition of macro ‘GTEST_ASSERT_’ if (const ::testing::AssertionResult gtest_ar = (expression)) \ ^ external/gtest/include/gtest/gtest_pred_impl.h:166:3: note: in expansion of macro ‘GTEST_PRED_FORMAT2_’ GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_FATAL_FAILURE_) ^ external/gtest/include/gtest/gtest.h:1993:3: note: in expansion of macro ‘ASSERT_PRED_FORMAT2’ ASSERT_PRED_FORMAT2(::testing::internal:: \ ^ external/gtest/include/gtest/gtest.h:1994:32: note: in expansion of macro ‘GTEST_IS_NULL_LITERAL_’ EqHelper<GTEST_IS_NULL_LITERAL_(expected)>::Compare, \ ^ external/gtest/include/gtest/gtest.h:2011:32: note: in expansion of macro ‘GTEST_ASSERT_EQ’ # define ASSERT_EQ(val1, val2) GTEST_ASSERT_EQ(val1, val2) ^ system/core/base/parseint_test.cpp:23:3: note: in expansion of macro ‘ASSERT_EQ’ ASSERT_EQ(false, android::base::ParseInt("x", &i)); ^ For whatever reason, the gcc for Windows isn't handling the template metaprogramming correctly, so to work-around the issue, I search-and-replaced "ASSERT_EQ(false, " to "ASSERT_FALSE(" and "ASSERT_EQ(true, " to "ASSERT_TRUE(" and that seems to compile just fine for Linux and Windows (and the tests pass on both platforms). Change-Id: I05132909d1f4b18afff23139652a218649689f2d Signed-off-by: Spencer Low <>
2015-09-11Merge "Ensure that libbase and liblog can be built for Windows."Dan Albert
2015-09-11Ensure that libbase and liblog can be built for Windows.Stephen Hines
Change-Id: If4adf1e2bd7ec36a7f02ae2e263d2db5187c6e7b
2015-09-04Add ParseInt (and ParseUint).Elliott Hughes
strtol and family are hard to use correctly, and most callers don't even try. Change-Id: I2833622a92cccd4662c0c5bdbbef5eeb4e496914
2015-09-02Remove USE_MINGW/CYGWIN; Whitelist windows modulesDan Willemsen
CYGWIN is not supported, USE_MINGW and HOST_OS==windows are being replaced with LOCAL_..._windows variables. Bug: 23566667 Change-Id: I3e4a1e4097dc994cf5abdce6939e83a91758fd75
2015-09-01adb/base win32 tests: fix comment and open() flagsSpencer Low
Match base's use of O_BINARY. Change-Id: I930b5c8fddde20966580069f2e681b99cb26f1a3 Signed-off-by: Spencer Low <>
2015-09-01Use O_BINARY in base/file for Windows.Elliott Hughes
This matches the behavior of the google3/Chrome APIs. It's probably what you want in all cases except where you plan on calling Split(content, "\n"), but we should probably have something like simpleperf's LineReader for that anyway. Change-Id: I1a128ed8c328bc95b0b2ef4068a65a8562721418
2015-08-13Fix the Mac libbase build.Elliott Hughes
Change-Id: I34224fa66850915ef47c88ef4c79efbc53f3f38e
2015-08-13libbase: logging fixesSpencer Low
Win32: - getprogname(): call basename() which is available in mingw's crt. Don't potentially go recursive with DCHECK_GT(). - Use Win32 critical section instead of mutex. Other: - Change log_characters check to compile-time. - Fix code that gets the basename of __FILE__. The previous code was not setting _file, so it didn't work. - Save and restore errno for LOG calls. Inspired by similar Chromium code. Change-Id: Ie7bb700918be726fa81d60177d1894d2daeff296 Signed-off-by: Spencer Low <>
2015-08-06win32: adb_test/libbase_test fixesSpencer Low
- My recent change with -DUNICODE=1 required changing GetProfilesDirectory() to GetProfilesDirectoryA() for the ANSI version of the API. - enh's edit to my previous change deleted a test that used /proc/version, but I think another test was missed. Merge that test into another. Change-Id: Ic748549848e7be922bcbf218d5b0c3fca2a90704 Signed-off-by: Spencer Low <>
2015-08-03adb_test/libbase_test: win32: get some tests workingSpencer Low
adb_test: * Fix adb_utils directory_exists test for Windows. The test actually fails because directory_exists() is not aware of junctions or symlinks, but I'm not really sure if that is a bad thing (since these are rare on Windows to begin with). * Fix crash during transport tests due to mutex not being initialized. * io tests fail for various reasons (see adb_io_test.cpp for more info). libbase_test: * Get it building on Win32 by implementing mkstemp() and mkdtemp(). * Run StringPrintf %z test on Windows because it passes because we build with __USE_MINGW_ANSI_STDIO which implements %z. * I didn't fixup the logging tests: some logging tests fail because when abort() is called on Windows, by default it pops up UI asking whether a crash dump should be sent to Microsoft. To some degree this makes sense, as I think LOG(FATAL) does crash dumping in Chromium. This should be revisited in the future. Change-Id: Iaa2433e5294ff162e0b2aa9fe6e4ec09a6893f7a Signed-off-by: Spencer Low <>
2015-08-03libbase_test: win32: get some tests workingSpencer Low
* Get it building on Win32 by implementing mkstemp() and mkdtemp(). * Run StringPrintf %z test on Windows because it passes because we build with __USE_MINGW_ANSI_STDIO which implements %z. Change-Id: Ia01f94e8258503381a1df6d3da6e40de59e57125 Signed-off-by: Spencer Low <>
2015-07-30Write mkdirs in more idiomatic C++ style.Alex Vallée
~ Rewrote mkdirs to be in C++ style. ~ Replaced adb_dir{start,stop} with std::string params and (r)find. + Added test for mkdirs. Also make base/test_utils.h public and support temporary directories as well as files. Change-Id: I6fcbdc5e0099f3359d3aac6b00c436f250ca1329
2015-07-09Revert "Turn on -Wformat-nonliteral."Dan Albert
One of my build aliases doesn't play nice with USE_MINGW=1, so my build lied to me. Will revert until I fix it up. This reverts commit 459df8f3a14d4c614f0211049800cf7cad6d30ad. Change-Id: I7905c5ae5ee85fb2d228ce63d81c79f140998c18
2015-07-09Turn on -Wformat-nonliteral.Dan Albert
Apparently there are two classes of this warning in clang. -Wformat-security is only emitted for cases of `func(nonliteral_fmt_string)` (no args), and -Wformat-nonliteral is emitted for cases *with* arguments. For whatever reason, the latter isn't included in -Wextra and must be manually enabled. To make this more easily portable to Windows, move the existing gnu_printf/__printf__ decision into base/macros.h as ATTRIBUTE_FORMAT. Change-Id: I3b0990e1d1f0a2e9c13b32f5cd60478946cb5fc6
2015-05-22Generalize Join to work for any container/element.Dan Albert
This is more scalable than explicitly instantiating templates for the cross product of containers and element types. Specifically I'm adding this so I can join an unordered_set in adb. Change-Id: I0055f3390a0ff26a886a0d41bbf0d4fe3d210f9c
2015-05-20Merge "adb / libbase: clean up NOGDI and evil ERROR macro"Dan Albert
2015-05-20adb / libbase: clean up NOGDI and evil ERROR macroSpencer Low
Instead of defining and undefining NOGDI: 1. Always #include "base/logging.h" after #include <windows.h>. Unfortunately, I could not find an easy way to give the user a warning/error if they include in the wrong order. 2. base/logging.h does #undef ERROR to undefine the evil ERROR macro that is from another era and probably a bad idea to begin with. Change-Id: I995d89620611e849af9d7ec47eb55fc0512377f2 Signed-off-by: Spencer Low <>
2015-05-20Don't use TEMP_FAILURE_RETRY on close()Nick Kralevich
See for details. Bug: 20501816 Change-Id: I38bf5052f44034c6f866d10d7d07187f0053a7a1
2015-05-13adb: win32: fix StringPrintf format string checking of %zd and PRIu64Spencer Low
At runtime, vsnprintf (and android::base::StringPrintf which calls it) call a mingw version of vsnprintf, not the vsnprintf from MSVCRT.DLL. The mingw version properly understands %zd and PRIu64 (the latter, provided that you #include <inttypes.h>). The problem was that android::base::StringPrintf was causing compile-time errors saying that %zd and PRIu64 were not recognized. It seems that this was because the attribute on the function prototypes specified `printf' instead of `gnu_printf'. Once that was fixed to match vsnprintf's attribute, the warnings went away. This uses similar preprocessor techniques as <android/log.h>. Also restore a %zd usage to avoid a static_cast<>, and make print_transfer_progress()'s format string compile-time checkable (and tweak some types and %llu => PRIu64). Change-Id: I80b31b9994858a28cb7c6847143b86108b8ab842 Signed-off-by: Spencer Low <>
2015-05-06adb: win32: fix adb emu commandSpencer Low
The adb emu command was never working because the socket connection to the emulator was closed without reading all of the data that the emulator sent. On Windows, this caused the emulator's recv() call to error-out, so it never got the command that was sent. Before settling on this fix, I also experimented changing the arguments to the socket shutdown() call and that didn't seem to help. I also tried removing the call to shutdown() and that didn't help. So that should rule out shutdown() as the problem. One experiment that helped was delaying before calling adb_close(), but that is of course fragile and doesn't address the real issue, which is not closing the socket until the commands have been read. Change-Id: I8fa4d740a2faa2c9922ec50792e16564a94f6eed Signed-off-by: Spencer Low <>
2015-05-04Add additional shielding against the ERROR macro.Dan Albert
Including the logging header with ERROR defined will always be a problem, so check for it explicitly. Move the NOGDI define from logging.cpp to logging.h since the standard library headers might be including windows.h, pulling in ERROR. Change-Id: Ib426973d2f1840710c0bf0e0cfb2420d0d322e27
2015-04-30Fix comparison between signed and unsigned error on darwinColin Cross
mode_t is a uint16_t on darwin, which causes sb.st_mode & ~S_IFMT to produce an int when the uint16_t is promoted for the operator. Cast to unsigned int before comparing against 0660U. Change-Id: Ib1439c08d9e2b297eeeba701891508d269c19a3d
2015-04-29Support base::logging on Windows.Dan Albert
libc++ doesn't support std::mutex and friends for Windows yet, so we just use a compatibility wrapper for now. Change-Id: I2413d4c089e7d0fb232444043c6b772153035dab
2015-04-29Get libbase tests working on Windows.Dan Albert
Tests using files from /proc still fail on Windows (obviously), but all tests are passing when run in Wine. Change-Id: Ie4c3ba65b642202f8fcaec73332a53bee6115fba
2015-04-29Print strerror instead of errno in tests.Dan Albert
Change-Id: Ibfab1b7cd439fdb5ae19855cc700613c00d4aff8
2015-04-27Remove strtok from adb.Elliott Hughes
Also fix android::base::Split to behave like Java, Python, and google3. Change-Id: Ifbffd4e92950a79e7aea5d153c95fe0980648417
2015-04-24Add ReadFully and WriteFully to libbase.Elliott Hughes
Change-Id: I6b7aa2a93398e7acdd1d74c71d9abed08a72b3c4
2015-04-17Fix comment typo.Elliott Hughes
Change-Id: I2d7082c44123e90d74b2669ab29d787b9aa64863
2015-04-09Add base/memory.h.Dan Albert
Right now this only includes an API for unaligned reads/writes. Change-Id: Ieb42498aa17cbd1035b66c51bd1c4f16fa2acfdb
2015-04-03Cleanup base/logging.Dan Albert
Some of this code was unused, most didn't need to be exposed, and we can just use basename(3). Also use a better default program name than "unknown". Change-Id: I62d990f64e4fd0c16aa4b7e907dd06e4f26ddcdd
2015-04-03Support arbitrary loggers.Dan Albert
While the defaults (logd or stderr) make sense for most use cases, there are places that can only log to the kernel, or need to log to a file, etc. Allow the user to pass in an arbitrary logging object, and provide LogdLogger and StderrLogger as defaults. Change-Id: I62368acc795ff313242bb205d65017404bf64e88
2015-04-03Support logging to other log buffers.Dan Albert
LOGTO(dest, severity) and PLOGTO(dest, severity) log to other log buffers. For example, `LOGTO(SYSTEM, FATAL) << "Foobar";`. Change-Id: Id1ca1c8fdae72d69b73945ae9b006525d0be1582
2015-04-03Merge "Remove LogMessage::LogLineLowStack."Dan Albert
2015-04-02Remove LogMessage::LogLineLowStack.Dan Albert
This was ported over from ART, but even they only use it in a single place. Change-Id: Ia34dc54b56c764ede79b2957bf3dc8df0f1323ee
2015-04-02Don't show lint errors for rvalue references.Dan Albert
Change-Id: Ic936c9e3778303d1d26813b844ccd3bb26701550
2015-03-30Enable building libbase on Windows.Dan Albert
We have to exclude the logging facilities for now (since we don't have a std::mutex on Windows), but there's plenty else in here that is worth having. Change-Id: I6d1369e34e08ea2e88a0b1130c4462e5d35d99e2
2015-03-27Merge "Pull in Windows compatibility header."Dan Albert
2015-03-26Pull in Windows compatibility header.Dan Albert
Needed for O_CLOEXEC, O_NOFOLLOW, and DEFFILEMODE. Change-Id: Id6c0465a6559c30ac8c085c28be0d47c9738f02a
2015-03-26Include what we use.Dan Albert
Change-Id: If510431d3d445de94f781b4fdec2e1b445f7c294
2015-03-23Move gettid() into libcutils.Dan Albert
Change-Id: Ic8a15036833e6d129b7998d954b804be391de399
2015-03-23Update string Split API.Dan Albert
Return a new vector rather than appending to the parameter. Delimiters are also a string rather than a character. Split on any character in the string. Change-Id: I039b332ace5578590df9e7ca0e8fa3db28db30a3
2015-03-20Add google3 style logging to libbase.Dan Albert
ART already had a flavor of this, but it was specialized for their use case a bit. Note that the logging.* tests are currently disabled for the device because there is no good way to capture the output of liblog. We can make something that will execute logcat and then then scan the output, but that's messy. Since we know it at least works on the host, we can add better device tests later. Change-Id: I47acd87a3312c0a5285b03f9c8dadef0c669f06a
2015-03-19Use mingw on Windows.Dan Albert
LOCAL_CLANG := true is a no-op on Linux/Darwin host builds, but apparently moves Windows binaries from mingw to clang, which is completely untested. Change-Id: Ibbc468d4a19a9e36bbcb93aa030fcc771af020ba
2015-03-16Add common string utilities to libbase.Dan Albert
These are useful outside of ART. Nothing changed (aside from fixing Trim to not segfault on empty strings), so ART should be able to move to using these. Change-Id: Id026ebffe8d31f784a91834786ab189680b13a0f