summaryrefslogtreecommitdiff
path: root/testing/misc_tools.c
diff options
context:
space:
mode:
authorMaxim Biro <nurupo.contributions@gmail.com>2017-02-19 21:59:02 -0500
committerMaxim Biro <nurupo.contributions@gmail.com>2017-03-01 20:43:30 -0500
commitaaca8251c8586c07814fb1b91482d35bc6cadd78 (patch)
tree6684c5a6ae4099e7a5588dc614403e266f64fae9 /testing/misc_tools.c
parentd4ca2941c5d203253493bbda03d46008d5a97e80 (diff)
Remove dependency on strings.h
Diffstat (limited to 'testing/misc_tools.c')
-rw-r--r--testing/misc_tools.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/testing/misc_tools.c b/testing/misc_tools.c
index 5a110b51..f0e12526 100644
--- a/testing/misc_tools.c
+++ b/testing/misc_tools.c
@@ -25,11 +25,11 @@
25#include "config.h" 25#include "config.h"
26#endif 26#endif
27 27
28#include <ctype.h>
28#include <stdint.h> 29#include <stdint.h>
29#include <stdio.h> 30#include <stdio.h>
30#include <stdlib.h> 31#include <stdlib.h>
31#include <string.h> 32#include <string.h>
32#include <strings.h>
33 33
34// You are responsible for freeing the return value! 34// You are responsible for freeing the return value!
35uint8_t *hex_string_to_bin(const char *hex_string) 35uint8_t *hex_string_to_bin(const char *hex_string)
@@ -50,12 +50,29 @@ uint8_t *hex_string_to_bin(const char *hex_string)
50 return ret; 50 return ret;
51} 51}
52 52
53/* Reimplementation of strncasecmp() function from strings.h, as strings.h is
54 * POSIX and not portable. Specifically it doesn't exist on MSVC.
55 */
56int tox_strncasecmp(const char *s1, const char *s2, size_t n)
57{
58 while (n--) {
59 int c1 = tolower(*(s1++));
60 int c2 = tolower(*(s2++));
61
62 if (c1 == '\0' || c2 == '\0' || c1 != c2) {
63 return c1 - c2;
64 }
65 }
66
67 return 0;
68}
69
53int cmdline_parsefor_ipv46(int argc, char **argv, uint8_t *ipv6enabled) 70int cmdline_parsefor_ipv46(int argc, char **argv, uint8_t *ipv6enabled)
54{ 71{
55 int argvoffset = 0, argi; 72 int argvoffset = 0, argi;
56 73
57 for (argi = 1; argi < argc; argi++) { 74 for (argi = 1; argi < argc; argi++) {
58 if (!strncasecmp(argv[argi], "--ipv", 5)) { 75 if (!tox_strncasecmp(argv[argi], "--ipv", 5)) {
59 if (argv[argi][5] && !argv[argi][6]) { 76 if (argv[argi][5] && !argv[argi][6]) {
60 char c = argv[argi][5]; 77 char c = argv[argi][5];
61 78