1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-31 14:50:15 +03:00

efi: add free_and_xstrdup16() helper modelled after free_and_strdup() in userspace

This commit is contained in:
Lennart Poettering 2024-09-09 15:46:52 +02:00
parent 9f6f3bd2fb
commit 52dd7c8131
2 changed files with 23 additions and 0 deletions

View File

@ -492,3 +492,24 @@ void *xmalloc(size_t size) {
assert_se(BS->AllocatePool(EfiLoaderData, size, &p) == EFI_SUCCESS);
return p;
}
bool free_and_xstrdup16(char16_t **p, const char16_t *s) {
char16_t *t;
assert(p);
/* Replaces a string pointer with a strdup()ed new string,
* possibly freeing the old one. */
if (streq_ptr(*p, s))
return false;
if (s)
t = xstrdup16(s);
else
t = NULL;
free(*p);
*p = t;
return true;
}

View File

@ -55,6 +55,8 @@ static inline void* xmemdup(const void *p, size_t l) {
#define xnew(type, n) ((type *) xmalloc_multiply((n), sizeof(type)))
bool free_and_xstrdup16(char16_t **p, const char16_t *s);
typedef struct {
EFI_PHYSICAL_ADDRESS addr;
size_t n_pages;