Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8e9aeb90 authored by Elliott Hughes's avatar Elliott Hughes
Browse files

Move libcutils source to C++.

Just the minimial changes to get this to actually build, because otherwise
we always bog down trying to rewrite everything (when the real answer
is usually "stop using libcutils, it's awful").

This doesn't move a handful of files: two are basically just BSD libc
source, a couple have outstanding code reviews, and one can be deleted
(but I'll do that in a separate change).

I'm also skipping the presubmit hooks because otherwise clang-format
wants to reformat everything. I'll follow up with that...

Bug: N/A
Test: builds
Change-Id: I06403f465b67c8e493bad466dd76b1151eed5993
parent 6707ef13
Loading
Loading
Loading
Loading
+24 −24
Original line number Diff line number Diff line
@@ -19,14 +19,14 @@
// which are also hard or even impossible to port to native Win32
libcutils_nonwindows_sources = [
    "android_get_control_file.cpp",
    "fs.c",
    "fs.cpp",
    "multiuser.c",
    "socket_inaddr_any_server_unix.c",
    "socket_local_client_unix.c",
    "socket_local_server_unix.c",
    "socket_network_client_unix.c",
    "socket_inaddr_any_server_unix.cpp",
    "socket_local_client_unix.cpp",
    "socket_local_server_unix.cpp",
    "socket_network_client_unix.cpp",
    "sockets_unix.cpp",
    "str_parms.c",
    "str_parms.cpp",
]

cc_library_headers {
@@ -56,21 +56,21 @@ cc_library {
    },
    host_supported: true,
    srcs: [
        "config_utils.c",
        "config_utils.cpp",
        "fs_config.cpp",
        "canned_fs_config.c",
        "hashmap.c",
        "iosched_policy.c",
        "load_file.c",
        "native_handle.c",
        "canned_fs_config.cpp",
        "hashmap.cpp",
        "iosched_policy.cpp",
        "load_file.cpp",
        "native_handle.cpp",
        "open_memstream.c",
        "record_stream.c",
        "record_stream.cpp",
        "sched_policy.cpp",
        "sockets.cpp",
        "strdup16to8.c",
        "strdup8to16.c",
        "strdup16to8.cpp",
        "strdup8to16.cpp",
        "strlcpy.c",
        "threads.c",
        "threads.cpp",
    ],

    target: {
@@ -83,14 +83,14 @@ cc_library {
        },
        not_windows: {
            srcs: libcutils_nonwindows_sources + [
                "ashmem-host.c",
                "trace-host.c",
                "ashmem-host.cpp",
                "trace-host.cpp",
            ],
        },
        windows: {
            srcs: [
                "socket_inaddr_any_server_windows.c",
                "socket_network_client_windows.c",
                "socket_inaddr_any_server_windows.cpp",
                "socket_network_client_windows.cpp",
                "sockets_windows.cpp",
            ],

@@ -105,13 +105,13 @@ cc_library {

        android: {
            srcs: libcutils_nonwindows_sources + [
                "android_reboot.c",
                "ashmem-dev.c",
                "android_reboot.cpp",
                "ashmem-dev.cpp",
                "klog.cpp",
                "partition_utils.c",
                "partition_utils.cpp",
                "properties.cpp",
                "qtaguid.cpp",
                "trace-dev.c",
                "trace-dev.cpp",
                "uevent.cpp",
            ],
        },
+3 −2
Original line number Diff line number Diff line
@@ -25,6 +25,9 @@
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#include <cutils/android_get_control_file.h>

#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
@@ -36,8 +39,6 @@
#include <sys/types.h>
#include <unistd.h>

#include <cutils/android_get_control_file.h>

#include "android_get_control_env.h"

#ifndef TEMP_FAILURE_RETRY
+4 −2
Original line number Diff line number Diff line
@@ -13,10 +13,12 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <cutils/android_reboot.h>

#include <stdio.h>
#include <stdlib.h>

#include <cutils/android_reboot.h>
#include <cutils/properties.h>

#define TAG "android_reboot"
@@ -26,7 +28,7 @@ int android_reboot(int cmd, int flags __unused, const char* arg) {
    const char* restart_cmd = NULL;
    char* prop_value;

    switch (cmd) {
    switch (static_cast<unsigned>(cmd)) {
        case ANDROID_RB_RESTART:  // deprecated
        case ANDROID_RB_RESTART2:
            restart_cmd = "reboot";
+6 −4
Original line number Diff line number Diff line
@@ -14,6 +14,8 @@
 * limitations under the License.
 */

#include <cutils/ashmem.h>

/*
 * Implementation of the user-space ashmem API for devices, which have our
 * ashmem-enabled kernel. See ashmem-sim.c for the "fake" tmp-based version,
@@ -31,8 +33,6 @@
#include <sys/sysmacros.h>
#include <sys/types.h>
#include <unistd.h>

#include <cutils/ashmem.h>
#include <log/log.h>

#define ASHMEM_DEVICE "/dev/ashmem"
@@ -192,7 +192,8 @@ int ashmem_set_prot_region(int fd, int prot)

int ashmem_pin_region(int fd, size_t offset, size_t len)
{
    struct ashmem_pin pin = { offset, len };
    // TODO: should LP64 reject too-large offset/len?
    ashmem_pin pin = { static_cast<uint32_t>(offset), static_cast<uint32_t>(len) };

    int ret = __ashmem_is_ashmem(fd, 1);
    if (ret < 0) {
@@ -204,7 +205,8 @@ int ashmem_pin_region(int fd, size_t offset, size_t len)

int ashmem_unpin_region(int fd, size_t offset, size_t len)
{
    struct ashmem_pin pin = { offset, len };
    // TODO: should LP64 reject too-large offset/len?
    ashmem_pin pin = { static_cast<uint32_t>(offset), static_cast<uint32_t>(len) };

    int ret = __ashmem_is_ashmem(fd, 1);
    if (ret < 0) {
+6 −5
Original line number Diff line number Diff line
@@ -14,6 +14,8 @@
 * limitations under the License.
 */

#include <cutils/ashmem.h>

/*
 * Implementation of the user-space ashmem API for the simulator, which lacks
 * an ashmem-enabled kernel. See ashmem-dev.c for the real ashmem-based version.
@@ -31,7 +33,6 @@
#include <time.h>
#include <unistd.h>

#include <cutils/ashmem.h>
#include <utils/Compat.h>

#ifndef __unused
@@ -40,12 +41,12 @@

int ashmem_create_region(const char *ignored __unused, size_t size)
{
    char template[PATH_MAX];
    snprintf(template, sizeof(template), "/tmp/android-ashmem-%d-XXXXXXXXX", getpid());
    int fd = mkstemp(template);
    char pattern[PATH_MAX];
    snprintf(pattern, sizeof(pattern), "/tmp/android-ashmem-%d-XXXXXXXXX", getpid());
    int fd = mkstemp(pattern);
    if (fd == -1) return -1;

    unlink(template);
    unlink(pattern);

    if (TEMP_FAILURE_RETRY(ftruncate(fd, size)) == -1) {
      close(fd);
Loading