scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit a911bb38dfeb9667c1a69afa86edcedb1d47b218
parent c48e71febf29a4600bc77c3e49390961bb718123
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 13 May 2020 00:11:35 +0200

libc: Add local copy of strnlen to vfprintf

Vfprintf sued to use strnlen, which was removed of the repo because
it is not defined in C99. This solution  is a fast solution that
adds it as a static function in vfprintf.

Diffstat:
Msrc/libc/stdio/vfprintf.c | 10++++++++++
1 file changed, 10 insertions(+), 0 deletions(-)

diff --git a/src/libc/stdio/vfprintf.c b/src/libc/stdio/vfprintf.c @@ -186,6 +186,16 @@ strout(char *s, size_t len, int width, int fill, FILE * restrict fp) return cnt; } +static size_t +strnlen(const char *s, size_t maxlen) +{ + size_t n; + + for (n = 0; n < maxlen && *s++; ++n) + ; + return n; +} + int vfprintf(FILE * restrict fp, const char * restrict fmt, va_list va) {