3 ms·
My thoughts on that is that the problem is at a level below sscanf; in other words, what else is affected? A mechanism for turning a string in memory into a st
by kazinator 6y ago
My thoughts on that is that the problem is at a level below sscanf; in other words, what else is affected?
A mechanism for turning a string in memory into a string should not be taking its length.
GBLIC has an extension called fmemopen. The API is:
FILE *fmemopen(void *buf, size_t size, const char *mode);
This interface smells like it might have the flaw that if someone wants "buf" to come from a null-terminated string, they must measure that string in order to supply the size parameter.
I.e. the underlying mechanism is binary, and does not stop at null characters.
There needs to be a separate mechanism with a different underlying stream implementation:
FILE *fstropen(const char *str); // mode implied: "r"
This doesn't require a size.
That fmemopen extension points to a solution to the original problem, though non-portable: open the entire buffer of numbers as a stream in one fmemopen call, and then use fscanf to march through it.
- froh 6y agofmemopen is meanwhile portable and part of posix. https://pubs.opengroup.org/onlinepubs/9699919799/functions/fmemopen.html https://pubs.opengroup.org/onlinepubs/9699919799/functions/f...