Skip to content

Commit

Permalink
Remove dependency on strings.h
Browse files Browse the repository at this point in the history
  • Loading branch information
nurupo committed Feb 20, 2017
1 parent bbb979d commit 213d5f2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion other/DHT_bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ static void manage_keys(DHT *dht)

int main(int argc, char *argv[])
{
if (argc == 2 && !strncasecmp(argv[1], "-h", 3)) {
if (argc == 2 && !tox_strncasecmp(argv[1], "-h", 3)) {
printf("Usage (connected) : %s [--ipv4|--ipv6] IP PORT KEY\n", argv[0]);
printf("Usage (unconnected): %s [--ipv4|--ipv6]\n", argv[0]);
exit(0);
Expand Down
17 changes: 15 additions & 2 deletions testing/misc_tools.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>

// You are responsible for freeing the return value!
uint8_t *hex_string_to_bin(const char *hex_string)
Expand All @@ -50,12 +49,26 @@ uint8_t *hex_string_to_bin(const char *hex_string)
return ret;
}

int tox_strncasecmp(const char* s1, const char* s2, size_t n)
{
while (n--) {
int c1 = tolower(*(s1++));
int c2 = tolower(*(s2++));

if (c1 == '\0' || c2 == '\0' || c1 != c2) {
return c1 - c2;
}
}

return 0;
}

int cmdline_parsefor_ipv46(int argc, char **argv, uint8_t *ipv6enabled)
{
int argvoffset = 0, argi;

for (argi = 1; argi < argc; argi++) {
if (!strncasecmp(argv[argi], "--ipv", 5)) {
if (!tox_strncasecmp(argv[argi], "--ipv", 5)) {
if (argv[argi][5] && !argv[argi][6]) {
char c = argv[argi][5];

Expand Down

0 comments on commit 213d5f2

Please sign in to comment.