@@ -225,6 +225,7 @@ struct strbuf;
225
225
#include <stddef.h>
226
226
#include <stdlib.h>
227
227
#include <stdarg.h>
228
+ #include <stdbool.h>
228
229
#include <string.h>
229
230
#ifdef HAVE_STRINGS_H
230
231
#include <strings.h> /* for strcasecmp() */
@@ -684,11 +685,11 @@ report_fn get_warn_routine(void);
684
685
void set_die_is_recursing_routine (int (* routine )(void ));
685
686
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 .
688
689
* The "out" parameter is set to "str + strlen(prefix)" (i.e., to the point in
689
690
* the string right after the prefix).
690
691
*
691
- * Otherwise, return 0 and leave "out" untouched.
692
+ * Otherwise, return false and leave "out" untouched.
692
693
*
693
694
* Examples:
694
695
*
@@ -699,57 +700,58 @@ void set_die_is_recursing_routine(int (*routine)(void));
699
700
* [skip prefix if present, otherwise use whole string]
700
701
* skip_prefix(name, "refs/heads/", &name);
701
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 )
704
705
{
705
706
do {
706
707
if (!* prefix ) {
707
708
* out = str ;
708
- return 1 ;
709
+ return true ;
709
710
}
710
711
} while (* str ++ == * prefix ++ );
711
- return 0 ;
712
+ return false ;
712
713
}
713
714
714
715
/*
715
716
* Like skip_prefix, but promises never to read past "len" bytes of the input
716
717
* buffer, and returns the remaining number of bytes in "out" via "outlen".
717
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 )
721
722
{
722
723
size_t prefix_len = strlen (prefix );
723
724
if (prefix_len <= len && !memcmp (buf , prefix , prefix_len )) {
724
725
* out = buf + prefix_len ;
725
726
* outlen = len - prefix_len ;
726
- return 1 ;
727
+ return true ;
727
728
}
728
- return 0 ;
729
+ return false ;
729
730
}
730
731
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.
734
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 )
737
738
{
738
739
size_t suflen = strlen (suffix );
739
740
if (* len < suflen || memcmp (buf + (* len - suflen ), suffix , suflen ))
740
- return 0 ;
741
+ return false ;
741
742
* len -= suflen ;
742
- return 1 ;
743
+ return true ;
743
744
}
744
745
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
748
749
* string.
749
750
*
750
751
* Note that we do _not_ NUL-terminate str to the new length.
751
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 )
753
755
{
754
756
* len = strlen (str );
755
757
return strip_suffix_mem (str , len , suffix );
0 commit comments