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()
This commit is contained in:
commit
eaebc89f88
@ -169,6 +169,8 @@ static int command_loop(const char *child)
|
||||
|
||||
while (1) {
|
||||
size_t i;
|
||||
const char *arg;
|
||||
|
||||
if (!fgets(buffer, MAXCOMMAND - 1, stdin)) {
|
||||
if (ferror(stdin))
|
||||
die("Command input error");
|
||||
@ -182,10 +184,10 @@ static int command_loop(const char *child)
|
||||
if (!strcmp(buffer, "capabilities")) {
|
||||
printf("*connect\n\n");
|
||||
fflush(stdout);
|
||||
} else if (!strncmp(buffer, "connect ", 8)) {
|
||||
} else if (skip_prefix(buffer, "connect ", &arg)) {
|
||||
printf("\n");
|
||||
fflush(stdout);
|
||||
return run_child(child, buffer + 8);
|
||||
return run_child(child, arg);
|
||||
} else {
|
||||
fprintf(stderr, "Bad command");
|
||||
return 1;
|
||||
|
@ -40,7 +40,7 @@ static void command_loop(int input_fd, int output_fd)
|
||||
if (!strcmp(buffer, "capabilities")) {
|
||||
printf("*connect\n\n");
|
||||
fflush(stdout);
|
||||
} else if (!strncmp(buffer, "connect ", 8)) {
|
||||
} else if (starts_with(buffer, "connect ")) {
|
||||
printf("\n");
|
||||
fflush(stdout);
|
||||
if (bidirectional_transfer_loop(input_fd,
|
||||
|
@ -620,7 +620,7 @@ static int config_to_packet_line(const char *key, const char *value, void *data)
|
||||
{
|
||||
struct packet_reader *writer = data;
|
||||
|
||||
if (!strncmp(key, "bundle.", 7))
|
||||
if (starts_with(key, "bundle."))
|
||||
packet_write_fmt(writer->fd, "%s=%s", key, value);
|
||||
|
||||
return 0;
|
||||
|
@ -1209,7 +1209,7 @@ static const char *copy_name(const char *buf)
|
||||
{
|
||||
const char *cp;
|
||||
for (cp = buf; *cp && *cp != '\n'; cp++) {
|
||||
if (!strncmp(cp, " <", 2))
|
||||
if (starts_with(cp, " <"))
|
||||
return xmemdupz(buf, cp - buf);
|
||||
}
|
||||
return xstrdup("");
|
||||
|
@ -209,7 +209,7 @@ static char *url_normalize_1(const char *url, struct url_info *out_info, char al
|
||||
*/
|
||||
if (!url_len || strchr(":/?#", *url)) {
|
||||
/* Missing host invalid for all URL schemes except file */
|
||||
if (strncmp(norm.buf, "file:", 5)) {
|
||||
if (!starts_with(norm.buf, "file:")) {
|
||||
if (out_info) {
|
||||
out_info->url = NULL;
|
||||
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
|
||||
if (url == slash_ptr) {
|
||||
/* Skip ":" port with no number, it's same as default */
|
||||
} else if (slash_ptr - url == 2 &&
|
||||
!strncmp(norm.buf, "http:", 5) &&
|
||||
starts_with(norm.buf, "http:") &&
|
||||
!strncmp(url, "80", 2)) {
|
||||
/* Skip http :80 as it's the default */
|
||||
} else if (slash_ptr - url == 3 &&
|
||||
!strncmp(norm.buf, "https:", 6) &&
|
||||
starts_with(norm.buf, "https:") &&
|
||||
!strncmp(url, "443", 3)) {
|
||||
/* Skip https :443 as it's the default */
|
||||
} else {
|
||||
|
7
ws.c
7
ws.c
@ -29,6 +29,7 @@ unsigned parse_whitespace_rule(const char *string)
|
||||
int i;
|
||||
size_t len;
|
||||
const char *ep;
|
||||
const char *arg;
|
||||
int negated = 0;
|
||||
|
||||
string = string + strspn(string, ", \t\n\r");
|
||||
@ -52,15 +53,15 @@ unsigned parse_whitespace_rule(const char *string)
|
||||
rule |= whitespace_rule_names[i].rule_bits;
|
||||
break;
|
||||
}
|
||||
if (strncmp(string, "tabwidth=", 9) == 0) {
|
||||
unsigned tabwidth = atoi(string + 9);
|
||||
if (skip_prefix(string, "tabwidth=", &arg)) {
|
||||
unsigned tabwidth = atoi(arg);
|
||||
if (0 < tabwidth && tabwidth < 0100) {
|
||||
rule &= ~WS_TAB_WIDTH_MASK;
|
||||
rule |= tabwidth;
|
||||
}
|
||||
else
|
||||
warning("tabwidth %.*s out of range",
|
||||
(int)(len - 9), string + 9);
|
||||
(int)(ep - arg), arg);
|
||||
}
|
||||
string = ep;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user