]> git.ozlabs.org Git - ccan/blobdiff - ccan/str/str.h
base64: fix for unsigned chars (e.g. ARM).
[ccan] / ccan / str / str.h
index d4ced0d8914386b04034a439a3309c8cd9f46da7..d919b84d49be3cf3a7c7435ffd9822fc17632363 100644 (file)
@@ -1,4 +1,4 @@
-/* Placed into the public domain. */
+/* CC0 (Public domain) - see LICENSE file for details */
 #ifndef CCAN_STR_H
 #define CCAN_STR_H
 #include "config.h"
@@ -66,10 +66,9 @@ static inline bool strends(const char *str, const char *postfix)
  * @needle: a substring
  *
  * Example:
- *     int i;
- *      i = strcount("aaa aaa", "a");  // i = 6;
- *      i = strcount("aaa aaa", "ab"); // i = 0;
- *      i = strcount("aaa aaa", "aa"); // i = 2;
+ *      assert(strcount("aaa aaa", "a") == 6);
+ *      assert(strcount("aaa aaa", "ab") == 0);
+ *      assert(strcount("aaa aaa", "aa") == 2);
  */
 size_t strcount(const char *haystack, const char *needle);
 
@@ -84,9 +83,9 @@ size_t strcount(const char *haystack, const char *needle);
  * values will fit (eg. sprintf(... "%p"). )
  *
  * Example:
- *     char str[STR_MAX_CHARS(i)];
+ *     char str[STR_MAX_CHARS(int)];
  *
- *     sprintf(str, "%i", i);
+ *     sprintf(str, "%i", 7);
  */
 #define STR_MAX_CHARS(type_or_expr)                            \
        ((sizeof(type_or_expr) * CHAR_BIT + 8) / 9 * 3 + 2      \
@@ -95,7 +94,7 @@ 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