summaryrefslogtreecommitdiffstats
path: root/base
Commit message (Collapse)AuthorAgeFilesLines
* libbase: add ConsumePrefix/ConsumeSuffix.Elliott Hughes2020-03-132-0/+33
| | | | | | | | | | | | adb was already using ConsumePrefix, and now we have another would-be user in cutils. (There appears to be one place in adb that should use ConsumeSuffix, so I'm assuming we'll want that sooner or later.) I've kept these inline because adb and google3's versions both were, and I'm easily led. Test: treehugger Change-Id: I29d99032f6f6ccbfaefece59725db8afb02a4c87
* Fix leak of mapped zip central directoriesRyan Mitchell2019-05-281-1/+1
| | | | | | | | | | | | Memory mapping the central directory of specific APKs caused memory mappings to build up over time because they were never unmapped correctly. This is because MappedFile is not calling munmap with the size of the data after aligning the mmap offset to a page boundary. Bug: 133463863 Test: install APKs and verify that the entire mapped CD is unmaped Test: ran aapt2 as daemon and confirmed that mapped CD is unmapped Change-Id: Icb6cfebe0e8d67160fee34c5e6423d0f05de526b
* Disallow operator!() on unique_fdBernie Innocenti2019-03-281-0/+3
| | | | | | | | | | | | | | This catches a common mistake where client code checks for errors using the common idiom that works for std::iostream and other file-like classes: unique_fd fd = open(...); if (!fd) { } Test: atest libbase_test Test: m droid Change-Id: I9629a7795537ecb3b57be9c741c06f80967e4cc2
* Merge changes from topic "lpdumpd"Yifan Hong2019-03-261-1/+6
|\ | | | | | | | | | | | | | | * changes: libbase: realpath is wrapped with TEMP_FAILURE_RETRY liblp: Replace open with GetControlFileOrOpen init: expand prop in 'file' libcutils: android_get_control_file uses realpath.
| * libbase: realpath is wrapped with TEMP_FAILURE_RETRYYifan Hong2019-03-221-1/+6
| | | | | | | | | | | | | | | | | | Although man page for realpath doesn't say so, the bionic implementation of realpath may exit with error code EINTR. In such cases, retry. Test: boots (sanity) Change-Id: Ic5feb7152374a81bd2f475ad74c4bc8c3afb3a20
* | [base] Convert Starts/Ends/Equals string functions to string_viewYurii Zubrytskyi2019-03-212-53/+22
|/ | | | | | Test: UTs Change-Id: I3751656d44e7a814488169c53d3e8af0da44f262
* Support zero-length mapped filesPirama Arumuga Nainar2019-03-071-1/+8
| | | | | | | | | Bug: http://b/119818070 "app crashes when reading asset of zero length" Add support for zero-length mappings for the Windows code path as well. Test: ran libbase_test on Windows under wine. Change-Id: Iccb65fa800c636444100c9369f41e36d24a53a99
* Hopefully fix more darwin build breakage.Josh Gao2019-02-191-11/+34
| | | | | | | | | Silence narrowing warnings by manually casting to a smaller type, convert static_asserts to CHECKs, and switch from using MSG_CMSG_CLOEXEC to manually setting FD_CLOEXEC. Test: mma Change-Id: I8aa02804179d754de860279fe34773800b937ab6
* Fix darwin build break.Josh Gao2019-02-191-1/+0
| | | | | | | The <malloc.h> include was vestigial from a previous revision. Test: mma on linux Change-Id: Iaf8351bec23c2792cefca0e5c9bd42664488f5c4
* Merge changes from topic "base_cmsg"Josh Gao2019-02-195-0/+524
|\ | | | | | | | | | | | | * changes: adb: switch to base::{Send,Receive}FileDescriptors. debuggerd: switch to base::{Send,Receive}FileDescriptors. base: add helpers for sending/receiving file descriptors.
| * base: add helpers for sending/receiving file descriptors.Josh Gao2019-02-135-0/+524
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Almost all of the uses of cmsg(3) in our source tree are wrong in at least one of the following ways: - not aligning the cmsg buffer - leaking fds if more fds are received than expected - blindly dereferencing CMSG_DATA without checking the header - using CMSG_SPACE instead of CMSG_LEN for .cmsg_len - using CMSG_LEN instead of CMSG_SPACE for .msg_controllen - using a length specified in number of fds instead of bytes Implement wrapper functions that implement this dumpster fire of an API correctly. Bug: http://b/122047630 Test: libbase_test32 Change-Id: I6ac34d67bbbf1bfa9727ab598248fc178ea19df9
* | base: add ScopedLockAssertion.Josh Gao2019-02-121-0/+38
|/ | | | | | | | | This is a useful helper for anyone that's using thread safety annotations alongside std::condition_variable, extract it from adb and move it to libbase. Test: mma Change-Id: Ic51e2f2a0e6a16628034b29d8ff32bf2155afccd
* MappedFile and FileMap should support zero-length mappings.Elliott Hughes2019-02-062-2/+20
| | | | | | Bug: http://b/119818070 "app crashes when reading asset of zero length" Test: ran tests Change-Id: Idd2ad6f6e72c8e445aff78a460fac96dea41c950
* base: don't overwrite errno in unique_fd::~unique_fd.Josh Gao2019-01-301-1/+5
| | | | | | | | | | | | unique_fd's destructor potentially mangling errno makes it difficult to use correctly in code that sets errno (or, in reality, it makes it so that errno values get randomly stomped upon if close actually sets errno, because no one accounts for this case). Preserve errno ourselves to avoid this. Test: treehugger Change-Id: Ib06e6f65866d86fff4032b2311021eaf9226a1af
* base: support optional flags in android::base::Pipe.Yabin Cui2019-01-181-6/+19
| | | | | | | | Bug: none Test: build and use it manually. Test: run libbase_tests. Change-Id: I50b5251e8da23ddce94711807859612bf890406b
* Libbase: NOLINT legacy unique_fd operator intAndreas Gampe2019-01-101-1/+1
| | | | | | | The use in implicit conversion is intentional. Test: m Change-Id: I6c756e772b274e8a525ba2ad792cc4a8e1fc0176
* Build libbase with _FILE_OFFSET_BITS=64.Elliott Hughes2018-12-191-0/+1
| | | | | | | | | | sehr points out that we already have two bugs caused by not doing this: file.cpp has a call to pread with an off64_t that gets truncated, and mapped_file.cpp does similar with mmap. Bug: N/A Test: ran tests Change-Id: Ia098a836457e5adf109541235ad71c0ad7219da8
* Add missing includes.Florian Mayer2018-12-061-0/+1
| | | | | Test: Builds. Change-Id: Ia8b79154902503cdd774dc3b4523466123b4324c
* Base: Explicitly set abort message on FATALAndreas Gampe2018-12-051-0/+8
| | | | | | | | | | | | | | | | | Currently bionic only stores the first invocation of android_set_abort_message, libbase splits the logging invocations into discrete lines, and liblog automatically calls bionic when fatal severity is used. This leads to only the first line of LOG(FATAL) being stored for tombstoned. Eagerly set the abort message directly before logging when the severity is FATAL. This ensures the complete message will be available. Bug: 120506942 Test: m Test: manual Change-Id: I104d6960a2b1f66f21f5ada383fb4ab0f35e96a9
* Merge "base: add more error-checking overloads for unique_fd."Josh Gao2018-12-031-0/+11
|\
| * base: add more error-checking overloads for unique_fd.Josh Gao2018-11-021-0/+11
| | | | | | | | | | | | | | | | unique_fd::operator int was a mistake... Bug: http://b/118818285 Test: treehugger Change-Id: I3775dd7b4666abec8b5ce2a43092d9601eb1128f
* | base: TemporaryDir add DoNotRemove() methodMark Salyzyn2018-11-142-0/+6
| | | | | | | | | | | | | | | | | | | | Recursively delete all contents in a temporary directory in the destructor. If the caller wants the contents preserved, then call DoNotRemove(). Test: compile Bug: 119313545 Change-Id: I3601c06334920055a60dd3074b249824f4d6f510
* | base: TemporaryDir rm -rf directory in destructorMark Salyzyn2018-11-141-6/+32
| | | | | | | | | | | | | | | | | | Recursively delete all contents in a temporary directory in the destructor. Test: compile Bug: 119313545 Change-Id: I9570a8591f4e51f8f4f1157e75ccc1b781f8a19d
* | base: Add sensitivity to TMPDIR environment for TemporaryDir and TemporaryFileMark Salyzyn2018-11-141-3/+6
| | | | | | | | | | | | Test: compile Bug: 119313545 Change-Id: I2917847f0e90df94d74f4bfc0b13fbc6a5f243c3
* | switch to using android-base/file.h instead of android-base/test_utils.hMark Salyzyn2018-11-143-4/+1
| | | | | | | | | | | | Test: compile Bug: 119313545 Change-Id: I4f7ad84743e974b4b4d1d7256088f6c8b749a237
* | base: move TemporaryFile and TemporaryDir to android-base/file.hMark Salyzyn2018-11-134-134/+136
| | | | | | | | | | | | | | | | | | | | Allow a wider legitimate audience to use TemporaryFile and TemporaryDir by moving them from android-base/test_utils.h to android-base/file.h. Test: compile Bug: 119313545 Change-Id: Ie558c5873ce5b3937914918b6bfb427e5b61d0da
* | libbase: add Fdopendir that takes a unique_fd.Mathieu Chartier2018-11-021-0/+12
|/ | | | | | | | | | | | | Using fdopendir with unique_fd correctly is more annoying than it should be, because fdopendir doesn't close the file descriptor received upon failure. Add an android::base::Fdopendir that does that handles the failure case. Bug: 118818285 Test: treehugger Change-Id: I5dbbe0eb82242bc7716f84735ffc7644febcfd65
* libbase: support char parameter in StartsWith/EndsWith.Yabin Cui2018-10-303-0/+22
| | | | | | Bug: 117568547 Test: run libbase_test. Change-Id: I5a6a412733c594f5a116f333b8e091d2d9f60e06
* libbase: a slightly cleaner solution to libbase's `off64_t` problem.Elliott Hughes2018-10-253-10/+25
| | | | | | | | | Given that I can't actually go back in time and just make bionic's `off_t` be 64-bit. Bug: N/A Test: builds Change-Id: Ic93336b07bffc0977bd0e9caad6a22ce29ca06ed
* Merge "libbase: quick fix for Mac build."Treehugger Robot2018-10-251-0/+5
|\
| * libbase: quick fix for Mac build.Elliott Hughes2018-10-251-0/+5
| | | | | | | | | | | | | | | | I'll come back for the better fix later... Bug: N/A Test: builds Change-Id: I967c2436cf5816cf9a0edcd3f04f307969e48bcb
* | Merge "libbase: add O_CLOEXEC to <android-base/file.h>."Elliott Hughes2018-10-252-2/+7
|\ \
| * | libbase: add O_CLOEXEC to <android-base/file.h>.Elliott Hughes2018-10-242-2/+7
| |/ | | | | | | | | | | | | | | We already expose O_BINARY, and O_CLOEXEC seems equally legitimate. Bug: N/A Test: builds Change-Id: I7f07e1bb2a5d6b5c5f293783c39ceab148fabefb
* / libbase: remove ARRAYSIZE_UNSAFE.Elliott Hughes2018-10-241-54/+14
|/ | | | | | | | Also fix the indentation of a neighboring comment. Bug: N/A Test: builds Change-Id: Iebe5f518b2ac14718f3cae91007e62b61bed9dc0
* Merge "Add a simple MappedFile to libbase and switch fastboot and ↵Elliott Hughes2018-10-244-0/+187
|\ | | | | | | libziparchive over."
| * Add a simple MappedFile to libbase and switch fastboot and libziparchive over.Elliott Hughes2018-10-234-0/+187
| | | | | | | | | | | | | | | | This allows us to remove libziparchive's dependency on libutils. Bug: http://b/79112958 Test: ran libbase and libziparchive tests, ran fastboot manually Change-Id: I95c651976dad222863e5b8c37d4514b778f5dce7
* | adb: rationalize fatal/error logging.Elliott Hughes2018-10-191-8/+3
|/ | | | | | | | | | | | | | | | | | | Let's use LOG(FATAL)/PLOG(FATAL) for actual fatal stuff. Add a Windows error(3) and move folks who didn't really mean "abort" fatal over to it. Also get rid of syntax_error which wasn't adding a lot of value, and most of the places it was adding "usage: " didn't seem entirely appropriate anyway. In particular, we seemed to have confused fastdeploy.cpp into aborting in most user error cases, and none of the reviewers noticed. Clearly we'd all lost track of far too many options. (I've also cleaned up a few random instances of fprintf(3) + exit(2).) Bug: N/A Test: manual Change-Id: I3e8440848a24e30d928de9eded505916bc324786
* Merge changes from topic "windows-libcxx"Pirama Arumuga Nainar2018-10-111-0/+1
|\ | | | | | | | | | | | | * changes: Do not enable -Wold-style-cast for Windows Add sys/types.h in utf8.h Adapt to switch to libc++ for Windows
| * Add sys/types.h in utf8.hPirama Arumuga Nainar2018-09-211-0/+1
| | | | | | | | | | | | | | | | | | Bug: http://b/91353691 It's needed for mode_t. Test: Build and test Windows modules under Wine. Change-Id: I3fa6b2946316a9bd2a0d800ae928ba5de480a283
* | Assert that ParseInt/ParseUint are only used with signed/unsigned numbers ↵Tom Cherry2018-10-051-0/+3
| | | | | | | | | | | | | | | | respectively Test: build fails when the signedness is mismatched Test: build succeeds otherwise Change-Id: Idd6b146cc167d4607eafc81dbad6c2a79b167094
* | Add noexcept to move constructors and assignment operators.Chih-Hung Hsieh2018-10-052-3/+3
| | | | | | | | | | | | Bug: 116614593 Test: build with WITH_TIDY=1 Change-Id: I5a7461386946ca623ab509609092aa0ac8418b80
* | Enable -Wexit-time-destructor for all targetsPirama Arumuga Nainar2018-09-261-2/+1
|/ | | | | | | This warning should be available for Windows as well. Test: mmma system/core/base Change-Id: Id2e7e4da2e5105870a8d1e10c793e4a54c5b3d04
* Suppress implicit-fallthrough warnings.Chih-Hung Hsieh2018-09-171-0/+2
| | | | | | | | Add FALLTHROUGH_INTENDED for clang compiler. Bug: 112564944 Test: build with global -Wimplicit-fallthrough. Change-Id: I40f8bbf94e207c9dd90921e9b762ba51abab5777
* Merge "Add Start/Stop/Reset to CapturedStdFd."Christopher Ferris2018-09-054-101/+161
|\
| * Add Start/Stop/Reset to CapturedStdFd.Christopher Ferris2018-09-044-101/+161
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Move the fd() function to be private since it should not have been exposed in the first place. Fix the way logging_test uses CapturedXXX. Adding this because the new isolated testing doesn't print errors to stderr so the ASSERT_ EXPECT_ messages can get swallowed. Also, it's easier to reuse a CapturedXXX object in a test with these functions. Test: New unit tests pass. Change-Id: I38b113fc184146ce434802f80a9b7997fa83e78a
* | libbase: add Fdopen that takes a unique_fd.Josh Gao2018-09-041-0/+12
|/ | | | | | | | | | | | | | | | | | | | Using fdopen with unique_fd correctly is more annoying than it should be, because fdopen doesn't close the file descriptor received upon failure, which means you have to something like the following: unique_fd ufd = ...; int fd = ufd.release(); FILE* file = fdopen(fd, "..."); if (!file) { close(fd); return; } Add an android::base::Fdopen that does that dance for you. Bug: http://b/113880863 Test: treehugger Change-Id: I6325acf1ff06484005c1053fe09672c5eeeecaa1
* Set errno for all error return cases.Christopher Ferris2018-08-292-4/+54
| | | | | Test: Updated unit tests pass. Change-Id: I2c1f14ed44ce144a46cb2866c146fca89a05539e
* Fix typo in parseint.untouched_on_failure testTom Cherry2018-08-231-1/+1
| | | | | | | | | This test means to check both that ParseInt() and ParseUint() do not change the result on failure, however it erroneously tested ParseInt() twice. Test: unit tests Change-Id: If534e2525827e19aba6cae0eef45668d57623efb
* Fix two ParseInt edge casesTom Cherry2018-08-222-0/+32
| | | | | | | | | | | | | | | 1) ParseInt and ParseUint accept strings that have spaces followed by a valid number, however the base check for determining hex numbers does not take this into account currently, but now does this this change. 2) ParseUint rejects negative numbers except in the case that the template argument is unsigned long long. That is a mistake; it should reject negative numbers in all cases and this change does that by rejecting any string with a - prefix. Bug: 112668205 Test: new (and old) unit tests Change-Id: I0179b42e50adc1b169cf0e6d830283b71210a029
* base: remove execute bit from utf8.hSpencer Low2018-08-111-0/+0
| | | | | | | | | I originally accidentally created this file with the execute bit on. Test: mma Change-Id: I8075ffdbb114475434ad48912a9dd24f19a9025b Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>