225
#include <stddef.h>
226
#include <stdlib.h>
227
#include <stdarg.h>
228
+#include <stdbool.h>
229
#include <string.h>
230
#ifdef HAVE_STRINGS_H
231
#include <strings.h> /* for strcasecmp() */
685
void set_die_is_recursing_routine(int (*routine)(void));
686
687
/*
687
- * If the string "str" begins with the string found in "prefix", return 1.
688
+ * If the string "str" begins with the string found in "prefix", return true.
689
* The "out" parameter is set to "str + strlen(prefix)" (i.e., to the point in
690
* the string right after the prefix).
691
*
691
- * Otherwise, return 0 and leave "out" untouched.
692
+ * Otherwise, return false and leave "out" untouched.
693
*
694
* Examples:
695
*
700
* [skip prefix if present, otherwise use whole string]
701
* skip_prefix(name, "refs/heads/", &name);
702
*/
702
-static inline int skip_prefix(const char *str, const char *prefix,
703
- const char **out)
703
+static inline bool skip_prefix(const char *str, const char *prefix,
704
+ const char **out)
705
{
706
do {
707
if (!*prefix) {
708
*out = str;
708
- return 1;
709
+ return true;
710
}
711
} while (*str++ == *prefix++);
711
- return 0;
712
+ return false;
713
}
714
715
/*
716
* Like skip_prefix, but promises never to read past "len" bytes of the input
717
* buffer, and returns the remaining number of bytes in "out" via "outlen".
718
*/
718
-static inline int skip_prefix_mem(const char *buf, size_t len,
719
- const char *prefix,
720
- const char **out, size_t *outlen)
719
+static inline bool skip_prefix_mem(const char *buf, size_t len,
720
+ const char *prefix,
721
+ const char **out, size_t *outlen)
722
{
723
size_t prefix_len = strlen(prefix);
724
if (prefix_len <= len && !memcmp(buf, prefix, prefix_len)) {
725
*out = buf + prefix_len;
726
*outlen = len - prefix_len;
726
- return 1;
727
+ return true;
728
}
728
- return 0;
729
+ return false;
730
}
731
732
/*
732
- * If buf ends with suffix, return 1 and subtract the length of the suffix
733
- * from *len. Otherwise, return 0 and leave *len untouched.
733
+ * If buf ends with suffix, return true and subtract the length of the suffix
734
+ * from *len. Otherwise, return false and leave *len untouched.
735
*/
735
-static inline int strip_suffix_mem(const char *buf, size_t *len,
736
- const char *suffix)
736
+static inline bool strip_suffix_mem(const char *buf, size_t *len,
737
+ const char *suffix)
738
{
739
size_t suflen = strlen(suffix);
740
if (*len < suflen || memcmp(buf + (*len - suflen), suffix, suflen))
740
- return 0;
741
+ return false;
742
*len -= suflen;
742
- return 1;
743
+ return true;
744
}
745
746
/*
746
- * If str ends with suffix, return 1 and set *len to the size of the string
747
- * without the suffix. Otherwise, return 0 and set *len to the size of the
747
+ * If str ends with suffix, return true and set *len to the size of the string
748
+ * without the suffix. Otherwise, return false and set *len to the size of the
749
* string.
750
*
751
* Note that we do _not_ NUL-terminate str to the new length.
752
*/
752
-static inline int strip_suffix(const char *str, const char *suffix, size_t *len)
753
+static inline bool strip_suffix(const char *str, const char *suffix,
754
+ size_t *len)
755
{
756
*len = strlen(str);
757
return strip_suffix_mem(str, len, suffix);