summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJan Janssen <medhefgo@web.de>2022-05-24 10:14:35 +0200
committerJan Janssen <medhefgo@web.de>2022-05-31 15:10:48 +0200
commitef4d71ad7f0ecbc19efb0df7f1ef0f821da25fdc (patch)
treeb3b7003548b76e790a8919f39261876ac452d941 /src
parentboot: Use strtolower8/16 (diff)
downloadsystemd-ef4d71ad7f0ecbc19efb0df7f1ef0f821da25fdc.tar.xz
systemd-ef4d71ad7f0ecbc19efb0df7f1ef0f821da25fdc.zip
boot: Add strcpy8/16
Diffstat (limited to 'src')
-rw-r--r--src/boot/efi/efi-string.c23
-rw-r--r--src/boot/efi/efi-string.h3
-rw-r--r--src/boot/efi/test-efi-string.c26
3 files changed, 52 insertions, 0 deletions
diff --git a/src/boot/efi/efi-string.c b/src/boot/efi/efi-string.c
index 17372ae9d4..4df705b30d 100644
--- a/src/boot/efi/efi-string.c
+++ b/src/boot/efi/efi-string.c
@@ -98,3 +98,26 @@ int strcasecmp8(const char *s1, const char *s2) {
int strcasecmp16(const char16_t *s1, const char16_t *s2) {
return strncasecmp16(s1, s2, SIZE_MAX);
}
+
+#define DEFINE_STRCPY(type, name) \
+ type *name(type * restrict dest, const type * restrict src) { \
+ assert(dest); \
+ type *ret = dest; \
+ \
+ if (!src) { \
+ *dest = '\0'; \
+ return ret; \
+ } \
+ \
+ while (*src) { \
+ *dest = *src; \
+ dest++; \
+ src++; \
+ } \
+ \
+ *dest = '\0'; \
+ return ret; \
+ }
+
+DEFINE_STRCPY(char, strcpy8);
+DEFINE_STRCPY(char16_t, strcpy16);
diff --git a/src/boot/efi/efi-string.h b/src/boot/efi/efi-string.h
index 2b9a1dfb97..d3c1786b47 100644
--- a/src/boot/efi/efi-string.h
+++ b/src/boot/efi/efi-string.h
@@ -57,3 +57,6 @@ static inline bool strcaseeq8(const char *s1, const char *s2) {
static inline bool strcaseeq16(const char16_t *s1, const char16_t *s2) {
return strcasecmp16(s1, s2) == 0;
}
+
+char *strcpy8(char * restrict dest, const char * restrict src);
+char16_t *strcpy16(char16_t * restrict dest, const char16_t * restrict src);
diff --git a/src/boot/efi/test-efi-string.c b/src/boot/efi/test-efi-string.c
index 83cb645688..384d5868ba 100644
--- a/src/boot/efi/test-efi-string.c
+++ b/src/boot/efi/test-efi-string.c
@@ -174,4 +174,30 @@ TEST(strncasecmp16) {
assert_se(strncasecmp16((char16_t[]){ UINT16_MAX }, (char16_t[]){ 0 }, 1) > 0);
}
+TEST(strcpy8) {
+ char buf[128];
+
+ assert_se(strcpy8(buf, "123") == buf);
+ assert_se(streq8(buf, "123"));
+ assert_se(strcpy8(buf, "") == buf);
+ assert_se(streq8(buf, ""));
+ assert_se(strcpy8(buf, "A") == buf);
+ assert_se(streq8(buf, "A"));
+ assert_se(strcpy8(buf, NULL) == buf);
+ assert_se(streq8(buf, ""));
+}
+
+TEST(strcpy16) {
+ char16_t buf[128];
+
+ assert_se(strcpy16(buf, u"123") == buf);
+ assert_se(streq16(buf, u"123"));
+ assert_se(strcpy16(buf, u"") == buf);
+ assert_se(streq16(buf, u""));
+ assert_se(strcpy16(buf, u"A") == buf);
+ assert_se(streq16(buf, u"A"));
+ assert_se(strcpy16(buf, NULL) == buf);
+ assert_se(streq16(buf, u""));
+}
+
DEFINE_TEST_MAIN(LOG_INFO);