boot: modernize mangle_stub_cmdline() a bit + drop leading whitespace

Let's modernize the function a bit, and make it return the string passed
in, as we usually do.

Most importanly though: also drop leading whitespace, not just trailing
whitespace.
This commit is contained in:
Lennart Poettering
2023-08-22 10:53:25 +02:00
parent c4d281fa1a
commit 90dab2b01e
2 changed files with 24 additions and 14 deletions
+23 -13
View File
@@ -265,26 +265,36 @@ char16_t *xstr8_to_path(const char *str8) {
return path;
}
void mangle_stub_cmdline(char16_t *cmdline) {
char16_t *p = cmdline;
static bool shall_be_whitespace(char16_t c) {
return c <= 0x20U || c == 0x7FU; /* All control characters + space */
}
char16_t* mangle_stub_cmdline(char16_t *cmdline) {
char16_t *p, *q, *e;
if (!cmdline)
return;
return cmdline;
for (; *cmdline != '\0'; cmdline++)
/* Convert ASCII control characters to spaces. */
if (*cmdline <= 0x1F)
*cmdline = ' ';
p = q = cmdline;
/* chomp the trailing whitespaces */
while (cmdline != p) {
--cmdline;
/* Skip initial whitespace */
while (shall_be_whitespace(*p))
p++;
if (*cmdline != ' ')
break;
/* Turn inner control characters into proper spaces */
for (e = p; *p != 0; p++) {
if (shall_be_whitespace(*p)) {
*(q++) = ' ';
continue;
}
*cmdline = '\0';
*(q++) = *p;
e = q; /* remember last non-whitespace char */
}
/* Chop off trailing whitespace */
*e = 0;
return cmdline;
}
EFI_STATUS chunked_read(EFI_FILE *file, size_t *size, void *buf) {
+1 -1
View File
@@ -98,7 +98,7 @@ EFI_STATUS efivar_get_boolean_u8(const EFI_GUID *vendor, const char16_t *name, b
void convert_efi_path(char16_t *path);
char16_t *xstr8_to_path(const char *stra);
void mangle_stub_cmdline(char16_t *cmdline);
char16_t *mangle_stub_cmdline(char16_t *cmdline);
EFI_STATUS chunked_read(EFI_FILE *file, size_t *size, void *buf);
EFI_STATUS file_read(EFI_FILE *dir, const char16_t *name, size_t off, size_t size, char **content, size_t *content_size);