3

I'm looking for a C function library, which would contain a collection of simple and plain utility functions "missing" from C or POSIX standards. I found this earlier question, but answers there list only full frameworks or libraries designed to replace/duplicate standard libraries instead of seamlessly fill the gaps.

To give you an example of functions I'm often missing, and would like to find a lib with tested implementations:

  • afgets, afread: read a line or entire file, like fgets and fread, except really reads all and returns a malloced buffer, in the spirit of GNU asprintf.
  • A selection of string trimming functions
  • systemf, popenf: Like system and popen, but take printf-like format string for command.
  • strjoin: join multiple strings given as vararg/array (which is hard to do with snprintf)
  • struct timeval arithmetic

These are just examples of functions I often miss for quick stuff. Then some features I'd desire (not mandatory):

  • Available on common Linux distros out-of-the-box, with man pages etc
  • Works also on Windows/Visual C
  • No extra dependencies, self-contained
  • As usable as existing C lib functions in C++
  • Preferably licensed under LGPL or BSD-like license, but GPL is ok too

Stuff which I am not looking for:

  • A string library with its own string type
  • A data structure library
  • A framework library which has special initialization, maybe even event loop etc.

So the question is, what is out there? Library name, homepage link, github link, duplicate question link... If you've made your own and have it at public repo, feel free to link to that too, if you dare expose it to many eyes.

7
  • 1
    Commenting on downvote/close: I thought Programmers was just the place for a question like this. The need for such a library is very real (first list of my bullets). Please leave feedback on how to improve the question, or comment why it's unsalvageable.
    – hyde
    Apr 3, 2013 at 7:16
  • 2
    I know one that is open source and in the early stages of active development. Currently a specification has been published: here. Contributors are welcome.
    – mouviciel
    Apr 3, 2013 at 7:18
  • @mouviciel :'D (assuming that was intentional and not a copy-paste error)
    – hyde
    Apr 3, 2013 at 7:28
  • possible duplicate of Is there any Boost equivalent library for C? Apr 3, 2013 at 8:08
  • @BartvanIngenSchenau While the APR answer there may be the closest thing available, I think that question wants some functionality and features provided by boost. At least the answers there answer it from this point of view, not "augments standard library without replacing it" point of view.
    – hyde
    Apr 3, 2013 at 9:06

1 Answer 1

6

The Apache Portable Runtime has a lot of what you want.

Do not expect anything to come from either C or POSIX. The C/C++ standards group think you should be using C++ and C is only for legacy apps. POSIX is run by a group of hardware manufacturers who will fight any change to the standard as they would incur the expense of implementing any change in their various OSes.

There are lots of functions not easily found on thier web site e.g. apr_file_read_full

7
  • At a quick glance APR (which is one answer in the linked question) looked like standard library replacement, but at a closer look it might be acceptable, +1. For example string funcs: apr.apache.org/docs/apr/1.4/group__apr__strings.html
    – hyde
    Apr 3, 2013 at 8:43
  • ...though I did not (yet) find a function to read a line of arbitrary length from a file, or entire file, which is a bit of a bummer.
    – hyde
    Apr 3, 2013 at 8:58
  • About apr_file_read_full, yeah I noticed that, with high hopes... But it does not read full file, it reads full buffer, blocking. I'm not actually sure what is the use case so common, that it warrants adding a special function to public API.
    – hyde
    Apr 3, 2013 at 9:52
  • 1
    I don't think the OP was looking for changes to the C or POSIX standards.
    – Blrfl
    Apr 3, 2013 at 10:06
  • 1
    @Man Vs Code -- totally agree C is far more relevent than C++, but the standards process has been hi-jacked by C++ proponents. Apr 19, 2013 at 23:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.