GCC Code Coverage Report


Directory: ../replacer/
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 95.6% 43 / 0 / 45
Functions: 100.0% 6 / 0 / 6
Branches: 71.4% 20 / 0 / 28

stringfunc.h
Line Branch Exec Source
1 /*
2 * stringfunc.h
3 *
4 * Created on: Sep 3, 2018
5 * Author: alexey
6 */
7
8 #ifndef REPLACER_STRINGFUNC_H_
9 #define REPLACER_STRINGFUNC_H_
10
11 #include <string.h>
12 #include <ctype.h>
13 #include <sys/types.h>
14
15 #if _XOPEN_SOURCE >= 700 || _POSIX_C_SOURCE >= 200809L
16 #define USE_INTERNAL_STRNLEN
17 #endif
18
19 #if POSIX_C_SOURCE >= 200809L || _XOPEN_SOURCE >= 700
20 #define USE_INTERNAL_STRxDUP
21 #endif
22
23 #undef INLINE_STATIC
24 #ifdef STRINGFUNC_NOINLINE
25 #define INLINE_STATIC
26 #else
27 #define INLINE_STATIC inline static
28 #endif
29
30 #ifdef USE_INTERNAL_STRNLEN
31 #define i360_inner_strnlen strnlen
32 #else
33 INLINE_STATIC
34 8 size_t i360_inner_strnlen(register const char *s, size_t maxlen) {
35 8 const char *string_term = memchr(s, '\0', maxlen);
36
2/2
✓ Branch 2 → 3 taken 4 times.
✓ Branch 2 → 4 taken 4 times.
8 return string_term ? (size_t)(string_term - s) : maxlen;
37 }
38 #endif
39
40 #ifdef USE_INTERNAL_STRxDUP
41 #define i360_inner_strdup strdup
42 #define i360_inner_strndup strndup
43 #else
44 INLINE_STATIC
45 2 char *i360_inner_strdup(char *src) {
46
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 2 times.
2 if (!src) return NULL;
47 2 int len = strlen(src);
48 2 char *result = malloc(len + 1);
49
1/2
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 2 times.
2 if (!result) return NULL;
50 2 memcpy(result, src, len + 1);
51 2 return result;
52 }
53
54 INLINE_STATIC
55 15 char *i360_inner_strndup(const char *src, size_t n) {
56
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 15 times.
15 if (!src) return NULL;
57 15 size_t len = i360_inner_strnlen(src, n);
58 15 len = len > n ? n : len;
59 15 char *result = malloc(len + 1);
60
2/4
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 10 times.
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 5 times.
15 if (!result) return NULL;
61 15 memcpy(result, src, len);
62 15 result[len] = '\0';
63 15 return result;
64 }
65 #endif
66
67 INLINE_STATIC
68 5 int i360_strcasecmp(const char *s1, const char *s2) {
69 5 int result = 0;
70
71 do {
72 9 result = tolower(*s1) - tolower(*s2);
73
5/6
✓ Branch 3 → 4 taken 5 times.
✓ Branch 3 → 6 taken 4 times.
✓ Branch 4 → 5 taken 4 times.
✓ Branch 4 → 6 taken 1 time.
✓ Branch 5 → 3 taken 4 times.
✗ Branch 5 → 6 not taken.
9 } while (!result && *s1++ && *s2++);
74
75 5 return result;
76 }
77
78 INLINE_STATIC
79 3 int i360_atobool(char *buf) {
80
3/4
✓ Branch 3 → 4 taken 2 times.
✓ Branch 3 → 6 taken 1 time.
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 2 times.
5 if (!i360_strcasecmp(buf, "on") ||
81 2 !i360_strcasecmp(buf, "true"))
82 1 return 1;
83 2 return 0;
84 }
85
86 INLINE_STATIC
87 3 ssize_t i360_atossize(char *buf) {
88 3 char *kilo = strchr(buf, 'k');
89 3 char *mega = strchr(buf, 'm');
90 3 char *giga = strchr(buf, 'g');
91 3 size_t value = 1;
92
2/2
✓ Branch 2 → 3 taken 1 time.
✓ Branch 2 → 4 taken 2 times.
3 if (mega) {
93 1 *mega = '\0';
94 1 value = 1024 * 1024;
95 }
96
2/2
✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 6 taken 2 times.
3 if (kilo) {
97 1 *kilo = '\0';
98 1 value = 1024;
99 }
100
1/2
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 3 times.
3 if (giga) {
101 *giga = '\0';
102 value = 1024 * 1024 * 1024;
103 }
104 3 ssize_t size = atoll(buf);
105 3 return size * value;
106 }
107
108 char *i360_my_strtrim(char const *string);
109 int i360_itoa(int num, char *str, int base);
110 int i360_ltoa(long num, char *str, long base);
111 int i360_lltoa(long long num, char *str, long base);
112 char *i360_realpath_local(const char *path_param, char *cwd_param, char *resolved_path, int path_len);
113 int i360_check_if_file_marked_as_danger(char *path_to_file, char *script_executed, int path_to_cfgdirectory_fd);
114 void i360_strnadd(char *dest, const char *src, size_t srclen, size_t buflen, size_t *buf_left);
115 int i360_translate_to_real_path(const char *param, char *cur_php_fname_dir, char *file_name, int len);
116 int i360_is_valid_ptr(const void *ptr);
117 void i360_make_sha256_ex(const char *src, size_t src_len, char *dst);
118 size_t i360_hex(uint64_t val, char *buffer);
119 int i360_has_prefix(char *str, char *substr);
120
121 #endif /* REPLACER_STRINGFUNC_H_ */
122