* Compare two strings with fixed length. * * @param s1 The first string. * @param s2 The second string. * @param maxlen Return at most maxlen characters as length of the string. * @return A non-zero value if s1 and s2 differ, or zero if s1 equals s2. */
| 109 | * @return A non-zero value if s1 and s2 differ, or zero if s1 equals s2. |
| 110 | */ |
| 111 | int strncmp(const char *s1, const char *s2, size_t maxlen) |
| 112 | { |
| 113 | int res = 0; |
| 114 | |
| 115 | for (size_t i = 0; i < maxlen; i++) { |
| 116 | res = s1[i] - s2[i]; |
| 117 | if (res || (s1[i] == '\0')) |
| 118 | break; |
| 119 | } |
| 120 | |
| 121 | return res; |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Copy a string with a maximum length. |
no outgoing calls
no test coverage detected