*/
int strcasecmp(const char *s1, const char *s2)
{
- int i;
+ int i, res;
for (i = 0; 1; i++) {
- if (tolower(s1[i]) != tolower(s2[i]))
- return s1[i] - s2[i];
+ res = tolower(s1[i]) - tolower(s2[i]);
+ if (res || (s1[i] == '\0'))
+ break;
}
- return 0;
+ return res;
}
/**
*/
int strncasecmp(const char *s1, const char *s2, size_t maxlen)
{
- int i;
+ int i, res;
+ res = 0;
for (i = 0; i < maxlen; i++) {
- if (tolower(s1[i]) != tolower(s2[i]))
- return s1[i] - s2[i];
+ res = tolower(s1[i]) - tolower(s2[i]);
+ if (res || (s1[i] == '\0'))
+ break;
}
- return 0;
+ return res;
}
/**
*/
int strcmp(const char *s1, const char *s2)
{
- int i;
+ int i, res;
for (i = 0; 1; i++) {
- if (s1[i] != s2[i])
- return s1[i] - s2[i];
+ res = s1[i] - s2[i];
+ if (res || (s1[i] == '\0'))
+ break;
}
- return 0;
+ return res;
}
/**
*/
int strncmp(const char *s1, const char *s2, size_t maxlen)
{
- int i;
+ int i, res;
+ res = 0;
for (i = 0; i < maxlen; i++) {
- if (s1[i] != s2[i])
- return s1[i] - s2[i];
+ res = s1[i] - s2[i];
+ if (res || (s1[i] == '\0'))
+ break;
}
- return 0;
+ return res;
}
/**
*
* @param d The destination string.
* @param s The source string.
- * @param n Not more than n characters from s will be appended to d.
+ * @param n d will have at most n-1 characters (plus NUL) after invocation.
* @return A pointer to the destination string.
*/
size_t strlcat(char *d, const char *s, size_t n)
if (ch >= '0' && ch <= '9')
return ch - '0';
else
- return tolower(ch) - 'a';
+ return 10 + tolower(ch) - 'a';
}
/**