Skip to content

Commit 41e0549

Browse files
authored
Merge pull request #53 from stefan11111/devel
strncmp(str, "foo", sizeof("foo") - 1) is the same as memcmp(str, "fo…
2 parents 75a57e5 + d164403 commit 41e0549

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

kirc.c

+24-24
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ static void handle_dcc(param p)
857857
int slot = -1;
858858
int file_fd;
859859

860-
if (!strncmp(message, "SEND", sizeof("SEND") - 1)) {
860+
if (!memcmp(message, "SEND", sizeof("SEND") - 1)) {
861861
while(++slot < CON_MAX && dcc_sessions.slots[slot].file_fd >= 0);
862862

863863
if (slot == CON_MAX) {
@@ -960,7 +960,7 @@ static void handle_dcc(param p)
960960
return;
961961
}
962962

963-
if (!strncmp(message, "ACCEPT", sizeof("ACCEPT") - 1)) {
963+
if (!memcmp(message, "ACCEPT", sizeof("ACCEPT") - 1)) {
964964
if(parse_dcc_accept_message(message, filename, &port, &file_size)) {
965965
return;
966966
}
@@ -981,29 +981,29 @@ static void handle_dcc(param p)
981981

982982
static void handle_ctcp(param p)
983983
{
984-
if (p->message[0] != '\001' && strncmp(p->message, "ACTION", sizeof("ACTION") - 1)) {
984+
if (p->message[0] != '\001' && memcmp(p->message, "ACTION", sizeof("ACTION") - 1)) {
985985
return;
986986
}
987987
const char *message = p->message + 1;
988-
if (!strncmp(message, "VERSION", sizeof("VERSION") - 1)) {
988+
if (!memcmp(message, "VERSION", sizeof("VERSION") - 1)) {
989989
raw("NOTICE %s :\001VERSION kirc " VERSION "\001\r\n", p->nickname);
990990
return;
991991
}
992-
if (!strncmp(message, "TIME", sizeof("TIME") - 1)) {
992+
if (!memcmp(message, "TIME", sizeof("TIME") - 1)) {
993993
char buf[26];
994994
if (!ctime_now(buf)) {
995995
raw("NOTICE %s :\001TIME %s\001\r\n", p->nickname, buf);
996996
}
997997
return;
998998
}
999-
if (!strncmp(message, "CLIENTINFO", sizeof("CLIENTINFO") - 1)) {
999+
if (!memcmp(message, "CLIENTINFO", sizeof("CLIENTINFO") - 1)) {
10001000
raw("NOTICE %s :\001CLIENTINFO " CTCP_CMDS "\001\r\n", p->nickname);
10011001
return;
1002-
}if (!strncmp(message, "PING", sizeof("PING") - 1)) {
1002+
}if (!memcmp(message, "PING", sizeof("PING") - 1)) {
10031003
raw("NOTICE %s :\001%s\r\n", p->nickname, message);
10041004
return;
10051005
}
1006-
if (!strncmp(message, "DCC", sizeof("DCC") - 1)) {
1006+
if (!memcmp(message, "DCC", sizeof("DCC") - 1)) {
10071007
handle_dcc(p);
10081008
return;
10091009
}
@@ -1049,7 +1049,7 @@ static void param_print_private(param p)
10491049
} else {
10501050
printf("%*s\x1b[33;1m%-.*s\x1b[0m ", s, "", p->nicklen, p->nickname);
10511051
}
1052-
if (!strncmp(p->message, "\x01" "ACTION", sizeof("ACTION"))) {
1052+
if (!memcmp(p->message, "\x01" "ACTION", sizeof("\x01" "ACTION") - 1)) {
10531053
p->message += sizeof("ACTION");
10541054
p->offset += sizeof("[ACTION] ");
10551055
printf("[ACTION] ");
@@ -1071,7 +1071,7 @@ static void param_print_channel(param p)
10711071

10721072
static void raw_parser(char *string)
10731073
{
1074-
if (!strncmp(string, "PING", sizeof("PING") - 1)) {
1074+
if (!memcmp(string, "PING", sizeof("PING") - 1)) {
10751075
string[1] = 'O';
10761076
raw("%s\r\n", string);
10771077
return;
@@ -1105,31 +1105,31 @@ static void raw_parser(char *string)
11051105
small_screen = 0;
11061106
p.nicklen = WRAP_LEN;
11071107
}
1108-
if (!strncmp(p.command, "001", sizeof("001") - 1) && *chan != '\0') {
1108+
if (!memcmp(p.command, "001", sizeof("001") - 1) && *chan != '\0') {
11091109
char *tok;
11101110
for (tok = strtok(chan, ",|"); tok != NULL; tok = strtok(NULL, ",|")) {
11111111
strcpy(chan, tok);
11121112
raw("JOIN #%s\r\n", tok);
11131113
}
11141114
return;
11151115
}
1116-
if (!strncmp(p.command, "QUIT", sizeof("QUIT") - 1)) {
1116+
if (!memcmp(p.command, "QUIT", sizeof("QUIT") - 1)) {
11171117
param_print_quit(&p);
11181118
printf("\x1b[0m\r\n");
11191119
return;
1120-
}if (!strncmp(p.command, "PART", sizeof("PART") - 1)) {
1120+
}if (!memcmp(p.command, "PART", sizeof("PART") - 1)) {
11211121
param_print_part(&p);
11221122
printf("\x1b[0m\r\n");
11231123
return;
1124-
}if (!strncmp(p.command, "JOIN", sizeof("JOIN") - 1)) {
1124+
}if (!memcmp(p.command, "JOIN", sizeof("JOIN") - 1)) {
11251125
param_print_join(&p);
11261126
printf("\x1b[0m\r\n");
11271127
return;
1128-
}if (!strncmp(p.command, "NICK", sizeof("NICK") - 1)) {
1128+
}if (!memcmp(p.command, "NICK", sizeof("NICK") - 1)) {
11291129
param_print_nick(&p);
11301130
printf("\x1b[0m\r\n");
11311131
return;
1132-
}if ((!strncmp(p.command, "PRIVMSG", sizeof("PRIVMSG") - 1)) || (!strncmp(p.command, "NOTICE", sizeof("NOTICE") - 1))) {
1132+
}if ((!memcmp(p.command, "PRIVMSG", sizeof("PRIVMSG") - 1)) || (!memcmp(p.command, "NOTICE", sizeof("NOTICE") - 1))) {
11331133
param_print_private(&p);
11341134
message_wrap(&p);
11351135
printf("\x1b[0m\r\n");
@@ -1231,7 +1231,7 @@ static void msg_command(state l)
12311231
offset ++;
12321232
}
12331233
raw("PRIVMSG %s :%s\r\n", l->buf + sizeof("msg") + offset, tok);
1234-
if (strncmp(l->buf + sizeof("msg") + offset, "NickServ", sizeof("NickServ") - 1)) {
1234+
if (memcmp(l->buf + sizeof("msg") + offset, "NickServ", sizeof("NickServ") - 1)) {
12351235
printf("\x1b[35mprivmsg %s :%s\x1b[0m\r\n", l->buf + sizeof("msg") + offset, tok);
12361236
}
12371237
}
@@ -1563,11 +1563,11 @@ static void handle_user_input(state l)
15631563
printf("\r\x1b[0K");
15641564
switch (l->buf[0]) {
15651565
case '/': /* send system command */
1566-
if (!strncmp(l->buf + 1, "JOIN", sizeof("JOIN") - 1) || !strncmp(l->buf + 1, "join", sizeof("join") - 1)) {
1566+
if (!memcmp(l->buf + 1, "JOIN", sizeof("JOIN") - 1) || !memcmp(l->buf + 1, "join", sizeof("join") - 1)) {
15671567
join_command(l);
15681568
return;
15691569
}
1570-
if (!strncmp(l->buf + 1, "PART", sizeof("PART") - 1) || !strncmp(l->buf + 1, "part", sizeof("part") - 1)) {
1570+
if (!memcmp(l->buf + 1, "PART", sizeof("PART") - 1) || !memcmp(l->buf + 1, "part", sizeof("part") - 1)) {
15711571
part_command(l);
15721572
return;
15731573
}
@@ -1578,23 +1578,23 @@ static void handle_user_input(state l)
15781578
"\x1b[35mprivmsg #%s :%s\x1b[0m\r\n", chan, l->buf + 2);
15791579
return;
15801580
}
1581-
if (!strncmp(l->buf + 1, "MSG", sizeof("MSG") - 1) || !strncmp(l->buf + 1, "msg", sizeof("msg") - 1)) {
1581+
if (!memcmp(l->buf + 1, "MSG", sizeof("MSG") - 1) || !memcmp(l->buf + 1, "msg", sizeof("msg") - 1)) {
15821582
msg_command(l);
15831583
return;
15841584
}
1585-
if (!strncmp(l->buf + 1, "NICK", sizeof("NICK") - 1) || !strncmp(l->buf + 1, "nick", sizeof("nick") - 1)) {
1585+
if (!memcmp(l->buf + 1, "NICK", sizeof("NICK") - 1) || !memcmp(l->buf + 1, "nick", sizeof("nick") - 1)) {
15861586
nick_command(l);
15871587
return;
15881588
}
1589-
if (!strncmp(l->buf + 1, "ACTION", sizeof("ACTION") - 1) || !strncmp(l->buf + 1, "action", sizeof("action") - 1)) {
1589+
if (!memcmp(l->buf + 1, "ACTION", sizeof("ACTION") - 1) || !memcmp(l->buf + 1, "action", sizeof("action") - 1)) {
15901590
action_command(l);
15911591
return;
15921592
}
1593-
if (!strncmp(l->buf + 1, "QUERY", sizeof("QUERY") - 1) || !strncmp(l->buf + 1, "query", sizeof("query") - 1)) {
1593+
if (!memcmp(l->buf + 1, "QUERY", sizeof("QUERY") - 1) || !memcmp(l->buf + 1, "query", sizeof("query") - 1)) {
15941594
query_command(l);
15951595
return;
15961596
}
1597-
if (!strncmp(l->buf + 1, "DCC", sizeof("DCC") - 1) || !strncmp(l->buf + 1, "dcc", sizeof("dcc") - 1)) {
1597+
if (!memcmp(l->buf + 1, "DCC", sizeof("DCC") - 1) || !memcmp(l->buf + 1, "dcc", sizeof("dcc") - 1)) {
15981598
dcc_command(l);
15991599
return;
16001600
}

0 commit comments

Comments
 (0)