[Zlib-devel] [PATCH] Avoid inclusion of unistd.h in all source files

John Bowler jbowler at frontiernet.net
Sun Apr 4 19:44:24 EDT 2010


From: Xin LI
>On Sat, Apr 3, 2010 at 10:12 PM, Mark Adler <madler at alumni.caltech.edu> wrote:
>> Actually on my to-do list is a define to avoid *all* #includes of libraries
>>in order to build a zlib for embedded applications.  It would remove all
>>the gz* functions and would require the user to provide memory allocation
>>routines.  Would that meet your needs?
>
>Yes, that would be helpful.

It would require that you patch at least some applications that use zlib.  Not all applications and possibly not all libraries explicitly set zstream::zalloc and zstream::zfree; libpng *does*, and the caller of libpng can override the default allocator that it uses, in turn.  The apps would fail (unexpectedly - no warnings until the inflate call) if you didn't patch them.

Another possibility is to layer the library, so that there is a layer with no system library dependencies; a layer where everything that has a system functionality (malloc in this case) is done via a callback.

However doing this would mean introducing a set of 'base' APIs to supplement those APIs, like inflate, that do the defaulting.  To make this useful the shared library would need to be the 'base' only (so no runtime dependency, including, potentially <string.h> and so on) and '-lz' would become a non-shared archive that would, on most architectures, would require '-lzbase' as well.

This is a lot of work, and a lot of it is in app code that currently only has '-lz' on the command line.  (Though automake apps could probably be made to just work.)

Still, removing file IO stuff certainly looks like a win for many embedded systems.

John Bowler <jbowler at acm.org>






More information about the Zlib-devel mailing list