2.1 Benefits of using Gnulib
Gnulib is useful to enhance various aspects of a package:
- Portability: With Gnulib, a package maintainer can program against the
POSIX and GNU libc APIs and nevertheless expect good portability to
platforms that don’t implement POSIX.
- Maintainability: When a package uses modules from Gnulib instead of code
written specifically for that package, the maintainer has less code to
maintain.
- Security: Gnulib provides functions that are immune against vulnerabilities
that plague the uses of the corresponding commonplace functions. For
example,
asprintf
, canonicalize_file_name
are not affected
by buffer sizing problems that affect sprintf
, realpath
.
openat
does not have the race conditions that open
has. Etc.
- Reliability: Gnulib provides functions that combine a call to a system
function with a check of the result. Examples are
xalloc
,
xprintf
, xstrtod
, xgetcwd
.
- Structure: Gnulib offers a way to structure code into modules, typically
one include file, one source code file, and one autoconf macro for each
functionality. Modularity helps maintainability.