int ptr_len_ncmp(const char* p1, int l1, const char* str, int n) { strncmp like functionality for comparing a ptr,len pair with a null terminated string for n chars
| 157 | // a null terminated string for n chars |
| 158 | // |
| 159 | inline int |
| 160 | ptr_len_ncmp(const char *p1, int l1, const char *str, int n) |
| 161 | { |
| 162 | while (l1 > 0 && n > 0) { |
| 163 | if (*str == '\0') { |
| 164 | return 1; |
| 165 | } |
| 166 | |
| 167 | char p1c = *p1; |
| 168 | char strc = *str; |
| 169 | |
| 170 | if (p1c != strc) { |
| 171 | if (p1c > strc) { |
| 172 | return 1; |
| 173 | } else if (p1c < strc) { |
| 174 | return -1; |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | p1++; |
| 179 | l1--; |
| 180 | n--; |
| 181 | str++; |
| 182 | } |
| 183 | |
| 184 | // If we've scanned our nchars, the match |
| 185 | // otherwise we're here because str is longer |
| 186 | // than p1 |
| 187 | |
| 188 | if (n == 0) { |
| 189 | return 0; |
| 190 | } else { |
| 191 | return -1; |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | // int ptr_len_ncasecmp(const char* p1, int l1, const char* str, int n) { |
| 196 | // |
no outgoing calls
no test coverage detected