Replace a dozen lines of code with a call to strnlen() / wcsnlen().

This commit is contained in:
David Schultz 2009-02-28 06:06:57 +00:00
parent 9c5cb6d8ae
commit 353ce11c8b
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=189138
2 changed files with 2 additions and 33 deletions

View File

@ -822,22 +822,7 @@ reswitch: switch (ch) {
}
} else if ((cp = GETARG(char *)) == NULL)
cp = "(null)";
if (prec >= 0) {
/*
* can't use strlen; can only look for the
* NUL in the first `prec' characters, and
* strlen() will go further.
*/
char *p = memchr(cp, 0, (size_t)prec);
if (p != NULL) {
size = p - cp;
if (size > prec)
size = prec;
} else
size = prec;
} else
size = strlen(cp);
size = (prec >= 0) ? strnlen(cp, prec) : strlen(cp);
sign = '\0';
break;
case 'U':

View File

@ -890,23 +890,7 @@ reswitch: switch (ch) {
cp = convbuf;
}
}
if (prec >= 0) {
/*
* can't use wcslen; can only look for the
* NUL in the first `prec' characters, and
* wcslen() will go further.
*/
wchar_t *p = wmemchr(cp, 0, (size_t)prec);
if (p != NULL) {
size = p - cp;
if (size > prec)
size = prec;
} else
size = prec;
} else
size = wcslen(cp);
size = (prec >= 0) ? wcsnlen(cp, prec) : wcslen(cp);
sign = '\0';
break;
case 'U':