Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1 | #ifndef STRING_H |
| 2 | #define STRING_H |
| 3 | |
| 4 | #include <stddef.h> |
Greg Watson | 1624782 | 2004-03-13 03:34:52 +0000 | [diff] [blame] | 5 | #include <stdlib.h> |
| 6 | |
David Hendricks | 6053a9c | 2018-01-28 18:01:10 -0800 | [diff] [blame] | 7 | #if !defined(__ROMCC__) |
| 8 | #include <console/vtxprintf.h> |
| 9 | #endif |
| 10 | |
Aaron Durbin | ac4b00e | 2013-04-26 11:58:35 -0500 | [diff] [blame] | 11 | /* Stringify a token */ |
| 12 | #ifndef STRINGIFY |
| 13 | #define _STRINGIFY(x) #x |
| 14 | #define STRINGIFY(x) _STRINGIFY(x) |
| 15 | #endif |
| 16 | |
Stefan Reinauer | a91e0fe | 2008-08-01 11:39:35 +0000 | [diff] [blame] | 17 | void *memcpy(void *dest, const void *src, size_t n); |
| 18 | void *memmove(void *dest, const void *src, size_t n); |
| 19 | void *memset(void *s, int c, size_t n); |
| 20 | int memcmp(const void *s1, const void *s2, size_t n); |
Gabe Black | 1025f3a | 2011-09-16 02:18:56 -0700 | [diff] [blame] | 21 | void *memchr(const void *s, int c, size_t n); |
Aaron Durbin | 5577a47 | 2016-11-08 09:42:13 -0600 | [diff] [blame] | 22 | #if !defined(__ROMCC__) |
Lee Leahy | 6d71a43 | 2017-03-07 15:24:16 -0800 | [diff] [blame] | 23 | int snprintf(char *buf, size_t size, const char *fmt, ...); |
David Hendricks | 6053a9c | 2018-01-28 18:01:10 -0800 | [diff] [blame] | 24 | int vsnprintf(char *buf, size_t size, const char *fmt, va_list args); |
Stefan Reinauer | 6bd571e | 2009-09-25 21:59:57 +0000 | [diff] [blame] | 25 | #endif |
Thomas Heijligen | 9204355 | 2019-01-29 12:48:01 +0100 | [diff] [blame] | 26 | char *strdup(const char *s); |
| 27 | char *strconcat(const char *s1, const char *s2); |
Julius Werner | a66c9b8 | 2019-05-20 14:53:47 -0700 | [diff] [blame^] | 28 | size_t strnlen(const char *src, size_t max); |
| 29 | size_t strlen(const char *src); |
| 30 | char *strchr(const char *s, int c); |
| 31 | char *strncpy(char *to, const char *from, int count); |
| 32 | char *strcpy(char *dst, const char *src); |
| 33 | int strcmp(const char *s1, const char *s2); |
| 34 | int strncmp(const char *s1, const char *s2, int maxlen); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 35 | |
Patrick Rudolph | 03c7b05 | 2018-03-29 10:05:34 +0200 | [diff] [blame] | 36 | /** |
| 37 | * Find a character in a string. |
| 38 | * |
| 39 | * @param s The string. |
| 40 | * @param c The character. |
| 41 | * @return A pointer to the last occurrence of the character in the |
| 42 | * string, or NULL if the character was not encountered within the string. |
| 43 | */ |
Julius Werner | a66c9b8 | 2019-05-20 14:53:47 -0700 | [diff] [blame^] | 44 | char *strrchr(const char *s, int c); |
Patrick Rudolph | 03c7b05 | 2018-03-29 10:05:34 +0200 | [diff] [blame] | 45 | |
Julius Werner | a66c9b8 | 2019-05-20 14:53:47 -0700 | [diff] [blame^] | 46 | /* |
| 47 | * Parses an unsigned integer and moves the input pointer forward to the first |
| 48 | * character that's not a valid digit. s and *s must not be NULL. Result |
| 49 | * undefined if it overruns the return type size. |
| 50 | */ |
| 51 | unsigned int skip_atoi(char **s); |
Stefan Reinauer | 36c8340 | 2009-03-01 10:16:01 +0000 | [diff] [blame] | 52 | |
Greg Watson | 1624782 | 2004-03-13 03:34:52 +0000 | [diff] [blame] | 53 | static inline int isspace(int c) |
| 54 | { |
| 55 | switch (c) { |
| 56 | case ' ': case '\f': case '\n': |
| 57 | case '\r': case '\t': case '\v': |
| 58 | return 1; |
| 59 | default: |
| 60 | return 0; |
| 61 | } |
| 62 | } |
| 63 | |
Nico Huber | f5b346c | 2017-11-01 13:21:40 +0100 | [diff] [blame] | 64 | static inline int isprint(int c) |
| 65 | { |
| 66 | return c >= ' ' && c <= '~'; |
| 67 | } |
| 68 | |
Greg Watson | 1624782 | 2004-03-13 03:34:52 +0000 | [diff] [blame] | 69 | static inline int isdigit(int c) |
| 70 | { |
| 71 | return (c >= '0' && c <= '9'); |
| 72 | } |
| 73 | |
| 74 | static inline int isxdigit(int c) |
| 75 | { |
| 76 | return ((c >= '0' && c <= '9') || |
| 77 | (c >= 'a' && c <= 'f') || |
| 78 | (c >= 'A' && c <= 'F')); |
| 79 | } |
| 80 | |
Greg Watson | f6d05f5 | 2004-03-17 17:02:28 +0000 | [diff] [blame] | 81 | static inline int isupper(int c) |
| 82 | { |
| 83 | return (c >= 'A' && c <= 'Z'); |
| 84 | } |
| 85 | |
Greg Watson | 1624782 | 2004-03-13 03:34:52 +0000 | [diff] [blame] | 86 | static inline int islower(int c) |
| 87 | { |
| 88 | return (c >= 'a' && c <= 'z'); |
| 89 | } |
| 90 | |
| 91 | static inline int toupper(int c) |
| 92 | { |
Elyes HAOUAS | 8ffd050 | 2016-09-01 19:01:41 +0200 | [diff] [blame] | 93 | if (islower(c)) |
| 94 | c -= 'a'-'A'; |
| 95 | return c; |
Greg Watson | 1624782 | 2004-03-13 03:34:52 +0000 | [diff] [blame] | 96 | } |
Greg Watson | f6d05f5 | 2004-03-17 17:02:28 +0000 | [diff] [blame] | 97 | |
| 98 | static inline int tolower(int c) |
| 99 | { |
Elyes HAOUAS | 8ffd050 | 2016-09-01 19:01:41 +0200 | [diff] [blame] | 100 | if (isupper(c)) |
| 101 | c -= 'A'-'a'; |
| 102 | return c; |
Greg Watson | f6d05f5 | 2004-03-17 17:02:28 +0000 | [diff] [blame] | 103 | } |
Julius Werner | 66c77c2 | 2019-05-13 17:45:27 -0700 | [diff] [blame] | 104 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 105 | #endif /* STRING_H */ |