Skip to content

Commit a29e8b6

Browse files
committed
Merge branch 'rs/c99-stdbool-test-balloon'
Test balloon to use C99 "bool" type from <stdbool.h>. * rs/c99-stdbool-test-balloon: git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool
2 parents aa6122c + 8277dbe commit a29e8b6

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

git-compat-util.h

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ struct strbuf;
225225
#include <stddef.h>
226226
#include <stdlib.h>
227227
#include <stdarg.h>
228+
#include <stdbool.h>
228229
#include <string.h>
229230
#ifdef HAVE_STRINGS_H
230231
#include <strings.h> /* for strcasecmp() */
@@ -684,11 +685,11 @@ report_fn get_warn_routine(void);
684685
void set_die_is_recursing_routine(int (*routine)(void));
685686

686687
/*
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.
688689
* The "out" parameter is set to "str + strlen(prefix)" (i.e., to the point in
689690
* the string right after the prefix).
690691
*
691-
* Otherwise, return 0 and leave "out" untouched.
692+
* Otherwise, return false and leave "out" untouched.
692693
*
693694
* Examples:
694695
*
@@ -699,57 +700,58 @@ void set_die_is_recursing_routine(int (*routine)(void));
699700
* [skip prefix if present, otherwise use whole string]
700701
* skip_prefix(name, "refs/heads/", &name);
701702
*/
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)
704705
{
705706
do {
706707
if (!*prefix) {
707708
*out = str;
708-
return 1;
709+
return true;
709710
}
710711
} while (*str++ == *prefix++);
711-
return 0;
712+
return false;
712713
}
713714

714715
/*
715716
* Like skip_prefix, but promises never to read past "len" bytes of the input
716717
* buffer, and returns the remaining number of bytes in "out" via "outlen".
717718
*/
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)
721722
{
722723
size_t prefix_len = strlen(prefix);
723724
if (prefix_len <= len && !memcmp(buf, prefix, prefix_len)) {
724725
*out = buf + prefix_len;
725726
*outlen = len - prefix_len;
726-
return 1;
727+
return true;
727728
}
728-
return 0;
729+
return false;
729730
}
730731

731732
/*
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.
734735
*/
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)
737738
{
738739
size_t suflen = strlen(suffix);
739740
if (*len < suflen || memcmp(buf + (*len - suflen), suffix, suflen))
740-
return 0;
741+
return false;
741742
*len -= suflen;
742-
return 1;
743+
return true;
743744
}
744745

745746
/*
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
748749
* string.
749750
*
750751
* Note that we do _not_ NUL-terminate str to the new length.
751752
*/
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)
753755
{
754756
*len = strlen(str);
755757
return strip_suffix_mem(str, len, suffix);

0 commit comments

Comments
 (0)