diff options
author | Nicholas Piggin <npiggin@gmail.com> | 2021-12-09 00:15:58 +1000 |
---|---|---|
committer | Cédric Le Goater <clg@kaod.org> | 2021-12-09 11:09:01 +0100 |
commit | 10d50007fb289ed5a625aa3c195b3a953f1e64c1 (patch) | |
tree | 219a676b25093770d7424872e628318b3045fd58 /ccan/str | |
parent | 03c0a9f086537310afe4ce2f5168e4fc41418f33 (diff) | |
download | skiboot-10d50007fb289ed5a625aa3c195b3a953f1e64c1.zip skiboot-10d50007fb289ed5a625aa3c195b3a953f1e64c1.tar.gz skiboot-10d50007fb289ed5a625aa3c195b3a953f1e64c1.tar.bz2 |
ccan: sync to upstream ccan.git commit ca7c5a9e04f3
sync to upstream ccan.git commit ca7c5a9e04f3 ("ccan: make tal_dump()
format more regular.").
The recipe used to sync upstream is:
$ cd ccan
$ ./tools/create-ccan-tree -b make tmp \
array_size check_type container_of heap \
short_types build_assert endian list str
$ # replace directories in skiboot/ccan/ with those in tmp/ccan/
$ cd ../skiboot
$ patch -p1 < ccan/skiboot.patch
This also adds a README.skiboot to help with future updates.
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Cédric Le Goater <clg@kaod.org>
Diffstat (limited to 'ccan/str')
23 files changed, 184 insertions, 22 deletions
diff --git a/ccan/str/_info b/ccan/str/_info index 548f059..b579525 100644 --- a/ccan/str/_info +++ b/ccan/str/_info @@ -1,6 +1,6 @@ +#include "config.h" #include <stdio.h> #include <string.h> -#include "config.h" /** * str - string helper routines @@ -26,11 +26,11 @@ * * int main(int argc, char *argv[]) * { - * if (argv[1] && streq(argv[1], "--verbose")) + * if (argc > 1 && streq(argv[1], "--verbose")) * printf("verbose set\n"); - * if (argv[1] && strstarts(argv[1], "--")) + * if (argc > 1 && strstarts(argv[1], "--")) * printf("Some option set\n"); - * if (argv[1] && strends(argv[1], "cow-powers")) + * if (argc > 1 && strends(argv[1], "cow-powers")) * printf("Magic option set\n"); * return 0; * } diff --git a/ccan/str/debug.c b/ccan/str/debug.c new file mode 100644 index 0000000..8c51944 --- /dev/null +++ b/ccan/str/debug.c @@ -0,0 +1,108 @@ +/* CC0 (Public domain) - see LICENSE file for details */ +#include "config.h" +#include <ccan/str/str_debug.h> +#include <assert.h> +#include <ctype.h> +#include <string.h> + +#ifdef CCAN_STR_DEBUG +/* Because we mug the real ones with macros, we need our own wrappers. */ +int str_isalnum(int i) +{ + assert(i >= -1 && i < 256); + return isalnum(i); +} + +int str_isalpha(int i) +{ + assert(i >= -1 && i < 256); + return isalpha(i); +} + +int str_isascii(int i) +{ + assert(i >= -1 && i < 256); + return isascii(i); +} + +#if HAVE_ISBLANK +int str_isblank(int i) +{ + assert(i >= -1 && i < 256); + return isblank(i); +} +#endif + +int str_iscntrl(int i) +{ + assert(i >= -1 && i < 256); + return iscntrl(i); +} + +int str_isdigit(int i) +{ + assert(i >= -1 && i < 256); + return isdigit(i); +} + +int str_isgraph(int i) +{ + assert(i >= -1 && i < 256); + return isgraph(i); +} + +int str_islower(int i) +{ + assert(i >= -1 && i < 256); + return islower(i); +} + +int str_isprint(int i) +{ + assert(i >= -1 && i < 256); + return isprint(i); +} + +int str_ispunct(int i) +{ + assert(i >= -1 && i < 256); + return ispunct(i); +} + +int str_isspace(int i) +{ + assert(i >= -1 && i < 256); + return isspace(i); +} + +int str_isupper(int i) +{ + assert(i >= -1 && i < 256); + return isupper(i); +} + +int str_isxdigit(int i) +{ + assert(i >= -1 && i < 256); + return isxdigit(i); +} + +#undef strstr +#undef strchr +#undef strrchr + +char *str_strstr(const char *haystack, const char *needle) +{ + return strstr(haystack, needle); +} + +char *str_strchr(const char *haystack, int c) +{ + return strchr(haystack, c); +} + +char *str_strrchr(const char *haystack, int c) +{ + return strrchr(haystack, c); +} +#endif diff --git a/ccan/str/str.h b/ccan/str/str.h index 89668c6..076840e 100644 --- a/ccan/str/str.h +++ b/ccan/str/str.h @@ -94,13 +94,27 @@ size_t strcount(const char *haystack, const char *needle); #if HAVE_TYPEOF /* Only a simple type can have 0 assigned, so test that. */ #define STR_MAX_CHARS_TCHECK_(type_or_expr) \ - ({ typeof(type_or_expr) x = 0; (void)x; 0; }) + (sizeof(({ typeof(type_or_expr) x = 0; x; }))*0) #else #define STR_MAX_CHARS_TCHECK_(type_or_expr) 0 #endif +#include <ccan/str/str_debug.h> + /* These checks force things out of line, hence they are under DEBUG. */ #ifdef CCAN_STR_DEBUG +#include <ccan/build_assert/build_assert.h> + +/* You can use a char if char is unsigned. */ +#if HAVE_BUILTIN_TYPES_COMPATIBLE_P && HAVE_TYPEOF +#define str_check_arg_(i) \ + ((i) + BUILD_ASSERT_OR_ZERO(!__builtin_types_compatible_p(typeof(i), \ + char) \ + || (char)255 > 0)) +#else +#define str_check_arg_(i) (i) +#endif + #if HAVE_TYPEOF /* With GNU magic, we can make const-respecting standard string functions. */ #undef strstr diff --git a/ccan/str/str_debug.h b/ccan/str/str_debug.h new file mode 100644 index 0000000..92c10c4 --- /dev/null +++ b/ccan/str/str_debug.h @@ -0,0 +1,30 @@ +/* CC0 (Public domain) - see LICENSE file for details */ +#ifndef CCAN_STR_DEBUG_H +#define CCAN_STR_DEBUG_H + +/* #define CCAN_STR_DEBUG 1 */ + +#ifdef CCAN_STR_DEBUG +/* Because we mug the real ones with macros, we need our own wrappers. */ +int str_isalnum(int i); +int str_isalpha(int i); +int str_isascii(int i); +#if HAVE_ISBLANK +int str_isblank(int i); +#endif +int str_iscntrl(int i); +int str_isdigit(int i); +int str_isgraph(int i); +int str_islower(int i); +int str_isprint(int i); +int str_ispunct(int i); +int str_isspace(int i); +int str_isupper(int i); +int str_isxdigit(int i); + +char *str_strstr(const char *haystack, const char *needle); +char *str_strchr(const char *s, int c); +char *str_strrchr(const char *s, int c); +#endif /* CCAN_STR_DEBUG */ + +#endif /* CCAN_STR_DEBUG_H */ diff --git a/ccan/str/test/compile_fail-STR_MAX_CHARS.c b/ccan/str/test/compile_fail-STR_MAX_CHARS.c index 74448c1..8e0fd2e 100644 --- a/ccan/str/test/compile_fail-STR_MAX_CHARS.c +++ b/ccan/str/test/compile_fail-STR_MAX_CHARS.c @@ -4,7 +4,7 @@ struct s { int val; }; -int main(int argc, char *argv[]) +int main(void) { struct s #ifdef FAIL diff --git a/ccan/str/test/compile_fail-isalnum.c b/ccan/str/test/compile_fail-isalnum.c index 930deff..5d98958 100644 --- a/ccan/str/test/compile_fail-isalnum.c +++ b/ccan/str/test/compile_fail-isalnum.c @@ -3,6 +3,7 @@ int main(int argc, char *argv[]) { + (void)argc; #ifdef FAIL #if !HAVE_BUILTIN_TYPES_COMPATIBLE_P || !HAVE_TYPEOF #error We need typeof to check isalnum. diff --git a/ccan/str/test/compile_fail-isalpha.c b/ccan/str/test/compile_fail-isalpha.c index 2005109..33d3655 100644 --- a/ccan/str/test/compile_fail-isalpha.c +++ b/ccan/str/test/compile_fail-isalpha.c @@ -3,6 +3,7 @@ int main(int argc, char *argv[]) { + (void)argc; #ifdef FAIL #if !HAVE_BUILTIN_TYPES_COMPATIBLE_P || !HAVE_TYPEOF #error We need typeof to check isalpha. diff --git a/ccan/str/test/compile_fail-isascii.c b/ccan/str/test/compile_fail-isascii.c index ee55e49..3946e0b 100644 --- a/ccan/str/test/compile_fail-isascii.c +++ b/ccan/str/test/compile_fail-isascii.c @@ -3,6 +3,7 @@ int main(int argc, char *argv[]) { + (void)argc; #ifdef FAIL #if !HAVE_BUILTIN_TYPES_COMPATIBLE_P || !HAVE_TYPEOF #error We need typeof to check isascii. diff --git a/ccan/str/test/compile_fail-isblank.c b/ccan/str/test/compile_fail-isblank.c index f4cb961..e14b0d7 100644 --- a/ccan/str/test/compile_fail-isblank.c +++ b/ccan/str/test/compile_fail-isblank.c @@ -3,6 +3,7 @@ int main(int argc, char *argv[]) { + (void)argc; #ifdef FAIL #if !HAVE_BUILTIN_TYPES_COMPATIBLE_P || !HAVE_TYPEOF || !HAVE_ISBLANK #error We need typeof to check isblank. diff --git a/ccan/str/test/compile_fail-iscntrl.c b/ccan/str/test/compile_fail-iscntrl.c index bc74146..f9abf1d 100644 --- a/ccan/str/test/compile_fail-iscntrl.c +++ b/ccan/str/test/compile_fail-iscntrl.c @@ -3,6 +3,7 @@ int main(int argc, char *argv[]) { + (void)argc; #ifdef FAIL #if !HAVE_BUILTIN_TYPES_COMPATIBLE_P || !HAVE_TYPEOF #error We need typeof to check iscntrl. diff --git a/ccan/str/test/compile_fail-isdigit.c b/ccan/str/test/compile_fail-isdigit.c index 71d1c71..a3ee439 100644 --- a/ccan/str/test/compile_fail-isdigit.c +++ b/ccan/str/test/compile_fail-isdigit.c @@ -3,6 +3,7 @@ int main(int argc, char *argv[]) { + (void)argc; #ifdef FAIL #if !HAVE_BUILTIN_TYPES_COMPATIBLE_P || !HAVE_TYPEOF #error We need typeof to check isdigit. diff --git a/ccan/str/test/compile_fail-islower.c b/ccan/str/test/compile_fail-islower.c index ca3f990..8f5c456 100644 --- a/ccan/str/test/compile_fail-islower.c +++ b/ccan/str/test/compile_fail-islower.c @@ -3,6 +3,7 @@ int main(int argc, char *argv[]) { + (void)argc; #ifdef FAIL #if !HAVE_BUILTIN_TYPES_COMPATIBLE_P || !HAVE_TYPEOF #error We need typeof to check islower. diff --git a/ccan/str/test/compile_fail-isprint.c b/ccan/str/test/compile_fail-isprint.c index 6432e41..85ed028 100644 --- a/ccan/str/test/compile_fail-isprint.c +++ b/ccan/str/test/compile_fail-isprint.c @@ -3,6 +3,7 @@ int main(int argc, char *argv[]) { + (void)argc; #ifdef FAIL #if !HAVE_BUILTIN_TYPES_COMPATIBLE_P || !HAVE_TYPEOF #error We need typeof to check isprint. diff --git a/ccan/str/test/compile_fail-ispunct.c b/ccan/str/test/compile_fail-ispunct.c index 5d941fc..09d4279 100644 --- a/ccan/str/test/compile_fail-ispunct.c +++ b/ccan/str/test/compile_fail-ispunct.c @@ -3,6 +3,7 @@ int main(int argc, char *argv[]) { + (void)argc; #ifdef FAIL #if !HAVE_BUILTIN_TYPES_COMPATIBLE_P || !HAVE_TYPEOF #error We need typeof to check ispunct. diff --git a/ccan/str/test/compile_fail-isspace.c b/ccan/str/test/compile_fail-isspace.c index bfee1f8..798cfcd 100644 --- a/ccan/str/test/compile_fail-isspace.c +++ b/ccan/str/test/compile_fail-isspace.c @@ -3,6 +3,7 @@ int main(int argc, char *argv[]) { + (void)argc; #ifdef FAIL #if !HAVE_BUILTIN_TYPES_COMPATIBLE_P || !HAVE_TYPEOF #error We need typeof to check isspace. diff --git a/ccan/str/test/compile_fail-isupper.c b/ccan/str/test/compile_fail-isupper.c index 4cf9fd3..56f5dee 100644 --- a/ccan/str/test/compile_fail-isupper.c +++ b/ccan/str/test/compile_fail-isupper.c @@ -3,6 +3,7 @@ int main(int argc, char *argv[]) { + (void)argc; #ifdef FAIL #if !HAVE_BUILTIN_TYPES_COMPATIBLE_P || !HAVE_TYPEOF #error We need typeof to check isupper. diff --git a/ccan/str/test/compile_fail-isxdigit.c b/ccan/str/test/compile_fail-isxdigit.c index 65e6006..ea4d526 100644 --- a/ccan/str/test/compile_fail-isxdigit.c +++ b/ccan/str/test/compile_fail-isxdigit.c @@ -3,6 +3,7 @@ int main(int argc, char *argv[]) { + (void)argc; #ifdef FAIL #if !HAVE_BUILTIN_TYPES_COMPATIBLE_P || !HAVE_TYPEOF #error We need typeof to check isxdigit. diff --git a/ccan/str/test/compile_fail-strchr.c b/ccan/str/test/compile_fail-strchr.c index 74a7314..bdaf034 100644 --- a/ccan/str/test/compile_fail-strchr.c +++ b/ccan/str/test/compile_fail-strchr.c @@ -1,7 +1,7 @@ #define CCAN_STR_DEBUG 1 #include <ccan/str/str.h> -int main(int argc, char *argv[]) +int main(void) { #ifdef FAIL #if !HAVE_TYPEOF diff --git a/ccan/str/test/compile_fail-strrchr.c b/ccan/str/test/compile_fail-strrchr.c index ba7d17e..57fba0e 100644 --- a/ccan/str/test/compile_fail-strrchr.c +++ b/ccan/str/test/compile_fail-strrchr.c @@ -1,7 +1,7 @@ #define CCAN_STR_DEBUG 1 #include <ccan/str/str.h> -int main(int argc, char *argv[]) +int main(void) { #ifdef FAIL #if !HAVE_TYPEOF diff --git a/ccan/str/test/compile_fail-strstr.c b/ccan/str/test/compile_fail-strstr.c index deefef6..7bd8ac2 100644 --- a/ccan/str/test/compile_fail-strstr.c +++ b/ccan/str/test/compile_fail-strstr.c @@ -1,7 +1,7 @@ #define CCAN_STR_DEBUG 1 #include <ccan/str/str.h> -int main(int argc, char *argv[]) +int main(void) { #ifdef FAIL #if !HAVE_TYPEOF diff --git a/ccan/str/test/compile_ok-STR_MAX_CHARS-static.c b/ccan/str/test/compile_ok-STR_MAX_CHARS-static.c new file mode 100644 index 0000000..bc6aff7 --- /dev/null +++ b/ccan/str/test/compile_ok-STR_MAX_CHARS-static.c @@ -0,0 +1,8 @@ +#include <ccan/str/str.h> + +int main(void) +{ + static char str[STR_MAX_CHARS(int)]; + + return str[0] ? 0 : 1; +} diff --git a/ccan/str/test/run-STR_MAX_CHARS.c b/ccan/str/test/run-STR_MAX_CHARS.c index 1343e04..fa45bad 100644 --- a/ccan/str/test/run-STR_MAX_CHARS.c +++ b/ccan/str/test/run-STR_MAX_CHARS.c @@ -4,9 +4,9 @@ #include <ccan/tap/tap.h> #include <stdint.h> -int main(int argc, char *argv[]) +int main(void) { - char *str = (char*)malloc(sizeof(char)*1000); + char str[1000]; struct { uint8_t u1byte; int8_t s1byte; @@ -19,11 +19,6 @@ int main(int argc, char *argv[]) void *ptr; } types; - (void)argc; - (void)argv; - - assert(str); - plan_tests(13); memset(&types, 0xFF, sizeof(types)); @@ -60,7 +55,5 @@ int main(int argc, char *argv[]) sprintf(str, "%p", types.ptr); ok1(strlen(str) < STR_MAX_CHARS(types.ptr)); - free(str); - return exit_status(); } diff --git a/ccan/str/test/run.c b/ccan/str/test/run.c index 216e141..9917fe7 100644 --- a/ccan/str/test/run.c +++ b/ccan/str/test/run.c @@ -21,13 +21,10 @@ static char *strdup_rev(const char *s) return ret; } -int main(int argc, char *argv[]) +int main(void) { unsigned int i, j, n; char *strings[NUM_SUBSTRINGS * NUM_SUBSTRINGS]; - - (void)argc; - (void)argv; n = 0; for (i = 0; i < NUM_SUBSTRINGS; i++) { |