The experiment I am currently working uses a software base with a complicated source history and no well defined license. It would be a considerable amount of work to rationalize things and release under a fixed license.
It is also intended to run a a random unixish platform, and only some of the libc's we support have GNU getline, but right now the code expects it.
Does anyone know of a re-implementation of the GNU getline
semantics that is available under a less restrictive license?
Edit:: I ask because Google didn't help, and I'd like to avoid writing one if possible (it might be a fun exercise, but it can't be the best use of my time.)
To be more specific, the interface in question is:
ssize_t getline (char **lineptr, size_t *n, FILE *stream);
The code by Will Hartung suffers from a very serious problem.
realloc
will most probably free the old block and allocate a new one, but thep
pointer within the code will continue to point to the original. This one tries to fix that by using array indexing instead. It also tries to more closely replicate the standard POSIX logic.If you are compiling for BSD use fgetln instead
I'm puzzled.
I looked at the link, read the description, and this is a fine utility.
But, are you saying you simply can't rewrite this function to spec? The spec seems quite clear,
Here:
15 minutes, and I haven't written C in 10 years. It minorly breaks the getline contract in that it only checks if the lineptr is NULL, rather than NULL and n == 0. You can fix that if you like. (The other case didn't make a whole lot of sense to me, I guess you could return -1 in that case.)
Replace the '\n' with a variable to implement "getdelim".
Do people still write code any more?
Use these portable versions from NetBSD: getdelim() and getline()
These come from libnbcompat in pkgsrc, and have a BSD license at the top of each file. You need both because getline() calls getdelim(). Fetch the latest versions of both files. See the BSD license at the top of each file. Modify the files to fit into your program: you might need to declare getline() and getdelim() in one of your header files, and modify both files to include your header instead of the nbcompat headers.
This version of getdelim() is portable because it calls fgetc(). For contrast, a getdelim() from a libc (like BSD libc or musl libc) would probably use private features of that libc, so it would not work across platforms.
In the years since POSIX 2008 specified getline(), more Unixish platforms have added the getline() function. It is rare that getline() is missing, but it can still happen on old platforms. A few people try to bootstrap NetBSD pkgsrc on old platforms (like PowerPC Mac OS X), so they want libnbcompat to provide missing POSIX functions like getline().
Take a look at Paul Hsieh's page on User Input. You can email the author if you want to know the exact terms.