liblog: convert to C++

Bug: 119867234
Test: liblog, logcat, logd unit tests

Change-Id: I2a33b6fc37f9860c0041e3573bfb59ea389f623c
diff --git a/liblog/Android.bp b/liblog/Android.bp
index 619a94b..e213e90 100644
--- a/liblog/Android.bp
+++ b/liblog/Android.bp
@@ -15,30 +15,30 @@
 //
 
 liblog_sources = [
-    "config_read.c",
-    "config_write.c",
-    "log_event_list.c",
-    "log_event_write.c",
+    "config_read.cpp",
+    "config_write.cpp",
+    "log_event_list.cpp",
+    "log_event_write.cpp",
     "log_ratelimit.cpp",
-    "logger_lock.c",
-    "logger_name.c",
-    "logger_read.c",
-    "logger_write.c",
-    "logprint.c",
-    "stderr_write.c",
+    "logger_lock.cpp",
+    "logger_name.cpp",
+    "logger_read.cpp",
+    "logger_write.cpp",
+    "logprint.cpp",
+    "stderr_write.cpp",
 ]
 liblog_host_sources = [
-    "fake_log_device.c",
-    "fake_writer.c",
+    "fake_log_device.cpp",
+    "fake_writer.cpp",
 ]
 liblog_target_sources = [
     "event_tag_map.cpp",
     "log_time.cpp",
-    "properties.c",
-    "pmsg_reader.c",
-    "pmsg_writer.c",
-    "logd_reader.c",
-    "logd_writer.c",
+    "properties.cpp",
+    "pmsg_reader.cpp",
+    "pmsg_writer.cpp",
+    "logd_reader.cpp",
+    "logd_writer.cpp",
 ]
 
 cc_library_headers {
@@ -86,7 +86,7 @@
             ldflags: ["-Wl,--hash-style=both"],
         },
         windows: {
-            srcs: ["uio.c"],
+            srcs: ["uio.cpp"],
             enabled: true,
         },
         not_windows: {
diff --git a/liblog/config_read.c b/liblog/config_read.cpp
similarity index 68%
rename from liblog/config_read.c
rename to liblog/config_read.cpp
index 51ffff6..80177a4 100644
--- a/liblog/config_read.c
+++ b/liblog/config_read.cpp
@@ -19,23 +19,21 @@
 #include "config_read.h"
 #include "logger.h"
 
-LIBLOG_HIDDEN struct listnode __android_log_transport_read = {
-  &__android_log_transport_read, &__android_log_transport_read
-};
-LIBLOG_HIDDEN struct listnode __android_log_persist_read = {
-  &__android_log_persist_read, &__android_log_persist_read
-};
+LIBLOG_HIDDEN struct listnode __android_log_transport_read = {&__android_log_transport_read,
+                                                              &__android_log_transport_read};
+LIBLOG_HIDDEN struct listnode __android_log_persist_read = {&__android_log_persist_read,
+                                                            &__android_log_persist_read};
 
-static void __android_log_add_transport(
-    struct listnode* list, struct android_log_transport_read* transport) {
-  size_t i;
+static void __android_log_add_transport(struct listnode* list,
+                                        struct android_log_transport_read* transport) {
+  uint32_t i;
 
   /* Try to keep one functioning transport for each log buffer id */
   for (i = LOG_ID_MIN; i < LOG_ID_MAX; i++) {
     struct android_log_transport_read* transp;
 
     if (list_empty(list)) {
-      if (!transport->available || ((*transport->available)(i) >= 0)) {
+      if (!transport->available || ((*transport->available)(static_cast<log_id_t>(i)) >= 0)) {
         list_add_tail(list, &transport->node);
         return;
       }
@@ -44,8 +42,8 @@
         if (!transp->available) {
           return;
         }
-        if (((*transp->available)(i) < 0) &&
-            (!transport->available || ((*transport->available)(i) >= 0))) {
+        if (((*transp->available)(static_cast<log_id_t>(i)) < 0) &&
+            (!transport->available || ((*transport->available)(static_cast<log_id_t>(i)) >= 0))) {
           list_add_tail(list, &transport->node);
           return;
         }
@@ -56,8 +54,7 @@
 
 LIBLOG_HIDDEN void __android_log_config_read() {
 #if (FAKE_LOG_DEVICE == 0)
-  if ((__android_log_transport == LOGGER_DEFAULT) ||
-      (__android_log_transport & LOGGER_LOGD)) {
+  if ((__android_log_transport == LOGGER_DEFAULT) || (__android_log_transport & LOGGER_LOGD)) {
     extern struct android_log_transport_read logdLoggerRead;
     extern struct android_log_transport_read pmsgLoggerRead;
 
diff --git a/liblog/config_write.c b/liblog/config_write.cpp
similarity index 69%
rename from liblog/config_write.c
rename to liblog/config_write.cpp
index 003ec8f..e65c238 100644
--- a/liblog/config_write.c
+++ b/liblog/config_write.cpp
@@ -19,23 +19,21 @@
 #include "config_write.h"
 #include "logger.h"
 
-LIBLOG_HIDDEN struct listnode __android_log_transport_write = {
-  &__android_log_transport_write, &__android_log_transport_write
-};
-LIBLOG_HIDDEN struct listnode __android_log_persist_write = {
-  &__android_log_persist_write, &__android_log_persist_write
-};
+LIBLOG_HIDDEN struct listnode __android_log_transport_write = {&__android_log_transport_write,
+                                                               &__android_log_transport_write};
+LIBLOG_HIDDEN struct listnode __android_log_persist_write = {&__android_log_persist_write,
+                                                             &__android_log_persist_write};
 
-static void __android_log_add_transport(
-    struct listnode* list, struct android_log_transport_write* transport) {
-  size_t i;
+static void __android_log_add_transport(struct listnode* list,
+                                        struct android_log_transport_write* transport) {
+  uint32_t i;
 
   /* Try to keep one functioning transport for each log buffer id */
   for (i = LOG_ID_MIN; i < LOG_ID_MAX; i++) {
     struct android_log_transport_write* transp;
 
     if (list_empty(list)) {
-      if (!transport->available || ((*transport->available)(i) >= 0)) {
+      if (!transport->available || ((*transport->available)(static_cast<log_id_t>(i)) >= 0)) {
         list_add_tail(list, &transport->node);
         return;
       }
@@ -44,8 +42,8 @@
         if (!transp->available) {
           return;
         }
-        if (((*transp->available)(i) < 0) &&
-            (!transport->available || ((*transport->available)(i) >= 0))) {
+        if (((*transp->available)(static_cast<log_id_t>(i)) < 0) &&
+            (!transport->available || ((*transport->available)(static_cast<log_id_t>(i)) >= 0))) {
           list_add_tail(list, &transport->node);
           return;
         }
@@ -55,20 +53,17 @@
 }
 
 LIBLOG_HIDDEN void __android_log_config_write() {
-  if ((__android_log_transport == LOGGER_DEFAULT) ||
-      (__android_log_transport & LOGGER_LOGD)) {
+  if ((__android_log_transport == LOGGER_DEFAULT) || (__android_log_transport & LOGGER_LOGD)) {
 #if (FAKE_LOG_DEVICE == 0)
     extern struct android_log_transport_write logdLoggerWrite;
     extern struct android_log_transport_write pmsgLoggerWrite;
 
-    __android_log_add_transport(&__android_log_transport_write,
-                                &logdLoggerWrite);
+    __android_log_add_transport(&__android_log_transport_write, &logdLoggerWrite);
     __android_log_add_transport(&__android_log_persist_write, &pmsgLoggerWrite);
 #else
     extern struct android_log_transport_write fakeLoggerWrite;
 
-    __android_log_add_transport(&__android_log_transport_write,
-                                &fakeLoggerWrite);
+    __android_log_add_transport(&__android_log_transport_write, &fakeLoggerWrite);
 #endif
   }
 
@@ -81,8 +76,7 @@
      * Remember we can be called here if we are already initialized.
      */
     if (list_empty(&__android_log_transport_write)) {
-      __android_log_add_transport(&__android_log_transport_write,
-                                  &stderrLoggerWrite);
+      __android_log_add_transport(&__android_log_transport_write, &stderrLoggerWrite);
     } else {
       struct android_log_transport_write* transp;
       write_transport_for_each(transp, &__android_log_transport_write) {
@@ -90,8 +84,7 @@
           return;
         }
       }
-      __android_log_add_transport(&__android_log_persist_write,
-                                  &stderrLoggerWrite);
+      __android_log_add_transport(&__android_log_persist_write, &stderrLoggerWrite);
     }
   }
 }
diff --git a/liblog/fake_log_device.c b/liblog/fake_log_device.cpp
similarity index 88%
rename from liblog/fake_log_device.c
rename to liblog/fake_log_device.cpp
index 1483c24..4f3a230 100644
--- a/liblog/fake_log_device.c
+++ b/liblog/fake_log_device.cpp
@@ -17,6 +17,9 @@
  * Intercepts log messages intended for the Android log device.
  * Messages are printed to stderr.
  */
+
+#include "fake_log_device.h"
+
 #include <ctype.h>
 #include <errno.h>
 #include <fcntl.h>
@@ -32,7 +35,6 @@
 #include <android/log.h>
 #include <log/uio.h>
 
-#include "fake_log_device.h"
 #include "log_portability.h"
 
 #define kMaxTagLen 16 /* from the long-dead utils/Log.cpp */
@@ -181,8 +183,7 @@
   logState->debugName[sizeof(logState->debugName) - 1] = '\0';
 
   /* identify binary logs */
-  if (!strcmp(pathName + kDevLogLen, "events") ||
-      !strcmp(pathName + kDevLogLen, "security")) {
+  if (!strcmp(pathName + kDevLogLen, "events") || !strcmp(pathName + kDevLogLen, "security")) {
     logState->isBinary = 1;
   }
 
@@ -204,8 +205,7 @@
       while (isspace(*tags)) tags++;
 
       i = 0;
-      while (*tags != '\0' && !isspace(*tags) && *tags != ':' &&
-             i < kMaxTagLen) {
+      while (*tags != '\0' && !isspace(*tags) && *tags != ':' && i < kMaxTagLen) {
         tagName[i++] = *tags++;
       }
       if (i == kMaxTagLen) {
@@ -313,13 +313,11 @@
  */
 static const char* getPriorityString(int priority) {
   /* the first character of each string should be unique */
-  static const char* priorityStrings[] = { "Verbose", "Debug", "Info",
-                                           "Warn",    "Error", "Assert" };
+  static const char* priorityStrings[] = {"Verbose", "Debug", "Info", "Warn", "Error", "Assert"};
   int idx;
 
   idx = (int)priority - (int)ANDROID_LOG_VERBOSE;
-  if (idx < 0 ||
-      idx >= (int)(sizeof(priorityStrings) / sizeof(priorityStrings[0])))
+  if (idx < 0 || idx >= (int)(sizeof(priorityStrings) / sizeof(priorityStrings[0])))
     return "?unknown?";
   return priorityStrings[idx];
 }
@@ -351,8 +349,7 @@
  *
  * Log format parsing taken from the long-dead utils/Log.cpp.
  */
-static void showLog(LogState* state, int logPrio, const char* tag,
-                    const char* msg) {
+static void showLog(LogState* state, int logPrio, const char* tag, const char* msg) {
 #if !defined(_WIN32)
   struct tm tmBuf;
 #endif
@@ -397,19 +394,16 @@
 
   switch (state->outputFormat) {
     case FORMAT_TAG:
-      prefixLen =
-          snprintf(prefixBuf, sizeof(prefixBuf), "%c/%-8s: ", priChar, tag);
+      prefixLen = snprintf(prefixBuf, sizeof(prefixBuf), "%c/%-8s: ", priChar, tag);
       strcpy(suffixBuf, "\n");
       suffixLen = 1;
       break;
     case FORMAT_PROCESS:
-      prefixLen =
-          snprintf(prefixBuf, sizeof(prefixBuf), "%c(%5d) ", priChar, pid);
+      prefixLen = snprintf(prefixBuf, sizeof(prefixBuf), "%c(%5d) ", priChar, pid);
       suffixLen = snprintf(suffixBuf, sizeof(suffixBuf), "  (%s)\n", tag);
       break;
     case FORMAT_THREAD:
-      prefixLen = snprintf(prefixBuf, sizeof(prefixBuf), "%c(%5d:%5d) ",
-                           priChar, pid, tid);
+      prefixLen = snprintf(prefixBuf, sizeof(prefixBuf), "%c(%5d:%5d) ", priChar, pid, tid);
       strcpy(suffixBuf, "\n");
       suffixLen = 1;
       break;
@@ -420,28 +414,24 @@
       suffixLen = 1;
       break;
     case FORMAT_TIME:
-      prefixLen =
-          snprintf(prefixBuf, sizeof(prefixBuf), "%s %-8s\n\t", timeBuf, tag);
+      prefixLen = snprintf(prefixBuf, sizeof(prefixBuf), "%s %-8s\n\t", timeBuf, tag);
       strcpy(suffixBuf, "\n");
       suffixLen = 1;
       break;
     case FORMAT_THREADTIME:
-      prefixLen =
-          snprintf(prefixBuf, sizeof(prefixBuf), "%s %5d %5d %c %-8s \n\t",
-                   timeBuf, pid, tid, priChar, tag);
+      prefixLen = snprintf(prefixBuf, sizeof(prefixBuf), "%s %5d %5d %c %-8s \n\t", timeBuf, pid,
+                           tid, priChar, tag);
       strcpy(suffixBuf, "\n");
       suffixLen = 1;
       break;
     case FORMAT_LONG:
-      prefixLen =
-          snprintf(prefixBuf, sizeof(prefixBuf), "[ %s %5d:%5d %c/%-8s ]\n",
-                   timeBuf, pid, tid, priChar, tag);
+      prefixLen = snprintf(prefixBuf, sizeof(prefixBuf), "[ %s %5d:%5d %c/%-8s ]\n", timeBuf, pid,
+                           tid, priChar, tag);
       strcpy(suffixBuf, "\n\n");
       suffixLen = 2;
       break;
     default:
-      prefixLen = snprintf(prefixBuf, sizeof(prefixBuf),
-                           "%c/%-8s(%5d): ", priChar, tag, pid);
+      prefixLen = snprintf(prefixBuf, sizeof(prefixBuf), "%c/%-8s(%5d): ", priChar, tag, pid);
       strcpy(suffixBuf, "\n");
       suffixLen = 1;
       break;
@@ -559,8 +549,7 @@
  *  tag (N bytes -- null-terminated ASCII string)
  *  message (N bytes -- null-terminated ASCII string)
  */
-LIBLOG_HIDDEN ssize_t fakeLogWritev(int fd, const struct iovec* vector,
-                                    int count) {
+LIBLOG_HIDDEN ssize_t fakeLogWritev(int fd, const struct iovec* vector, int count) {
   LogState* state;
 
   /* Make sure that no-one frees the LogState while we're using it.
@@ -572,17 +561,24 @@
   state = fdToLogState(fd);
   if (state == NULL) {
     errno = EBADF;
-    goto error;
+    unlock();
+    return -1;
   }
 
   if (state->isBinary) {
     TRACE("%s: ignoring binary log\n", state->debugName);
-    goto bail;
+    unlock();
+    int len = 0;
+    for (int i = 0; i < count; ++i) {
+      len += vector[i].iov_len;
+    }
+    return len;
   }
 
   if (count != 3) {
     TRACE("%s: writevLog with count=%d not expected\n", state->debugName, count);
-    goto error;
+    unlock();
+    return -1;
   }
 
   /* pull out the three fields */
@@ -598,7 +594,6 @@
       break; /* reached end of configured values */
 
     if (strcmp(state->tagSet[i].tag, tag) == 0) {
-      // TRACE("MATCH tag '%s'\n", tag);
       minPrio = state->tagSet[i].minPriority;
       break;
     }
@@ -606,21 +601,14 @@
 
   if (logPrio >= minPrio) {
     showLog(state, logPrio, tag, msg);
-  } else {
-    // TRACE("+++ NOLOG(%d): %s %s", logPrio, tag, msg);
   }
 
-bail:
   unlock();
   int len = 0;
   for (i = 0; i < count; ++i) {
     len += vector[i].iov_len;
   }
   return len;
-
-error:
-  unlock();
-  return -1;
 }
 
 /*
@@ -663,22 +651,16 @@
   return fd;
 }
 
-LIBLOG_HIDDEN ssize_t __send_log_msg(char* buf __unused,
-                                     size_t buf_size __unused) {
+LIBLOG_HIDDEN ssize_t __send_log_msg(char*, size_t) {
   return -ENODEV;
 }
 
-LIBLOG_ABI_PUBLIC int __android_log_is_loggable(int prio,
-                                                const char* tag __unused,
-                                                int def) {
+LIBLOG_ABI_PUBLIC int __android_log_is_loggable(int prio, const char*, int def) {
   int logLevel = def;
   return logLevel >= 0 && prio >= logLevel;
 }
 
-LIBLOG_ABI_PUBLIC int __android_log_is_loggable_len(int prio,
-                                                    const char* tag __unused,
-                                                    size_t len __unused,
-                                                    int def) {
+LIBLOG_ABI_PUBLIC int __android_log_is_loggable_len(int prio, const char*, size_t, int def) {
   int logLevel = def;
   return logLevel >= 0 && prio >= logLevel;
 }
diff --git a/liblog/fake_log_device.h b/liblog/fake_log_device.h
index 7b0e745..d88eaee 100644
--- a/liblog/fake_log_device.h
+++ b/liblog/fake_log_device.h
@@ -23,9 +23,18 @@
 
 struct iovec;
 
+__BEGIN_DECLS
+
 LIBLOG_HIDDEN int fakeLogOpen(const char* pathName);
 LIBLOG_HIDDEN int fakeLogClose(int fd);
 LIBLOG_HIDDEN ssize_t fakeLogWritev(int fd, const struct iovec* vector,
                                     int count);
 
+LIBLOG_HIDDEN ssize_t __send_log_msg(char*, size_t);
+LIBLOG_ABI_PUBLIC int __android_log_is_loggable(int prio, const char*, int def);
+LIBLOG_ABI_PUBLIC int __android_log_is_loggable_len(int prio, const char*, size_t, int def);
+LIBLOG_ABI_PRIVATE int __android_log_is_debuggable();
+
+__END_DECLS
+
 #endif  // _LIBLOG_FAKE_LOG_DEVICE_H
diff --git a/liblog/fake_writer.c b/liblog/fake_writer.cpp
similarity index 82%
rename from liblog/fake_writer.c
rename to liblog/fake_writer.cpp
index 403dc72..46d171b 100644
--- a/liblog/fake_writer.c
+++ b/liblog/fake_writer.cpp
@@ -27,19 +27,18 @@
 
 static int fakeOpen();
 static void fakeClose();
-static int fakeWrite(log_id_t log_id, struct timespec* ts, struct iovec* vec,
-                     size_t nr);
+static int fakeWrite(log_id_t log_id, struct timespec* ts, struct iovec* vec, size_t nr);
 
-static int logFds[(int)LOG_ID_MAX] = { -1, -1, -1, -1, -1, -1 };
+static int logFds[(int)LOG_ID_MAX] = {-1, -1, -1, -1, -1, -1};
 
 LIBLOG_HIDDEN struct android_log_transport_write fakeLoggerWrite = {
-  .node = { &fakeLoggerWrite.node, &fakeLoggerWrite.node },
-  .context.priv = &logFds,
-  .name = "fake",
-  .available = NULL,
-  .open = fakeOpen,
-  .close = fakeClose,
-  .write = fakeWrite,
+    .node = {&fakeLoggerWrite.node, &fakeLoggerWrite.node},
+    .context.priv = &logFds,
+    .name = "fake",
+    .available = NULL,
+    .open = fakeOpen,
+    .close = fakeClose,
+    .write = fakeWrite,
 };
 
 static int fakeOpen() {
@@ -54,7 +53,7 @@
     if (logFds[i] >= 0) {
       continue;
     }
-    snprintf(buf, sizeof(buf), "/dev/log_%s", android_log_id_to_name(i));
+    snprintf(buf, sizeof(buf), "/dev/log_%s", android_log_id_to_name(static_cast<log_id_t>(i)));
     logFds[i] = fakeLogOpen(buf);
     if (logFds[i] < 0) {
       fprintf(stderr, "fakeLogOpen(%s) failed\n", buf);
@@ -72,8 +71,7 @@
   }
 }
 
-static int fakeWrite(log_id_t log_id, struct timespec* ts __unused,
-                     struct iovec* vec, size_t nr) {
+static int fakeWrite(log_id_t log_id, struct timespec*, struct iovec* vec, size_t nr) {
   ssize_t ret;
   size_t i;
   int logFd, len;
diff --git a/liblog/include/log/log_read.h b/liblog/include/log/log_read.h
index 93b9d4e..b03d677 100644
--- a/liblog/include/log/log_read.h
+++ b/liblog/include/log/log_read.h
@@ -17,6 +17,8 @@
 #ifndef _LIBS_LOG_LOG_READ_H
 #define _LIBS_LOG_LOG_READ_H
 
+#include <sys/types.h>
+
 /* deal with possible sys/cdefs.h conflict with fcntl.h */
 #ifdef __unused
 #define __unused_defined __unused
@@ -47,6 +49,8 @@
  * access to raw information, or parsing is an issue.
  */
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wzero-length-array"
 /*
  * The userspace structure for version 1 of the logger_entry ABI.
  */
@@ -59,9 +63,7 @@
   int32_t tid;    /* generating process's tid */
   int32_t sec;    /* seconds since Epoch */
   int32_t nsec;   /* nanoseconds */
-#ifndef __cplusplus
   char msg[0]; /* the entry's payload */
-#endif
 };
 #endif
 
@@ -78,9 +80,7 @@
   int32_t sec;       /* seconds since Epoch */
   int32_t nsec;      /* nanoseconds */
   uint32_t euid;     /* effective UID of logger */
-#ifndef __cplusplus
   char msg[0]; /* the entry's payload */
-#endif
 } __attribute__((__packed__));
 #endif
 
@@ -97,9 +97,7 @@
   int32_t sec;       /* seconds since Epoch */
   int32_t nsec;      /* nanoseconds */
   uint32_t lid;      /* log id of the payload */
-#ifndef __cplusplus
   char msg[0]; /* the entry's payload */
-#endif
 } __attribute__((__packed__));
 #endif
 
@@ -117,11 +115,10 @@
   uint32_t nsec;     /* nanoseconds */
   uint32_t lid;      /* log id of the payload, bottom 4 bits currently */
   uint32_t uid;      /* generating process's uid */
-#ifndef __cplusplus
   char msg[0]; /* the entry's payload */
-#endif
 };
 #endif
+#pragma clang diagnostic pop
 
 /*
  * The maximum size of the log entry payload that can be
diff --git a/liblog/include/log/log_time.h b/liblog/include/log/log_time.h
index 309f5d1..5830e6e 100644
--- a/liblog/include/log/log_time.h
+++ b/liblog/include/log/log_time.h
@@ -34,6 +34,8 @@
 
 #ifdef __cplusplus
 
+extern "C" {
+
 /*
  * NB: we did NOT define a copy constructor. This will result in structure
  * no longer being compatible with pass-by-value which is desired
@@ -170,6 +172,7 @@
   char* strptime(const char* s, const char* format = default_format);
 #endif
 } __attribute__((__packed__));
+}
 
 #else /* __cplusplus */
 
diff --git a/liblog/log_event_list.c b/liblog/log_event_list.cpp
similarity index 88%
rename from liblog/log_event_list.c
rename to liblog/log_event_list.cpp
index 14002ce..088ea94 100644
--- a/liblog/log_event_list.c
+++ b/liblog/log_event_list.cpp
@@ -29,21 +29,26 @@
 
 #define MAX_EVENT_PAYLOAD (LOGGER_ENTRY_MAX_PAYLOAD - sizeof(int32_t))
 
-typedef struct {
+enum ReadWriteFlag {
+  kAndroidLoggerRead = 1,
+  kAndroidLoggerWrite = 2,
+};
+
+struct android_log_context_internal {
   uint32_t tag;
-  unsigned pos; /* Read/write position into buffer */
+  unsigned pos;                                    /* Read/write position into buffer */
   unsigned count[ANDROID_MAX_LIST_NEST_DEPTH + 1]; /* Number of elements   */
   unsigned list[ANDROID_MAX_LIST_NEST_DEPTH + 1];  /* pos for list counter */
   unsigned list_nest_depth;
   unsigned len; /* Length or raw buffer. */
   bool overflow;
   bool list_stop; /* next call decrement list_nest_depth and issue a stop */
-  enum {
-    kAndroidLoggerRead = 1,
-    kAndroidLoggerWrite = 2,
-  } read_write_flag;
+  ReadWriteFlag read_write_flag;
   uint8_t storage[LOGGER_ENTRY_MAX_PAYLOAD];
-} android_log_context_internal;
+};
+
+// TODO(tomcherry): real C++ structs.
+typedef struct android_log_context_internal android_log_context_internal;
 
 static void init_context(android_log_context_internal* context, uint32_t tag) {
   size_t needed;
@@ -60,8 +65,8 @@
   context->pos += needed;
 }
 
-static void init_parser_context(android_log_context_internal* context,
-                                const char* msg, size_t len) {
+static void init_parser_context(android_log_context_internal* context, const char* msg,
+                                size_t len) {
   len = (len <= MAX_EVENT_PAYLOAD) ? len : MAX_EVENT_PAYLOAD;
   context->len = len;
   memcpy(context->storage, msg, len);
@@ -71,7 +76,8 @@
 LIBLOG_ABI_PUBLIC android_log_context create_android_logger(uint32_t tag) {
   android_log_context_internal* context;
 
-  context = calloc(1, sizeof(android_log_context_internal));
+  context =
+      static_cast<android_log_context_internal*>(calloc(1, sizeof(android_log_context_internal)));
   if (!context) {
     return NULL;
   }
@@ -80,12 +86,12 @@
   return (android_log_context)context;
 }
 
-LIBLOG_ABI_PUBLIC android_log_context create_android_log_parser(const char* msg,
-                                                                size_t len) {
+LIBLOG_ABI_PUBLIC android_log_context create_android_log_parser(const char* msg, size_t len) {
   android_log_context_internal* context;
   size_t i;
 
-  context = calloc(1, sizeof(android_log_context_internal));
+  context =
+      static_cast<android_log_context_internal*>(calloc(1, sizeof(android_log_context_internal)));
   if (!context) {
     return NULL;
   }
@@ -123,8 +129,8 @@
   return 0;
 }
 
-LIBLOG_ABI_PUBLIC int android_log_parser_reset(android_log_context ctx,
-                                               const char* msg, size_t len) {
+LIBLOG_ABI_PUBLIC int android_log_parser_reset(android_log_context ctx, const char* msg,
+                                               size_t len) {
   android_log_context_internal* context;
 
   context = (android_log_context_internal*)ctx;
@@ -138,7 +144,6 @@
   return 0;
 }
 
-
 LIBLOG_ABI_PUBLIC int android_log_write_list_begin(android_log_context ctx) {
   size_t needed;
   android_log_context_internal* context;
@@ -180,8 +185,7 @@
   buf[3] = (val >> 24) & 0xFF;
 }
 
-LIBLOG_ABI_PUBLIC int android_log_write_int32(android_log_context ctx,
-                                              int32_t value) {
+LIBLOG_ABI_PUBLIC int android_log_write_int32(android_log_context ctx, int32_t value) {
   size_t needed;
   android_log_context_internal* context;
 
@@ -215,8 +219,7 @@
   buf[7] = (val >> 56) & 0xFF;
 }
 
-LIBLOG_ABI_PUBLIC int android_log_write_int64(android_log_context ctx,
-                                              int64_t value) {
+LIBLOG_ABI_PUBLIC int android_log_write_int64(android_log_context ctx, int64_t value) {
   size_t needed;
   android_log_context_internal* context;
 
@@ -239,8 +242,7 @@
   return 0;
 }
 
-LIBLOG_ABI_PUBLIC int android_log_write_string8_len(android_log_context ctx,
-                                                    const char* value,
+LIBLOG_ABI_PUBLIC int android_log_write_string8_len(android_log_context ctx, const char* value,
                                                     size_t maxlen) {
   size_t needed;
   ssize_t len;
@@ -276,13 +278,11 @@
   return len;
 }
 
-LIBLOG_ABI_PUBLIC int android_log_write_string8(android_log_context ctx,
-                                                const char* value) {
+LIBLOG_ABI_PUBLIC int android_log_write_string8(android_log_context ctx, const char* value) {
   return android_log_write_string8_len(ctx, value, MAX_EVENT_PAYLOAD);
 }
 
-LIBLOG_ABI_PUBLIC int android_log_write_float32(android_log_context ctx,
-                                                float value) {
+LIBLOG_ABI_PUBLIC int android_log_write_float32(android_log_context ctx, float value) {
   size_t needed;
   uint32_t ivalue;
   android_log_context_internal* context;
@@ -337,8 +337,7 @@
 /*
  * Logs the list of elements to the event log.
  */
-LIBLOG_ABI_PUBLIC int android_log_write_list(android_log_context ctx,
-                                             log_id_t id) {
+LIBLOG_ABI_PUBLIC int android_log_write_list(android_log_context ctx, log_id_t id) {
   android_log_context_internal* context;
   const char* msg;
   ssize_t len;
@@ -368,13 +367,11 @@
   }
   return (id == LOG_ID_EVENTS)
              ? __android_log_bwrite(context->tag, msg, len)
-             : ((id == LOG_ID_STATS)
-                    ? __android_log_stats_bwrite(context->tag, msg, len)
-                    : __android_log_security_bwrite(context->tag, msg, len));
+             : ((id == LOG_ID_STATS) ? __android_log_stats_bwrite(context->tag, msg, len)
+                                     : __android_log_security_bwrite(context->tag, msg, len));
 }
 
-LIBLOG_ABI_PRIVATE int android_log_write_list_buffer(android_log_context ctx,
-                                                     const char** buffer) {
+LIBLOG_ABI_PRIVATE int android_log_write_list_buffer(android_log_context ctx, const char** buffer) {
   android_log_context_internal* context;
   const char* msg;
   ssize_t len;
@@ -428,8 +425,7 @@
  * this and continues to call this function, the behavior is undefined
  * (although it won't crash).
  */
-static android_log_list_element android_log_read_next_internal(
-    android_log_context ctx, int peek) {
+static android_log_list_element android_log_read_next_internal(android_log_context ctx, int peek) {
   android_log_list_element elem;
   unsigned pos;
   android_log_context_internal* context;
@@ -444,9 +440,9 @@
       (context->count[context->list_nest_depth] >=
        (MAX_EVENT_PAYLOAD / (sizeof(uint8_t) + sizeof(uint8_t))))) {
     elem.type = EVENT_TYPE_UNKNOWN;
-    if (context && (context->list_stop ||
-                    ((context->list_nest_depth <= ANDROID_MAX_LIST_NEST_DEPTH) &&
-                     !context->count[context->list_nest_depth]))) {
+    if (context &&
+        (context->list_stop || ((context->list_nest_depth <= ANDROID_MAX_LIST_NEST_DEPTH) &&
+                                !context->count[context->list_nest_depth]))) {
       elem.type = EVENT_TYPE_LIST_STOP;
     }
     elem.complete = true;
@@ -460,9 +456,8 @@
   pos = context->pos;
   if (context->list_stop) {
     elem.type = EVENT_TYPE_LIST_STOP;
-    elem.complete = !context->count[0] &&
-                    (!context->list_nest_depth ||
-                     ((context->list_nest_depth == 1) && !context->count[1]));
+    elem.complete = !context->count[0] && (!context->list_nest_depth ||
+                                           ((context->list_nest_depth == 1) && !context->count[1]));
     if (!peek) {
       /* Suck in superfluous stop */
       if (context->storage[pos] == EVENT_TYPE_LIST_STOP) {
@@ -485,7 +480,7 @@
     return elem;
   }
 
-  elem.type = context->storage[pos++];
+  elem.type = static_cast<AndroidEventLogType>(context->storage[pos++]);
   switch ((int)elem.type) {
     case EVENT_TYPE_FLOAT:
     /* Rely on union to translate elem.data.int32 into elem.data.float32 */
@@ -598,12 +593,10 @@
   }
 }
 
-LIBLOG_ABI_PUBLIC android_log_list_element
-android_log_read_next(android_log_context ctx) {
+LIBLOG_ABI_PUBLIC android_log_list_element android_log_read_next(android_log_context ctx) {
   return android_log_read_next_internal(ctx, 0);
 }
 
-LIBLOG_ABI_PUBLIC android_log_list_element
-android_log_peek_next(android_log_context ctx) {
+LIBLOG_ABI_PUBLIC android_log_list_element android_log_peek_next(android_log_context ctx) {
   return android_log_read_next_internal(ctx, 1);
 }
diff --git a/liblog/log_event_write.c b/liblog/log_event_write.cpp
similarity index 89%
rename from liblog/log_event_write.c
rename to liblog/log_event_write.cpp
index 45a6f37..e644a3b 100644
--- a/liblog/log_event_write.c
+++ b/liblog/log_event_write.cpp
@@ -24,9 +24,8 @@
 
 #define MAX_SUBTAG_LEN 32
 
-LIBLOG_ABI_PUBLIC int __android_log_error_write(int tag, const char* subTag,
-                                                int32_t uid, const char* data,
-                                                uint32_t dataLen) {
+LIBLOG_ABI_PUBLIC int __android_log_error_write(int tag, const char* subTag, int32_t uid,
+                                                const char* data, uint32_t dataLen) {
   int ret = -EINVAL;
 
   if (subTag && (data || !dataLen)) {
diff --git a/liblog/log_portability.h b/liblog/log_portability.h
index 88805c7..4a1f59c 100644
--- a/liblog/log_portability.h
+++ b/liblog/log_portability.h
@@ -46,7 +46,7 @@
 #if defined(_WIN32)
 #define LIBLOG_WEAK static /* Accept that it is totally private */
 #else
-#define LIBLOG_WEAK __attribute__((weak, visibility("default")))
+#define LIBLOG_WEAK extern "C" __attribute__((weak, visibility("default")))
 #endif
 
 /* possible missing definitions in sys/cdefs.h */
@@ -62,11 +62,6 @@
 #endif
 #endif
 
-/* Unused argument. For C code only, remove symbol name for C++ */
-#ifndef __unused
-#define __unused __attribute__((__unused__))
-#endif
-
 /* possible missing definitions in unistd.h */
 
 #ifndef TEMP_FAILURE_RETRY
diff --git a/liblog/logd_reader.c b/liblog/logd_reader.cpp
similarity index 86%
rename from liblog/logd_reader.c
rename to liblog/logd_reader.cpp
index 603ba24..05bbcbc 100644
--- a/liblog/logd_reader.c
+++ b/liblog/logd_reader.cpp
@@ -47,8 +47,7 @@
 static int logdVersion(struct android_log_logger* logger,
                        struct android_log_transport_context* transp);
 static int logdRead(struct android_log_logger_list* logger_list,
-                    struct android_log_transport_context* transp,
-                    struct log_msg* log_msg);
+                    struct android_log_transport_context* transp, struct log_msg* log_msg);
 static int logdPoll(struct android_log_logger_list* logger_list,
                     struct android_log_transport_context* transp);
 static void logdClose(struct android_log_logger_list* logger_list,
@@ -56,37 +55,33 @@
 static int logdClear(struct android_log_logger* logger,
                      struct android_log_transport_context* transp);
 static ssize_t logdSetSize(struct android_log_logger* logger,
-                           struct android_log_transport_context* transp,
-                           size_t size);
+                           struct android_log_transport_context* transp, size_t size);
 static ssize_t logdGetSize(struct android_log_logger* logger,
                            struct android_log_transport_context* transp);
 static ssize_t logdGetReadableSize(struct android_log_logger* logger,
                                    struct android_log_transport_context* transp);
 static ssize_t logdGetPrune(struct android_log_logger_list* logger,
-                            struct android_log_transport_context* transp,
-                            char* buf, size_t len);
+                            struct android_log_transport_context* transp, char* buf, size_t len);
 static ssize_t logdSetPrune(struct android_log_logger_list* logger,
-                            struct android_log_transport_context* transp,
-                            char* buf, size_t len);
+                            struct android_log_transport_context* transp, char* buf, size_t len);
 static ssize_t logdGetStats(struct android_log_logger_list* logger,
-                            struct android_log_transport_context* transp,
-                            char* buf, size_t len);
+                            struct android_log_transport_context* transp, char* buf, size_t len);
 
 LIBLOG_HIDDEN struct android_log_transport_read logdLoggerRead = {
-  .node = { &logdLoggerRead.node, &logdLoggerRead.node },
-  .name = "logd",
-  .available = logdAvailable,
-  .version = logdVersion,
-  .read = logdRead,
-  .poll = logdPoll,
-  .close = logdClose,
-  .clear = logdClear,
-  .getSize = logdGetSize,
-  .setSize = logdSetSize,
-  .getReadableSize = logdGetReadableSize,
-  .getPrune = logdGetPrune,
-  .setPrune = logdSetPrune,
-  .getStats = logdGetStats,
+    .node = {&logdLoggerRead.node, &logdLoggerRead.node},
+    .name = "logd",
+    .available = logdAvailable,
+    .version = logdVersion,
+    .read = logdRead,
+    .poll = logdPoll,
+    .close = logdClose,
+    .clear = logdClear,
+    .getSize = logdGetSize,
+    .setSize = logdSetSize,
+    .getReadableSize = logdGetReadableSize,
+    .getPrune = logdGetPrune,
+    .setPrune = logdSetPrune,
+    .getStats = logdGetStats,
 };
 
 static int logdAvailable(log_id_t logId) {
@@ -109,8 +104,7 @@
 
 #if defined(_WIN32)
 
-LIBLOG_WEAK int socket_local_client(const char* name, int namespaceId,
-                                    int type) {
+LIBLOG_WEAK int socket_local_client(const char* name, int namespaceId, int type) {
   errno = ENOSYS;
   return -ENOSYS;
 }
@@ -131,8 +125,7 @@
 
 /* Documented in header file. */
 LIBLOG_WEAK int socket_make_sockaddr_un(const char* name, int namespaceId,
-                                        struct sockaddr_un* p_addr,
-                                        socklen_t* alen) {
+                                        struct sockaddr_un* p_addr, socklen_t* alen) {
   memset(p_addr, 0, sizeof(*p_addr));
   size_t namelen;
 
@@ -158,8 +151,7 @@
 
       namelen = strlen(name) + strlen(FILESYSTEM_SOCKET_PREFIX);
       /* unix_path_max appears to be missing on linux */
-      if (namelen >
-          sizeof(*p_addr) - offsetof(struct sockaddr_un, sun_path) - 1) {
+      if (namelen > sizeof(*p_addr) - offsetof(struct sockaddr_un, sun_path) - 1) {
         goto error;
       }
 
@@ -171,8 +163,7 @@
     case ANDROID_SOCKET_NAMESPACE_RESERVED:
       namelen = strlen(name) + strlen(ANDROID_RESERVED_SOCKET_PREFIX);
       /* unix_path_max appears to be missing on linux */
-      if (namelen >
-          sizeof(*p_addr) - offsetof(struct sockaddr_un, sun_path) - 1) {
+      if (namelen > sizeof(*p_addr) - offsetof(struct sockaddr_un, sun_path) - 1) {
         goto error;
       }
 
@@ -183,8 +174,7 @@
     case ANDROID_SOCKET_NAMESPACE_FILESYSTEM:
       namelen = strlen(name);
       /* unix_path_max appears to be missing on linux */
-      if (namelen >
-          sizeof(*p_addr) - offsetof(struct sockaddr_un, sun_path) - 1) {
+      if (namelen > sizeof(*p_addr) - offsetof(struct sockaddr_un, sun_path) - 1) {
         goto error;
       }
 
@@ -210,8 +200,8 @@
  *
  * Used by AndroidSocketImpl
  */
-LIBLOG_WEAK int socket_local_client_connect(int fd, const char* name,
-                                            int namespaceId, int type __unused) {
+LIBLOG_WEAK int socket_local_client_connect(int fd, const char* name, int namespaceId,
+                                            int type __unused) {
   struct sockaddr_un addr;
   socklen_t alen;
   int err;
@@ -236,8 +226,7 @@
  * connect to peer named "name"
  * returns fd or -1 on error
  */
-LIBLOG_WEAK int socket_local_client(const char* name, int namespaceId,
-                                    int type) {
+LIBLOG_WEAK int socket_local_client(const char* name, int namespaceId, int type) {
   int s;
 
   s = socket(AF_LOCAL, type, 0);
@@ -255,14 +244,13 @@
 /* End of ../libcutils/socket_local_client.c */
 
 /* worker for sending the command to the logger */
-static ssize_t send_log_msg(struct android_log_logger* logger, const char* msg,
-                            char* buf, size_t buf_size) {
+static ssize_t send_log_msg(struct android_log_logger* logger, const char* msg, char* buf,
+                            size_t buf_size) {
   ssize_t ret;
   size_t len;
   char* cp;
   int errno_save = 0;
-  int sock = socket_local_client("logd", ANDROID_SOCKET_NAMESPACE_RESERVED,
-                                 SOCK_STREAM);
+  int sock = socket_local_client("logd", ANDROID_SOCKET_NAMESPACE_RESERVED, SOCK_STREAM);
   if (sock < 0) {
     return sock;
   }
@@ -342,8 +330,7 @@
                      struct android_log_transport_context* transp __unused) {
   char buf[512];
 
-  return check_log_success(buf,
-                           send_log_msg(logger, "clear %d", buf, sizeof(buf)));
+  return check_log_success(buf, send_log_msg(logger, "clear %d", buf, sizeof(buf)));
 }
 
 /* returns the total size of the log's ring buffer */
@@ -364,8 +351,7 @@
 }
 
 static ssize_t logdSetSize(struct android_log_logger* logger,
-                           struct android_log_transport_context* transp __unused,
-                           size_t size) {
+                           struct android_log_transport_context* transp __unused, size_t size) {
   char buf[512];
 
   snprintf(buf, sizeof(buf), "setLogSize %d %zu", logger->logId, size);
@@ -378,8 +364,7 @@
  * log consumed)
  */
 static ssize_t logdGetReadableSize(struct android_log_logger* logger,
-                                   struct android_log_transport_context* transp
-                                       __unused) {
+                                   struct android_log_transport_context* transp __unused) {
   char buf[512];
 
   ssize_t ret = send_log_msg(logger, "getLogSizeUsed %d", buf, sizeof(buf));
@@ -407,8 +392,8 @@
  * returns statistics
  */
 static ssize_t logdGetStats(struct android_log_logger_list* logger_list,
-                            struct android_log_transport_context* transp __unused,
-                            char* buf, size_t len) {
+                            struct android_log_transport_context* transp __unused, char* buf,
+                            size_t len) {
   struct android_log_logger* logger;
   char* cp = buf;
   size_t remaining = len;
@@ -434,14 +419,14 @@
 }
 
 static ssize_t logdGetPrune(struct android_log_logger_list* logger_list __unused,
-                            struct android_log_transport_context* transp __unused,
-                            char* buf, size_t len) {
+                            struct android_log_transport_context* transp __unused, char* buf,
+                            size_t len) {
   return send_log_msg(NULL, "getPruneList", buf, len);
 }
 
 static ssize_t logdSetPrune(struct android_log_logger_list* logger_list __unused,
-                            struct android_log_transport_context* transp __unused,
-                            char* buf, size_t len) {
+                            struct android_log_transport_context* transp __unused, char* buf,
+                            size_t len) {
   const char cmd[] = "setPruneList ";
   const size_t cmdlen = sizeof(cmd) - 1;
 
@@ -455,8 +440,7 @@
   return check_log_success(buf, send_log_msg(NULL, NULL, buf, len));
 }
 
-static void caught_signal(int signum __unused) {
-}
+static void caught_signal(int signum __unused) {}
 
 static int logdOpen(struct android_log_logger_list* logger_list,
                     struct android_log_transport_context* transp) {
@@ -476,12 +460,10 @@
     return sock;
   }
 
-  sock = socket_local_client("logdr", ANDROID_SOCKET_NAMESPACE_RESERVED,
-                             SOCK_SEQPACKET);
+  sock = socket_local_client("logdr", ANDROID_SOCKET_NAMESPACE_RESERVED, SOCK_SEQPACKET);
   if (sock == 0) {
     /* Guarantee not file descriptor zero */
-    int newsock = socket_local_client(
-        "logdr", ANDROID_SOCKET_NAMESPACE_RESERVED, SOCK_SEQPACKET);
+    int newsock = socket_local_client("logdr", ANDROID_SOCKET_NAMESPACE_RESERVED, SOCK_SEQPACKET);
     close(sock);
     sock = newsock;
   }
@@ -492,8 +474,7 @@
     return sock;
   }
 
-  strcpy(buffer, (logger_list->mode & ANDROID_LOG_NONBLOCK) ? "dumpAndClose"
-                                                            : "stream");
+  strcpy(buffer, (logger_list->mode & ANDROID_LOG_NONBLOCK) ? "dumpAndClose" : "stream");
   cp = buffer + strlen(buffer);
 
   strcpy(cp, " lids");
@@ -518,14 +499,13 @@
   if (logger_list->start.tv_sec || logger_list->start.tv_nsec) {
     if (logger_list->mode & ANDROID_LOG_WRAP) {
       // ToDo: alternate API to allow timeout to be adjusted.
-      ret = snprintf(cp, remaining, " timeout=%u",
-                     ANDROID_LOG_WRAP_DEFAULT_TIMEOUT);
+      ret = snprintf(cp, remaining, " timeout=%u", ANDROID_LOG_WRAP_DEFAULT_TIMEOUT);
       ret = min(ret, remaining);
       remaining -= ret;
       cp += ret;
     }
-    ret = snprintf(cp, remaining, " start=%" PRIu32 ".%09" PRIu32,
-                   logger_list->start.tv_sec, logger_list->start.tv_nsec);
+    ret = snprintf(cp, remaining, " start=%" PRIu32 ".%09" PRIu32, logger_list->start.tv_sec,
+                   logger_list->start.tv_nsec);
     ret = min(ret, remaining);
     remaining -= ret;
     cp += ret;
@@ -576,8 +556,7 @@
 
 /* Read from the selected logs */
 static int logdRead(struct android_log_logger_list* logger_list,
-                    struct android_log_transport_context* transp,
-                    struct log_msg* log_msg) {
+                    struct android_log_transport_context* transp, struct log_msg* log_msg) {
   int ret, e;
   struct sigaction ignore;
   struct sigaction old_sigaction;
diff --git a/liblog/logd_writer.c b/liblog/logd_writer.cpp
similarity index 85%
rename from liblog/logd_writer.c
rename to liblog/logd_writer.cpp
index e0e3eca..4731487 100644
--- a/liblog/logd_writer.c
+++ b/liblog/logd_writer.cpp
@@ -45,17 +45,16 @@
 static int logdAvailable(log_id_t LogId);
 static int logdOpen();
 static void logdClose();
-static int logdWrite(log_id_t logId, struct timespec* ts, struct iovec* vec,
-                     size_t nr);
+static int logdWrite(log_id_t logId, struct timespec* ts, struct iovec* vec, size_t nr);
 
 LIBLOG_HIDDEN struct android_log_transport_write logdLoggerWrite = {
-  .node = { &logdLoggerWrite.node, &logdLoggerWrite.node },
-  .context.sock = -EBADF,
-  .name = "logd",
-  .available = logdAvailable,
-  .open = logdOpen,
-  .close = logdClose,
-  .write = logdWrite,
+    .node = {&logdLoggerWrite.node, &logdLoggerWrite.node},
+    .context.sock = -EBADF,
+    .name = "logd",
+    .available = logdAvailable,
+    .open = logdOpen,
+    .close = logdClose,
+    .write = logdWrite,
 };
 
 /* log_init_lock assumed */
@@ -64,8 +63,7 @@
 
   i = atomic_load(&logdLoggerWrite.context.sock);
   if (i < 0) {
-    int sock = TEMP_FAILURE_RETRY(
-        socket(PF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0));
+    int sock = TEMP_FAILURE_RETRY(socket(PF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0));
     if (sock < 0) {
       ret = -errno;
     } else {
@@ -74,15 +72,15 @@
       un.sun_family = AF_UNIX;
       strcpy(un.sun_path, "/dev/socket/logdw");
 
-      if (TEMP_FAILURE_RETRY(connect(sock, (struct sockaddr*)&un,
-                                     sizeof(struct sockaddr_un))) < 0) {
+      if (TEMP_FAILURE_RETRY(connect(sock, (struct sockaddr*)&un, sizeof(struct sockaddr_un))) <
+          0) {
         ret = -errno;
         switch (ret) {
           case -ENOTCONN:
           case -ECONNREFUSED:
           case -ENOENT:
             i = atomic_exchange(&logdLoggerWrite.context.sock, ret);
-          /* FALLTHRU */
+            [[fallthrough]];
           default:
             break;
         }
@@ -124,16 +122,15 @@
   return 1;
 }
 
-static int logdWrite(log_id_t logId, struct timespec* ts, struct iovec* vec,
-                     size_t nr) {
+static int logdWrite(log_id_t logId, struct timespec* ts, struct iovec* vec, size_t nr) {
   ssize_t ret;
   int sock;
   static const unsigned headerLength = 1;
   struct iovec newVec[nr + headerLength];
   android_log_header_t header;
   size_t i, payloadSize;
-  static atomic_int_fast32_t dropped;
-  static atomic_int_fast32_t droppedSecurity;
+  static atomic_int dropped;
+  static atomic_int droppedSecurity;
 
   sock = atomic_load(&logdLoggerWrite.context.sock);
   if (sock < 0) switch (sock) {
@@ -181,8 +178,7 @@
   newVec[0].iov_len = sizeof(header);
 
   if (sock >= 0) {
-    int32_t snapshot =
-        atomic_exchange_explicit(&droppedSecurity, 0, memory_order_relaxed);
+    int32_t snapshot = atomic_exchange_explicit(&droppedSecurity, 0, memory_order_relaxed);
     if (snapshot) {
       android_log_event_int_t buffer;
 
@@ -196,14 +192,12 @@
 
       ret = TEMP_FAILURE_RETRY(writev(sock, newVec, 2));
       if (ret != (ssize_t)(sizeof(header) + sizeof(buffer))) {
-        atomic_fetch_add_explicit(&droppedSecurity, snapshot,
-                                  memory_order_relaxed);
+        atomic_fetch_add_explicit(&droppedSecurity, snapshot, memory_order_relaxed);
       }
     }
     snapshot = atomic_exchange_explicit(&dropped, 0, memory_order_relaxed);
-    if (snapshot &&
-        __android_log_is_loggable_len(ANDROID_LOG_INFO, "liblog",
-                                      strlen("liblog"), ANDROID_LOG_VERBOSE)) {
+    if (snapshot && __android_log_is_loggable_len(ANDROID_LOG_INFO, "liblog", strlen("liblog"),
+                                                  ANDROID_LOG_VERBOSE)) {
       android_log_event_int_t buffer;
 
       header.id = LOG_ID_EVENTS;
@@ -267,12 +261,11 @@
         return ret;
       }
 
-      ret = TEMP_FAILURE_RETRY(
-          writev(atomic_load(&logdLoggerWrite.context.sock), newVec, i));
+      ret = TEMP_FAILURE_RETRY(writev(atomic_load(&logdLoggerWrite.context.sock), newVec, i));
       if (ret < 0) {
         ret = -errno;
       }
-    /* FALLTHRU */
+      [[fallthrough]];
     default:
       break;
   }
diff --git a/liblog/logger.h b/liblog/logger.h
index af83228..7bb9b20 100644
--- a/liblog/logger.h
+++ b/liblog/logger.h
@@ -29,7 +29,7 @@
 __BEGIN_DECLS
 
 /* Union, sock or fd of zero is not allowed unless static initialized */
-union android_log_context {
+union android_log_context_union {
   void* priv;
   atomic_int sock;
   atomic_int fd;
@@ -41,7 +41,7 @@
   struct listnode node;
   const char* name;                  /* human name to describe the transport */
   unsigned logMask;                  /* mask cache of available() success */
-  union android_log_context context; /* Initialized by static allocation */
+  union android_log_context_union context; /* Initialized by static allocation */
 
   int (*available)(log_id_t logId); /* Does not cause resources to be taken */
   int (*open)();   /* can be called multiple times, reusing current resources */
@@ -115,7 +115,7 @@
 
 struct android_log_transport_context {
   struct listnode node;
-  union android_log_context context; /* zero init per-transport context */
+  union android_log_context_union context; /* zero init per-transport context */
   struct android_log_logger_list* parent;
 
   struct android_log_transport_read* transport;
@@ -161,7 +161,7 @@
 LIBLOG_HIDDEN int __android_log_trylock();
 LIBLOG_HIDDEN void __android_log_unlock();
 
-LIBLOG_HIDDEN int __android_log_transport;
+extern LIBLOG_HIDDEN int __android_log_transport;
 
 __END_DECLS
 
diff --git a/liblog/logger_lock.c b/liblog/logger_lock.cpp
similarity index 100%
rename from liblog/logger_lock.c
rename to liblog/logger_lock.cpp
diff --git a/liblog/logger_name.c b/liblog/logger_name.cpp
similarity index 79%
rename from liblog/logger_name.c
rename to liblog/logger_name.cpp
index 479bbfe..c6f3cb7 100644
--- a/liblog/logger_name.c
+++ b/liblog/logger_name.cpp
@@ -15,6 +15,7 @@
 */
 
 #include <string.h>
+#include <type_traits>
 
 #include <log/log.h>
 
@@ -22,7 +23,7 @@
 
 /* In the future, we would like to make this list extensible */
 static const char* LOG_NAME[LOG_ID_MAX] = {
-      /* clang-format off */
+    /* clang-format off */
   [LOG_ID_MAIN] = "main",
   [LOG_ID_RADIO] = "radio",
   [LOG_ID_EVENTS] = "events",
@@ -31,7 +32,7 @@
   [LOG_ID_STATS] = "stats",
   [LOG_ID_SECURITY] = "security",
   [LOG_ID_KERNEL] = "kernel",
-  /* clang-format on */
+    /* clang-format on */
 };
 
 LIBLOG_ABI_PUBLIC const char* android_log_id_to_name(log_id_t log_id) {
@@ -41,12 +42,15 @@
   return LOG_NAME[log_id];
 }
 
+static_assert(std::is_same<std::underlying_type<log_id_t>::type, uint32_t>::value,
+              "log_id_t must be an unsigned int");
+
 LIBLOG_ABI_PUBLIC log_id_t android_name_to_log_id(const char* logName) {
   const char* b;
-  int ret;
+  unsigned int ret;
 
   if (!logName) {
-    return -1; /* NB: log_id_t is unsigned */
+    return static_cast<log_id_t>(0xFFFFFFFF);
   }
   b = strrchr(logName, '/');
   if (!b) {
@@ -58,8 +62,8 @@
   for (ret = LOG_ID_MIN; ret < LOG_ID_MAX; ++ret) {
     const char* l = LOG_NAME[ret];
     if (l && !strcmp(b, l)) {
-      return ret;
+      return static_cast<log_id_t>(ret);
     }
   }
-  return -1; /* should never happen */
+  return static_cast<log_id_t>(0xFFFFFFFF); /* should never happen */
 }
diff --git a/liblog/logger_read.c b/liblog/logger_read.cpp
similarity index 76%
rename from liblog/logger_read.c
rename to liblog/logger_read.cpp
index 29ebaf7..e429c36 100644
--- a/liblog/logger_read.c
+++ b/liblog/logger_read.cpp
@@ -14,6 +14,8 @@
 ** limitations under the License.
 */
 
+#include "log/log_read.h"
+
 #include <errno.h>
 #include <fcntl.h>
 #include <pthread.h>
@@ -34,8 +36,7 @@
 /* android_logger_alloc unimplemented, no use case */
 /* android_logger_free not exported */
 static void android_logger_free(struct logger* logger) {
-  struct android_log_logger* logger_internal =
-      (struct android_log_logger*)logger;
+  struct android_log_logger* logger_internal = (struct android_log_logger*)logger;
 
   if (!logger_internal) {
     return;
@@ -71,15 +72,13 @@
 
   __android_log_lock();
   /* mini __write_to_log_initialize() to populate transports */
-  if (list_empty(&__android_log_transport_read) &&
-      list_empty(&__android_log_persist_read)) {
+  if (list_empty(&__android_log_transport_read) && list_empty(&__android_log_persist_read)) {
     __android_log_config_read();
   }
   __android_log_unlock();
 
-  node = (logger_list->mode & ANDROID_LOG_PSTORE)
-             ? &__android_log_persist_read
-             : &__android_log_transport_read;
+  node = (logger_list->mode & ANDROID_LOG_PSTORE) ? &__android_log_persist_read
+                                                  : &__android_log_transport_read;
 
   read_transport_for_each(transport, node) {
     struct android_log_transport_context* transp;
@@ -92,15 +91,14 @@
       if ((logId == LOG_ID_SECURITY) && (__android_log_uid() != AID_SYSTEM)) {
         continue;
       }
-      if (transport->read &&
-          (!transport->available || (transport->available(logId) >= 0))) {
+      if (transport->read && (!transport->available || (transport->available(logId) >= 0))) {
         logMask |= 1 << logId;
       }
     }
     if (!logMask) {
       continue;
     }
-    transp = calloc(1, sizeof(*transp));
+    transp = static_cast<android_log_transport_context*>(calloc(1, sizeof(*transp)));
     if (!transp) {
       return -ENOMEM;
     }
@@ -116,31 +114,29 @@
   return 0;
 }
 
-#define LOGGER_FUNCTION(logger, def, func, args...)                   \
-  ssize_t ret = -EINVAL;                                              \
-  struct android_log_transport_context* transp;                       \
-  struct android_log_logger* logger_internal =                        \
-      (struct android_log_logger*)(logger);                           \
-                                                                      \
-  if (!logger_internal) {                                             \
-    return ret;                                                       \
-  }                                                                   \
-  ret = init_transport_context(logger_internal->parent);              \
-  if (ret < 0) {                                                      \
-    return ret;                                                       \
-  }                                                                   \
-                                                                      \
-  ret = (def);                                                        \
-  transport_context_for_each(transp, logger_internal->parent) {       \
-    if ((transp->logMask & (1 << logger_internal->logId)) &&          \
-        transp->transport && transp->transport->func) {               \
-      ssize_t retval =                                                \
-          (transp->transport->func)(logger_internal, transp, ##args); \
-      if ((ret >= 0) || (ret == (def))) {                             \
-        ret = retval;                                                 \
-      }                                                               \
-    }                                                                 \
-  }                                                                   \
+#define LOGGER_FUNCTION(logger, def, func, args...)                                  \
+  ssize_t ret = -EINVAL;                                                             \
+  struct android_log_transport_context* transp;                                      \
+  struct android_log_logger* logger_internal = (struct android_log_logger*)(logger); \
+                                                                                     \
+  if (!logger_internal) {                                                            \
+    return ret;                                                                      \
+  }                                                                                  \
+  ret = init_transport_context(logger_internal->parent);                             \
+  if (ret < 0) {                                                                     \
+    return ret;                                                                      \
+  }                                                                                  \
+                                                                                     \
+  ret = (def);                                                                       \
+  transport_context_for_each(transp, logger_internal->parent) {                      \
+    if ((transp->logMask & (1 << logger_internal->logId)) && transp->transport &&    \
+        transp->transport->func) {                                                   \
+      ssize_t retval = (transp->transport->func)(logger_internal, transp, ##args);   \
+      if ((ret >= 0) || (ret == (def))) {                                            \
+        ret = retval;                                                                \
+      }                                                                              \
+    }                                                                                \
+  }                                                                                  \
   return ret
 
 LIBLOG_ABI_PUBLIC int android_logger_clear(struct logger* logger) {
@@ -152,8 +148,7 @@
   LOGGER_FUNCTION(logger, -ENODEV, getSize);
 }
 
-LIBLOG_ABI_PUBLIC int android_logger_set_log_size(struct logger* logger,
-                                                  unsigned long size) {
+LIBLOG_ABI_PUBLIC int android_logger_set_log_size(struct logger* logger, unsigned long size) {
   LOGGER_FUNCTION(logger, -ENODEV, setSize, size);
 }
 
@@ -161,8 +156,7 @@
  * returns the readable size of the log's ring buffer (that is, amount of the
  * log consumed)
  */
-LIBLOG_ABI_PUBLIC long android_logger_get_log_readable_size(
-    struct logger* logger) {
+LIBLOG_ABI_PUBLIC long android_logger_get_log_readable_size(struct logger* logger) {
   LOGGER_FUNCTION(logger, -ENODEV, getReadableSize);
 }
 
@@ -173,51 +167,50 @@
   LOGGER_FUNCTION(logger, 4, version);
 }
 
-#define LOGGER_LIST_FUNCTION(logger_list, def, func, args...)              \
-  struct android_log_transport_context* transp;                            \
-  struct android_log_logger_list* logger_list_internal =                   \
-      (struct android_log_logger_list*)(logger_list);                      \
-                                                                           \
-  ssize_t ret = init_transport_context(logger_list_internal);              \
-  if (ret < 0) {                                                           \
-    return ret;                                                            \
-  }                                                                        \
-                                                                           \
-  ret = (def);                                                             \
-  transport_context_for_each(transp, logger_list_internal) {               \
-    if (transp->transport && (transp->transport->func)) {                  \
-      ssize_t retval =                                                     \
-          (transp->transport->func)(logger_list_internal, transp, ##args); \
-      if ((ret >= 0) || (ret == (def))) {                                  \
-        ret = retval;                                                      \
-      }                                                                    \
-    }                                                                      \
-  }                                                                        \
+#define LOGGER_LIST_FUNCTION(logger_list, def, func, args...)                           \
+  struct android_log_transport_context* transp;                                         \
+  struct android_log_logger_list* logger_list_internal =                                \
+      (struct android_log_logger_list*)(logger_list);                                   \
+                                                                                        \
+  ssize_t ret = init_transport_context(logger_list_internal);                           \
+  if (ret < 0) {                                                                        \
+    return ret;                                                                         \
+  }                                                                                     \
+                                                                                        \
+  ret = (def);                                                                          \
+  transport_context_for_each(transp, logger_list_internal) {                            \
+    if (transp->transport && (transp->transport->func)) {                               \
+      ssize_t retval = (transp->transport->func)(logger_list_internal, transp, ##args); \
+      if ((ret >= 0) || (ret == (def))) {                                               \
+        ret = retval;                                                                   \
+      }                                                                                 \
+    }                                                                                   \
+  }                                                                                     \
   return ret
 
 /*
  * returns statistics
  */
-LIBLOG_ABI_PUBLIC ssize_t android_logger_get_statistics(
-    struct logger_list* logger_list, char* buf, size_t len) {
+LIBLOG_ABI_PUBLIC ssize_t android_logger_get_statistics(struct logger_list* logger_list, char* buf,
+                                                        size_t len) {
   LOGGER_LIST_FUNCTION(logger_list, -ENODEV, getStats, buf, len);
 }
 
-LIBLOG_ABI_PUBLIC ssize_t android_logger_get_prune_list(
-    struct logger_list* logger_list, char* buf, size_t len) {
+LIBLOG_ABI_PUBLIC ssize_t android_logger_get_prune_list(struct logger_list* logger_list, char* buf,
+                                                        size_t len) {
   LOGGER_LIST_FUNCTION(logger_list, -ENODEV, getPrune, buf, len);
 }
 
-LIBLOG_ABI_PUBLIC int android_logger_set_prune_list(
-    struct logger_list* logger_list, char* buf, size_t len) {
+LIBLOG_ABI_PUBLIC int android_logger_set_prune_list(struct logger_list* logger_list, char* buf,
+                                                    size_t len) {
   LOGGER_LIST_FUNCTION(logger_list, -ENODEV, setPrune, buf, len);
 }
 
-LIBLOG_ABI_PUBLIC struct logger_list* android_logger_list_alloc(
-    int mode, unsigned int tail, pid_t pid) {
+LIBLOG_ABI_PUBLIC struct logger_list* android_logger_list_alloc(int mode, unsigned int tail,
+                                                                pid_t pid) {
   struct android_log_logger_list* logger_list;
 
-  logger_list = calloc(1, sizeof(*logger_list));
+  logger_list = static_cast<android_log_logger_list*>(calloc(1, sizeof(*logger_list)));
   if (!logger_list) {
     return NULL;
   }
@@ -231,11 +224,11 @@
   return (struct logger_list*)logger_list;
 }
 
-LIBLOG_ABI_PUBLIC struct logger_list* android_logger_list_alloc_time(
-    int mode, log_time start, pid_t pid) {
+LIBLOG_ABI_PUBLIC struct logger_list* android_logger_list_alloc_time(int mode, log_time start,
+                                                                     pid_t pid) {
   struct android_log_logger_list* logger_list;
 
-  logger_list = calloc(1, sizeof(*logger_list));
+  logger_list = static_cast<android_log_logger_list*>(calloc(1, sizeof(*logger_list)));
   if (!logger_list) {
     return NULL;
   }
@@ -253,8 +246,8 @@
 /* android_logger_list_unregister unimplemented, no use case */
 
 /* Open the named log and add it to the logger list */
-LIBLOG_ABI_PUBLIC struct logger* android_logger_open(
-    struct logger_list* logger_list, log_id_t logId) {
+LIBLOG_ABI_PUBLIC struct logger* android_logger_open(struct logger_list* logger_list,
+                                                     log_id_t logId) {
   struct android_log_logger_list* logger_list_internal =
       (struct android_log_logger_list*)logger_list;
   struct android_log_logger* logger;
@@ -269,7 +262,7 @@
     }
   }
 
-  logger = calloc(1, sizeof(*logger));
+  logger = static_cast<android_log_logger*>(calloc(1, sizeof(*logger)));
   if (!logger) {
     goto err;
   }
@@ -296,8 +289,8 @@
 }
 
 /* Open the single named log and make it part of a new logger list */
-LIBLOG_ABI_PUBLIC struct logger_list* android_logger_list_open(
-    log_id_t logId, int mode, unsigned int tail, pid_t pid) {
+LIBLOG_ABI_PUBLIC struct logger_list* android_logger_list_open(log_id_t logId, int mode,
+                                                               unsigned int tail, pid_t pid) {
   struct logger_list* logger_list = android_logger_list_alloc(mode, tail, pid);
 
   if (!logger_list) {
@@ -364,8 +357,8 @@
   }
 
   /* at least one transport */
-  transp = node_to_item(logger_list_internal->transport.next,
-                        struct android_log_transport_context, node);
+  transp = node_to_item(logger_list_internal->transport.next, struct android_log_transport_context,
+                        node);
 
   /* more than one transport? */
   if (transp->node.next != &logger_list_internal->transport) {
@@ -386,11 +379,9 @@
             retval = transp->ret = 0;
           } else if ((logger_list_internal->mode & ANDROID_LOG_NONBLOCK) ||
                      !transp->transport->poll) {
-            retval = android_transport_read(logger_list_internal, transp,
-                                            &transp->logMsg);
+            retval = android_transport_read(logger_list_internal, transp, &transp->logMsg);
           } else {
-            int pollval =
-                (*transp->transport->poll)(logger_list_internal, transp);
+            int pollval = (*transp->transport->poll)(logger_list_internal, transp);
             if (pollval <= 0) {
               sched_yield();
               pollval = (*transp->transport->poll)(logger_list_internal, transp);
@@ -402,8 +393,7 @@
               }
               retval = transp->ret = pollval;
             } else if (pollval > 0) {
-              retval = android_transport_read(logger_list_internal, transp,
-                                              &transp->logMsg);
+              retval = android_transport_read(logger_list_internal, transp, &transp->logMsg);
             }
           }
         }
@@ -416,11 +406,9 @@
               (oldest->logMsg.entry.nsec > transp->logMsg.entry.nsec)))) {
           oldest = transp;
         }
-        transp = node_to_item(transp->node.next,
-                              struct android_log_transport_context, node);
+        transp = node_to_item(transp->node.next, struct android_log_transport_context, node);
       } while (transp != node_to_item(&logger_list_internal->transport,
-                                      struct android_log_transport_context,
-                                      node));
+                                      struct android_log_transport_context, node));
       if (!oldest && (logger_list_internal->mode & ANDROID_LOG_NONBLOCK)) {
         return (ret < 0) ? ret : -EAGAIN;
       }
@@ -434,10 +422,10 @@
     ret = oldest->ret;
     if (ret < oldest->logMsg.entry.hdr_size) {
       // zero truncated header fields.
-      memset(log_msg, 0,
-             (oldest->logMsg.entry.hdr_size > sizeof(oldest->logMsg)
-                  ? sizeof(oldest->logMsg)
-                  : oldest->logMsg.entry.hdr_size));
+      memset(
+          log_msg, 0,
+          (oldest->logMsg.entry.hdr_size > sizeof(oldest->logMsg) ? sizeof(oldest->logMsg)
+                                                                  : oldest->logMsg.entry.hdr_size));
     }
     memcpy(log_msg, &oldest->logMsg, ret);
     oldest->logMsg.entry.len = 0; /* Mark it as copied */
@@ -471,8 +459,7 @@
 
   while (!list_empty(&logger_list_internal->logger)) {
     struct listnode* node = list_head(&logger_list_internal->logger);
-    struct android_log_logger* logger =
-        node_to_item(node, struct android_log_logger, node);
+    struct android_log_logger* logger = node_to_item(node, struct android_log_logger, node);
     android_logger_free((struct logger*)logger);
   }
 
diff --git a/liblog/logger_write.c b/liblog/logger_write.cpp
similarity index 89%
rename from liblog/logger_write.c
rename to liblog/logger_write.cpp
index 6dcda9b..fbe6874 100644
--- a/liblog/logger_write.c
+++ b/liblog/logger_write.cpp
@@ -37,19 +37,14 @@
 #define LOG_BUF_SIZE 1024
 
 static int __write_to_log_init(log_id_t, struct iovec* vec, size_t nr);
-static int (*write_to_log)(log_id_t, struct iovec* vec,
-                           size_t nr) = __write_to_log_init;
+static int (*write_to_log)(log_id_t, struct iovec* vec, size_t nr) = __write_to_log_init;
 
 /*
  * This is used by the C++ code to decide if it should write logs through
  * the C code.  Basically, if /dev/socket/logd is available, we're running in
  * the simulator rather than a desktop tool and want to use the device.
  */
-static enum {
-  kLogUninitialized,
-  kLogNotAvailable,
-  kLogAvailable
-} g_log_status = kLogUninitialized;
+static enum { kLogUninitialized, kLogNotAvailable, kLogAvailable } g_log_status = kLogUninitialized;
 
 static int check_log_uid_permissions() {
 #if defined(__ANDROID__)
@@ -70,7 +65,7 @@
           if (num_groups <= 0) {
             return -EPERM;
           }
-          groups = calloc(num_groups, sizeof(gid_t));
+          groups = static_cast<gid_t*>(calloc(num_groups, sizeof(gid_t)));
           if (!groups) {
             return -ENOMEM;
           }
@@ -93,9 +88,8 @@
   return 0;
 }
 
-static void __android_log_cache_available(
-    struct android_log_transport_write* node) {
-  size_t i;
+static void __android_log_cache_available(struct android_log_transport_write* node) {
+  uint32_t i;
 
   if (node->logMask) {
     return;
@@ -104,13 +98,13 @@
   for (i = LOG_ID_MIN; i < LOG_ID_MAX; ++i) {
     if (node->write && (i != LOG_ID_KERNEL) &&
         ((i != LOG_ID_SECURITY) || (check_log_uid_permissions() == 0)) &&
-        (!node->available || ((*node->available)(i) >= 0))) {
+        (!node->available || ((*node->available)(static_cast<log_id_t>(i)) >= 0))) {
       node->logMask |= 1 << i;
     }
   }
 }
 
-LIBLOG_ABI_PUBLIC int __android_log_dev_available() {
+LIBLOG_ABI_PUBLIC extern "C" int __android_log_dev_available() {
   struct android_log_transport_write* node;
 
   if (list_empty(&__android_log_transport_write)) {
@@ -308,10 +302,9 @@
       }
     }
     if (m && (m != (EventTagMap*)(uintptr_t)-1LL)) {
-      tag = android_lookupEventTag_len(m, &len, get4LE(vec[0].iov_base));
+      tag = android_lookupEventTag_len(m, &len, get4LE(static_cast<uint8_t*>(vec[0].iov_base)));
     }
-    ret = __android_log_is_loggable_len(ANDROID_LOG_INFO, tag, len,
-                                        ANDROID_LOG_VERBOSE);
+    ret = __android_log_is_loggable_len(ANDROID_LOG_INFO, tag, len, ANDROID_LOG_VERBOSE);
     if (f) { /* local copy marked for close */
       android_closeEventTagMap(f);
     }
@@ -322,7 +315,7 @@
   } else {
     /* Validate the incoming tag, tag content can not split across iovec */
     char prio = ANDROID_LOG_VERBOSE;
-    const char* tag = vec[0].iov_base;
+    const char* tag = static_cast<const char*>(vec[0].iov_base);
     size_t len = vec[0].iov_len;
     if (!tag) {
       len = 0;
@@ -408,13 +401,12 @@
   return ret;
 }
 
-LIBLOG_ABI_PUBLIC int __android_log_write(int prio, const char* tag,
-                                          const char* msg) {
+LIBLOG_ABI_PUBLIC int __android_log_write(int prio, const char* tag, const char* msg) {
   return __android_log_buf_write(LOG_ID_MAIN, prio, tag, msg);
 }
 
-LIBLOG_ABI_PUBLIC int __android_log_buf_write(int bufID, int prio,
-                                              const char* tag, const char* msg) {
+LIBLOG_ABI_PUBLIC int __android_log_buf_write(int bufID, int prio, const char* tag,
+                                              const char* msg) {
   struct iovec vec[3];
   char tmp_tag[32];
 
@@ -457,7 +449,7 @@
         bufID = LOG_ID_RADIO;
         snprintf(tmp_tag, sizeof(tmp_tag), "use-Rlog/RLOG-%s", tag);
         tag = tmp_tag;
-      /* FALLTHRU */
+        [[fallthrough]];
       default:
         break;
     }
@@ -476,11 +468,10 @@
   vec[2].iov_base = (void*)msg;
   vec[2].iov_len = strlen(msg) + 1;
 
-  return write_to_log(bufID, vec, 3);
+  return write_to_log(static_cast<log_id_t>(bufID), vec, 3);
 }
 
-LIBLOG_ABI_PUBLIC int __android_log_vprint(int prio, const char* tag,
-                                           const char* fmt, va_list ap) {
+LIBLOG_ABI_PUBLIC int __android_log_vprint(int prio, const char* tag, const char* fmt, va_list ap) {
   char buf[LOG_BUF_SIZE];
 
   vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
@@ -488,8 +479,7 @@
   return __android_log_write(prio, tag, buf);
 }
 
-LIBLOG_ABI_PUBLIC int __android_log_print(int prio, const char* tag,
-                                          const char* fmt, ...) {
+LIBLOG_ABI_PUBLIC int __android_log_print(int prio, const char* tag, const char* fmt, ...) {
   va_list ap;
   char buf[LOG_BUF_SIZE];
 
@@ -500,8 +490,7 @@
   return __android_log_write(prio, tag, buf);
 }
 
-LIBLOG_ABI_PUBLIC int __android_log_buf_print(int bufID, int prio,
-                                              const char* tag, const char* fmt,
+LIBLOG_ABI_PUBLIC int __android_log_buf_print(int bufID, int prio, const char* tag, const char* fmt,
                                               ...) {
   va_list ap;
   char buf[LOG_BUF_SIZE];
@@ -513,8 +502,8 @@
   return __android_log_buf_write(bufID, prio, tag, buf);
 }
 
-LIBLOG_ABI_PUBLIC void __android_log_assert(const char* cond, const char* tag,
-                                            const char* fmt, ...) {
+LIBLOG_ABI_PUBLIC void __android_log_assert(const char* cond, const char* tag, const char* fmt,
+                                            ...) {
   char buf[LOG_BUF_SIZE];
 
   if (fmt) {
@@ -536,7 +525,8 @@
   // Log assertion failures to stderr for the benefit of "adb shell" users
   // and gtests (http://b/23675822).
   struct iovec iov[2] = {
-    { buf, strlen(buf) }, { (char*)"\n", 1 },
+      {buf, strlen(buf)},
+      {(char*)"\n", 1},
   };
   TEMP_FAILURE_RETRY(writev(2, iov, 2));
 
@@ -545,8 +535,7 @@
            /* NOTREACHED */
 }
 
-LIBLOG_ABI_PUBLIC int __android_log_bwrite(int32_t tag, const void* payload,
-                                           size_t len) {
+LIBLOG_ABI_PUBLIC int __android_log_bwrite(int32_t tag, const void* payload, size_t len) {
   struct iovec vec[2];
 
   vec[0].iov_base = &tag;
@@ -557,9 +546,7 @@
   return write_to_log(LOG_ID_EVENTS, vec, 2);
 }
 
-LIBLOG_ABI_PUBLIC int __android_log_stats_bwrite(int32_t tag,
-                                                 const void* payload,
-                                                 size_t len) {
+LIBLOG_ABI_PUBLIC int __android_log_stats_bwrite(int32_t tag, const void* payload, size_t len) {
   struct iovec vec[2];
 
   vec[0].iov_base = &tag;
@@ -570,9 +557,7 @@
   return write_to_log(LOG_ID_STATS, vec, 2);
 }
 
-LIBLOG_ABI_PUBLIC int __android_log_security_bwrite(int32_t tag,
-                                                    const void* payload,
-                                                    size_t len) {
+LIBLOG_ABI_PUBLIC int __android_log_security_bwrite(int32_t tag, const void* payload, size_t len) {
   struct iovec vec[2];
 
   vec[0].iov_base = &tag;
@@ -588,8 +573,8 @@
  * for the general case where we're generating lists of stuff, but very
  * handy if we just want to dump an integer into the log.
  */
-LIBLOG_ABI_PUBLIC int __android_log_btwrite(int32_t tag, char type,
-                                            const void* payload, size_t len) {
+LIBLOG_ABI_PUBLIC int __android_log_btwrite(int32_t tag, char type, const void* payload,
+                                            size_t len) {
   struct iovec vec[3];
 
   vec[0].iov_base = &tag;
@@ -627,8 +612,7 @@
  * Like __android_log_security_bwrite, but used for writing strings to the
  * security log.
  */
-LIBLOG_ABI_PUBLIC int __android_log_security_bswrite(int32_t tag,
-                                                     const char* payload) {
+LIBLOG_ABI_PUBLIC int __android_log_security_bswrite(int32_t tag, const char* payload) {
   struct iovec vec[4];
   char type = EVENT_TYPE_STRING;
   uint32_t len = strlen(payload);
@@ -695,8 +679,7 @@
 
     write_to_log = __write_to_log_init;
     /* generically we only expect these two values for write_to_log */
-  } else if ((write_to_log != __write_to_log_init) &&
-             (write_to_log != __write_to_log_daemon)) {
+  } else if ((write_to_log != __write_to_log_init) && (write_to_log != __write_to_log_daemon)) {
     write_to_log = __write_to_log_init;
   }
 
@@ -716,8 +699,7 @@
   } else {
     __android_log_transport &= LOGGER_LOGD | LOGGER_STDERR;
     ret = __android_log_transport;
-    if ((write_to_log != __write_to_log_init) &&
-        (write_to_log != __write_to_log_daemon)) {
+    if ((write_to_log != __write_to_log_init) && (write_to_log != __write_to_log_daemon)) {
       ret = -EINVAL;
     }
   }
diff --git a/liblog/logprint.c b/liblog/logprint.cpp
similarity index 90%
rename from liblog/logprint.c
rename to liblog/logprint.cpp
index 7937cb1..798b089 100644
--- a/liblog/logprint.c
+++ b/liblog/logprint.cpp
@@ -15,7 +15,6 @@
 ** limitations under the License.
 */
 
-#define _GNU_SOURCE /* for asprintf */
 #ifndef __MINGW32__
 #define HAVE_STRSEP
 #endif
@@ -154,7 +153,7 @@
     case ANDROID_LOG_DEFAULT:
     case ANDROID_LOG_UNKNOWN:
     default:                  return '?';
-    /* clang-format on */
+      /* clang-format on */
   }
 }
 
@@ -172,16 +171,14 @@
     case ANDROID_LOG_DEFAULT:
     case ANDROID_LOG_UNKNOWN:
     default:                  return ANDROID_COLOR_DEFAULT;
-    /* clang-format on */
+      /* clang-format on */
   }
 }
 
-static android_LogPriority filterPriForTag(AndroidLogFormat* p_format,
-                                           const char* tag) {
+static android_LogPriority filterPriForTag(AndroidLogFormat* p_format, const char* tag) {
   FilterInfo* p_curFilter;
 
-  for (p_curFilter = p_format->filters; p_curFilter != NULL;
-       p_curFilter = p_curFilter->p_next) {
+  for (p_curFilter = p_format->filters; p_curFilter != NULL; p_curFilter = p_curFilter->p_next) {
     if (0 == strcmp(tag, p_curFilter->mTag)) {
       if (p_curFilter->mPri == ANDROID_LOG_DEFAULT) {
         return p_format->global_pri;
@@ -198,8 +195,7 @@
  * returns 1 if this log line should be printed based on its priority
  * and tag, and 0 if it should not
  */
-LIBLOG_ABI_PUBLIC int android_log_shouldPrintLine(AndroidLogFormat* p_format,
-                                                  const char* tag,
+LIBLOG_ABI_PUBLIC int android_log_shouldPrintLine(AndroidLogFormat* p_format, const char* tag,
                                                   android_LogPriority pri) {
   return pri >= filterPriForTag(p_format, tag);
 }
@@ -207,7 +203,7 @@
 LIBLOG_ABI_PUBLIC AndroidLogFormat* android_log_format_new() {
   AndroidLogFormat* p_ret;
 
-  p_ret = calloc(1, sizeof(AndroidLogFormat));
+  p_ret = static_cast<AndroidLogFormat*>(calloc(1, sizeof(AndroidLogFormat)));
 
   p_ret->global_pri = ANDROID_LOG_VERBOSE;
   p_ret->format = FORMAT_BRIEF;
@@ -302,8 +298,7 @@
 /**
  * Returns FORMAT_OFF on invalid string
  */
-LIBLOG_ABI_PUBLIC AndroidLogPrintFormat
-android_log_formatFromString(const char* formatString) {
+LIBLOG_ABI_PUBLIC AndroidLogPrintFormat android_log_formatFromString(const char* formatString) {
   static AndroidLogPrintFormat format;
 
   /* clang-format off */
@@ -326,7 +321,7 @@
   else if (!strcmp(formatString, "monotonic")) format = FORMAT_MODIFIER_MONOTONIC;
   else if (!strcmp(formatString, "uid")) format = FORMAT_MODIFIER_UID;
   else if (!strcmp(formatString, "descriptive")) format = FORMAT_MODIFIER_DESCRIPT;
-  /* clang-format on */
+    /* clang-format on */
 
 #ifndef __MINGW32__
   else {
@@ -344,9 +339,8 @@
      */
     tzset();
     if (!tzname[0] ||
-        ((!strcmp(tzname[0], utc) || !strcmp(tzname[0], gmt)) /* error? */
-         && strcasecmp(formatString, utc) &&
-         strcasecmp(formatString, gmt))) { /* ok */
+        ((!strcmp(tzname[0], utc) || !strcmp(tzname[0], gmt))                  /* error? */
+         && strcasecmp(formatString, utc) && strcasecmp(formatString, gmt))) { /* ok */
       if (cp) {
         setenv(tz, cp, 1);
       } else {
@@ -581,7 +575,7 @@
     msg[msgEnd] = '\0';
   }
 
-  entry->priority = msg[0];
+  entry->priority = static_cast<android_LogPriority>(msg[0]);
   entry->tag = msg + 1;
   entry->tagLen = msgStart - 1;
   entry->message = msg + msgStart;
@@ -643,9 +637,8 @@
   TYPE_MONOTONIC = 's'
 };
 
-static int android_log_printBinaryEvent(const unsigned char** pEventData,
-                                        size_t* pEventDataLen, char** pOutBuf,
-                                        size_t* pOutBufLen, const char** fmtStr,
+static int android_log_printBinaryEvent(const unsigned char** pEventData, size_t* pEventDataLen,
+                                        char** pOutBuf, size_t* pOutBufLen, const char** fmtStr,
                                         size_t* fmtLen) {
   const unsigned char* eventData = *pEventData;
   size_t eventDataLen = *pEventDataLen;
@@ -729,13 +722,10 @@
     }
 
     if (findChar(&cp, &len, '|') && findChar(&cp, &len, INT_MAX)) {
-      static const unsigned char typeTable[] = {
-        EVENT_TYPE_INT, EVENT_TYPE_LONG, EVENT_TYPE_STRING, EVENT_TYPE_LIST,
-        EVENT_TYPE_FLOAT
-      };
+      static const unsigned char typeTable[] = {EVENT_TYPE_INT, EVENT_TYPE_LONG, EVENT_TYPE_STRING,
+                                                EVENT_TYPE_LIST, EVENT_TYPE_FLOAT};
 
-      if ((*cp >= '1') &&
-          (*cp < (char)('1' + (sizeof(typeTable) / sizeof(typeTable[0])))) &&
+      if ((*cp >= '1') && (*cp < (char)('1' + (sizeof(typeTable) / sizeof(typeTable[0])))) &&
           (type != typeTable[(size_t)(*cp - '1')]))
         len = 0;
 
@@ -858,8 +848,8 @@
         outBufLen--;
 
         for (i = 0; i < count; i++) {
-          result = android_log_printBinaryEvent(
-              &eventData, &eventDataLen, &outBuf, &outBufLen, fmtStr, fmtLen);
+          result = android_log_printBinaryEvent(&eventData, &eventDataLen, &outBuf, &outBufLen,
+                                                fmtStr, fmtLen);
           if (result != 0) goto bail;
 
           if (i < (count - 1)) {
@@ -889,24 +879,21 @@
         case TYPE_BYTES:
           if ((lval != 0) && ((lval % 1024) == 0)) {
             /* repaint with multiplier */
-            static const char suffixTable[] = { 'K', 'M', 'G', 'T' };
+            static const char suffixTable[] = {'K', 'M', 'G', 'T'};
             size_t idx = 0;
             outBuf -= outCount;
             outBufLen += outCount;
             do {
               lval /= 1024;
               if ((lval % 1024) != 0) break;
-            } while (++idx <
-                     ((sizeof(suffixTable) / sizeof(suffixTable[0])) - 1));
-            outCount = snprintf(outBuf, outBufLen, "%" PRId64 "%cB", lval,
-                                suffixTable[idx]);
+            } while (++idx < ((sizeof(suffixTable) / sizeof(suffixTable[0])) - 1));
+            outCount = snprintf(outBuf, outBufLen, "%" PRId64 "%cB", lval, suffixTable[idx]);
           } else {
             outCount = snprintf(outBuf, outBufLen, "B");
           }
           break;
         case TYPE_MILLISECONDS:
-          if (((lval <= -1000) || (1000 <= lval)) &&
-              (outBufLen || (outBuf[-1] == '0'))) {
+          if (((lval <= -1000) || (1000 <= lval)) && (outBufLen || (outBuf[-1] == '0'))) {
             /* repaint as (fractional) seconds, possibly saving space */
             if (outBufLen) outBuf[0] = outBuf[-1];
             outBuf[-1] = outBuf[-2];
@@ -943,22 +930,19 @@
           }
           if (val >= minute) {
             if (val >= hour) {
-              outCount = snprintf(outBuf, outBufLen, "%" PRIu64 ":",
-                                  (val / hour) % (day / hour));
+              outCount = snprintf(outBuf, outBufLen, "%" PRIu64 ":", (val / hour) % (day / hour));
               if (outCount >= outBufLen) break;
               outBuf += outCount;
               outBufLen -= outCount;
             }
             outCount =
-                snprintf(outBuf, outBufLen,
-                         (val >= hour) ? "%02" PRIu64 ":" : "%" PRIu64 ":",
+                snprintf(outBuf, outBufLen, (val >= hour) ? "%02" PRIu64 ":" : "%" PRIu64 ":",
                          (val / minute) % (hour / minute));
             if (outCount >= outBufLen) break;
             outBuf += outCount;
             outBufLen -= outCount;
           }
-          outCount = snprintf(outBuf, outBufLen,
-                              (val >= minute) ? "%02" PRIu64 : "%" PRIu64 "s",
+          outCount = snprintf(outBuf, outBufLen, (val >= minute) ? "%02" PRIu64 : "%" PRIu64 "s",
                               val % minute);
         } break;
         case TYPE_ALLOCATIONS:
@@ -1015,7 +999,7 @@
  */
 LIBLOG_ABI_PUBLIC int android_log_processBinaryLogBuffer(
     struct logger_entry* buf, AndroidLogEntry* entry,
-    const EventTagMap* map __unused, /* only on !__ANDROID__ */
+    [[maybe_unused]] const EventTagMap* map, /* only on !__ANDROID__ */
     char* messageBuf, int messageBufLen) {
   size_t inCount;
   uint32_t tagIndex;
@@ -1100,8 +1084,8 @@
   int result = 0;
 
   if ((inCount > 0) || fmtLen) {
-    result = android_log_printBinaryEvent(&eventData, &inCount, &outBuf,
-                                          &outRemaining, &fmtStr, &fmtLen);
+    result = android_log_printBinaryEvent(&eventData, &inCount, &outBuf, &outRemaining, &fmtStr,
+                                          &fmtLen);
   }
   if ((result == 1) && fmtStr) {
     /* We overflowed :-(, let's repaint the line w/o format dressings */
@@ -1112,8 +1096,7 @@
     eventData += 4;
     outBuf = messageBuf;
     outRemaining = messageBufLen - 1;
-    result = android_log_printBinaryEvent(&eventData, &inCount, &outBuf,
-                                          &outRemaining, NULL, NULL);
+    result = android_log_printBinaryEvent(&eventData, &inCount, &outBuf, &outRemaining, NULL, NULL);
   }
   if (result < 0) {
     fprintf(stderr, "Binary log entry conversion failed\n");
@@ -1187,8 +1170,7 @@
   }
 
   for (utf32 = 1, num_to_read = 1, mask = 0x40, to_ignore_mask = 0x80;
-       num_to_read < 5 && (first_char & mask);
-       num_to_read++, to_ignore_mask |= mask, mask >>= 1) {
+       num_to_read < 5 && (first_char & mask); num_to_read++, to_ignore_mask |= mask, mask >>= 1) {
     if (num_to_read > len) {
       return -1;
     }
@@ -1226,8 +1208,7 @@
     len = utf8_character_length(message, len);
 
     if (len < 0) {
-      snprintf(buf, sizeof(buf),
-               ((messageLen > 1) && isdigit(message[1])) ? "\\%03o" : "\\%o",
+      snprintf(buf, sizeof(buf), ((messageLen > 1) && isdigit(message[1])) ? "\\%03o" : "\\%o",
                *message & 0377);
       len = 1;
     } else {
@@ -1281,8 +1262,7 @@
   return p;
 }
 
-static struct timespec* sumTimespec(struct timespec* left,
-                                    struct timespec* right) {
+static struct timespec* sumTimespec(struct timespec* left, struct timespec* right) {
   left->tv_nsec += right->tv_nsec;
   left->tv_sec += right->tv_sec;
   if (left->tv_nsec >= (long)NS_PER_SEC) {
@@ -1292,8 +1272,7 @@
   return left;
 }
 
-static struct timespec* subTimespec(struct timespec* result,
-                                    struct timespec* left,
+static struct timespec* subTimespec(struct timespec* result, struct timespec* left,
                                     struct timespec* right) {
   result->tv_nsec = left->tv_nsec - right->tv_nsec;
   result->tv_sec = left->tv_sec - right->tv_sec;
@@ -1309,8 +1288,7 @@
 }
 
 #ifdef __ANDROID__
-static void convertMonotonic(struct timespec* result,
-                             const AndroidLogEntry* entry) {
+static void convertMonotonic(struct timespec* result, const AndroidLogEntry* entry) {
   struct listnode* node;
   struct conversionList {
     struct listnode node; /* first */
@@ -1322,8 +1300,8 @@
   /* If we do not have a conversion list, build one up */
   if (list_empty(&convertHead)) {
     bool suspended_pending = false;
-    struct timespec suspended_monotonic = { 0, 0 };
-    struct timespec suspended_diff = { 0, 0 };
+    struct timespec suspended_monotonic = {0, 0};
+    struct timespec suspended_diff = {0, 0};
 
     /*
      * Read dmesg for _some_ synchronization markers and insert
@@ -1413,15 +1391,14 @@
           } else {
             unsetenv(tz);
           }
-          list = calloc(1, sizeof(struct conversionList));
+          list = static_cast<conversionList*>(calloc(1, sizeof(conversionList)));
           list_init(&list->node);
           list->time = time;
           subTimespec(&list->convert, &time, &monotonic);
           list_add_tail(&convertHead, &list->node);
         }
         if (suspended_pending && !list_empty(&convertHead)) {
-          list = node_to_item(list_tail(&convertHead), struct conversionList,
-                              node);
+          list = node_to_item(list_tail(&convertHead), struct conversionList, node);
           if (subTimespec(&time, subTimespec(&time, &list->time, &list->convert),
                           &suspended_monotonic)
                   ->tv_sec > 0) {
@@ -1434,13 +1411,13 @@
           time = suspended_monotonic;
           sumTimespec(&time, &convert);
           /* breakpoint just before sleep */
-          list = calloc(1, sizeof(struct conversionList));
+          list = static_cast<conversionList*>(calloc(1, sizeof(conversionList)));
           list_init(&list->node);
           list->time = time;
           list->convert = convert;
           list_add_tail(&convertHead, &list->node);
           /* breakpoint just after sleep */
-          list = calloc(1, sizeof(struct conversionList));
+          list = static_cast<conversionList*>(calloc(1, sizeof(conversionList)));
           list_init(&list->node);
           list->time = time;
           sumTimespec(&list->time, &suspended_diff);
@@ -1453,7 +1430,7 @@
       pclose(p);
     }
     /* last entry is our current time conversion */
-    list = calloc(1, sizeof(struct conversionList));
+    list = static_cast<conversionList*>(calloc(1, sizeof(conversionList)));
     list_init(&list->node);
     clock_gettime(CLOCK_REALTIME, &list->time);
     clock_gettime(CLOCK_MONOTONIC, &convert);
@@ -1469,7 +1446,7 @@
       time = suspended_monotonic;
       sumTimespec(&time, &convert);
       /* breakpoint just after sleep */
-      list = calloc(1, sizeof(struct conversionList));
+      list = static_cast<conversionList*>(calloc(1, sizeof(conversionList)));
       list_init(&list->node);
       list->time = time;
       sumTimespec(&list->time, &suspended_diff);
@@ -1477,7 +1454,7 @@
       sumTimespec(&list->convert, &suspended_diff);
       list_add_head(&convertHead, &list->node);
       /* breakpoint just before sleep */
-      list = calloc(1, sizeof(struct conversionList));
+      list = static_cast<conversionList*>(calloc(1, sizeof(conversionList)));
       list_init(&list->node);
       list->time = time;
       list->convert = convert;
@@ -1548,8 +1525,7 @@
  * Returns NULL on malloc error
  */
 
-LIBLOG_ABI_PUBLIC char* android_log_formatLogLine(AndroidLogFormat* p_format,
-                                                  char* defaultBuffer,
+LIBLOG_ABI_PUBLIC char* android_log_formatLogLine(AndroidLogFormat* p_format, char* defaultBuffer,
                                                   size_t defaultBufferSize,
                                                   const AndroidLogEntry* entry,
                                                   size_t* p_outLength) {
@@ -1600,26 +1576,23 @@
   }
   if (p_format->epoch_output || p_format->monotonic_output) {
     ptm = NULL;
-    snprintf(timeBuf, sizeof(timeBuf),
-             p_format->monotonic_output ? "%6lld" : "%19lld", (long long)now);
+    snprintf(timeBuf, sizeof(timeBuf), p_format->monotonic_output ? "%6lld" : "%19lld",
+             (long long)now);
   } else {
 #if !defined(_WIN32)
     ptm = localtime_r(&now, &tmBuf);
 #else
     ptm = localtime(&now);
 #endif
-    strftime(timeBuf, sizeof(timeBuf),
-             &"%Y-%m-%d %H:%M:%S"[p_format->year_output ? 0 : 3], ptm);
+    strftime(timeBuf, sizeof(timeBuf), &"%Y-%m-%d %H:%M:%S"[p_format->year_output ? 0 : 3], ptm);
   }
   len = strlen(timeBuf);
   if (p_format->nsec_time_output) {
     len += snprintf(timeBuf + len, sizeof(timeBuf) - len, ".%09ld", nsec);
   } else if (p_format->usec_time_output) {
-    len += snprintf(timeBuf + len, sizeof(timeBuf) - len, ".%06ld",
-                    nsec / US_PER_NSEC);
+    len += snprintf(timeBuf + len, sizeof(timeBuf) - len, ".%06ld", nsec / US_PER_NSEC);
   } else {
-    len += snprintf(timeBuf + len, sizeof(timeBuf) - len, ".%03ld",
-                    nsec / MS_PER_NSEC);
+    len += snprintf(timeBuf + len, sizeof(timeBuf) - len, ".%03ld", nsec / MS_PER_NSEC);
   }
   if (p_format->zone_output && ptm) {
     strftime(timeBuf + len, sizeof(timeBuf) - len, " %z", ptm);
@@ -1629,8 +1602,8 @@
    * Construct a buffer containing the log header and log message.
    */
   if (p_format->colored_output) {
-    prefixLen = snprintf(prefixBuf, sizeof(prefixBuf), "\x1B[38;5;%dm",
-                         colorFromPri(entry->priority));
+    prefixLen =
+        snprintf(prefixBuf, sizeof(prefixBuf), "\x1B[38;5;%dm", colorFromPri(entry->priority));
     prefixLen = MIN(prefixLen, sizeof(prefixBuf));
 
     const char suffixContents[] = "\x1B[0m";
@@ -1649,8 +1622,7 @@
 #if !defined(__MINGW32__)
 #if (FAKE_LOG_DEVICE == 0)
 #ifndef __BIONIC__
-#warning \
-    "This code assumes that getpwuid is thread safe, only true with Bionic!"
+#warning "This code assumes that getpwuid is thread safe, only true with Bionic!"
 #endif
 #endif
       struct passwd* pwd = getpwuid(entry->uid);
@@ -1669,21 +1641,21 @@
 
   switch (p_format->format) {
     case FORMAT_TAG:
-      len = snprintf(prefixBuf + prefixLen, sizeof(prefixBuf) - prefixLen,
-                     "%c/%-8.*s: ", priChar, (int)entry->tagLen, entry->tag);
+      len = snprintf(prefixBuf + prefixLen, sizeof(prefixBuf) - prefixLen, "%c/%-8.*s: ", priChar,
+                     (int)entry->tagLen, entry->tag);
       strcpy(suffixBuf + suffixLen, "\n");
       ++suffixLen;
       break;
     case FORMAT_PROCESS:
-      len = snprintf(suffixBuf + suffixLen, sizeof(suffixBuf) - suffixLen,
-                     "  (%.*s)\n", (int)entry->tagLen, entry->tag);
+      len = snprintf(suffixBuf + suffixLen, sizeof(suffixBuf) - suffixLen, "  (%.*s)\n",
+                     (int)entry->tagLen, entry->tag);
       suffixLen += MIN(len, sizeof(suffixBuf) - suffixLen);
-      len = snprintf(prefixBuf + prefixLen, sizeof(prefixBuf) - prefixLen,
-                     "%c(%s%5d) ", priChar, uid, entry->pid);
+      len = snprintf(prefixBuf + prefixLen, sizeof(prefixBuf) - prefixLen, "%c(%s%5d) ", priChar,
+                     uid, entry->pid);
       break;
     case FORMAT_THREAD:
-      len = snprintf(prefixBuf + prefixLen, sizeof(prefixBuf) - prefixLen,
-                     "%c(%s%5d:%5d) ", priChar, uid, entry->pid, entry->tid);
+      len = snprintf(prefixBuf + prefixLen, sizeof(prefixBuf) - prefixLen, "%c(%s%5d:%5d) ",
+                     priChar, uid, entry->pid, entry->tid);
       strcpy(suffixBuf + suffixLen, "\n");
       ++suffixLen;
       break;
@@ -1695,8 +1667,8 @@
       break;
     case FORMAT_TIME:
       len = snprintf(prefixBuf + prefixLen, sizeof(prefixBuf) - prefixLen,
-                     "%s %c/%-8.*s(%s%5d): ", timeBuf, priChar,
-                     (int)entry->tagLen, entry->tag, uid, entry->pid);
+                     "%s %c/%-8.*s(%s%5d): ", timeBuf, priChar, (int)entry->tagLen, entry->tag, uid,
+                     entry->pid);
       strcpy(suffixBuf + suffixLen, "\n");
       ++suffixLen;
       break;
@@ -1706,24 +1678,24 @@
         *ret = ' ';
       }
       len = snprintf(prefixBuf + prefixLen, sizeof(prefixBuf) - prefixLen,
-                     "%s %s%5d %5d %c %-8.*s: ", timeBuf, uid, entry->pid,
-                     entry->tid, priChar, (int)entry->tagLen, entry->tag);
+                     "%s %s%5d %5d %c %-8.*s: ", timeBuf, uid, entry->pid, entry->tid, priChar,
+                     (int)entry->tagLen, entry->tag);
       strcpy(suffixBuf + suffixLen, "\n");
       ++suffixLen;
       break;
     case FORMAT_LONG:
       len = snprintf(prefixBuf + prefixLen, sizeof(prefixBuf) - prefixLen,
-                     "[ %s %s%5d:%5d %c/%-8.*s ]\n", timeBuf, uid, entry->pid,
-                     entry->tid, priChar, (int)entry->tagLen, entry->tag);
+                     "[ %s %s%5d:%5d %c/%-8.*s ]\n", timeBuf, uid, entry->pid, entry->tid, priChar,
+                     (int)entry->tagLen, entry->tag);
       strcpy(suffixBuf + suffixLen, "\n\n");
       suffixLen += 2;
       prefixSuffixIsHeaderFooter = 1;
       break;
     case FORMAT_BRIEF:
     default:
-      len = snprintf(prefixBuf + prefixLen, sizeof(prefixBuf) - prefixLen,
-                     "%c/%-8.*s(%s%5d): ", priChar, (int)entry->tagLen,
-                     entry->tag, uid, entry->pid);
+      len =
+          snprintf(prefixBuf + prefixLen, sizeof(prefixBuf) - prefixLen,
+                   "%c/%-8.*s(%s%5d): ", priChar, (int)entry->tagLen, entry->tag, uid, entry->pid);
       strcpy(suffixBuf + suffixLen, "\n");
       ++suffixLen;
       break;
@@ -1847,16 +1819,15 @@
  * Returns count bytes written
  */
 
-LIBLOG_ABI_PUBLIC int android_log_printLogLine(AndroidLogFormat* p_format,
-                                               int fd,
+LIBLOG_ABI_PUBLIC int android_log_printLogLine(AndroidLogFormat* p_format, int fd,
                                                const AndroidLogEntry* entry) {
   int ret;
   char defaultBuffer[512];
   char* outBuffer = NULL;
   size_t totalLen;
 
-  outBuffer = android_log_formatLogLine(
-      p_format, defaultBuffer, sizeof(defaultBuffer), entry, &totalLen);
+  outBuffer =
+      android_log_formatLogLine(p_format, defaultBuffer, sizeof(defaultBuffer), entry, &totalLen);
 
   if (!outBuffer) return -1;
 
diff --git a/liblog/pmsg_reader.c b/liblog/pmsg_reader.cpp
similarity index 84%
rename from liblog/pmsg_reader.c
rename to liblog/pmsg_reader.cpp
index bf0e4fe..7bc6e4a 100644
--- a/liblog/pmsg_reader.c
+++ b/liblog/pmsg_reader.cpp
@@ -32,28 +32,27 @@
 static int pmsgVersion(struct android_log_logger* logger,
                        struct android_log_transport_context* transp);
 static int pmsgRead(struct android_log_logger_list* logger_list,
-                    struct android_log_transport_context* transp,
-                    struct log_msg* log_msg);
+                    struct android_log_transport_context* transp, struct log_msg* log_msg);
 static void pmsgClose(struct android_log_logger_list* logger_list,
                       struct android_log_transport_context* transp);
 static int pmsgClear(struct android_log_logger* logger,
                      struct android_log_transport_context* transp);
 
 LIBLOG_HIDDEN struct android_log_transport_read pmsgLoggerRead = {
-  .node = { &pmsgLoggerRead.node, &pmsgLoggerRead.node },
-  .name = "pmsg",
-  .available = pmsgAvailable,
-  .version = pmsgVersion,
-  .read = pmsgRead,
-  .poll = NULL,
-  .close = pmsgClose,
-  .clear = pmsgClear,
-  .setSize = NULL,
-  .getSize = NULL,
-  .getReadableSize = NULL,
-  .getPrune = NULL,
-  .setPrune = NULL,
-  .getStats = NULL,
+    .node = {&pmsgLoggerRead.node, &pmsgLoggerRead.node},
+    .name = "pmsg",
+    .available = pmsgAvailable,
+    .version = pmsgVersion,
+    .read = pmsgRead,
+    .poll = NULL,
+    .close = pmsgClose,
+    .clear = pmsgClear,
+    .setSize = NULL,
+    .getSize = NULL,
+    .getReadableSize = NULL,
+    .getPrune = NULL,
+    .setPrune = NULL,
+    .getStats = NULL,
 };
 
 static int pmsgAvailable(log_id_t logId) {
@@ -68,8 +67,7 @@
 
 /* Determine the credentials of the caller */
 static bool uid_has_log_permission(uid_t uid) {
-  return (uid == AID_SYSTEM) || (uid == AID_LOG) || (uid == AID_ROOT) ||
-         (uid == AID_LOGD);
+  return (uid == AID_SYSTEM) || (uid == AID_LOG) || (uid == AID_ROOT) || (uid == AID_LOGD);
 }
 
 static uid_t get_best_effective_uid() {
@@ -130,8 +128,7 @@
 }
 
 static int pmsgRead(struct android_log_logger_list* logger_list,
-                    struct android_log_transport_context* transp,
-                    struct log_msg* log_msg) {
+                    struct android_log_transport_context* transp, struct log_msg* log_msg) {
   ssize_t ret;
   off_t current, next;
   uid_t uid;
@@ -174,8 +171,7 @@
       if (fd <= 0) {
         return -EBADF;
       }
-      ret = TEMP_FAILURE_RETRY(
-          read(fd, &buf.p.magic + preread_count, sizeof(buf) - preread_count));
+      ret = TEMP_FAILURE_RETRY(read(fd, &buf.p.magic + preread_count, sizeof(buf) - preread_count));
       if (ret < 0) {
         return -errno;
       }
@@ -185,11 +181,10 @@
       return preread_count ? -EIO : -EAGAIN;
     }
     if ((buf.p.magic != LOGGER_MAGIC) || (buf.p.len <= sizeof(buf)) ||
-        (buf.p.len > (sizeof(buf) + LOGGER_ENTRY_MAX_PAYLOAD)) ||
-        (buf.l.id >= LOG_ID_MAX) || (buf.l.realtime.tv_nsec >= NS_PER_SEC) ||
+        (buf.p.len > (sizeof(buf) + LOGGER_ENTRY_MAX_PAYLOAD)) || (buf.l.id >= LOG_ID_MAX) ||
+        (buf.l.realtime.tv_nsec >= NS_PER_SEC) ||
         ((buf.l.id != LOG_ID_EVENTS) && (buf.l.id != LOG_ID_SECURITY) &&
-         ((buf.prio == ANDROID_LOG_UNKNOWN) ||
-          (buf.prio == ANDROID_LOG_DEFAULT) ||
+         ((buf.prio == ANDROID_LOG_UNKNOWN) || (buf.prio == ANDROID_LOG_DEFAULT) ||
           (buf.prio >= ANDROID_LOG_SILENT)))) {
       do {
         memmove(&buf.p.magic, &buf.p.magic + 1, --preread_count);
@@ -213,8 +208,7 @@
         if (fd <= 0) {
           return -EBADF;
         }
-        ret = TEMP_FAILURE_RETRY(
-            read(fd, msg + sizeof(buf.prio), buf.p.len - sizeof(buf)));
+        ret = TEMP_FAILURE_RETRY(read(fd, msg + sizeof(buf.prio), buf.p.len - sizeof(buf)));
         if (ret < 0) {
           return -errno;
         }
@@ -250,8 +244,7 @@
     if (fd <= 0) {
       return -EBADF;
     }
-    next = TEMP_FAILURE_RETRY(
-        lseek(fd, (off_t)(buf.p.len - sizeof(buf)), SEEK_CUR));
+    next = TEMP_FAILURE_RETRY(lseek(fd, (off_t)(buf.p.len - sizeof(buf)), SEEK_CUR));
     if (next < 0) {
       return -errno;
     }
@@ -277,9 +270,10 @@
   return result;
 }
 
-LIBLOG_ABI_PRIVATE ssize_t
-__android_log_pmsg_file_read(log_id_t logId, char prio, const char* prefix,
-                             __android_log_pmsg_file_read_fn fn, void* arg) {
+LIBLOG_ABI_PRIVATE ssize_t __android_log_pmsg_file_read(log_id_t logId, char prio,
+                                                        const char* prefix,
+                                                        __android_log_pmsg_file_read_fn fn,
+                                                        void* arg) {
   ssize_t ret;
   struct android_log_logger_list logger_list;
   struct android_log_transport_context transp;
@@ -312,14 +306,12 @@
   memset(&logger_list, 0, sizeof(logger_list));
   memset(&transp, 0, sizeof(transp));
 
-  logger_list.mode =
-      ANDROID_LOG_PSTORE | ANDROID_LOG_NONBLOCK | ANDROID_LOG_RDONLY;
+  logger_list.mode = ANDROID_LOG_PSTORE | ANDROID_LOG_NONBLOCK | ANDROID_LOG_RDONLY;
   transp.logMask = (unsigned)-1;
   if (logId != LOG_ID_ANY) {
     transp.logMask = (1 << logId);
   }
-  transp.logMask &=
-      ~((1 << LOG_ID_KERNEL) | (1 << LOG_ID_EVENTS) | (1 << LOG_ID_SECURITY));
+  transp.logMask &= ~((1 << LOG_ID_KERNEL) | (1 << LOG_ID_EVENTS) | (1 << LOG_ID_SECURITY));
   if (!transp.logMask) {
     return -EINVAL;
   }
@@ -346,15 +338,13 @@
 
   /* Read the file content */
   while (pmsgRead(&logger_list, &transp, &transp.logMsg) > 0) {
-    char* cp;
-    size_t hdr_size = transp.logMsg.entry.hdr_size
-                          ? transp.logMsg.entry.hdr_size
-                          : sizeof(transp.logMsg.entry_v1);
+    const char* cp;
+    size_t hdr_size = transp.logMsg.entry.hdr_size ? transp.logMsg.entry.hdr_size
+                                                   : sizeof(transp.logMsg.entry_v1);
     char* msg = (char*)&transp.logMsg + hdr_size;
-    char* split = NULL;
+    const char* split = NULL;
 
-    if ((hdr_size < sizeof(transp.logMsg.entry_v1)) ||
-        (hdr_size > sizeof(transp.logMsg.entry))) {
+    if ((hdr_size < sizeof(transp.logMsg.entry_v1)) || (hdr_size > sizeof(transp.logMsg.entry))) {
       continue;
     }
     /* Check for invalid sequence number */
@@ -366,8 +356,7 @@
 
     /* Determine if it has <dirbase>:<filebase> format for tag */
     len = transp.logMsg.entry.len - sizeof(prio);
-    for (cp = msg + sizeof(prio); *cp && isprint(*cp) && !isspace(*cp) && --len;
-         ++cp) {
+    for (cp = msg + sizeof(prio); *cp && isprint(*cp) && !isspace(*cp) && --len; ++cp) {
       if (*cp == ':') {
         if (split) {
           break;
@@ -395,13 +384,12 @@
         continue;
       }
       offset = split - prefix;
-      if ((msg[offset + sizeof(prio)] != ':') ||
-          strncmp(msg + sizeof(prio), prefix, offset)) {
+      if ((msg[offset + sizeof(prio)] != ':') || strncmp(msg + sizeof(prio), prefix, offset)) {
         continue;
       }
       ++offset;
-      if ((prefix_len > offset) && strncmp(&msg[offset + sizeof(prio)],
-                                           split + 1, prefix_len - offset)) {
+      if ((prefix_len > offset) &&
+          strncmp(&msg[offset + sizeof(prio)], split + 1, prefix_len - offset)) {
         continue;
       }
     }
@@ -413,8 +401,8 @@
     /* check if there is an existing entry */
     list_for_each(node, &name_list) {
       names = node_to_item(node, struct names, node);
-      if (!strcmp(names->name, msg + sizeof(prio)) &&
-          (names->id == transp.logMsg.entry.lid) && (names->prio == *msg)) {
+      if (!strcmp(names->name, msg + sizeof(prio)) && (names->id == transp.logMsg.entry.lid) &&
+          (names->prio == *msg)) {
         break;
       }
     }
@@ -425,13 +413,13 @@
       unsigned long long nl;
 
       len = strlen(msg + sizeof(prio)) + 1;
-      names = calloc(1, sizeof(*names) + len);
+      names = static_cast<struct names*>(calloc(1, sizeof(*names) + len));
       if (!names) {
         ret = -ENOMEM;
         break;
       }
       strcpy(names->name, msg + sizeof(prio));
-      names->id = transp.logMsg.entry.lid;
+      names->id = static_cast<log_id_t>(transp.logMsg.entry.lid);
       names->prio = *msg;
       list_init(&names->content);
       /*
@@ -491,19 +479,17 @@
     }
 
     /* Add content */
-    content =
-        calloc(1, sizeof(content->node) + hdr_size + transp.logMsg.entry.len);
+    content = static_cast<struct content*>(
+        calloc(1, sizeof(content->node) + hdr_size + transp.logMsg.entry.len));
     if (!content) {
       ret = -ENOMEM;
       break;
     }
-    memcpy(&content->entry, &transp.logMsg.entry,
-           hdr_size + transp.logMsg.entry.len);
+    memcpy(&content->entry, &transp.logMsg.entry, hdr_size + transp.logMsg.entry.len);
 
     /* Insert in sequence number sorted order, to ease reconstruction */
     list_for_each_reverse(node, &names->content) {
-      if ((node_to_item(node, struct content, node))->entry.nsec <
-          transp.logMsg.entry.nsec) {
+      if ((node_to_item(node, struct content, node))->entry.nsec < transp.logMsg.entry.nsec) {
         break;
       }
     }
@@ -536,7 +522,7 @@
       }
 
       if (!buf) {
-        buf = malloc(sizeof(char));
+        buf = static_cast<char*>(malloc(sizeof(char)));
         if (!buf) {
           ret = -ENOMEM;
           list_remove(content_node);
@@ -549,7 +535,7 @@
       /* Missing sequence numbers */
       while (sequence < content->entry.nsec) {
         /* plus space for enforced nul */
-        buf = realloc_or_free(buf, len + sizeof(char) + sizeof(char));
+        buf = static_cast<char*>(realloc_or_free(buf, len + sizeof(char) + sizeof(char)));
         if (!buf) {
           break;
         }
@@ -564,16 +550,14 @@
         continue;
       }
       /* plus space for enforced nul */
-      buf = realloc_or_free(buf, len + add_len + sizeof(char));
+      buf = static_cast<char*>(realloc_or_free(buf, len + add_len + sizeof(char)));
       if (!buf) {
         ret = -ENOMEM;
         list_remove(content_node);
         free(content);
         continue;
       }
-      memcpy(buf + len,
-             (char*)&content->entry + content->entry.hdr_size + tag_len +
-                 sizeof(prio),
+      memcpy(buf + len, (char*)&content->entry + content->entry.hdr_size + tag_len + sizeof(prio),
              add_len);
       len += add_len;
       buf[len] = '\0'; /* enforce trailing hidden nul */
diff --git a/liblog/pmsg_writer.c b/liblog/pmsg_writer.cpp
similarity index 88%
rename from liblog/pmsg_writer.c
rename to liblog/pmsg_writer.cpp
index dc42856..c50c7f7 100644
--- a/liblog/pmsg_writer.c
+++ b/liblog/pmsg_writer.cpp
@@ -37,17 +37,16 @@
 static int pmsgOpen();
 static void pmsgClose();
 static int pmsgAvailable(log_id_t logId);
-static int pmsgWrite(log_id_t logId, struct timespec* ts, struct iovec* vec,
-                     size_t nr);
+static int pmsgWrite(log_id_t logId, struct timespec* ts, struct iovec* vec, size_t nr);
 
 LIBLOG_HIDDEN struct android_log_transport_write pmsgLoggerWrite = {
-  .node = { &pmsgLoggerWrite.node, &pmsgLoggerWrite.node },
-  .context.fd = -1,
-  .name = "pmsg",
-  .available = pmsgAvailable,
-  .open = pmsgOpen,
-  .close = pmsgClose,
-  .write = pmsgWrite,
+    .node = {&pmsgLoggerWrite.node, &pmsgLoggerWrite.node},
+    .context.fd = -1,
+    .name = "pmsg",
+    .available = pmsgAvailable,
+    .open = pmsgOpen,
+    .close = pmsgClose,
+    .write = pmsgWrite,
 };
 
 static int pmsgOpen() {
@@ -76,8 +75,7 @@
   if (logId > LOG_ID_SECURITY) {
     return -EINVAL;
   }
-  if ((logId != LOG_ID_SECURITY) && (logId != LOG_ID_EVENTS) &&
-      !__android_log_is_debuggable()) {
+  if ((logId != LOG_ID_SECURITY) && (logId != LOG_ID_EVENTS) && !__android_log_is_debuggable()) {
     return -EINVAL;
   }
   if (atomic_load(&pmsgLoggerWrite.context.fd) < 0) {
@@ -96,8 +94,7 @@
   return src[0] | (src[1] << 8) | (src[2] << 16) | (src[3] << 24);
 }
 
-static int pmsgWrite(log_id_t logId, struct timespec* ts, struct iovec* vec,
-                     size_t nr) {
+static int pmsgWrite(log_id_t logId, struct timespec* ts, struct iovec* vec, size_t nr) {
   static const unsigned headerLength = 2;
   struct iovec newVec[nr + headerLength];
   android_log_header_t header;
@@ -110,7 +107,7 @@
       return -EINVAL;
     }
 
-    if (SNET_EVENT_LOG_TAG != get4LE(vec[0].iov_base)) {
+    if (SNET_EVENT_LOG_TAG != get4LE(static_cast<uint8_t*>(vec[0].iov_base))) {
       return -EPERM;
     }
   }
@@ -169,8 +166,7 @@
   }
   pmsgHeader.len += payloadSize;
 
-  ret = TEMP_FAILURE_RETRY(
-      writev(atomic_load(&pmsgLoggerWrite.context.fd), newVec, i));
+  ret = TEMP_FAILURE_RETRY(writev(atomic_load(&pmsgLoggerWrite.context.fd), newVec, i));
   if (ret < 0) {
     ret = errno ? -errno : -ENOTCONN;
   }
@@ -203,10 +199,8 @@
 }
 
 /* Write a buffer as filename references (tag = <basedir>:<basename>) */
-LIBLOG_ABI_PRIVATE ssize_t __android_log_pmsg_file_write(log_id_t logId,
-                                                         char prio,
-                                                         const char* filename,
-                                                         const char* buf,
+LIBLOG_ABI_PRIVATE ssize_t __android_log_pmsg_file_write(log_id_t logId, char prio,
+                                                         const char* filename, const char* buf,
                                                          size_t len) {
   bool weOpened;
   size_t length, packet_len;
@@ -249,13 +243,11 @@
   vec[1].iov_len = length;
 
   weOpened = false;
-  for (ts.tv_nsec = 0, length = len; length;
-       ts.tv_nsec += ANDROID_LOG_PMSG_FILE_SEQUENCE) {
+  for (ts.tv_nsec = 0, length = len; length; ts.tv_nsec += ANDROID_LOG_PMSG_FILE_SEQUENCE) {
     ssize_t ret;
     size_t transfer;
 
-    if ((ts.tv_nsec / ANDROID_LOG_PMSG_FILE_SEQUENCE) >=
-        ANDROID_LOG_PMSG_FILE_MAX_SEQUENCE) {
+    if ((ts.tv_nsec / ANDROID_LOG_PMSG_FILE_SEQUENCE) >= ANDROID_LOG_PMSG_FILE_MAX_SEQUENCE) {
       len -= length;
       break;
     }
diff --git a/liblog/properties.c b/liblog/properties.cpp
similarity index 86%
rename from liblog/properties.c
rename to liblog/properties.cpp
index 11be827..764877e 100644
--- a/liblog/properties.c
+++ b/liblog/properties.cpp
@@ -14,9 +14,10 @@
 ** limitations under the License.
 */
 
+#include <log/log_properties.h>
+
 #include <ctype.h>
 #include <pthread.h>
-#include <stdbool.h>
 #include <stdlib.h>
 #include <string.h>
 #define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
@@ -160,11 +161,11 @@
       }
       if (!last_tag || !last_tag[0]) {
         if (!last_tag) {
-          last_tag = calloc(1, len + 1);
+          last_tag = static_cast<char*>(calloc(1, len + 1));
           last_tag_len = 0;
           if (last_tag) last_tag_len = len + 1;
         } else if (len >= last_tag_len) {
-          last_tag = realloc(last_tag, len + 1);
+          last_tag = static_cast<char*>(realloc(last_tag, len + 1));
           last_tag_len = 0;
           if (last_tag) last_tag_len = len + 1;
         }
@@ -258,22 +259,19 @@
     case 'A': return ANDROID_LOG_FATAL;
     case BOOLEAN_FALSE: /* FALLTHRU */ /* Not Officially supported */
     case 'S': return -1; /* ANDROID_LOG_SUPPRESS */
-    /* clang-format on */
+      /* clang-format on */
   }
   return default_prio;
 }
 
-LIBLOG_ABI_PUBLIC int __android_log_is_loggable_len(int prio, const char* tag,
-                                                    size_t len,
+LIBLOG_ABI_PUBLIC int __android_log_is_loggable_len(int prio, const char* tag, size_t len,
                                                     int default_prio) {
   int logLevel = __android_log_level(tag, len, default_prio);
   return logLevel >= 0 && prio >= logLevel;
 }
 
-LIBLOG_ABI_PUBLIC int __android_log_is_loggable(int prio, const char* tag,
-                                                int default_prio) {
-  int logLevel =
-      __android_log_level(tag, (tag && *tag) ? strlen(tag) : 0, default_prio);
+LIBLOG_ABI_PUBLIC int __android_log_is_loggable(int prio, const char* tag, int default_prio) {
+  int logLevel = __android_log_level(tag, (tag && *tag) ? strlen(tag) : 0, default_prio);
   return logLevel >= 0 && prio >= logLevel;
 }
 
@@ -286,7 +284,7 @@
   if (tag_cache.c) { /* ro property does not change after set */
     ret = tag_cache.c == '1';
   } else if (lock()) {
-    struct cache_char temp_cache = { { NULL, -1 }, '\0' };
+    struct cache_char temp_cache = {{NULL, 0xFFFFFFFF}, '\0'};
     refresh_cache(&temp_cache, key);
     ret = temp_cache.c == '1';
   } else {
@@ -332,8 +330,7 @@
     return self->evaluate(self);
   }
 
-  change_detected = check_cache(&self->cache_persist.cache) ||
-                    check_cache(&self->cache_ro.cache);
+  change_detected = check_cache(&self->cache_persist.cache) || check_cache(&self->cache_ro.cache);
   current_serial = __system_property_area_serial();
   if (current_serial != self->serial) {
     change_detected = 1;
@@ -365,15 +362,12 @@
  * to handle developer requirements.
  */
 LIBLOG_ABI_PUBLIC clockid_t android_log_clockid() {
-  static struct cache2_char clockid = {
-    PTHREAD_MUTEX_INITIALIZER, 0,
-    "persist.logd.timestamp",  { { NULL, -1 }, '\0' },
-    "ro.logd.timestamp",       { { NULL, -1 }, '\0' },
-    evaluate_persist_ro
-  };
+  static struct cache2_char clockid = {PTHREAD_MUTEX_INITIALIZER, 0,
+                                       "persist.logd.timestamp",  {{NULL, 0xFFFFFFFF}, '\0'},
+                                       "ro.logd.timestamp",       {{NULL, 0xFFFFFFFF}, '\0'},
+                                       evaluate_persist_ro};
 
-  return (tolower(do_cache2_char(&clockid)) == 'm') ? CLOCK_MONOTONIC
-                                                    : CLOCK_REALTIME;
+  return (tolower(do_cache2_char(&clockid)) == 'm') ? CLOCK_MONOTONIC : CLOCK_REALTIME;
 }
 
 /*
@@ -388,11 +382,10 @@
 
 LIBLOG_ABI_PUBLIC int __android_log_security() {
   static struct cache2_char security = {
-    PTHREAD_MUTEX_INITIALIZER, 0,
-    "persist.logd.security",   { { NULL, -1 }, BOOLEAN_FALSE },
-    "ro.device_owner",         { { NULL, -1 }, BOOLEAN_FALSE },
-    evaluate_security
-  };
+      PTHREAD_MUTEX_INITIALIZER, 0,
+      "persist.logd.security",   {{NULL, 0xFFFFFFFF}, BOOLEAN_FALSE},
+      "ro.device_owner",         {{NULL, 0xFFFFFFFF}, BOOLEAN_FALSE},
+      evaluate_security};
 
   return do_cache2_char(&security);
 }
@@ -423,8 +416,7 @@
   char property[PROP_VALUE_MAX];
 };
 
-static void refresh_cache_property(struct cache_property* cache,
-                                   const char* key) {
+static void refresh_cache_property(struct cache_property* cache, const char* key) {
   if (!cache->cache.pinfo) {
     cache->cache.pinfo = __system_property_find(key);
     if (!cache->cache.pinfo) {
@@ -436,19 +428,18 @@
 }
 
 /* get boolean with the logger twist that supports eng adjustments */
-LIBLOG_ABI_PRIVATE bool __android_logger_property_get_bool(const char* key,
-                                                           int flag) {
-  struct cache_property property = { { NULL, -1 }, { 0 } };
+LIBLOG_ABI_PRIVATE bool __android_logger_property_get_bool(const char* key, int flag) {
+  struct cache_property property = {{NULL, 0xFFFFFFFF}, {0}};
   if (flag & BOOL_DEFAULT_FLAG_PERSIST) {
     char newkey[strlen("persist.") + strlen(key) + 1];
     snprintf(newkey, sizeof(newkey), "ro.%s", key);
     refresh_cache_property(&property, newkey);
     property.cache.pinfo = NULL;
-    property.cache.serial = -1;
+    property.cache.serial = 0xFFFFFFFF;
     snprintf(newkey, sizeof(newkey), "persist.%s", key);
     refresh_cache_property(&property, newkey);
     property.cache.pinfo = NULL;
-    property.cache.serial = -1;
+    property.cache.serial = 0xFFFFFFFF;
   }
 
   refresh_cache_property(&property, key);
@@ -477,8 +468,7 @@
   }
 
   if ((flag & BOOL_DEFAULT_FLAG_SVELTE) &&
-      __android_logger_property_get_bool("ro.config.low_ram",
-                                         BOOL_DEFAULT_FALSE)) {
+      __android_logger_property_get_bool("ro.config.low_ram", BOOL_DEFAULT_FALSE)) {
     return false;
   }
   if ((flag & BOOL_DEFAULT_FLAG_ENG) && !__android_log_is_debuggable()) {
@@ -531,8 +521,7 @@
   unsigned long (*const evaluate)(const struct cache2_property_size* self);
 };
 
-static inline unsigned long do_cache2_property_size(
-    struct cache2_property_size* self) {
+static inline unsigned long do_cache2_property_size(struct cache2_property_size* self) {
   uint32_t current_serial;
   int change_detected;
   unsigned long v;
@@ -542,8 +531,7 @@
     return self->evaluate(self);
   }
 
-  change_detected = check_cache(&self->cache_persist.cache) ||
-                    check_cache(&self->cache_ro.cache);
+  change_detected = check_cache(&self->cache_persist.cache) || check_cache(&self->cache_ro.cache);
   current_serial = __system_property_area_serial();
   if (current_serial != self->serial) {
     change_detected = 1;
@@ -560,8 +548,7 @@
   return v;
 }
 
-static unsigned long property_get_size_from_cache(
-    const struct cache_property* cache) {
+static unsigned long property_get_size_from_cache(const struct cache_property* cache) {
   char* cp;
   unsigned long value = strtoul(cache->property, &cp, 10);
 
@@ -569,11 +556,11 @@
     case 'm':
     case 'M':
       value *= 1024;
-    /* FALLTHRU */
+      [[fallthrough]];
     case 'k':
     case 'K':
       value *= 1024;
-    /* FALLTHRU */
+      [[fallthrough]];
     case '\0':
       break;
 
@@ -588,8 +575,7 @@
   return value;
 }
 
-static unsigned long evaluate_property_get_size(
-    const struct cache2_property_size* self) {
+static unsigned long evaluate_property_get_size(const struct cache2_property_size* self) {
   unsigned long size = property_get_size_from_cache(&self->cache_persist);
   if (size) {
     return size;
@@ -601,37 +587,35 @@
   static const char global_tunable[] = "persist.logd.size"; /* Settings App */
   static const char global_default[] = "ro.logd.size";      /* BoardConfig.mk */
   static struct cache2_property_size global = {
-    /* clang-format off */
+      /* clang-format off */
     PTHREAD_MUTEX_INITIALIZER, 0,
-    global_tunable, { { NULL, -1 }, {} },
-    global_default, { { NULL, -1 }, {} },
+    global_tunable, { { NULL, 0xFFFFFFFF }, {} },
+    global_default, { { NULL, 0xFFFFFFFF }, {} },
     evaluate_property_get_size
-    /* clang-format on */
+      /* clang-format on */
   };
   char key_persist[strlen(global_tunable) + strlen(".security") + 1];
   char key_ro[strlen(global_default) + strlen(".security") + 1];
   struct cache2_property_size local = {
-    /* clang-format off */
+      /* clang-format off */
     PTHREAD_MUTEX_INITIALIZER, 0,
-    key_persist, { { NULL, -1 }, {} },
-    key_ro,      { { NULL, -1 }, {} },
+    key_persist, { { NULL, 0xFFFFFFFF }, {} },
+    key_ro,      { { NULL, 0xFFFFFFFF }, {} },
     evaluate_property_get_size
-    /* clang-format on */
+      /* clang-format on */
   };
   unsigned long property_size, default_size;
 
   default_size = do_cache2_property_size(&global);
   if (!default_size) {
-    default_size = __android_logger_property_get_bool("ro.config.low_ram",
-                                                      BOOL_DEFAULT_FALSE)
+    default_size = __android_logger_property_get_bool("ro.config.low_ram", BOOL_DEFAULT_FALSE)
                        ? LOG_BUFFER_MIN_SIZE /* 64K  */
                        : LOG_BUFFER_SIZE;    /* 256K */
   }
 
   snprintf(key_persist, sizeof(key_persist), "%s.%s", global_tunable,
            android_log_id_to_name(logId));
-  snprintf(key_ro, sizeof(key_ro), "%s.%s", global_default,
-           android_log_id_to_name(logId));
+  snprintf(key_ro, sizeof(key_ro), "%s.%s", global_default, android_log_id_to_name(logId));
   property_size = do_cache2_property_size(&local);
 
   if (!property_size) {
diff --git a/liblog/stderr_write.c b/liblog/stderr_write.cpp
similarity index 90%
rename from liblog/stderr_write.c
rename to liblog/stderr_write.cpp
index dbe5309..f9cb37d 100644
--- a/liblog/stderr_write.c
+++ b/liblog/stderr_write.cpp
@@ -45,8 +45,7 @@
 static int stderrOpen();
 static void stderrClose();
 static int stderrAvailable(log_id_t logId);
-static int stderrWrite(log_id_t logId, struct timespec* ts, struct iovec* vec,
-                       size_t nr);
+static int stderrWrite(log_id_t logId, struct timespec* ts, struct iovec* vec, size_t nr);
 
 struct stderrContext {
   AndroidLogFormat* logformat;
@@ -56,13 +55,13 @@
 };
 
 LIBLOG_HIDDEN struct android_log_transport_write stderrLoggerWrite = {
-  .node = { &stderrLoggerWrite.node, &stderrLoggerWrite.node },
-  .context.priv = NULL,
-  .name = "stderr",
-  .available = stderrAvailable,
-  .open = stderrOpen,
-  .close = stderrClose,
-  .write = stderrWrite,
+    .node = {&stderrLoggerWrite.node, &stderrLoggerWrite.node},
+    .context.priv = NULL,
+    .name = "stderr",
+    .available = stderrAvailable,
+    .open = stderrOpen,
+    .close = stderrClose,
+    .write = stderrWrite,
 };
 
 static int stderrOpen() {
@@ -78,7 +77,7 @@
     return fileno(stderr);
   }
 
-  ctx = calloc(1, sizeof(struct stderrContext));
+  ctx = static_cast<stderrContext*>(calloc(1, sizeof(stderrContext)));
   if (!ctx) {
     return -ENOMEM;
   }
@@ -123,7 +122,7 @@
 }
 
 static void stderrClose() {
-  struct stderrContext* ctx = stderrLoggerWrite.context.priv;
+  stderrContext* ctx = static_cast<stderrContext*>(stderrLoggerWrite.context.priv);
 
   if (ctx) {
     stderrLoggerWrite.context.priv = NULL;
@@ -147,14 +146,13 @@
   return 1;
 }
 
-static int stderrWrite(log_id_t logId, struct timespec* ts, struct iovec* vec,
-                       size_t nr) {
+static int stderrWrite(log_id_t logId, struct timespec* ts, struct iovec* vec, size_t nr) {
   struct log_msg log_msg;
   AndroidLogEntry entry;
   char binaryMsgBuf[1024];
   int err;
   size_t i;
-  struct stderrContext* ctx = stderrLoggerWrite.context.priv;
+  stderrContext* ctx = static_cast<stderrContext*>(stderrLoggerWrite.context.priv);
 
   if (!ctx) return -EBADF;
   if (!vec || !nr) return -EINVAL;
diff --git a/liblog/uio.c b/liblog/uio.cpp
similarity index 92%
rename from liblog/uio.c
rename to liblog/uio.cpp
index e127202..05145d7 100644
--- a/liblog/uio.c
+++ b/liblog/uio.cpp
@@ -26,7 +26,7 @@
   int total = 0;
 
   for (; count > 0; count--, vecs++) {
-    char* buf = vecs->iov_base;
+    char* buf = static_cast<char*>(vecs->iov_base);
     int len = vecs->iov_len;
 
     while (len > 0) {
@@ -50,7 +50,7 @@
   int total = 0;
 
   for (; count > 0; count--, vecs++) {
-    const char* buf = vecs->iov_base;
+    const char* buf = static_cast<const char*>(vecs->iov_base);
     int len = vecs->iov_len;
 
     while (len > 0) {