Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
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 '13 at 7:16
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 '13 at 7:18
@mouviciel :'D (assuming that was intentional and not a copy-paste error) – hyde Apr 3 '13 at 7:28
possible duplicate of Is there any Boost equivalent library for C? – Bart van Ingen Schenau Apr 3 '13 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 '13 at 9:06
up vote 5 down vote accepted

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

share|improve this answer
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: – hyde Apr 3 '13 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 '13 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 '13 at 9:52
I don't think the OP was looking for changes to the C or POSIX standards. – Blrfl Apr 3 '13 at 10:06
@hyde -- just allocate a buffer big enough for the file, and, slurp it in with apr_file_read_full. Not quite the whole thing but doable with only three function calls. – James Anderson Apr 4 '13 at 1:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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