# define TEST_STATIC
#else
/* Provide our own "EFI API" if we are running as a unit test. */
-# include <stddef.h>
-# include <stdint.h>
-# include <uchar.h>
+# include "efi-string.h"
# include "string-util-fundamental.h"
# define CHAR8 char
# define UINT32 uint32_t
# define UINT64 uint64_t
# define UINTN size_t
-# define strlena(s) strlen(s)
# define strncaseeqa(a, b, n) strncaseeq((a), (b), (n))
# define TEST_STATIC static
#endif
return NULL;
if (*name) {
- if (strncaseeqa(name, key->key_name, key->key_name_len) && strlena(name) == key->key_name_len)
+ if (strncaseeqa(name, key->key_name, key->key_name_len) && strlen8((const char *) name) == key->key_name_len)
name += key->key_name_len;
else
return NULL;
if (BAD_OFFSET(kv->data_offset, kv->data_size, bcd_len))
continue;
- if (strncaseeqa(name, kv->name, kv->name_len) && strlena(name) == kv->name_len)
+ if (strncaseeqa(name, kv->name, kv->name_len) && strlen8((const char *) name) == kv->name_len)
return kv;
}
assert(line_in);
- len = strlen_ptr(*line_in);
+ len = strlen16(*line_in);
size = len + 1024;
line = xnew(CHAR16, size);
print = xnew(CHAR16, x_max + 1);
/* length of the longest entry */
line_width = 0;
for (UINTN i = 0; i < config->entry_count; i++)
- line_width = MAX(line_width, StrLen(config->entries[i]->title_show));
+ line_width = MAX(line_width, strlen16(config->entries[i]->title_show));
line_width = MIN(line_width + 2 * entry_padding, x_max);
/* offsets to center the entries on the screen */
UINTN j, padding;
lines[i] = xnew(CHAR16, line_width + 1);
- padding = (line_width - MIN(StrLen(config->entries[i]->title_show), line_width)) / 2;
+ padding = (line_width - MIN(strlen16(config->entries[i]->title_show), line_width)) / 2;
for (j = 0; j < padding; j++)
lines[i][j] = ' ';
* input. Therefore, draw one less character then we could for the status message.
* Note that the same does not apply for the separator line as it will never be drawn
* on the last line. */
- UINTN len = StrnLen(status, x_max - 1);
+ UINTN len = strnlen16(status, x_max - 1);
UINTN x = (x_max - len) / 2;
status[len] = '\0';
print_at(0, y_status, COLOR_NORMAL, clearline + x_max - x);
* foobar+4-0.efi → foobar+3-1.efi → foobar+2-2.efi → foobar+1-3.efi → foobar+0-4.efi → STOP!
*/
- i = StrLen(file);
+ i = strlen16(file);
/* Chop off any suffix such as ".conf" or ".efi" */
if (suffix) {
UINTN suffix_length;
- suffix_length = StrLen(suffix);
+ suffix_length = strlen16(suffix);
if (i < suffix_length)
return;
config->entries[i]->title_show = xpool_print(
L"%s (%.*s)",
t,
- StrnLen(config->entries[i]->machine_id, 8),
+ strnlen16(config->entries[i]->machine_id, 8),
config->entries[i]->machine_id);
}
l = 6 + 13*8 + 1 + 1; /* Fixed CPIO header size, slash separator, and NUL byte after the file name*/
- target_dir_prefix_size = strlena(target_dir_prefix);
+ target_dir_prefix_size = strlen8((const char *) target_dir_prefix);
if (l > UINTN_MAX - target_dir_prefix_size)
return EFI_OUT_OF_RESOURCES;
l += target_dir_prefix_size;
- fname_size = StrLen(fname);
+ fname_size = strlen16(fname);
if (l > UINTN_MAX - fname_size)
return EFI_OUT_OF_RESOURCES;
l += fname_size; /* append space for file name */
l = 6 + 13*8 + 1; /* Fixed CPIO header size, and NUL byte after the file name*/
- path_size = strlena(path);
+ path_size = strlen8((const char *) path);
if (l > UINTN_MAX - path_size)
return EFI_OUT_OF_RESOURCES;
l += path_size;
continue;
if (!is_ascii(dirent->FileName))
continue;
- if (StrLen(dirent->FileName) > 255) /* Max filename size on Linux */
+ if (strlen16(dirent->FileName) > 255) /* Max filename size on Linux */
continue;
d = xstrdup(dirent->FileName);
'-isystem', efi_incdir,
'-isystem', efi_incdir / efi_arch[1],
'-I', fundamental_path,
+ '-I', meson.current_source_dir(),
'-DSD_BOOT',
'-DGNU_EFI_USE_MS_ABI',
'-include', efi_config_h,
if efi_arch[1] in ['ia32', 'x86_64', 'arm', 'aarch64']
systemd_boot_sources += files('bcd.c')
tests += [
- [files('test-bcd.c'),
+ [files('test-bcd.c', 'efi-string.c'),
[],
[libzstd],
[],
'HAVE_ZSTD'],
]
fuzzers += [
- [files('fuzz-bcd.c')],
+ [files('fuzz-bcd.c', 'efi-string.c')],
]
endif
const struct PeSectionHeader *sect = section_table + i;
for (UINTN j = 0; sections[j]; j++) {
- if (CompareMem(sect->Name, sections[j], strlena(sections[j])) != 0)
+ if (CompareMem(sect->Name, sections[j], strlen8((const char *) sections[j])) != 0)
continue;
if (addrs)
uint8_t result[HASH_VALUE_SIZE];
sha256_init_ctx(&hash);
- sha256_process_bytes(array[i].string, strlena((const CHAR8*) array[i].string), &hash);
+ sha256_process_bytes(array[i].string, strlen8(array[i].string), &hash);
sha256_finish_ctx(&hash, result);
assert(CompareMem(result, array[i].hash, HASH_VALUE_SIZE) == 0);
assert(stra);
- len = strlena(stra);
+ len = strlen8((const char *) stra);
str = xnew(CHAR16, len + 1);
strlen = 0;
assert(stra);
- len = strlena(stra);
+ len = strlen8((const char *) stra);
str = xnew(CHAR16, len + 2);
str[0] = '\\';
return EFI_SUCCESS;
}
-UINTN strnlena(const CHAR8 *p, UINTN maxlen) {
- UINTN c;
-
- if (!p)
- return 0;
-
- for (c = 0; c < maxlen; c++)
- if (p[c] == 0)
- break;
-
- return c;
-}
-
INTN strncasecmpa(const CHAR8 *a, const CHAR8 *b, UINTN maxlen) {
if (!a || !b)
return CMP(a, b);
assert(p || sz == 0);
- sz = strnlena(p, sz);
+ sz = strnlen8((const char *) p, sz);
n = xallocate_pool(sz + 1);
EFI_STATUS readdir_harder(EFI_FILE *handle, EFI_FILE_INFO **buffer, UINTN *buffer_size);
-UINTN strnlena(const CHAR8 *p, UINTN maxlen);
CHAR8 *xstrndup8(const CHAR8 *p, UINTN sz);
INTN strncasecmpa(const CHAR8 *a, const CHAR8 *b, UINTN maxlen);
static inline BOOLEAN strncaseeqa(const CHAR8 *a, const CHAR8 *b, UINTN maxlen) {
#pragma once
#ifdef SD_BOOT
-#include <efi.h>
-#include <efilib.h>
+# include <efi.h>
+# include <efilib.h>
+# include "efi-string.h"
#else
-#include <string.h>
+# include <string.h>
#endif
#include "macro-fundamental.h"
#ifdef SD_BOOT
-#define strlen(a) StrLen((a))
-#define strcmp(a, b) StrCmp((a), (b))
-#define strncmp(a, b, n) StrnCmp((a), (b), (n))
-#define strcasecmp(a, b) StriCmp((a), (b))
-#define STR_C(str) (L ## str)
-#define memcmp(a, b, n) CompareMem(a, b, n)
+# define strlen(a) strlen16((a))
+# define strcmp(a, b) StrCmp((a), (b))
+# define strncmp(a, b, n) StrnCmp((a), (b), (n))
+# define strcasecmp(a, b) StriCmp((a), (b))
+# define STR_C(str) (L ## str)
+# define memcmp(a, b, n) CompareMem(a, b, n)
#else
-#define STR_C(str) (str)
+# define STR_C(str) (str)
#endif
#define streq(a,b) (strcmp((a),(b)) == 0)