Skip to content

Commit eaebc89

Browse files
committed
Merge branch 'jk/strncmp-to-api-funcs'
Code clean-up. * jk/strncmp-to-api-funcs: convert trivial uses of strncmp() to skip_prefix() convert trivial uses of strncmp() to starts_with()
2 parents 3ed618f + d43b993 commit eaebc89

File tree

6 files changed

+14
-11
lines changed

6 files changed

+14
-11
lines changed

builtin/remote-ext.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ static int command_loop(const char *child)
169169

170170
while (1) {
171171
size_t i;
172+
const char *arg;
173+
172174
if (!fgets(buffer, MAXCOMMAND - 1, stdin)) {
173175
if (ferror(stdin))
174176
die("Command input error");
@@ -182,10 +184,10 @@ static int command_loop(const char *child)
182184
if (!strcmp(buffer, "capabilities")) {
183185
printf("*connect\n\n");
184186
fflush(stdout);
185-
} else if (!strncmp(buffer, "connect ", 8)) {
187+
} else if (skip_prefix(buffer, "connect ", &arg)) {
186188
printf("\n");
187189
fflush(stdout);
188-
return run_child(child, buffer + 8);
190+
return run_child(child, arg);
189191
} else {
190192
fprintf(stderr, "Bad command");
191193
return 1;

builtin/remote-fd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static void command_loop(int input_fd, int output_fd)
4040
if (!strcmp(buffer, "capabilities")) {
4141
printf("*connect\n\n");
4242
fflush(stdout);
43-
} else if (!strncmp(buffer, "connect ", 8)) {
43+
} else if (starts_with(buffer, "connect ")) {
4444
printf("\n");
4545
fflush(stdout);
4646
if (bidirectional_transfer_loop(input_fd,

bundle-uri.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ static int config_to_packet_line(const char *key, const char *value, void *data)
620620
{
621621
struct packet_reader *writer = data;
622622

623-
if (!strncmp(key, "bundle.", 7))
623+
if (starts_with(key, "bundle."))
624624
packet_write_fmt(writer->fd, "%s=%s", key, value);
625625

626626
return 0;

ref-filter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,7 @@ static const char *copy_name(const char *buf)
12091209
{
12101210
const char *cp;
12111211
for (cp = buf; *cp && *cp != '\n'; cp++) {
1212-
if (!strncmp(cp, " <", 2))
1212+
if (starts_with(cp, " <"))
12131213
return xmemdupz(buf, cp - buf);
12141214
}
12151215
return xstrdup("");

urlmatch.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ static char *url_normalize_1(const char *url, struct url_info *out_info, char al
209209
*/
210210
if (!url_len || strchr(":/?#", *url)) {
211211
/* Missing host invalid for all URL schemes except file */
212-
if (strncmp(norm.buf, "file:", 5)) {
212+
if (!starts_with(norm.buf, "file:")) {
213213
if (out_info) {
214214
out_info->url = NULL;
215215
out_info->err = _("missing host and scheme is not 'file:'");
@@ -268,11 +268,11 @@ static char *url_normalize_1(const char *url, struct url_info *out_info, char al
268268
if (url == slash_ptr) {
269269
/* Skip ":" port with no number, it's same as default */
270270
} else if (slash_ptr - url == 2 &&
271-
!strncmp(norm.buf, "http:", 5) &&
271+
starts_with(norm.buf, "http:") &&
272272
!strncmp(url, "80", 2)) {
273273
/* Skip http :80 as it's the default */
274274
} else if (slash_ptr - url == 3 &&
275-
!strncmp(norm.buf, "https:", 6) &&
275+
starts_with(norm.buf, "https:") &&
276276
!strncmp(url, "443", 3)) {
277277
/* Skip https :443 as it's the default */
278278
} else {

ws.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ unsigned parse_whitespace_rule(const char *string)
2929
int i;
3030
size_t len;
3131
const char *ep;
32+
const char *arg;
3233
int negated = 0;
3334

3435
string = string + strspn(string, ", \t\n\r");
@@ -52,15 +53,15 @@ unsigned parse_whitespace_rule(const char *string)
5253
rule |= whitespace_rule_names[i].rule_bits;
5354
break;
5455
}
55-
if (strncmp(string, "tabwidth=", 9) == 0) {
56-
unsigned tabwidth = atoi(string + 9);
56+
if (skip_prefix(string, "tabwidth=", &arg)) {
57+
unsigned tabwidth = atoi(arg);
5758
if (0 < tabwidth && tabwidth < 0100) {
5859
rule &= ~WS_TAB_WIDTH_MASK;
5960
rule |= tabwidth;
6061
}
6162
else
6263
warning("tabwidth %.*s out of range",
63-
(int)(len - 9), string + 9);
64+
(int)(ep - arg), arg);
6465
}
6566
string = ep;
6667
}

0 commit comments

Comments
 (0)