Is there a reason you allocate a bunch of memory and copy the strings rather than just doing multiple writes?
(*lol_write)(fd, STDERR_COLOR, STDERR_COLOR_SIZE);
(*lol_write)(fd, buf, count);
(*lol_write)(fd, COL_RESET, COL_RESET_SIZE);Is there a reason you allocate a bunch of memory and copy the strings rather than just doing multiple writes?
(*lol_write)(fd, STDERR_COLOR, STDERR_COLOR_SIZE);
(*lol_write)(fd, buf, count);
(*lol_write)(fd, COL_RESET, COL_RESET_SIZE);Note that using ordinary write multiple times has atomicity implications - if you have multiple processes writing to STDERR, you might find their output interleaved in unfortunate ways. Using a single write with a temporary buffer or writev avoids this (provided you're not writing more than PIPE_BUF bytes total)
I was more bothered by the use of alloca(). Even on a 32-bit system with a 32-bit size_t, you can blow your stack to hell with a single call to this modified write(). Having to do a full malloc() here would be pretty lame, but as others suggested, writev() should do nicely.
The other nice property of using writev() is that you don't have to bother with the dlopen/dlsym crap. Can just call writev() directly from the overridden write() in either case.
Of course, that doesn't catch people writing to stderr using writev() directly, but I think that's ok. (The current impl doesn't catch that case anyway.)
(edit: pull request submitted! https://github.com/sickill/stderred/pull/6)