From 118bd4294f227de85646191c8a9beb07375fb729 Mon Sep 17 00:00:00 2001 From: R0rt1z2 Date: Wed, 19 Jul 2023 19:18:44 +0000 Subject: [PATCH] compat: Add libutils shim * This is required because some old libraries still rely on the strncpy16() function. Change-Id: I77da329d1296d946f43ffe6708444b1d25607342 --- Android.bp | 8 ++++++++ libutils/String16.cpp | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 libutils/String16.cpp diff --git a/Android.bp b/Android.bp index a494c8a..adf427b 100644 --- a/Android.bp +++ b/Android.bp @@ -335,6 +335,14 @@ cc_library_shared { vendor_available: true, } +cc_library_shared { + name: "libutils_shim", + shared_libs: ["libutils"], + srcs: ["libutils/String16.cpp"], + system_ext_specific: true, + vendor_available: true, +} + cc_library { name: "libip_checksum_shim", whole_static_libs: [ diff --git a/libutils/String16.cpp b/libutils/String16.cpp new file mode 100644 index 0000000..ef0e3bd --- /dev/null +++ b/libutils/String16.cpp @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2023 The LineageOS Project + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +extern "C" { +char16_t* strncpy16(char16_t* dst, const char16_t* src, size_t n) { + char16_t* q = dst; + const char16_t* p = src; + char ch; + while (n) { + n--; + *q++ = ch = *p++; + if (!ch) break; + } + *q = 0; + return dst; +} +}