|
|
compat.c - iomenu - interactive terminal-based selection menu |
|
|
 |
git clone git://bitreich.org/iomenu git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/iomenu (git://bitreich.org) |
|
|
 |
Log |
|
|
 |
Files |
|
|
 |
Refs |
|
|
 |
Tags |
|
|
 |
README |
|
|
 |
LICENSE |
|
|
|
--- |
|
|
|
compat.c (848B) |
|
|
|
--- |
|
|
|
1 #include "compat.h" |
|
|
|
2 #include <ctype.h> |
|
|
|
3 #include <stddef.h> |
|
|
|
4 #include <string.h> |
|
|
|
5 |
|
|
|
6 char * |
|
|
|
7 strcasestr(const char *str1, const char *str2) |
|
|
|
8 { |
|
|
|
9 const char *s1; |
|
|
|
10 const char *s2; |
|
|
|
11 |
|
|
|
12 for (;;) { |
|
|
|
13 s1 = str1; |
|
|
|
14 s2 = str2; |
|
|
|
15 while (*s1 != '\0' && tolower(*s1) == tolower(*s2)) |
|
|
|
16 s1++, s2++; |
|
|
|
17 if (*s2 == '\0') |
|
|
|
18 return (char *) str1; |
|
|
|
19 if (*s1 == '\0') |
|
|
|
20 return NULL; |
|
|
|
21 str1++; |
|
|
|
22 } |
|
|
|
23 |
|
|
|
24 return NULL; |
|
|
|
25 } |
|
|
|
26 |
|
|
|
27 size_t |
|
|
|
28 strlcpy(char *buf, char const *str, size_t sz) |
|
|
|
29 { |
|
|
|
30 size_t len, cpy; |
|
|
|
31 |
|
|
|
32 len = strlen(str); |
|
|
|
33 cpy = (len > sz) ? (sz) : (len); |
|
|
|
34 memcpy(buf, str, cpy + 1); |
|
|
|
35 buf[sz - 1] = '\0'; |
|
|
|
36 return len; |
|
|
|
37 } |
|
|
|
38 |
|
|
|
39 char * |
|
|
|
40 strsep(char **str_p, char const *sep) |
|
|
|
41 { |
|
|
|
42 char *s, *prev; |
|
|
|
43 |
|
|
|
44 if (*str_p == NULL) |
|
|
|
45 return NULL; |
|
|
|
46 |
|
|
|
47 for (s = prev = *str_p; strchr(sep, *s) == NULL; s++) |
|
|
|
48 continue; |
|
|
|
49 |
|
|
|
50 if (*s == '\0') { |
|
|
|
51 *str_p = NULL; |
|
|
|
52 } else { |
|
|
|
53 *s = '\0'; |
|
|
|
54 *str_p = s + 1; |
|
|
|
55 } |
|
|
|
56 return prev; |
|
|
|
57 } |
|