summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElliott Hughes2017-11-10 12:22:07 -0600
committerElliott Hughes2017-11-10 15:18:10 -0600
commit8e9aeb9053695a14539653093937158d15385ca6 (patch)
treeb02f7ad2149812eea2cb2802b7f238856b66619c
parent6707ef139d9786887649e3e3c2e3e251a95dc96d (diff)
downloadplatform-system-core-8e9aeb9053695a14539653093937158d15385ca6.tar.gz
platform-system-core-8e9aeb9053695a14539653093937158d15385ca6.tar.xz
platform-system-core-8e9aeb9053695a14539653093937158d15385ca6.zip
Move libcutils source to C++.
Just the minimial changes to get this to actually build, because otherwise we always bog down trying to rewrite everything (when the real answer is usually "stop using libcutils, it's awful"). This doesn't move a handful of files: two are basically just BSD libc source, a couple have outstanding code reviews, and one can be deleted (but I'll do that in a separate change). I'm also skipping the presubmit hooks because otherwise clang-format wants to reformat everything. I'll follow up with that... Bug: N/A Test: builds Change-Id: I06403f465b67c8e493bad466dd76b1151eed5993
-rw-r--r--libcutils/Android.bp48
-rw-r--r--libcutils/android_get_control_file.cpp5
-rw-r--r--libcutils/android_reboot.cpp (renamed from libcutils/android_reboot.c)6
-rw-r--r--libcutils/ashmem-dev.cpp (renamed from libcutils/ashmem-dev.c)10
-rw-r--r--libcutils/ashmem-host.cpp (renamed from libcutils/ashmem-host.c)11
-rw-r--r--libcutils/canned_fs_config.cpp (renamed from libcutils/canned_fs_config.c)8
-rw-r--r--libcutils/config_utils.cpp (renamed from libcutils/config_utils.c)11
-rw-r--r--libcutils/fs.cpp (renamed from libcutils/fs.c)36
-rw-r--r--libcutils/fs_config.cpp3
-rw-r--r--libcutils/hashmap.cpp (renamed from libcutils/hashmap.c)9
-rw-r--r--libcutils/include/cutils/android_reboot.h1
-rw-r--r--libcutils/include/cutils/partition_utils.h2
-rw-r--r--libcutils/include/cutils/record_stream.h1
-rw-r--r--libcutils/include/private/canned_fs_config.h4
-rw-r--r--libcutils/include/private/fs_config.h1
-rw-r--r--libcutils/iosched_policy.cpp (renamed from libcutils/iosched_policy.c)6
-rw-r--r--libcutils/klog.cpp3
-rw-r--r--libcutils/load_file.cpp (renamed from libcutils/load_file.c)2
-rw-r--r--libcutils/native_handle.cpp (renamed from libcutils/native_handle.c)2
-rw-r--r--libcutils/partition_utils.cpp (renamed from libcutils/partition_utils.c)2
-rw-r--r--libcutils/properties.cpp3
-rw-r--r--libcutils/qtaguid.cpp3
-rw-r--r--libcutils/record_stream.cpp (renamed from libcutils/record_stream.c)3
-rw-r--r--libcutils/sched_policy.cpp3
-rw-r--r--libcutils/socket_inaddr_any_server_unix.cpp (renamed from libcutils/socket_inaddr_any_server_unix.c)4
-rw-r--r--libcutils/socket_inaddr_any_server_windows.cpp (renamed from libcutils/socket_inaddr_any_server_windows.c)4
-rw-r--r--libcutils/socket_local_client_unix.cpp (renamed from libcutils/socket_local_client_unix.c)4
-rw-r--r--libcutils/socket_local_server_unix.cpp (renamed from libcutils/socket_local_server_unix.c)4
-rw-r--r--libcutils/socket_network_client_unix.cpp (renamed from libcutils/socket_network_client_unix.c)4
-rw-r--r--libcutils/socket_network_client_windows.cpp (renamed from libcutils/socket_network_client_windows.c)0
-rw-r--r--libcutils/sockets_unix.cpp3
-rw-r--r--libcutils/sockets_windows.cpp2
-rw-r--r--libcutils/str_parms.cpp (renamed from libcutils/str_parms.c)44
-rw-r--r--libcutils/strdup16to8.cpp (renamed from libcutils/strdup16to8.c)11
-rw-r--r--libcutils/strdup8to16.cpp (renamed from libcutils/strdup8to16.c)5
-rw-r--r--libcutils/tests/trace-dev_test.cpp2
-rw-r--r--libcutils/threads.cpp (renamed from libcutils/threads.c)2
-rw-r--r--libcutils/trace-container.cpp (renamed from libcutils/trace-container.c)2
-rw-r--r--libcutils/trace-dev.cpp (renamed from libcutils/trace-dev.c)2
-rw-r--r--libcutils/trace-host.cpp (renamed from libcutils/trace-host.c)0
40 files changed, 150 insertions, 126 deletions
diff --git a/libcutils/Android.bp b/libcutils/Android.bp
index 8fb3a52d7..a21d1caab 100644
--- a/libcutils/Android.bp
+++ b/libcutils/Android.bp
@@ -19,14 +19,14 @@
19// which are also hard or even impossible to port to native Win32 19// which are also hard or even impossible to port to native Win32
20libcutils_nonwindows_sources = [ 20libcutils_nonwindows_sources = [
21 "android_get_control_file.cpp", 21 "android_get_control_file.cpp",
22 "fs.c", 22 "fs.cpp",
23 "multiuser.c", 23 "multiuser.c",
24 "socket_inaddr_any_server_unix.c", 24 "socket_inaddr_any_server_unix.cpp",
25 "socket_local_client_unix.c", 25 "socket_local_client_unix.cpp",
26 "socket_local_server_unix.c", 26 "socket_local_server_unix.cpp",
27 "socket_network_client_unix.c", 27 "socket_network_client_unix.cpp",
28 "sockets_unix.cpp", 28 "sockets_unix.cpp",
29 "str_parms.c", 29 "str_parms.cpp",
30] 30]
31 31
32cc_library_headers { 32cc_library_headers {
@@ -56,21 +56,21 @@ cc_library {
56 }, 56 },
57 host_supported: true, 57 host_supported: true,
58 srcs: [ 58 srcs: [
59 "config_utils.c", 59 "config_utils.cpp",
60 "fs_config.cpp", 60 "fs_config.cpp",
61 "canned_fs_config.c", 61 "canned_fs_config.cpp",
62 "hashmap.c", 62 "hashmap.cpp",
63 "iosched_policy.c", 63 "iosched_policy.cpp",
64 "load_file.c", 64 "load_file.cpp",
65 "native_handle.c", 65 "native_handle.cpp",
66 "open_memstream.c", 66 "open_memstream.c",
67 "record_stream.c", 67 "record_stream.cpp",
68 "sched_policy.cpp", 68 "sched_policy.cpp",
69 "sockets.cpp", 69 "sockets.cpp",
70 "strdup16to8.c", 70 "strdup16to8.cpp",
71 "strdup8to16.c", 71 "strdup8to16.cpp",
72 "strlcpy.c", 72 "strlcpy.c",
73 "threads.c", 73 "threads.cpp",
74 ], 74 ],
75 75
76 target: { 76 target: {
@@ -83,14 +83,14 @@ cc_library {
83 }, 83 },
84 not_windows: { 84 not_windows: {
85 srcs: libcutils_nonwindows_sources + [ 85 srcs: libcutils_nonwindows_sources + [
86 "ashmem-host.c", 86 "ashmem-host.cpp",
87 "trace-host.c", 87 "trace-host.cpp",
88 ], 88 ],
89 }, 89 },
90 windows: { 90 windows: {
91 srcs: [ 91 srcs: [
92 "socket_inaddr_any_server_windows.c", 92 "socket_inaddr_any_server_windows.cpp",
93 "socket_network_client_windows.c", 93 "socket_network_client_windows.cpp",
94 "sockets_windows.cpp", 94 "sockets_windows.cpp",
95 ], 95 ],
96 96
@@ -105,13 +105,13 @@ cc_library {
105 105
106 android: { 106 android: {
107 srcs: libcutils_nonwindows_sources + [ 107 srcs: libcutils_nonwindows_sources + [
108 "android_reboot.c", 108 "android_reboot.cpp",
109 "ashmem-dev.c", 109 "ashmem-dev.cpp",
110 "klog.cpp", 110 "klog.cpp",
111 "partition_utils.c", 111 "partition_utils.cpp",
112 "properties.cpp", 112 "properties.cpp",
113 "qtaguid.cpp", 113 "qtaguid.cpp",
114 "trace-dev.c", 114 "trace-dev.cpp",
115 "uevent.cpp", 115 "uevent.cpp",
116 ], 116 ],
117 }, 117 },
diff --git a/libcutils/android_get_control_file.cpp b/libcutils/android_get_control_file.cpp
index 780d9f136..d8121f5cd 100644
--- a/libcutils/android_get_control_file.cpp
+++ b/libcutils/android_get_control_file.cpp
@@ -25,6 +25,9 @@
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28
29#include <cutils/android_get_control_file.h>
30
28#include <ctype.h> 31#include <ctype.h>
29#include <errno.h> 32#include <errno.h>
30#include <fcntl.h> 33#include <fcntl.h>
@@ -36,8 +39,6 @@
36#include <sys/types.h> 39#include <sys/types.h>
37#include <unistd.h> 40#include <unistd.h>
38 41
39#include <cutils/android_get_control_file.h>
40
41#include "android_get_control_env.h" 42#include "android_get_control_env.h"
42 43
43#ifndef TEMP_FAILURE_RETRY 44#ifndef TEMP_FAILURE_RETRY
diff --git a/libcutils/android_reboot.c b/libcutils/android_reboot.cpp
index 996d89d9b..5e864d442 100644
--- a/libcutils/android_reboot.c
+++ b/libcutils/android_reboot.cpp
@@ -13,10 +13,12 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16
17#include <cutils/android_reboot.h>
18
16#include <stdio.h> 19#include <stdio.h>
17#include <stdlib.h> 20#include <stdlib.h>
18 21
19#include <cutils/android_reboot.h>
20#include <cutils/properties.h> 22#include <cutils/properties.h>
21 23
22#define TAG "android_reboot" 24#define TAG "android_reboot"
@@ -26,7 +28,7 @@ int android_reboot(int cmd, int flags __unused, const char* arg) {
26 const char* restart_cmd = NULL; 28 const char* restart_cmd = NULL;
27 char* prop_value; 29 char* prop_value;
28 30
29 switch (cmd) { 31 switch (static_cast<unsigned>(cmd)) {
30 case ANDROID_RB_RESTART: // deprecated 32 case ANDROID_RB_RESTART: // deprecated
31 case ANDROID_RB_RESTART2: 33 case ANDROID_RB_RESTART2:
32 restart_cmd = "reboot"; 34 restart_cmd = "reboot";
diff --git a/libcutils/ashmem-dev.c b/libcutils/ashmem-dev.cpp
index 95f2259ec..15ace0e64 100644
--- a/libcutils/ashmem-dev.c
+++ b/libcutils/ashmem-dev.cpp
@@ -14,6 +14,8 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17#include <cutils/ashmem.h>
18
17/* 19/*
18 * Implementation of the user-space ashmem API for devices, which have our 20 * Implementation of the user-space ashmem API for devices, which have our
19 * ashmem-enabled kernel. See ashmem-sim.c for the "fake" tmp-based version, 21 * ashmem-enabled kernel. See ashmem-sim.c for the "fake" tmp-based version,
@@ -31,8 +33,6 @@
31#include <sys/sysmacros.h> 33#include <sys/sysmacros.h>
32#include <sys/types.h> 34#include <sys/types.h>
33#include <unistd.h> 35#include <unistd.h>
34
35#include <cutils/ashmem.h>
36#include <log/log.h> 36#include <log/log.h>
37 37
38#define ASHMEM_DEVICE "/dev/ashmem" 38#define ASHMEM_DEVICE "/dev/ashmem"
@@ -192,7 +192,8 @@ int ashmem_set_prot_region(int fd, int prot)
192 192
193int ashmem_pin_region(int fd, size_t offset, size_t len) 193int ashmem_pin_region(int fd, size_t offset, size_t len)
194{ 194{
195 struct ashmem_pin pin = { offset, len }; 195 // TODO: should LP64 reject too-large offset/len?
196 ashmem_pin pin = { static_cast<uint32_t>(offset), static_cast<uint32_t>(len) };
196 197
197 int ret = __ashmem_is_ashmem(fd, 1); 198 int ret = __ashmem_is_ashmem(fd, 1);
198 if (ret < 0) { 199 if (ret < 0) {
@@ -204,7 +205,8 @@ int ashmem_pin_region(int fd, size_t offset, size_t len)
204 205
205int ashmem_unpin_region(int fd, size_t offset, size_t len) 206int ashmem_unpin_region(int fd, size_t offset, size_t len)
206{ 207{
207 struct ashmem_pin pin = { offset, len }; 208 // TODO: should LP64 reject too-large offset/len?
209 ashmem_pin pin = { static_cast<uint32_t>(offset), static_cast<uint32_t>(len) };
208 210
209 int ret = __ashmem_is_ashmem(fd, 1); 211 int ret = __ashmem_is_ashmem(fd, 1);
210 if (ret < 0) { 212 if (ret < 0) {
diff --git a/libcutils/ashmem-host.c b/libcutils/ashmem-host.cpp
index 1f9f753e4..d2c28f393 100644
--- a/libcutils/ashmem-host.c
+++ b/libcutils/ashmem-host.cpp
@@ -14,6 +14,8 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17#include <cutils/ashmem.h>
18
17/* 19/*
18 * Implementation of the user-space ashmem API for the simulator, which lacks 20 * Implementation of the user-space ashmem API for the simulator, which lacks
19 * an ashmem-enabled kernel. See ashmem-dev.c for the real ashmem-based version. 21 * an ashmem-enabled kernel. See ashmem-dev.c for the real ashmem-based version.
@@ -31,7 +33,6 @@
31#include <time.h> 33#include <time.h>
32#include <unistd.h> 34#include <unistd.h>
33 35
34#include <cutils/ashmem.h>
35#include <utils/Compat.h> 36#include <utils/Compat.h>
36 37
37#ifndef __unused 38#ifndef __unused
@@ -40,12 +41,12 @@
40 41
41int ashmem_create_region(const char *ignored __unused, size_t size) 42int ashmem_create_region(const char *ignored __unused, size_t size)
42{ 43{
43 char template[PATH_MAX]; 44 char pattern[PATH_MAX];
44 snprintf(template, sizeof(template), "/tmp/android-ashmem-%d-XXXXXXXXX", getpid()); 45 snprintf(pattern, sizeof(pattern), "/tmp/android-ashmem-%d-XXXXXXXXX", getpid());
45 int fd = mkstemp(template); 46 int fd = mkstemp(pattern);
46 if (fd == -1) return -1; 47 if (fd == -1) return -1;
47 48
48 unlink(template); 49 unlink(pattern);
49 50
50 if (TEMP_FAILURE_RETRY(ftruncate(fd, size)) == -1) { 51 if (TEMP_FAILURE_RETRY(ftruncate(fd, size)) == -1) {
51 close(fd); 52 close(fd);
diff --git a/libcutils/canned_fs_config.c b/libcutils/canned_fs_config.cpp
index 819a846a6..6b5763b16 100644
--- a/libcutils/canned_fs_config.c
+++ b/libcutils/canned_fs_config.cpp
@@ -14,6 +14,10 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17#include <private/android_filesystem_config.h>
18#include <private/canned_fs_config.h>
19#include <private/fs_config.h>
20
17#include <errno.h> 21#include <errno.h>
18#include <inttypes.h> 22#include <inttypes.h>
19#include <limits.h> 23#include <limits.h>
@@ -22,10 +26,6 @@
22#include <stdlib.h> 26#include <stdlib.h>
23#include <string.h> 27#include <string.h>
24 28
25#include <private/android_filesystem_config.h>
26#include <private/fs_config.h>
27#include <private/canned_fs_config.h>
28
29typedef struct { 29typedef struct {
30 const char* path; 30 const char* path;
31 unsigned uid; 31 unsigned uid;
diff --git a/libcutils/config_utils.c b/libcutils/config_utils.cpp
index fc5ca7876..a3af01a58 100644
--- a/libcutils/config_utils.c
+++ b/libcutils/config_utils.cpp
@@ -14,20 +14,19 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17#include <cutils/config_utils.h>
18
17#include <string.h> 19#include <string.h>
18#include <ctype.h> 20#include <ctype.h>
19#include <stdlib.h> 21#include <stdlib.h>
20#include <fcntl.h> 22#include <fcntl.h>
21#include <unistd.h> 23#include <unistd.h>
22 24
23#include <cutils/config_utils.h>
24#include <cutils/misc.h> 25#include <cutils/misc.h>
25 26
26cnode* config_node(const char *name, const char *value) 27cnode* config_node(const char *name, const char *value)
27{ 28{
28 cnode *node; 29 cnode* node = static_cast<cnode*>(calloc(sizeof(cnode), 1));
29
30 node = calloc(sizeof(cnode), 1);
31 if(node) { 30 if(node) {
32 node->name = name ? name : ""; 31 node->name = name ? name : "";
33 node->value = value ? value : ""; 32 node->value = value ? value : "";
@@ -311,9 +310,9 @@ void config_load(cnode *root, char *data)
311 310
312void config_load_file(cnode *root, const char *fn) 311void config_load_file(cnode *root, const char *fn)
313{ 312{
314 char *data; 313 char* data = static_cast<char*>(load_file(fn, nullptr));
315 data = load_file(fn, 0);
316 config_load(root, data); 314 config_load(root, data);
315 // TODO: deliberate leak :-/
317} 316}
318 317
319void config_free(cnode *root) 318void config_free(cnode *root)
diff --git a/libcutils/fs.c b/libcutils/fs.cpp
index b253b1cd9..ef85accce 100644
--- a/libcutils/fs.c
+++ b/libcutils/fs.cpp
@@ -14,6 +14,8 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17#include <cutils/fs.h>
18
17#define LOG_TAG "cutils" 19#define LOG_TAG "cutils"
18 20
19/* These defines are only needed because prebuilt headers are out of date */ 21/* These defines are only needed because prebuilt headers are out of date */
@@ -32,7 +34,6 @@
32#include <sys/types.h> 34#include <sys/types.h>
33#include <unistd.h> 35#include <unistd.h>
34 36
35#include <cutils/fs.h>
36#include <log/log.h> 37#include <log/log.h>
37 38
38#define ALL_PERMS (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO) 39#define ALL_PERMS (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO)
@@ -40,6 +41,11 @@
40 41
41static int fs_prepare_path_impl(const char* path, mode_t mode, uid_t uid, gid_t gid, 42static int fs_prepare_path_impl(const char* path, mode_t mode, uid_t uid, gid_t gid,
42 int allow_fixup, int prepare_as_dir) { 43 int allow_fixup, int prepare_as_dir) {
44 // TODO: fix the goto hell below.
45 int type_ok;
46 int owner_match;
47 int mode_match;
48
43 // Check if path needs to be created 49 // Check if path needs to be created
44 struct stat sb; 50 struct stat sb;
45 int create_result = -1; 51 int create_result = -1;
@@ -53,14 +59,14 @@ static int fs_prepare_path_impl(const char* path, mode_t mode, uid_t uid, gid_t
53 } 59 }
54 60
55 // Exists, verify status 61 // Exists, verify status
56 int type_ok = prepare_as_dir ? S_ISDIR(sb.st_mode) : S_ISREG(sb.st_mode); 62 type_ok = prepare_as_dir ? S_ISDIR(sb.st_mode) : S_ISREG(sb.st_mode);
57 if (!type_ok) { 63 if (!type_ok) {
58 ALOGE("Not a %s: %s", (prepare_as_dir ? "directory" : "regular file"), path); 64 ALOGE("Not a %s: %s", (prepare_as_dir ? "directory" : "regular file"), path);
59 return -1; 65 return -1;
60 } 66 }
61 67
62 int owner_match = ((sb.st_uid == uid) && (sb.st_gid == gid)); 68 owner_match = ((sb.st_uid == uid) && (sb.st_gid == gid));
63 int mode_match = ((sb.st_mode & ALL_PERMS) == mode); 69 mode_match = ((sb.st_mode & ALL_PERMS) == mode);
64 if (owner_match && mode_match) { 70 if (owner_match && mode_match) {
65 return 0; 71 return 0;
66 } else if (allow_fixup) { 72 } else if (allow_fixup) {
@@ -188,23 +194,20 @@ fail_closed:
188#ifndef __APPLE__ 194#ifndef __APPLE__
189 195
190int fs_mkdirs(const char* path, mode_t mode) { 196int fs_mkdirs(const char* path, mode_t mode) {
191 int res = 0; 197 if (*path != '/') {
192 int fd = 0; 198 ALOGE("Relative paths are not allowed: %s", path);
193 struct stat sb; 199 return -EINVAL;
194 char* buf = strdup(path);
195
196 if (*buf != '/') {
197 ALOGE("Relative paths are not allowed: %s", buf);
198 res = -EINVAL;
199 goto done;
200 } 200 }
201 201
202 if ((fd = open("/", 0)) == -1) { 202 int fd = open("/", 0);
203 if (fd == -1) {
203 ALOGE("Failed to open(/): %s", strerror(errno)); 204 ALOGE("Failed to open(/): %s", strerror(errno));
204 res = -errno; 205 return -errno;
205 goto done;
206 } 206 }
207 207
208 struct stat sb;
209 int res = 0;
210 char* buf = strdup(path);
208 char* segment = buf + 1; 211 char* segment = buf + 1;
209 char* p = segment; 212 char* p = segment;
210 while (*p != '\0') { 213 while (*p != '\0') {
@@ -266,7 +269,6 @@ int fs_mkdirs(const char* path, mode_t mode) {
266 269
267done_close: 270done_close:
268 close(fd); 271 close(fd);
269done:
270 free(buf); 272 free(buf);
271 return res; 273 return res;
272} 274}
diff --git a/libcutils/fs_config.cpp b/libcutils/fs_config.cpp
index 7603ffce6..f45472e7e 100644
--- a/libcutils/fs_config.cpp
+++ b/libcutils/fs_config.cpp
@@ -14,6 +14,8 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17#include <private/fs_config.h>
18
17// This file is used to define the properties of the filesystem 19// This file is used to define the properties of the filesystem
18// images generated by build tools (mkbootfs and mkyaffs2image) and 20// images generated by build tools (mkbootfs and mkyaffs2image) and
19// by the device side of adb. 21// by the device side of adb.
@@ -31,7 +33,6 @@
31 33
32#include <log/log.h> 34#include <log/log.h>
33#include <private/android_filesystem_config.h> 35#include <private/android_filesystem_config.h>
34#include <private/fs_config.h>
35#include <utils/Compat.h> 36#include <utils/Compat.h>
36 37
37#ifndef O_BINARY 38#ifndef O_BINARY
diff --git a/libcutils/hashmap.c b/libcutils/hashmap.cpp
index ede3b981d..65b6ab185 100644
--- a/libcutils/hashmap.c
+++ b/libcutils/hashmap.cpp
@@ -15,6 +15,7 @@
15 */ 15 */
16 16
17#include <cutils/hashmap.h> 17#include <cutils/hashmap.h>
18
18#include <assert.h> 19#include <assert.h>
19#include <errno.h> 20#include <errno.h>
20#include <cutils/threads.h> 21#include <cutils/threads.h>
@@ -45,7 +46,7 @@ Hashmap* hashmapCreate(size_t initialCapacity,
45 assert(hash != NULL); 46 assert(hash != NULL);
46 assert(equals != NULL); 47 assert(equals != NULL);
47 48
48 Hashmap* map = malloc(sizeof(Hashmap)); 49 Hashmap* map = static_cast<Hashmap*>(malloc(sizeof(Hashmap)));
49 if (map == NULL) { 50 if (map == NULL) {
50 return NULL; 51 return NULL;
51 } 52 }
@@ -58,7 +59,7 @@ Hashmap* hashmapCreate(size_t initialCapacity,
58 map->bucketCount <<= 1; 59 map->bucketCount <<= 1;
59 } 60 }
60 61
61 map->buckets = calloc(map->bucketCount, sizeof(Entry*)); 62 map->buckets = static_cast<Entry**>(calloc(map->bucketCount, sizeof(Entry*)));
62 if (map->buckets == NULL) { 63 if (map->buckets == NULL) {
63 free(map); 64 free(map);
64 return NULL; 65 return NULL;
@@ -106,7 +107,7 @@ static void expandIfNecessary(Hashmap* map) {
106 if (map->size > (map->bucketCount * 3 / 4)) { 107 if (map->size > (map->bucketCount * 3 / 4)) {
107 // Start off with a 0.33 load factor. 108 // Start off with a 0.33 load factor.
108 size_t newBucketCount = map->bucketCount << 1; 109 size_t newBucketCount = map->bucketCount << 1;
109 Entry** newBuckets = calloc(newBucketCount, sizeof(Entry*)); 110 Entry** newBuckets = static_cast<Entry**>(calloc(newBucketCount, sizeof(Entry*)));
110 if (newBuckets == NULL) { 111 if (newBuckets == NULL) {
111 // Abort expansion. 112 // Abort expansion.
112 return; 113 return;
@@ -171,7 +172,7 @@ int hashmapHash(void* key, size_t keySize) {
171} 172}
172 173
173static Entry* createEntry(void* key, int hash, void* value) { 174static Entry* createEntry(void* key, int hash, void* value) {
174 Entry* entry = malloc(sizeof(Entry)); 175 Entry* entry = static_cast<Entry*>(malloc(sizeof(Entry)));
175 if (entry == NULL) { 176 if (entry == NULL) {
176 return NULL; 177 return NULL;
177 } 178 }
diff --git a/libcutils/include/cutils/android_reboot.h b/libcutils/include/cutils/android_reboot.h
index a903adba3..99030eddd 100644
--- a/libcutils/include/cutils/android_reboot.h
+++ b/libcutils/include/cutils/android_reboot.h
@@ -17,6 +17,7 @@
17#ifndef __CUTILS_ANDROID_REBOOT_H__ 17#ifndef __CUTILS_ANDROID_REBOOT_H__
18#define __CUTILS_ANDROID_REBOOT_H__ 18#define __CUTILS_ANDROID_REBOOT_H__
19 19
20#include <sys/cdefs.h>
20 21
21__BEGIN_DECLS 22__BEGIN_DECLS
22 23
diff --git a/libcutils/include/cutils/partition_utils.h b/libcutils/include/cutils/partition_utils.h
index 72ca80d35..7518559a4 100644
--- a/libcutils/include/cutils/partition_utils.h
+++ b/libcutils/include/cutils/partition_utils.h
@@ -17,6 +17,8 @@
17#ifndef __CUTILS_PARTITION_WIPED_H__ 17#ifndef __CUTILS_PARTITION_WIPED_H__
18#define __CUTILS_PARTITION_WIPED_H__ 18#define __CUTILS_PARTITION_WIPED_H__
19 19
20#include <sys/cdefs.h>
21
20__BEGIN_DECLS 22__BEGIN_DECLS
21 23
22int partition_wiped(char *source); 24int partition_wiped(char *source);
diff --git a/libcutils/include/cutils/record_stream.h b/libcutils/include/cutils/record_stream.h
index bfac87a53..bcfc80d5d 100644
--- a/libcutils/include/cutils/record_stream.h
+++ b/libcutils/include/cutils/record_stream.h
@@ -25,6 +25,7 @@
25extern "C" { 25extern "C" {
26#endif 26#endif
27 27
28#include <stddef.h>
28 29
29typedef struct RecordStream RecordStream; 30typedef struct RecordStream RecordStream;
30 31
diff --git a/libcutils/include/private/canned_fs_config.h b/libcutils/include/private/canned_fs_config.h
index 71e1537b2..135b91c6c 100644
--- a/libcutils/include/private/canned_fs_config.h
+++ b/libcutils/include/private/canned_fs_config.h
@@ -19,8 +19,12 @@
19 19
20#include <inttypes.h> 20#include <inttypes.h>
21 21
22__BEGIN_DECLS
23
22int load_canned_fs_config(const char* fn); 24int load_canned_fs_config(const char* fn);
23void canned_fs_config(const char* path, int dir, const char* target_out_path, unsigned* uid, 25void canned_fs_config(const char* path, int dir, const char* target_out_path, unsigned* uid,
24 unsigned* gid, unsigned* mode, uint64_t* capabilities); 26 unsigned* gid, unsigned* mode, uint64_t* capabilities);
25 27
28__END_DECLS
29
26#endif 30#endif
diff --git a/libcutils/include/private/fs_config.h b/libcutils/include/private/fs_config.h
index aab504281..892649187 100644
--- a/libcutils/include/private/fs_config.h
+++ b/libcutils/include/private/fs_config.h
@@ -24,6 +24,7 @@
24 24
25#include <stdint.h> 25#include <stdint.h>
26#include <sys/cdefs.h> 26#include <sys/cdefs.h>
27#include <sys/types.h>
27 28
28#if defined(__BIONIC__) 29#if defined(__BIONIC__)
29#include <linux/capability.h> 30#include <linux/capability.h>
diff --git a/libcutils/iosched_policy.c b/libcutils/iosched_policy.cpp
index 13c2cebbc..012c537ac 100644
--- a/libcutils/iosched_policy.c
+++ b/libcutils/iosched_policy.cpp
@@ -14,6 +14,8 @@
14** limitations under the License. 14** limitations under the License.
15*/ 15*/
16 16
17#include <cutils/iosched_policy.h>
18
17#include <errno.h> 19#include <errno.h>
18#include <fcntl.h> 20#include <fcntl.h>
19#include <stdio.h> 21#include <stdio.h>
@@ -21,8 +23,6 @@
21#include <string.h> 23#include <string.h>
22#include <unistd.h> 24#include <unistd.h>
23 25
24#include <cutils/iosched_policy.h>
25
26#if defined(__ANDROID__) 26#if defined(__ANDROID__)
27#define IOPRIO_WHO_PROCESS (1) 27#define IOPRIO_WHO_PROCESS (1)
28#define IOPRIO_CLASS_SHIFT (13) 28#define IOPRIO_CLASS_SHIFT (13)
@@ -49,7 +49,7 @@ int android_get_ioprio(int pid __android_unused, IoSchedClass *clazz, int *iopri
49 return -1; 49 return -1;
50 } 50 }
51 51
52 *clazz = (rc >> IOPRIO_CLASS_SHIFT); 52 *clazz = static_cast<IoSchedClass>(rc >> IOPRIO_CLASS_SHIFT);
53 *ioprio = (rc & 0xff); 53 *ioprio = (rc & 0xff);
54#else 54#else
55 *clazz = IoSchedClass_NONE; 55 *clazz = IoSchedClass_NONE;
diff --git a/libcutils/klog.cpp b/libcutils/klog.cpp
index d301276f9..6a9f4df8a 100644
--- a/libcutils/klog.cpp
+++ b/libcutils/klog.cpp
@@ -14,6 +14,8 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17#include <cutils/klog.h>
18
17#include <errno.h> 19#include <errno.h>
18#include <fcntl.h> 20#include <fcntl.h>
19#include <stdarg.h> 21#include <stdarg.h>
@@ -25,7 +27,6 @@
25#include <unistd.h> 27#include <unistd.h>
26 28
27#include <cutils/android_get_control_file.h> 29#include <cutils/android_get_control_file.h>
28#include <cutils/klog.h>
29 30
30static int klog_level = KLOG_INFO_LEVEL; 31static int klog_level = KLOG_INFO_LEVEL;
31 32
diff --git a/libcutils/load_file.c b/libcutils/load_file.cpp
index 99f2965ae..346105c5c 100644
--- a/libcutils/load_file.c
+++ b/libcutils/load_file.cpp
@@ -15,6 +15,8 @@
15** limitations under the License. 15** limitations under the License.
16*/ 16*/
17 17
18#include <cutils/misc.h>
19
18#include <stdlib.h> 20#include <stdlib.h>
19#include <unistd.h> 21#include <unistd.h>
20#include <fcntl.h> 22#include <fcntl.h>
diff --git a/libcutils/native_handle.c b/libcutils/native_handle.cpp
index 95bbc41c4..66f7a3d59 100644
--- a/libcutils/native_handle.c
+++ b/libcutils/native_handle.cpp
@@ -45,7 +45,7 @@ native_handle_t* native_handle_create(int numFds, int numInts) {
45 } 45 }
46 46
47 size_t mallocSize = sizeof(native_handle_t) + (sizeof(int) * (numFds + numInts)); 47 size_t mallocSize = sizeof(native_handle_t) + (sizeof(int) * (numFds + numInts));
48 native_handle_t* h = malloc(mallocSize); 48 native_handle_t* h = static_cast<native_handle_t*>(malloc(mallocSize));
49 if (h) { 49 if (h) {
50 h->version = sizeof(native_handle_t); 50 h->version = sizeof(native_handle_t);
51 h->numFds = numFds; 51 h->numFds = numFds;
diff --git a/libcutils/partition_utils.c b/libcutils/partition_utils.cpp
index 823b16289..6735d6cc8 100644
--- a/libcutils/partition_utils.c
+++ b/libcutils/partition_utils.cpp
@@ -14,6 +14,8 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17#include <cutils/partition_utils.h>
18
17#include <fcntl.h> 19#include <fcntl.h>
18#include <sys/ioctl.h> 20#include <sys/ioctl.h>
19#include <sys/mount.h> /* for BLKGETSIZE */ 21#include <sys/mount.h> /* for BLKGETSIZE */
diff --git a/libcutils/properties.cpp b/libcutils/properties.cpp
index 25ff1a3ad..5dbbeba48 100644
--- a/libcutils/properties.cpp
+++ b/libcutils/properties.cpp
@@ -14,6 +14,8 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17#include <cutils/properties.h>
18
17#define LOG_TAG "properties" 19#define LOG_TAG "properties"
18// #define LOG_NDEBUG 0 20// #define LOG_NDEBUG 0
19 21
@@ -25,7 +27,6 @@
25#include <string.h> 27#include <string.h>
26#include <unistd.h> 28#include <unistd.h>
27 29
28#include <cutils/properties.h>
29#include <cutils/sockets.h> 30#include <cutils/sockets.h>
30#include <log/log.h> 31#include <log/log.h>
31 32
diff --git a/libcutils/qtaguid.cpp b/libcutils/qtaguid.cpp
index 86a5dc4b3..b94d134be 100644
--- a/libcutils/qtaguid.cpp
+++ b/libcutils/qtaguid.cpp
@@ -14,6 +14,8 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17#include <cutils/qtaguid.h>
18
17// #define LOG_NDEBUG 0 19// #define LOG_NDEBUG 0
18 20
19#define LOG_TAG "qtaguid" 21#define LOG_TAG "qtaguid"
@@ -26,7 +28,6 @@
26#include <string.h> 28#include <string.h>
27#include <unistd.h> 29#include <unistd.h>
28 30
29#include <cutils/qtaguid.h>
30#include <log/log.h> 31#include <log/log.h>
31 32
32class netdHandler { 33class netdHandler {
diff --git a/libcutils/record_stream.c b/libcutils/record_stream.cpp
index 2bc4226ed..5a86b8393 100644
--- a/libcutils/record_stream.c
+++ b/libcutils/record_stream.cpp
@@ -15,11 +15,12 @@
15** limitations under the License. 15** limitations under the License.
16*/ 16*/
17 17
18#include <cutils/record_stream.h>
19
18#include <stdlib.h> 20#include <stdlib.h>
19#include <unistd.h> 21#include <unistd.h>
20#include <assert.h> 22#include <assert.h>
21#include <errno.h> 23#include <errno.h>
22#include <cutils/record_stream.h>
23#include <string.h> 24#include <string.h>
24#include <stdint.h> 25#include <stdint.h>
25#if defined(_WIN32) 26#if defined(_WIN32)
diff --git a/libcutils/sched_policy.cpp b/libcutils/sched_policy.cpp
index b00fa8561..0e6d33333 100644
--- a/libcutils/sched_policy.cpp
+++ b/libcutils/sched_policy.cpp
@@ -14,6 +14,8 @@
14** limitations under the License. 14** limitations under the License.
15*/ 15*/
16 16
17#include <cutils/sched_policy.h>
18
17#define LOG_TAG "SchedPolicy" 19#define LOG_TAG "SchedPolicy"
18 20
19#include <errno.h> 21#include <errno.h>
@@ -24,7 +26,6 @@
24#include <unistd.h> 26#include <unistd.h>
25 27
26#include <log/log.h> 28#include <log/log.h>
27#include <cutils/sched_policy.h>
28 29
29#define UNUSED __attribute__((__unused__)) 30#define UNUSED __attribute__((__unused__))
30 31
diff --git a/libcutils/socket_inaddr_any_server_unix.c b/libcutils/socket_inaddr_any_server_unix.cpp
index 387258fdf..27c5333f3 100644
--- a/libcutils/socket_inaddr_any_server_unix.c
+++ b/libcutils/socket_inaddr_any_server_unix.cpp
@@ -14,6 +14,8 @@
14** limitations under the License. 14** limitations under the License.
15*/ 15*/
16 16
17#include <cutils/sockets.h>
18
17#include <errno.h> 19#include <errno.h>
18#include <stddef.h> 20#include <stddef.h>
19#include <stdlib.h> 21#include <stdlib.h>
@@ -25,8 +27,6 @@
25#include <sys/types.h> 27#include <sys/types.h>
26#include <netinet/in.h> 28#include <netinet/in.h>
27 29
28#include <cutils/sockets.h>
29
30#define LISTEN_BACKLOG 4 30#define LISTEN_BACKLOG 4
31 31
32/* open listen() port on any interface */ 32/* open listen() port on any interface */
diff --git a/libcutils/socket_inaddr_any_server_windows.c b/libcutils/socket_inaddr_any_server_windows.cpp
index c15200ad5..1d7320698 100644
--- a/libcutils/socket_inaddr_any_server_windows.c
+++ b/libcutils/socket_inaddr_any_server_windows.cpp
@@ -26,10 +26,10 @@
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28 28
29#include <errno.h>
30
31#include <cutils/sockets.h> 29#include <cutils/sockets.h>
32 30
31#include <errno.h>
32
33#define LISTEN_BACKLOG 4 33#define LISTEN_BACKLOG 4
34 34
35extern bool initialize_windows_sockets(); 35extern bool initialize_windows_sockets();
diff --git a/libcutils/socket_local_client_unix.c b/libcutils/socket_local_client_unix.cpp
index 92fb9f17d..68b2b0ce9 100644
--- a/libcutils/socket_local_client_unix.c
+++ b/libcutils/socket_local_client_unix.cpp
@@ -14,14 +14,14 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17#include <cutils/sockets.h>
18
17#include <errno.h> 19#include <errno.h>
18#include <stddef.h> 20#include <stddef.h>
19#include <stdlib.h> 21#include <stdlib.h>
20#include <string.h> 22#include <string.h>
21#include <unistd.h> 23#include <unistd.h>
22 24
23#include <cutils/sockets.h>
24
25#if defined(_WIN32) 25#if defined(_WIN32)
26 26
27int socket_local_client(const char *name, int namespaceId, int type) 27int socket_local_client(const char *name, int namespaceId, int type)
diff --git a/libcutils/socket_local_server_unix.c b/libcutils/socket_local_server_unix.cpp
index db9e1e04d..855e5da4e 100644
--- a/libcutils/socket_local_server_unix.c
+++ b/libcutils/socket_local_server_unix.cpp
@@ -94,7 +94,7 @@ int socket_local_server_bind(int s, const char *name, int namespaceId)
94 * Returns fd on success, -1 on fail 94 * Returns fd on success, -1 on fail
95 */ 95 */
96 96
97int socket_local_server(const char *name, int namespace, int type) 97int socket_local_server(const char *name, int namespaceId, int type)
98{ 98{
99 int err; 99 int err;
100 int s; 100 int s;
@@ -102,7 +102,7 @@ int socket_local_server(const char *name, int namespace, int type)
102 s = socket(AF_LOCAL, type, 0); 102 s = socket(AF_LOCAL, type, 0);
103 if (s < 0) return -1; 103 if (s < 0) return -1;
104 104
105 err = socket_local_server_bind(s, name, namespace); 105 err = socket_local_server_bind(s, name, namespaceId);
106 106
107 if (err < 0) { 107 if (err < 0) {
108 close(s); 108 close(s);
diff --git a/libcutils/socket_network_client_unix.c b/libcutils/socket_network_client_unix.cpp
index 1b87c49be..be3c53575 100644
--- a/libcutils/socket_network_client_unix.c
+++ b/libcutils/socket_network_client_unix.cpp
@@ -14,6 +14,8 @@
14** limitations under the License. 14** limitations under the License.
15*/ 15*/
16 16
17#include <cutils/sockets.h>
18
17#include <errno.h> 19#include <errno.h>
18#include <fcntl.h> 20#include <fcntl.h>
19#include <stddef.h> 21#include <stddef.h>
@@ -27,8 +29,6 @@
27#include <netinet/in.h> 29#include <netinet/in.h>
28#include <netdb.h> 30#include <netdb.h>
29 31
30#include <cutils/sockets.h>
31
32static int toggle_O_NONBLOCK(int s) { 32static int toggle_O_NONBLOCK(int s) {
33 int flags = fcntl(s, F_GETFL); 33 int flags = fcntl(s, F_GETFL);
34 if (flags == -1 || fcntl(s, F_SETFL, flags ^ O_NONBLOCK) == -1) { 34 if (flags == -1 || fcntl(s, F_SETFL, flags ^ O_NONBLOCK) == -1) {
diff --git a/libcutils/socket_network_client_windows.c b/libcutils/socket_network_client_windows.cpp
index ab1a52f74..ab1a52f74 100644
--- a/libcutils/socket_network_client_windows.c
+++ b/libcutils/socket_network_client_windows.cpp
diff --git a/libcutils/sockets_unix.cpp b/libcutils/sockets_unix.cpp
index e91f35831..2849aa886 100644
--- a/libcutils/sockets_unix.cpp
+++ b/libcutils/sockets_unix.cpp
@@ -14,6 +14,8 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17#include <cutils/sockets.h>
18
17#define LOG_TAG "socket-unix" 19#define LOG_TAG "socket-unix"
18 20
19#include <stdio.h> 21#include <stdio.h>
@@ -26,7 +28,6 @@
26#include <unistd.h> 28#include <unistd.h>
27 29
28#include <cutils/android_get_control_file.h> 30#include <cutils/android_get_control_file.h>
29#include <cutils/sockets.h>
30#include <log/log.h> 31#include <log/log.h>
31 32
32#include "android_get_control_env.h" 33#include "android_get_control_env.h"
diff --git a/libcutils/sockets_windows.cpp b/libcutils/sockets_windows.cpp
index 3064c70e5..3e49b85b4 100644
--- a/libcutils/sockets_windows.cpp
+++ b/libcutils/sockets_windows.cpp
@@ -37,7 +37,7 @@
37// Both adb (1) and Chrome (2) purposefully avoid WSACleanup() with no issues. 37// Both adb (1) and Chrome (2) purposefully avoid WSACleanup() with no issues.
38// (1) https://android.googlesource.com/platform/system/core.git/+/master/adb/sysdeps_win32.cpp 38// (1) https://android.googlesource.com/platform/system/core.git/+/master/adb/sysdeps_win32.cpp
39// (2) https://code.google.com/p/chromium/codesearch#chromium/src/net/base/winsock_init.cc 39// (2) https://code.google.com/p/chromium/codesearch#chromium/src/net/base/winsock_init.cc
40extern "C" bool initialize_windows_sockets() { 40bool initialize_windows_sockets() {
41 // There's no harm in calling WSAStartup() multiple times but no benefit 41 // There's no harm in calling WSAStartup() multiple times but no benefit
42 // either, we may as well skip it after the first. 42 // either, we may as well skip it after the first.
43 static bool init_success = false; 43 static bool init_success = false;
diff --git a/libcutils/str_parms.c b/libcutils/str_parms.cpp
index 8dafdedac..139d62f6d 100644
--- a/libcutils/str_parms.c
+++ b/libcutils/str_parms.cpp
@@ -14,6 +14,8 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17#include <cutils/str_parms.h>
18
17#define LOG_TAG "str_params" 19#define LOG_TAG "str_params"
18//#define LOG_NDEBUG 0 20//#define LOG_NDEBUG 0
19 21
@@ -26,7 +28,6 @@
26 28
27#include <cutils/hashmap.h> 29#include <cutils/hashmap.h>
28#include <cutils/memory.h> 30#include <cutils/memory.h>
29#include <cutils/str_parms.h>
30#include <log/log.h> 31#include <log/log.h>
31 32
32#define UNUSED __attribute__((unused)) 33#define UNUSED __attribute__((unused))
@@ -62,30 +63,24 @@ __attribute__((no_sanitize("integer")))
62static int str_hash_fn(void *str) 63static int str_hash_fn(void *str)
63{ 64{
64 uint32_t hash = 5381; 65 uint32_t hash = 5381;
65 char *p;
66 66
67 for (p = str; p && *p; p++) 67 for (char* p = static_cast<char*>(str); p && *p; p++)
68 hash = ((hash << 5) + hash) + *p; 68 hash = ((hash << 5) + hash) + *p;
69 return (int)hash; 69 return (int)hash;
70} 70}
71 71
72struct str_parms *str_parms_create(void) 72struct str_parms *str_parms_create(void)
73{ 73{
74 struct str_parms *str_parms; 74 str_parms* s = static_cast<str_parms*>(calloc(1, sizeof(str_parms)));
75 if (!s) return NULL;
75 76
76 str_parms = calloc(1, sizeof(struct str_parms)); 77 s->map = hashmapCreate(5, str_hash_fn, str_eq);
77 if (!str_parms) 78 if (!s->map) {
79 free(s);
78 return NULL; 80 return NULL;
81 }
79 82
80 str_parms->map = hashmapCreate(5, str_hash_fn, str_eq); 83 return s;
81 if (!str_parms->map)
82 goto err;
83
84 return str_parms;
85
86err:
87 free(str_parms);
88 return NULL;
89} 84}
90 85
91struct remove_ctxt { 86struct remove_ctxt {
@@ -95,7 +90,7 @@ struct remove_ctxt {
95 90
96static bool remove_pair(void *key, void *value, void *context) 91static bool remove_pair(void *key, void *value, void *context)
97{ 92{
98 struct remove_ctxt *ctxt = context; 93 remove_ctxt* ctxt = static_cast<remove_ctxt*>(context);
99 bool should_continue; 94 bool should_continue;
100 95
101 /* 96 /*
@@ -109,7 +104,7 @@ static bool remove_pair(void *key, void *value, void *context)
109 if (!ctxt->key) { 104 if (!ctxt->key) {
110 should_continue = true; 105 should_continue = true;
111 goto do_remove; 106 goto do_remove;
112 } else if (!strcmp(ctxt->key, key)) { 107 } else if (!strcmp(ctxt->key, static_cast<const char*>(key))) {
113 should_continue = false; 108 should_continue = false;
114 goto do_remove; 109 goto do_remove;
115 } 110 }
@@ -292,9 +287,8 @@ int str_parms_has_key(struct str_parms *str_parms, const char *key) {
292int str_parms_get_str(struct str_parms *str_parms, const char *key, char *val, 287int str_parms_get_str(struct str_parms *str_parms, const char *key, char *val,
293 int len) 288 int len)
294{ 289{
295 char *value; 290 // TODO: hashmapGet should take a const* key.
296 291 char* value = static_cast<char*>(hashmapGet(str_parms->map, (void*)key));
297 value = hashmapGet(str_parms->map, (void *)key);
298 if (value) 292 if (value)
299 return strlcpy(val, value, len); 293 return strlcpy(val, value, len);
300 294
@@ -303,10 +297,10 @@ int str_parms_get_str(struct str_parms *str_parms, const char *key, char *val,
303 297
304int str_parms_get_int(struct str_parms *str_parms, const char *key, int *val) 298int str_parms_get_int(struct str_parms *str_parms, const char *key, int *val)
305{ 299{
306 char *value;
307 char *end; 300 char *end;
308 301
309 value = hashmapGet(str_parms->map, (void *)key); 302 // TODO: hashmapGet should take a const* key.
303 char* value = static_cast<char*>(hashmapGet(str_parms->map, (void*)key));
310 if (!value) 304 if (!value)
311 return -ENOENT; 305 return -ENOENT;
312 306
@@ -321,10 +315,10 @@ int str_parms_get_float(struct str_parms *str_parms, const char *key,
321 float *val) 315 float *val)
322{ 316{
323 float out; 317 float out;
324 char *value;
325 char *end; 318 char *end;
326 319
327 value = hashmapGet(str_parms->map, (void *)key); 320 // TODO: hashmapGet should take a const* key.
321 char* value = static_cast<char*>(hashmapGet(str_parms->map, (void*)(key)));
328 if (!value) 322 if (!value)
329 return -ENOENT; 323 return -ENOENT;
330 324
@@ -338,7 +332,7 @@ int str_parms_get_float(struct str_parms *str_parms, const char *key,
338 332
339static bool combine_strings(void *key, void *value, void *context) 333static bool combine_strings(void *key, void *value, void *context)
340{ 334{
341 char **old_str = context; 335 char** old_str = static_cast<char**>(context);
342 char *new_str; 336 char *new_str;
343 int ret; 337 int ret;
344 338
diff --git a/libcutils/strdup16to8.c b/libcutils/strdup16to8.cpp
index 4dc987e41..d89181e14 100644
--- a/libcutils/strdup16to8.c
+++ b/libcutils/strdup16to8.cpp
@@ -15,10 +15,10 @@
15** limitations under the License. 15** limitations under the License.
16*/ 16*/
17 17
18#include <limits.h> /* for SIZE_MAX */
19
20#include <cutils/jstring.h> 18#include <cutils/jstring.h>
19
21#include <assert.h> 20#include <assert.h>
21#include <limits.h> /* for SIZE_MAX */
22#include <stdlib.h> 22#include <stdlib.h>
23 23
24 24
@@ -145,14 +145,11 @@ extern char* strncpy16to8(char* utf8Str, const char16_t* utf16Str, size_t len)
145 */ 145 */
146char * strndup16to8 (const char16_t* s, size_t n) 146char * strndup16to8 (const char16_t* s, size_t n)
147{ 147{
148 char* ret;
149 size_t len;
150
151 if (s == NULL) { 148 if (s == NULL) {
152 return NULL; 149 return NULL;
153 } 150 }
154 151
155 len = strnlen16to8(s, n); 152 size_t len = strnlen16to8(s, n);
156 153
157 /* We are paranoid, and we check for SIZE_MAX-1 154 /* We are paranoid, and we check for SIZE_MAX-1
158 * too since it is an overflow value for our 155 * too since it is an overflow value for our
@@ -161,7 +158,7 @@ char * strndup16to8 (const char16_t* s, size_t n)
161 if (len >= SIZE_MAX-1) 158 if (len >= SIZE_MAX-1)
162 return NULL; 159 return NULL;
163 160
164 ret = malloc(len + 1); 161 char* ret = static_cast<char*>(malloc(len + 1));
165 if (ret == NULL) 162 if (ret == NULL)
166 return NULL; 163 return NULL;
167 164
diff --git a/libcutils/strdup8to16.c b/libcutils/strdup8to16.cpp
index c23cf8b9a..d1e51b9ca 100644
--- a/libcutils/strdup8to16.c
+++ b/libcutils/strdup8to16.cpp
@@ -16,9 +16,10 @@
16*/ 16*/
17 17
18#include <cutils/jstring.h> 18#include <cutils/jstring.h>
19
19#include <assert.h> 20#include <assert.h>
20#include <stdlib.h>
21#include <limits.h> 21#include <limits.h>
22#include <stdlib.h>
22 23
23/* See http://www.unicode.org/reports/tr22/ for discussion 24/* See http://www.unicode.org/reports/tr22/ for discussion
24 * on invalid sequences 25 * on invalid sequences
@@ -116,7 +117,7 @@ static inline uint32_t getUtf32FromUtf8(const char** pUtf8Ptr)
116 int i; 117 int i;
117 118
118 /* Mask for leader byte for lengths 1, 2, 3, and 4 respectively*/ 119 /* Mask for leader byte for lengths 1, 2, 3, and 4 respectively*/
119 static const char leaderMask[4] = {0xff, 0x1f, 0x0f, 0x07}; 120 static const unsigned char leaderMask[4] = {0xff, 0x1f, 0x0f, 0x07};
120 121
121 /* Bytes that start with bits "10" are not leading characters. */ 122 /* Bytes that start with bits "10" are not leading characters. */
122 if (((**pUtf8Ptr) & 0xc0) == 0x80) { 123 if (((**pUtf8Ptr) & 0xc0) == 0x80) {
diff --git a/libcutils/tests/trace-dev_test.cpp b/libcutils/tests/trace-dev_test.cpp
index edf981b39..f8d4f0064 100644
--- a/libcutils/tests/trace-dev_test.cpp
+++ b/libcutils/tests/trace-dev_test.cpp
@@ -25,7 +25,7 @@
25#include <android-base/test_utils.h> 25#include <android-base/test_utils.h>
26#include <gtest/gtest.h> 26#include <gtest/gtest.h>
27 27
28#include "../trace-dev.c" 28#include "../trace-dev.cpp"
29 29
30class TraceDevTest : public ::testing::Test { 30class TraceDevTest : public ::testing::Test {
31 protected: 31 protected:
diff --git a/libcutils/threads.c b/libcutils/threads.cpp
index 4bae39e0f..beea8bdfc 100644
--- a/libcutils/threads.c
+++ b/libcutils/threads.cpp
@@ -14,7 +14,7 @@
14** limitations under the License. 14** limitations under the License.
15*/ 15*/
16 16
17#include "cutils/threads.h" 17#include <cutils/threads.h>
18 18
19// For gettid. 19// For gettid.
20#if defined(__APPLE__) 20#if defined(__APPLE__)
diff --git a/libcutils/trace-container.c b/libcutils/trace-container.cpp
index 03e91b1f2..d981f8fa5 100644
--- a/libcutils/trace-container.c
+++ b/libcutils/trace-container.cpp
@@ -14,6 +14,8 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17#include <cutils/trace.h>
18
17#include "trace-dev.inc" 19#include "trace-dev.inc"
18 20
19#include <cutils/sockets.h> 21#include <cutils/sockets.h>
diff --git a/libcutils/trace-dev.c b/libcutils/trace-dev.cpp
index 4468e83f6..4da821555 100644
--- a/libcutils/trace-dev.c
+++ b/libcutils/trace-dev.cpp
@@ -14,6 +14,8 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17#include <cutils/trace.h>
18
17#include "trace-dev.inc" 19#include "trace-dev.inc"
18 20
19static pthread_once_t atrace_once_control = PTHREAD_ONCE_INIT; 21static pthread_once_t atrace_once_control = PTHREAD_ONCE_INIT;
diff --git a/libcutils/trace-host.c b/libcutils/trace-host.cpp
index 05842cd7d..05842cd7d 100644
--- a/libcutils/trace-host.c
+++ b/libcutils/trace-host.cpp