Hacker News new | ask | show | jobs
by Joker_vD 895 days ago
Most of the standard C library implementations, including FreeBSD's libc [0] and glibc [1] have sscanf implemented like that, by calling fscanf on a dummy FILE object (with its size populated by strlen() at every call, no caching).

Of course, there are implementations whose authors thought about that and decided to do the reasonable thing instead, e.g. musl [2] and Plauger's old stdlib [3].

[0] https://github.com/lattera/freebsd/blob/master/lib/libc/stdi...

[1] https://github.com/bminor/glibc/blob/dff8da6b3e89b986bb7f6b1... , https://github.com/bminor/glibc/blob/dff8da6b3e89b986bb7f6b1... , https://github.com/bminor/glibc/blob/dff8da6b3e89b986bb7f6b1... — two additional files and five times as much code compared to FreeBSD's implementation for pretty much the same functionality, wow.

[2] https://git.musl-libc.org/cgit/musl/tree/src/stdio/vsscanf.c

[3] https://github.com/wuzhouhui/c_standard_lib/blob/master/STDI...