Blame src/libnm-systemd-shared/src/fundamental/string-util-fundamental.h

Packit Bot c44df3
/* SPDX-License-Identifier: LGPL-2.1-or-later */
Packit Bot c44df3
#pragma once
Packit Bot c44df3
Packit Bot c44df3
#ifdef SD_BOOT
Packit Bot c44df3
#include <efi.h>
Packit Bot c44df3
#include <efilib.h>
Packit Bot c44df3
#else
Packit Bot c44df3
#include <string.h>
Packit Bot c44df3
#endif
Packit Bot c44df3
Packit Bot c44df3
#include "macro-fundamental.h"
Packit Bot c44df3
Packit Bot c44df3
#ifdef SD_BOOT
Packit Bot c44df3
#define strlen(a)        StrLen((a))
Packit Bot c44df3
#define strcmp(a, b)     StrCmp((a), (b))
Packit Bot c44df3
#define strncmp(a, b, n) StrnCmp((a), (b), (n))
Packit Bot c44df3
#define strcasecmp(a, b) StriCmp((a), (b))
Packit Bot c44df3
#define STR_C(str)       (L ## str)
Packit Bot c44df3
#else
Packit Bot c44df3
#define STR_C(str)       (str)
Packit Bot c44df3
#endif
Packit Bot c44df3
Packit Bot c44df3
#define streq(a,b) (strcmp((a),(b)) == 0)
Packit Bot c44df3
#define strneq(a, b, n) (strncmp((a), (b), (n)) == 0)
Packit Bot c44df3
#define strcaseeq(a,b) (strcasecmp((a),(b)) == 0)
Packit Bot c44df3
#ifndef SD_BOOT
Packit Bot c44df3
#define strncaseeq(a, b, n) (strncasecmp((a), (b), (n)) == 0)
Packit Bot c44df3
#endif
Packit Bot c44df3
Packit Bot c44df3
static inline sd_int strcmp_ptr(const sd_char *a, const sd_char *b) {
Packit Bot c44df3
        if (a && b)
Packit Bot c44df3
                return strcmp(a, b);
Packit Bot c44df3
Packit Bot c44df3
        return CMP(a, b);
Packit Bot c44df3
}
Packit Bot c44df3
Packit Bot c44df3
static inline sd_int strcasecmp_ptr(const sd_char *a, const sd_char *b) {
Packit Bot c44df3
        if (a && b)
Packit Bot c44df3
                return strcasecmp(a, b);
Packit Bot c44df3
Packit Bot c44df3
        return CMP(a, b);
Packit Bot c44df3
}
Packit Bot c44df3
Packit Bot c44df3
static inline sd_bool streq_ptr(const sd_char *a, const sd_char *b) {
Packit Bot c44df3
        return strcmp_ptr(a, b) == 0;
Packit Bot c44df3
}
Packit Bot c44df3
Packit Bot c44df3
static inline sd_bool strcaseeq_ptr(const sd_char *a, const sd_char *b) {
Packit Bot c44df3
        return strcasecmp_ptr(a, b) == 0;
Packit Bot c44df3
}
Packit Bot c44df3
Packit Bot c44df3
sd_char *startswith(const sd_char *s, const sd_char *prefix) _pure_;
Packit Bot c44df3
#ifndef SD_BOOT
Packit Bot c44df3
sd_char *startswith_no_case(const sd_char *s, const sd_char *prefix) _pure_;
Packit Bot c44df3
#endif
Packit Bot c44df3
sd_char *endswith(const sd_char *s, const sd_char *postfix) _pure_;
Packit Bot c44df3
sd_char *endswith_no_case(const sd_char *s, const sd_char *postfix) _pure_;
Packit Bot c44df3
Packit Bot c44df3
static inline sd_bool isempty(const sd_char *a) {
Packit Bot c44df3
        return !a || a[0] == '\0';
Packit Bot c44df3
}
Packit Bot c44df3
Packit Bot c44df3
static inline const sd_char *yes_no(sd_bool b) {
Packit Bot c44df3
        return b ? STR_C("yes") : STR_C("no");
Packit Bot c44df3
}
Packit Bot c44df3
Packit Bot c44df3
sd_int strverscmp_improved(const sd_char *a, const sd_char *b);