summaryrefslogtreecommitdiffstats
path: root/libcutils
diff options
context:
space:
mode:
Diffstat (limited to 'libcutils')
-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 @@
// which are also hard or even impossible to port to native Win32
libcutils_nonwindows_sources = [
"android_get_control_file.cpp",
- "fs.c",
+ "fs.cpp",
"multiuser.c",
- "socket_inaddr_any_server_unix.c",
- "socket_local_client_unix.c",
- "socket_local_server_unix.c",
- "socket_network_client_unix.c",
+ "socket_inaddr_any_server_unix.cpp",
+ "socket_local_client_unix.cpp",
+ "socket_local_server_unix.cpp",
+ "socket_network_client_unix.cpp",
"sockets_unix.cpp",
- "str_parms.c",
+ "str_parms.cpp",
]
cc_library_headers {
@@ -56,21 +56,21 @@ cc_library {
},
host_supported: true,
srcs: [
- "config_utils.c",
+ "config_utils.cpp",
"fs_config.cpp",
- "canned_fs_config.c",
- "hashmap.c",
- "iosched_policy.c",
- "load_file.c",
- "native_handle.c",
+ "canned_fs_config.cpp",
+ "hashmap.cpp",
+ "iosched_policy.cpp",
+ "load_file.cpp",
+ "native_handle.cpp",
"open_memstream.c",
- "record_stream.c",
+ "record_stream.cpp",
"sched_policy.cpp",
"sockets.cpp",
- "strdup16to8.c",
- "strdup8to16.c",
+ "strdup16to8.cpp",
+ "strdup8to16.cpp",
"strlcpy.c",
- "threads.c",
+ "threads.cpp",
],
target: {
@@ -83,14 +83,14 @@ cc_library {
},
not_windows: {
srcs: libcutils_nonwindows_sources + [
- "ashmem-host.c",
- "trace-host.c",
+ "ashmem-host.cpp",
+ "trace-host.cpp",
],
},
windows: {
srcs: [
- "socket_inaddr_any_server_windows.c",
- "socket_network_client_windows.c",
+ "socket_inaddr_any_server_windows.cpp",
+ "socket_network_client_windows.cpp",
"sockets_windows.cpp",
],
@@ -105,13 +105,13 @@ cc_library {
android: {
srcs: libcutils_nonwindows_sources + [
- "android_reboot.c",
- "ashmem-dev.c",
+ "android_reboot.cpp",
+ "ashmem-dev.cpp",
"klog.cpp",
- "partition_utils.c",
+ "partition_utils.cpp",
"properties.cpp",
"qtaguid.cpp",
- "trace-dev.c",
+ "trace-dev.cpp",
"uevent.cpp",
],
},
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 @@
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
+
+#include <cutils/android_get_control_file.h>
+
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
@@ -36,8 +39,6 @@
#include <sys/types.h>
#include <unistd.h>
-#include <cutils/android_get_control_file.h>
-
#include "android_get_control_env.h"
#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 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
+#include <cutils/android_reboot.h>
+
#include <stdio.h>
#include <stdlib.h>
-#include <cutils/android_reboot.h>
#include <cutils/properties.h>
#define TAG "android_reboot"
@@ -26,7 +28,7 @@ int android_reboot(int cmd, int flags __unused, const char* arg) {
const char* restart_cmd = NULL;
char* prop_value;
- switch (cmd) {
+ switch (static_cast<unsigned>(cmd)) {
case ANDROID_RB_RESTART: // deprecated
case ANDROID_RB_RESTART2:
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 @@
* limitations under the License.
*/
+#include <cutils/ashmem.h>
+
/*
* Implementation of the user-space ashmem API for devices, which have our
* ashmem-enabled kernel. See ashmem-sim.c for the "fake" tmp-based version,
@@ -31,8 +33,6 @@
#include <sys/sysmacros.h>
#include <sys/types.h>
#include <unistd.h>
-
-#include <cutils/ashmem.h>
#include <log/log.h>
#define ASHMEM_DEVICE "/dev/ashmem"
@@ -192,7 +192,8 @@ int ashmem_set_prot_region(int fd, int prot)
int ashmem_pin_region(int fd, size_t offset, size_t len)
{
- struct ashmem_pin pin = { offset, len };
+ // TODO: should LP64 reject too-large offset/len?
+ ashmem_pin pin = { static_cast<uint32_t>(offset), static_cast<uint32_t>(len) };
int ret = __ashmem_is_ashmem(fd, 1);
if (ret < 0) {
@@ -204,7 +205,8 @@ int ashmem_pin_region(int fd, size_t offset, size_t len)
int ashmem_unpin_region(int fd, size_t offset, size_t len)
{
- struct ashmem_pin pin = { offset, len };
+ // TODO: should LP64 reject too-large offset/len?
+ ashmem_pin pin = { static_cast<uint32_t>(offset), static_cast<uint32_t>(len) };
int ret = __ashmem_is_ashmem(fd, 1);
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 @@
* limitations under the License.
*/
+#include <cutils/ashmem.h>
+
/*
* Implementation of the user-space ashmem API for the simulator, which lacks
* an ashmem-enabled kernel. See ashmem-dev.c for the real ashmem-based version.
@@ -31,7 +33,6 @@
#include <time.h>
#include <unistd.h>
-#include <cutils/ashmem.h>
#include <utils/Compat.h>
#ifndef __unused
@@ -40,12 +41,12 @@
int ashmem_create_region(const char *ignored __unused, size_t size)
{
- char template[PATH_MAX];
- snprintf(template, sizeof(template), "/tmp/android-ashmem-%d-XXXXXXXXX", getpid());
- int fd = mkstemp(template);
+ char pattern[PATH_MAX];
+ snprintf(pattern, sizeof(pattern), "/tmp/android-ashmem-%d-XXXXXXXXX", getpid());
+ int fd = mkstemp(pattern);
if (fd == -1) return -1;
- unlink(template);
+ unlink(pattern);
if (TEMP_FAILURE_RETRY(ftruncate(fd, size)) == -1) {
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 @@
* limitations under the License.
*/
+#include <private/android_filesystem_config.h>
+#include <private/canned_fs_config.h>
+#include <private/fs_config.h>
+
#include <errno.h>
#include <inttypes.h>
#include <limits.h>
@@ -22,10 +26,6 @@
#include <stdlib.h>
#include <string.h>
-#include <private/android_filesystem_config.h>
-#include <private/fs_config.h>
-#include <private/canned_fs_config.h>
-
typedef struct {
const char* path;
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 @@
* limitations under the License.
*/
+#include <cutils/config_utils.h>
+
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
-#include <cutils/config_utils.h>
#include <cutils/misc.h>
cnode* config_node(const char *name, const char *value)
{
- cnode *node;
-
- node = calloc(sizeof(cnode), 1);
+ cnode* node = static_cast<cnode*>(calloc(sizeof(cnode), 1));
if(node) {
node->name = name ? name : "";
node->value = value ? value : "";
@@ -311,9 +310,9 @@ void config_load(cnode *root, char *data)
void config_load_file(cnode *root, const char *fn)
{
- char *data;
- data = load_file(fn, 0);
+ char* data = static_cast<char*>(load_file(fn, nullptr));
config_load(root, data);
+ // TODO: deliberate leak :-/
}
void 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 @@
* limitations under the License.
*/
+#include <cutils/fs.h>
+
#define LOG_TAG "cutils"
/* These defines are only needed because prebuilt headers are out of date */
@@ -32,7 +34,6 @@
#include <sys/types.h>
#include <unistd.h>
-#include <cutils/fs.h>
#include <log/log.h>
#define ALL_PERMS (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO)
@@ -40,6 +41,11 @@
static int fs_prepare_path_impl(const char* path, mode_t mode, uid_t uid, gid_t gid,
int allow_fixup, int prepare_as_dir) {
+ // TODO: fix the goto hell below.
+ int type_ok;
+ int owner_match;
+ int mode_match;
+
// Check if path needs to be created
struct stat sb;
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
}
// Exists, verify status
- int type_ok = prepare_as_dir ? S_ISDIR(sb.st_mode) : S_ISREG(sb.st_mode);
+ type_ok = prepare_as_dir ? S_ISDIR(sb.st_mode) : S_ISREG(sb.st_mode);
if (!type_ok) {
ALOGE("Not a %s: %s", (prepare_as_dir ? "directory" : "regular file"), path);
return -1;
}
- int owner_match = ((sb.st_uid == uid) && (sb.st_gid == gid));
- int mode_match = ((sb.st_mode & ALL_PERMS) == mode);
+ owner_match = ((sb.st_uid == uid) && (sb.st_gid == gid));
+ mode_match = ((sb.st_mode & ALL_PERMS) == mode);
if (owner_match && mode_match) {
return 0;
} else if (allow_fixup) {
@@ -188,23 +194,20 @@ fail_closed:
#ifndef __APPLE__
int fs_mkdirs(const char* path, mode_t mode) {
- int res = 0;
- int fd = 0;
- struct stat sb;
- char* buf = strdup(path);
-
- if (*buf != '/') {
- ALOGE("Relative paths are not allowed: %s", buf);
- res = -EINVAL;
- goto done;
+ if (*path != '/') {
+ ALOGE("Relative paths are not allowed: %s", path);
+ return -EINVAL;
}
- if ((fd = open("/", 0)) == -1) {
+ int fd = open("/", 0);
+ if (fd == -1) {
ALOGE("Failed to open(/): %s", strerror(errno));
- res = -errno;
- goto done;
+ return -errno;
}
+ struct stat sb;
+ int res = 0;
+ char* buf = strdup(path);
char* segment = buf + 1;
char* p = segment;
while (*p != '\0') {
@@ -266,7 +269,6 @@ int fs_mkdirs(const char* path, mode_t mode) {
done_close:
close(fd);
-done:
free(buf);
return res;
}
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 @@
* limitations under the License.
*/
+#include <private/fs_config.h>
+
// This file is used to define the properties of the filesystem
// images generated by build tools (mkbootfs and mkyaffs2image) and
// by the device side of adb.
@@ -31,7 +33,6 @@
#include <log/log.h>
#include <private/android_filesystem_config.h>
-#include <private/fs_config.h>
#include <utils/Compat.h>
#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 @@
*/
#include <cutils/hashmap.h>
+
#include <assert.h>
#include <errno.h>
#include <cutils/threads.h>
@@ -45,7 +46,7 @@ Hashmap* hashmapCreate(size_t initialCapacity,
assert(hash != NULL);
assert(equals != NULL);
- Hashmap* map = malloc(sizeof(Hashmap));
+ Hashmap* map = static_cast<Hashmap*>(malloc(sizeof(Hashmap)));
if (map == NULL) {
return NULL;
}
@@ -58,7 +59,7 @@ Hashmap* hashmapCreate(size_t initialCapacity,
map->bucketCount <<= 1;
}
- map->buckets = calloc(map->bucketCount, sizeof(Entry*));
+ map->buckets = static_cast<Entry**>(calloc(map->bucketCount, sizeof(Entry*)));
if (map->buckets == NULL) {
free(map);
return NULL;
@@ -106,7 +107,7 @@ static void expandIfNecessary(Hashmap* map) {
if (map->size > (map->bucketCount * 3 / 4)) {
// Start off with a 0.33 load factor.
size_t newBucketCount = map->bucketCount << 1;
- Entry** newBuckets = calloc(newBucketCount, sizeof(Entry*));
+ Entry** newBuckets = static_cast<Entry**>(calloc(newBucketCount, sizeof(Entry*)));
if (newBuckets == NULL) {
// Abort expansion.
return;
@@ -171,7 +172,7 @@ int hashmapHash(void* key, size_t keySize) {
}
static Entry* createEntry(void* key, int hash, void* value) {
- Entry* entry = malloc(sizeof(Entry));
+ Entry* entry = static_cast<Entry*>(malloc(sizeof(Entry)));
if (entry == NULL) {
return NULL;
}
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 @@
#ifndef __CUTILS_ANDROID_REBOOT_H__
#define __CUTILS_ANDROID_REBOOT_H__
+#include <sys/cdefs.h>
__BEGIN_DECLS
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 @@
#ifndef __CUTILS_PARTITION_WIPED_H__
#define __CUTILS_PARTITION_WIPED_H__
+#include <sys/cdefs.h>
+
__BEGIN_DECLS
int 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 @@
extern "C" {
#endif
+#include <stddef.h>
typedef struct RecordStream RecordStream;
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 @@
#include <inttypes.h>
+__BEGIN_DECLS
+
int load_canned_fs_config(const char* fn);
void canned_fs_config(const char* path, int dir, const char* target_out_path, unsigned* uid,
unsigned* gid, unsigned* mode, uint64_t* capabilities);
+__END_DECLS
+
#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 @@
#include <stdint.h>
#include <sys/cdefs.h>
+#include <sys/types.h>
#if defined(__BIONIC__)
#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 @@
** limitations under the License.
*/
+#include <cutils/iosched_policy.h>
+
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
@@ -21,8 +23,6 @@
#include <string.h>
#include <unistd.h>
-#include <cutils/iosched_policy.h>
-
#if defined(__ANDROID__)
#define IOPRIO_WHO_PROCESS (1)
#define IOPRIO_CLASS_SHIFT (13)
@@ -49,7 +49,7 @@ int android_get_ioprio(int pid __android_unused, IoSchedClass *clazz, int *iopri
return -1;
}
- *clazz = (rc >> IOPRIO_CLASS_SHIFT);
+ *clazz = static_cast<IoSchedClass>(rc >> IOPRIO_CLASS_SHIFT);
*ioprio = (rc & 0xff);
#else
*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 @@
* limitations under the License.
*/
+#include <cutils/klog.h>
+
#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
@@ -25,7 +27,6 @@
#include <unistd.h>
#include <cutils/android_get_control_file.h>
-#include <cutils/klog.h>
static int klog_level = KLOG_INFO_LEVEL;
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 @@
** limitations under the License.
*/
+#include <cutils/misc.h>
+
#include <stdlib.h>
#include <unistd.h>
#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) {
}
size_t mallocSize = sizeof(native_handle_t) + (sizeof(int) * (numFds + numInts));
- native_handle_t* h = malloc(mallocSize);
+ native_handle_t* h = static_cast<native_handle_t*>(malloc(mallocSize));
if (h) {
h->version = sizeof(native_handle_t);
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 @@
* limitations under the License.
*/
+#include <cutils/partition_utils.h>
+
#include <fcntl.h>
#include <sys/ioctl.h>
#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 @@
* limitations under the License.
*/
+#include <cutils/properties.h>
+
#define LOG_TAG "properties"
// #define LOG_NDEBUG 0
@@ -25,7 +27,6 @@
#include <string.h>
#include <unistd.h>
-#include <cutils/properties.h>
#include <cutils/sockets.h>
#include <log/log.h>
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 @@
* limitations under the License.
*/
+#include <cutils/qtaguid.h>
+
// #define LOG_NDEBUG 0
#define LOG_TAG "qtaguid"
@@ -26,7 +28,6 @@
#include <string.h>
#include <unistd.h>
-#include <cutils/qtaguid.h>
#include <log/log.h>
class 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 @@
** limitations under the License.
*/
+#include <cutils/record_stream.h>
+
#include <stdlib.h>
#include <unistd.h>
#include <assert.h>
#include <errno.h>
-#include <cutils/record_stream.h>
#include <string.h>
#include <stdint.h>
#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 @@
** limitations under the License.
*/
+#include <cutils/sched_policy.h>
+
#define LOG_TAG "SchedPolicy"
#include <errno.h>
@@ -24,7 +26,6 @@
#include <unistd.h>
#include <log/log.h>
-#include <cutils/sched_policy.h>
#define UNUSED __attribute__((__unused__))
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 @@
** limitations under the License.
*/
+#include <cutils/sockets.h>
+
#include <errno.h>
#include <stddef.h>
#include <stdlib.h>
@@ -25,8 +27,6 @@
#include <sys/types.h>
#include <netinet/in.h>
-#include <cutils/sockets.h>
-
#define LISTEN_BACKLOG 4
/* 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 @@
* SUCH DAMAGE.
*/
-#include <errno.h>
-
#include <cutils/sockets.h>
+#include <errno.h>
+
#define LISTEN_BACKLOG 4
extern 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 @@
* limitations under the License.
*/
+#include <cutils/sockets.h>
+
#include <errno.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <cutils/sockets.h>
-
#if defined(_WIN32)
int 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)
* Returns fd on success, -1 on fail
*/
-int socket_local_server(const char *name, int namespace, int type)
+int socket_local_server(const char *name, int namespaceId, int type)
{
int err;
int s;
@@ -102,7 +102,7 @@ int socket_local_server(const char *name, int namespace, int type)
s = socket(AF_LOCAL, type, 0);
if (s < 0) return -1;
- err = socket_local_server_bind(s, name, namespace);
+ err = socket_local_server_bind(s, name, namespaceId);
if (err < 0) {
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 @@
** limitations under the License.
*/
+#include <cutils/sockets.h>
+
#include <errno.h>
#include <fcntl.h>
#include <stddef.h>
@@ -27,8 +29,6 @@
#include <netinet/in.h>
#include <netdb.h>
-#include <cutils/sockets.h>
-
static int toggle_O_NONBLOCK(int s) {
int flags = fcntl(s, F_GETFL);
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 @@
* limitations under the License.
*/
+#include <cutils/sockets.h>
+
#define LOG_TAG "socket-unix"
#include <stdio.h>
@@ -26,7 +28,6 @@
#include <unistd.h>
#include <cutils/android_get_control_file.h>
-#include <cutils/sockets.h>
#include <log/log.h>
#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 @@
// Both adb (1) and Chrome (2) purposefully avoid WSACleanup() with no issues.
// (1) https://android.googlesource.com/platform/system/core.git/+/master/adb/sysdeps_win32.cpp
// (2) https://code.google.com/p/chromium/codesearch#chromium/src/net/base/winsock_init.cc
-extern "C" bool initialize_windows_sockets() {
+bool initialize_windows_sockets() {
// There's no harm in calling WSAStartup() multiple times but no benefit
// either, we may as well skip it after the first.
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 @@
* limitations under the License.
*/
+#include <cutils/str_parms.h>
+
#define LOG_TAG "str_params"
//#define LOG_NDEBUG 0
@@ -26,7 +28,6 @@
#include <cutils/hashmap.h>
#include <cutils/memory.h>
-#include <cutils/str_parms.h>
#include <log/log.h>
#define UNUSED __attribute__((unused))
@@ -62,30 +63,24 @@ __attribute__((no_sanitize("integer")))
static int str_hash_fn(void *str)
{
uint32_t hash = 5381;
- char *p;
- for (p = str; p && *p; p++)
+ for (char* p = static_cast<char*>(str); p && *p; p++)
hash = ((hash << 5) + hash) + *p;
return (int)hash;
}
struct str_parms *str_parms_create(void)
{
- struct str_parms *str_parms;
+ str_parms* s = static_cast<str_parms*>(calloc(1, sizeof(str_parms)));
+ if (!s) return NULL;
- str_parms = calloc(1, sizeof(struct str_parms));
- if (!str_parms)
+ s->map = hashmapCreate(5, str_hash_fn, str_eq);
+ if (!s->map) {
+ free(s);
return NULL;
+ }
- str_parms->map = hashmapCreate(5, str_hash_fn, str_eq);
- if (!str_parms->map)
- goto err;
-
- return str_parms;
-
-err:
- free(str_parms);
- return NULL;
+ return s;
}
struct remove_ctxt {
@@ -95,7 +90,7 @@ struct remove_ctxt {
static bool remove_pair(void *key, void *value, void *context)
{
- struct remove_ctxt *ctxt = context;
+ remove_ctxt* ctxt = static_cast<remove_ctxt*>(context);
bool should_continue;
/*
@@ -109,7 +104,7 @@ static bool remove_pair(void *key, void *value, void *context)
if (!ctxt->key) {
should_continue = true;
goto do_remove;
- } else if (!strcmp(ctxt->key, key)) {
+ } else if (!strcmp(ctxt->key, static_cast<const char*>(key))) {
should_continue = false;
goto do_remove;
}
@@ -292,9 +287,8 @@ int str_parms_has_key(struct str_parms *str_parms, const char *key) {
int str_parms_get_str(struct str_parms *str_parms, const char *key, char *val,
int len)
{
- char *value;
-
- value = hashmapGet(str_parms->map, (void *)key);
+ // TODO: hashmapGet should take a const* key.
+ char* value = static_cast<char*>(hashmapGet(str_parms->map, (void*)key));
if (value)
return strlcpy(val, value, len);
@@ -303,10 +297,10 @@ int str_parms_get_str(struct str_parms *str_parms, const char *key, char *val,
int str_parms_get_int(struct str_parms *str_parms, const char *key, int *val)
{
- char *value;
char *end;
- value = hashmapGet(str_parms->map, (void *)key);
+ // TODO: hashmapGet should take a const* key.
+ char* value = static_cast<char*>(hashmapGet(str_parms->map, (void*)key));
if (!value)
return -ENOENT;
@@ -321,10 +315,10 @@ int str_parms_get_float(struct str_parms *str_parms, const char *key,
float *val)
{
float out;
- char *value;
char *end;
- value = hashmapGet(str_parms->map, (void *)key);
+ // TODO: hashmapGet should take a const* key.
+ char* value = static_cast<char*>(hashmapGet(str_parms->map, (void*)(key)));
if (!value)
return -ENOENT;
@@ -338,7 +332,7 @@ int str_parms_get_float(struct str_parms *str_parms, const char *key,
static bool combine_strings(void *key, void *value, void *context)
{
- char **old_str = context;
+ char** old_str = static_cast<char**>(context);
char *new_str;
int ret;
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 @@
** limitations under the License.
*/
-#include <limits.h> /* for SIZE_MAX */
-
#include <cutils/jstring.h>
+
#include <assert.h>
+#include <limits.h> /* for SIZE_MAX */
#include <stdlib.h>
@@ -145,14 +145,11 @@ extern char* strncpy16to8(char* utf8Str, const char16_t* utf16Str, size_t len)
*/
char * strndup16to8 (const char16_t* s, size_t n)
{
- char* ret;
- size_t len;
-
if (s == NULL) {
return NULL;
}
- len = strnlen16to8(s, n);
+ size_t len = strnlen16to8(s, n);
/* We are paranoid, and we check for SIZE_MAX-1
* too since it is an overflow value for our
@@ -161,7 +158,7 @@ char * strndup16to8 (const char16_t* s, size_t n)
if (len >= SIZE_MAX-1)
return NULL;
- ret = malloc(len + 1);
+ char* ret = static_cast<char*>(malloc(len + 1));
if (ret == NULL)
return NULL;
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 @@
*/
#include <cutils/jstring.h>
+
#include <assert.h>
-#include <stdlib.h>
#include <limits.h>
+#include <stdlib.h>
/* See http://www.unicode.org/reports/tr22/ for discussion
* on invalid sequences
@@ -116,7 +117,7 @@ static inline uint32_t getUtf32FromUtf8(const char** pUtf8Ptr)
int i;
/* Mask for leader byte for lengths 1, 2, 3, and 4 respectively*/
- static const char leaderMask[4] = {0xff, 0x1f, 0x0f, 0x07};
+ static const unsigned char leaderMask[4] = {0xff, 0x1f, 0x0f, 0x07};
/* Bytes that start with bits "10" are not leading characters. */
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 @@
#include <android-base/test_utils.h>
#include <gtest/gtest.h>
-#include "../trace-dev.c"
+#include "../trace-dev.cpp"
class TraceDevTest : public ::testing::Test {
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 @@
** limitations under the License.
*/
-#include "cutils/threads.h"
+#include <cutils/threads.h>
// For gettid.
#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 @@
* limitations under the License.
*/
+#include <cutils/trace.h>
+
#include "trace-dev.inc"
#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 @@
* limitations under the License.
*/
+#include <cutils/trace.h>
+
#include "trace-dev.inc"
static 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