summaryrefslogtreecommitdiff
path: root/include/str.h
diff options
context:
space:
mode:
authorPeter Jones <pjones@redhat.com>2021-03-09 11:54:58 -0500
committerPeter Jones <pjones@redhat.com>2021-03-10 15:54:20 -0500
commit766aac4d5cfbe76026be5ce718b0883ee211f323 (patch)
tree56b15cac9a128b4285d58bc1e2a4b12cff5ed881 /include/str.h
parent78809820b5a3f79a0bfbec00e630e40011acf4ec (diff)
downloadefi-boot-shim-766aac4d5cfbe76026be5ce718b0883ee211f323.tar.gz
efi-boot-shim-766aac4d5cfbe76026be5ce718b0883ee211f323.zip
Consolidate most of our standard lib functions to lib
Signed-off-by: Peter Jones <pjones@redhat.com>
Diffstat (limited to 'include/str.h')
-rw-r--r--include/str.h118
1 files changed, 2 insertions, 116 deletions
diff --git a/include/str.h b/include/str.h
index c4d12113..189aceff 100644
--- a/include/str.h
+++ b/include/str.h
@@ -9,122 +9,8 @@
#pragma GCC diagnostic ignored "-Wnonnull-compare"
#endif
-static inline UNUSED NONNULL(1) unsigned long
-strnlena(const CHAR8 *s, unsigned long n)
-{
- unsigned long i;
- for (i = 0; i < n; i++)
- if (s[i] == '\0')
- break;
- return i;
-}
-
-static inline UNUSED RETURNS_NONNULL NONNULL(1, 2) CHAR8 *
-strncpya(CHAR8 *dest, const CHAR8 *src, unsigned long n)
-{
- unsigned long i;
-
- for (i = 0; i < n && src[i] != '\0'; i++)
- dest[i] = src[i];
- for (; i < n; i++)
- dest[i] = '\0';
-
- return dest;
-}
-
-static inline UNUSED RETURNS_NONNULL NONNULL(1, 2) CHAR8 *
-strcata(CHAR8 *dest, const CHAR8 *src)
-{
- unsigned long dest_len = strlena(dest);
- unsigned long i;
-
- for (i = 0; src[i] != '\0'; i++)
- dest[dest_len + i] = src[i];
- dest[dest_len + i] = '\0';
-
- return dest;
-}
-
-static inline UNUSED NONNULL(1) CHAR8 *
-strdup(const CHAR8 * const src)
-{
- UINTN len;
- CHAR8 *news = NULL;
-
- len = strlena(src);
- news = AllocateZeroPool(len + 1);
- if (news)
- strncpya(news, src, len);
- return news;
-}
-
-static inline UNUSED NONNULL(1) CHAR8 *
-strndupa(const CHAR8 * const src, const UINTN srcmax)
-{
- UINTN len;
- CHAR8 *news = NULL;
-
- len = strnlena(src, srcmax);
- news = AllocateZeroPool(len + 1);
- if (news)
- strncpya(news, src, len);
- return news;
-}
-
-static inline UNUSED RETURNS_NONNULL NONNULL(1, 2) char *
-stpcpy(char *dest, const char * const src)
-{
- size_t i = 0;
- for (i = 0; src[i]; i++)
- dest[i] = src[i];
- dest[i] = '\000';
- return &dest[i];
-}
-
-static inline UNUSED CHAR8 *
-translate_slashes(CHAR8 *out, const char *str)
-{
- int i;
- int j;
- if (str == NULL || out == NULL)
- return NULL;
-
- for (i = 0, j = 0; str[i] != '\0'; i++, j++) {
- if (str[i] == '\\') {
- out[j] = '/';
- if (str[i+1] == '\\')
- i++;
- } else
- out[j] = str[i];
- }
- out[j] = '\0';
- return out;
-}
-
-static inline UNUSED RETURNS_NONNULL NONNULL(1) CHAR8 *
-strchrnula(const CHAR8 *s, int c)
-{
- unsigned int i;
-
- for (i = 0; s[i] != '\000' && s[i] != c; i++)
- ;
-
- return (CHAR8 *)&s[i];
-}
-
-static inline UNUSED NONNULL(1) CHAR8 *
-strchra(const CHAR8 *s, int c)
-{
- const CHAR8 *s1;
-
- s1 = strchrnula(s, c);
- if (!s1 || s1[0] == '\000')
- return NULL;
-
- return (CHAR8 *)s1;
-}
-
-static inline UNUSED RETURNS_NONNULL NONNULL(1) char *
+static inline UNUSED RETURNS_NONNULL NONNULL(1)
+char *
strnchrnul(const char *s, size_t max, int c)
{
unsigned int i;