2 @section Benefits of using Gnulib
4 Gnulib is useful to enhance various aspects of a package:
8 Portability: With Gnulib, a package maintainer can program against the
9 POSIX and GNU libc APIs and nevertheless expect good portability to
10 platforms that don't implement POSIX.
13 Maintainability: When a package uses modules from Gnulib instead of code
14 written specifically for that package, the maintainer has less code to
18 Security: Gnulib provides functions that are immune against vulnerabilities
19 that plague the uses of the corresponding commonplace functions. For
20 example, @code{asprintf}, @code{canonicalize_file_name} are not affected
21 by buffer sizing problems that affect @code{sprintf}, @code{realpath}.
22 @code{openat} does not have the race conditions that @code{open} has. Etc.
25 Reliability: Gnulib provides functions that combine a call to a system
26 function with a check of the result. Examples are @code{xalloc},
27 @code{xprintf}, @code{xstrtod}, @code{xgetcwd}.
30 Structure: Gnulib offers a way to structure code into modules, typically
31 one include file, one source code file, and one autoconf macro for each
32 functionality. Modularity helps maintainability.
35 @node Library vs Reusable Code
36 @section Library vs. Reusable Code
38 Classical libraries are installed as binary object code. Gnulib is
39 different: It is used as a source code library. Each package that uses
40 Gnulib thus ships with part of the Gnulib source code. The used portion
41 of Gnulib is tailored to the package: A build tool, called
42 @code{gnulib-tool}, is provided that copies a tailored subset of Gnulib
45 @node Portability and Application Code
46 @section Portability and Application Code
48 One of the goals of Gnulib is to make portable programming easy, on
49 the basis of the standards relevant for GNU (and Unix). The objective
50 behind that is to avoid a fragmentation of the user community into
51 disjoint user communities according to the operating system, and
52 instead allow synergies between users on different operating systems.
54 Another goal of Gnulib is to provide application code that can be shared
55 between several applications. Some people wonder: "What? glibc doesn't
56 have a function to copy a file?" Indeed, the scope of a system's libc is
57 to implement the relevant standards (ISO C, POSIX) and to provide
58 access functions to the kernel's system calls, and little more.
60 There is no clear borderline between both areas.
62 For example, Gnulib has a facility for generating the name of backup
63 files. While this task is entirely at the application level---no
64 standard specifies an API for it---the na@"{@dotless{i}}ve code has
65 some portability problems because on some platforms the length of file
66 name components is limited to 30 characters or so. Gnulib handles
69 Similarly, Gnulib has a facility for executing a command in a
70 subprocess. It is at the same time a portability enhancement (it
71 works on GNU, Unix, and Windows, compared to the classical
72 @code{fork}/@code{exec} idiom which is not portable to Windows), as well
73 as an application aid: it takes care of redirecting stdin and/or
74 stdout if desired, and emits an error message if the subprocess
77 @node Target Platforms
78 @section Target Platforms
80 Gnulib supports a number of platforms that we call the ``reasonable
81 portability targets''. This class consists of widespread operating systems,
82 for three years after their last availability, or---for proprietary
83 operating systems---as long as the vendor provides commercial support for
84 it. Already existing Gnulib code for older operating systems is usually
85 left in place for longer than these three years. So it comes that programs
86 that use Gnulib run pretty well also on these older operating systems.
88 Some operating systems are not very widespread, but are Free Software and
89 are actively developed. Such platforms are also supported by Gnulib, if
90 that OS's developers community keeps in touch with the Gnulib developers,
91 by providing bug reports, analyses, or patches. For such platforms, Gnulib
92 supports only the versions of the last year or the last few months,
93 depending on the maturity of said OS project, the number of its users, and
94 how often these users upgrade.
96 Niche operating systems are generally unsupported by Gnulib, unless some
97 of their developers or users contribute support to Gnulib.
99 The degree of support Gnulib guarantees for a platform depends on the
100 amount of testing it gets from volunteers. Platforms on which Gnulib
101 is frequently tested are the best supported. Then come platforms with
102 occasional testing, then platforms which are rarely tested. Usually,
103 we fix bugs when they are reported. Except that some rarely tested
104 platforms are also low priority; bug fixes for these platforms can
108 * Supported Platforms::
109 * Formerly Supported Platforms::
110 * Unsupported Platforms::
113 @node Supported Platforms
114 @subsection Supported Platforms
116 As of 2024, the list of supported platforms is the following:
120 glibc systems. With glibc 2.19 or newer, they are frequently tested.
121 @c [Not very relevant in the long term.]
122 @c The distributions Ubuntu, Debian, Fedora, CentOS are frequently tested.
123 @c Arch Linux is occasionally tested.
124 @c gNewSense, Trisquel, OpenSUSE are rarely tested.
128 glibc on Linux is frequently tested.
130 glibc on kFreeBSD is rarely tested.
132 @c There is Alpine Linux 3.19, and also musl-gcc on Ubuntu.
133 musl libc on Linux is occasionally tested.
136 macOS@. In versions 12.5, it's occasionally tested. In version
137 10.5, it's rarely tested.
139 FreeBSD 14.0 or newer is occasionally tested.
141 OpenBSD 7.0 or newer is occasionally tested.
143 NetBSD 10.0 or newer is occasionally tested.
145 AIX 7.1 and 7.3 are occasionally tested.
147 Solaris 10 and 11.4 are occasionally tested. Solaris 9 is rarely
148 tested and low priority.
150 Android is occasionally tested, through the Termux app on Android 11.
152 Cygwin 2.9 and 3.4 are occasionally tested. Cygwin 1.7.x no longer tested.
157 mingw is occasionally tested. Only the latest version of mingw is
158 tested; older versions are not supported.
160 MSVC 14 (Microsoft Visual Studio 2015 14.0) is occasionally tested.
161 Only ``release'' builds (compiler option @samp{-MD}) are supported,
162 not ``debug'' builds (compiler option @samp{-MDd}).
164 Note that some modules are currently unsupported on native Windows:
165 @code{mgetgroups}, @code{getugroups}, @code{idcache},
166 @code{userspec}, @code{openpty}, @code{login_tty}, @code{forkpty},
167 @code{pt_chown}, @code{grantpt}, @code{pty}, @code{savewd},
168 @code{mkancesdirs}, @code{mkdir-p}, @code{euidaccess}, @code{faccessat}.
169 The versions of Windows that are supported are Windows 10 and newer.
171 GNU Hurd 0.9 is rarely tested.
173 Minix 3.3.0 is no longer tested.
175 Haiku is no longer tested.
177 uClibc on Linux is no longer tested.
179 QNX is no longer tested.
182 @node Formerly Supported Platforms
183 @subsection Formerly Supported Platforms
185 The following platforms were supported in the past, but are no longer
189 glibc versions 2.1.x and older.
191 Mac OS X 10.4 and older.
197 @c IRIX 6.5 cc has no option for C99 support. You would need to use gcc instead.
209 Gnulib supports these operating systems only in an unvirtualized environment.
210 When you run an OS inside a virtual machine, you have to be aware that the
211 virtual machine can bring in bugs of its own. For example, floating-point
212 operations on Solaris can behave slightly differently in QEMU than on real
213 hardware. And Haiku's @command{bash} program misbehaves in VirtualBox 3,
214 whereas it behaves fine in VirtualBox 4.
216 Similarly, running native Windows binaries on GNU/Linux under WINE is
217 rarely tested and low priority: WINE has a set of behaviours and bugs that
218 is slightly different from native Windows.
220 @node Unsupported Platforms
221 @subsection Unsupported Platforms
223 @cindex integer arithmetic portability
224 @cindex portability, integer arithmetic
226 Some platforms with C compilers are not supported by Gnulib because
227 the platforms violate Gnulib's C portability assumptions. @xref{Other
228 portability assumptions}.
230 These assumptions are not required by the C or POSIX standards but
231 hold on almost all practical porting targets. If you need to port
232 Gnulib code to a platform where these assumptions are not true, we
233 would appreciate hearing of any fixes. We need fixes that do not
234 increase runtime overhead on standard hosts and that are relatively
237 These platforms are listed below to illustrate problems that Gnulib
238 and Gnulib-using code would have if it were intended to be portable to
239 all practical POSIX or C platforms.
243 Clang's @option{-fsanitize=undefined} option causes the program to
244 crash if it adds zero to a null pointer -- behavior that is undefined
245 in strict C, but which yields a null pointer on all practical porting
246 targets and which the Gnulib portability guidelines allow.
248 If you use Clang with @option{-fsanitize=undefined}, you can work
249 around the problem by also using @samp{-fno-sanitize=pointer-overflow},
250 although this may also disable some unrelated and useful pointer checks.
251 Perhaps someday the Clang developers will fix the infelicity.
254 The IBM i's pointers are 128 bits wide and it lacks the two types
255 @code{intptr_t} and @code{uintptr_t}, which are optional in the C and
256 POSIX standards. However, these two types are required for the XSI
257 extension to POSIX, and many Gnulib modules use them. To work around
258 this compatibility problem, Gnulib-using applications can be run on
259 the IBM i's PASE emulation environment. The IBM i's architecture
260 descends from the System/38 (1978).
263 The Unisys ClearPath Dorado's machine word is 36 bits. Its signed
264 integers use a ones'-complement representation. On these machines,
265 @code{CHAR_BIT == 9} and @code{INT_MIN == -INT_MAX}. By default
266 @code{UINT_MAX} is @math{2^{36} - 2}, which does not conform to the C
267 requirement that it be one less than a power of two. Although
268 compiler options can raise @code{UINT_MAX} to be @math{2^{36} - 1},
269 this can break system code that uses @math{-0} as a flag value.
270 This platform's architecture descends from the UNIVAC 1103 (1953).
273 The Unisys ClearPath Libra's machine word is 48 bits
274 with a 4-bit tag and a 4-bit data extension. Its
275 @code{unsigned int} uses the low-order 40 bits of the word, and
276 @code{int} uses the low-order 41 bits of the word with a
277 signed-magnitude representation. On these machines, @code{INT_MAX ==
278 UINT_MAX}, @code{INT_MIN == -INT_MAX}, and @code{sizeof (int) == 6}.
279 This platform's architecture descends from the Burroughs B5000 (1961).
282 The following platforms are not supported by Gnulib. The cost of
283 supporting them would exceed the benefit because they are rarely used, or
284 poorly documented, or have been supplanted by other platforms, or diverge
285 too much from POSIX, or some combination of these and other factors.
286 Please don't bother sending us patches for them.
292 DJGPP and EMX (the 32-bit operating systems running in DOS).
294 MSDOS (the 16-bit operating system).
296 Windows Mobile, Symbian OS, iOS.
302 Gnulib is divided into modules. Every module implements a single
303 facility. Modules can depend on other modules.
305 A module consists of a number of files and a module description. The
306 files are copied by @code{gnulib-tool} into the package that will use it,
307 usually verbatim, without changes. Source code files (.h, .c files)
308 reside in the @file{lib/} subdirectory. Autoconf macro files reside in
309 the @file{m4/} subdirectory. Build scripts reside in the
310 @file{build-aux/} subdirectory.
312 The module description contains the list of files; @code{gnulib-tool}
313 copies these files. It contains the module's
314 dependencies; @code{gnulib-tool} installs them as well. It also
315 contains the autoconf macro invocation (usually a single line or
316 nothing at all); @code{gnulib-tool} ensures this is invoked from the
317 package's @file{configure.ac} file. And also a @file{Makefile.am}
318 snippet; @code{gnulib-tool} collects these into a @file{Makefile.am}
319 for the tailored Gnulib part. The module description and include file
320 specification are for documentation purposes; they are combined into
323 The module system serves two purposes:
327 It ensures consistency of the used autoconf macros and @file{Makefile.am}
328 rules with the source code. For example, source code which uses the
329 @code{getopt_long} function---this is a common way to implement parsing
330 of command line options in a way that complies with the GNU standards---needs
331 the source code (@file{lib/getopt.c} and others), the autoconf macro
332 which detects whether the system's libc already has this function (in
333 @file{m4/getopt.m4}), and a few @file{Makefile.am} lines that create the
334 substitute @file{getopt.h} if not. These three pieces belong together.
335 They cannot be used without each other. The module description and
336 @code{gnulib-tool} ensure that they are copied altogether into the
340 It allows for scalability. It is well-known since the inception of the
341 MODULA-2 language around 1978 that dissection into modules with
342 dependencies allows for building large sets of code in a maintainable way.
343 The maintainability comes from the facts that:
347 Every module has a single purpose; you don't worry about other parts of
348 the program while creating, reading or modifying the code of a module.
351 The code you have to read in order to understand a module is limited to
352 the source of the module and the .h files of the modules listed as
353 dependencies. It is for this reason also that we recommend to put the
354 comments describing the functions exported by a module into its .h file.
357 In other words, the module is the elementary unit of code in Gnulib,
358 comparable to a class in object-oriented languages like Java or C#.
361 The module system is the basis of @code{gnulib-tool}. When
362 @code{gnulib-tool} copies a part of Gnulib into a package, it first
363 compiles a module list, starting with the requested modules and adding all
364 the dependencies, and then collects the files, @file{configure.ac}
365 snippets and @file{Makefile.am} snippets.
367 @node Various Kinds of Modules
368 @section Various Kinds of Modules
370 There are modules of various kinds in Gnulib. For a complete list of the
371 modules, see in @file{MODULES.html}.
373 @subsection Support for ISO C or POSIX functions.
375 When a function is not implemented by a system, the Gnulib module provides
376 an implementation under the same name. Examples are the @samp{snprintf}
377 and @samp{readlink} modules.
379 Similarly, when a function is not correctly implemented by a system,
380 Gnulib provides a replacement. For functions, we use the pattern
383 #if !HAVE_WORKING_FOO
389 and implement the @code{foo} function under the name @code{rpl_foo}. This
390 renaming is needed to avoid conflicts at compile time (in case the system
391 header files declare @code{foo}) and at link/run time (because the code
392 making use of @code{foo} could end up residing in a shared library, and
393 the executable program using this library could be defining @code{foo}
396 For header files, such as @code{stdint.h}, we provide
397 the substitute only if the system doesn't provide a correct one. The
398 template of this replacement is distributed in a slightly different name,
399 with @samp{.in} inserted before the @samp{.h} extension, so that on
400 systems which do provide a correct
401 header file the system's one is used.
403 The modules in this category are supported in C++ mode as well. This
404 means, while the autoconfiguration uses the C compiler, the resulting
405 header files and function substitutes can be used with a matching C++
408 @subsection Enhancements of ISO C or POSIX functions
410 These are sometimes POSIX functions with GNU extensions also found in
411 glibc---examples: @samp{getopt}, @samp{fnmatch}---and often new
412 APIs---for example, for all functions that allocate memory in one way
413 or the other, we have variants which also include the error checking
414 against the out-of-memory condition.
416 @subsection Portable general use facilities
418 Examples are a module for copying a file---the portability problems
419 relate to the copying of the file's modification time, access rights,
420 and extended attributes---or a module for extracting the tail
421 component of a file name---here the portability to native Windows
422 requires a different API than the classical POSIX @code{basename} function.
424 @subsection Reusable application code
426 Examples are an error reporting function, a module that allows output of
427 numbers with K/M/G suffixes, or cryptographic facilities.
429 @subsection Object oriented classes
431 Examples are data structures like @samp{list}, or abstract output stream
432 classes that work around the fact that an application cannot implement an
433 stdio @code{FILE} with its logic. Here, while staying in C, we use
434 implementation techniques like tables of function pointers, known from the
435 C++ language or from the Linux kernel.
437 @subsection Interfaces to external libraries
440 Examples are the @samp{iconv} module, which interfaces to the
441 @code{iconv} facility, regardless whether it is contained in libc or in
442 an external @code{libiconv}.
444 Or the @samp{readline} module, which interfaces to the GNU readline library.
446 @subsection Build / maintenance infrastructure
448 @mindex maintainer-makefile
449 An example is the @samp{maintainer-makefile} module, which provides extra
450 Makefile tags for maintaining a package.
452 @node Collaborative Development
453 @section Collaborative Development
455 Gnulib is maintained collaboratively. The mailing list is
456 @code{<bug-gnulib at gnu dot org>}. Be warned that some people on the
457 list may be very active at some times and unresponsive at other times.
459 Every module has one or more maintainers. While issues are discussed
460 collaboratively on the list, the maintainer of a module nevertheless has
461 a veto right regarding changes in his module.
463 All patches should be posted to the list, regardless whether they are
464 proposed patches or whether they are committed immediately by the
465 maintainer of the particular module. The purpose is not only to inform
466 the other users of the module, but mainly to allow peer review. It is not
467 uncommon that several people contribute comments or spot bugs after a
470 Conversely, if you are using Gnulib, and a patch is posted that affects
471 one of the modules that your package uses, you have an interest in
472 proofreading the patch.
477 Most modules are under the GPL@. Some, mostly modules which can
478 reasonably be used in libraries, are under LGPL@. Few modules are
479 under other licenses, such as LGPLv2+, unlimited, or public domain.
481 If the module description file says "GPL", it means "GPLv3+" (GPLv3
482 or newer, at the licensee's choice); if it says "LGPL", it means
483 "LGPLv3+" (LGPLv3 or newer, at the licensee's choice).
485 The source files, more precisely the files in @file{lib/} and
486 @file{build-aux/}, are under a license compatible with the module's
487 license. Most often, they are under the same license. But files can be
488 shared among several modules, and in these cases it can happen that a
489 source file is under a weaker license than noted in the module
490 description -- namely under the weakest license among the licenses of
491 the modules that contain the file.
493 Different licenses apply to files in special directories:
497 Module description files are under this copyright:
500 Copyright @copyright{} 20XX--20YY Free Software Foundation, Inc.@*
501 Copying and distribution of this file, with or without modification,
502 in any medium, are permitted without royalty provided the copyright
503 notice and this notice are preserved. This file is offered as-is,
504 without any warranty.
508 Autoconf macro files are under this copyright:
511 Copyright @copyright{} 20XX--20YY Free Software Foundation, Inc.@*
512 This file is free software; the Free Software Foundation
513 gives unlimited permission to copy and/or distribute it,
514 with or without modifications, as long as this notice is preserved.
515 This file is offered as-is, without any warranty.
518 or under this copyright:
521 Copyright @copyright{} 20XX--20YY Free Software Foundation, Inc.@*
522 This file is free software, distributed under the terms of the GNU
523 General Public License as published by the Free Software Foundation;
524 either version 2 of the License, or (at your option) any later version.
525 As a special exception to the GNU General Public License, this file
526 may be distributed as part of a program that contains a configuration
527 script generated by Autoconf, under the same distribution terms as
528 the rest of that program.
531 We denote either of these license statements as ``unlimited''.
534 If a license statement is not present in a test module, the test files are
535 under GPL@. Even if the corresponding source module is under LGPL, this is
536 not a problem, since compiled tests are not installed by ``make install''.
539 Documentation files are under this copyright:
542 Copyright @copyright{} 2004--20YY Free Software Foundation, Inc.@*
543 Permission is granted to copy, distribute and/or modify this document
544 under the terms of the GNU Free Documentation License, Version 1.3 or
545 any later version published by the Free Software Foundation; with no
546 Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A
547 copy of the license is at @url{https://www.gnu.org/licenses/fdl-1.3.en.html}.
551 If you want to use some Gnulib modules under LGPL, you can do so by
552 passing the option @samp{--lgpl} to @code{gnulib-tool}. This will
553 ensure that all imported modules can be used under the LGPL license.
554 Similarly, if you want some Gnulib modules
555 under LGPLv2+ (Lesser GPL version 2.1 or newer), you can do so by
556 passing the option @samp{--lgpl=2} to @code{gnulib-tool}.
558 Keep in mind that when you submit patches to files in Gnulib, you should
559 license them under a compatible license. This means that sometimes the
560 contribution will have to be LGPL, if the original file is available
561 under LGPL@. You can find out about it by looking at the license header
564 @node Steady Development
565 @section Steady Development
567 Gnulib modules are continually adapted, to match new practices, to be
568 consistent with newly added modules, or simply as a response to build
571 If you are willing to report an occasional regression, we recommend to
572 use the newest version from git always, except in periods of major
573 changes. Most Gnulib users do this.
578 Gnulib is open in the sense that we gladly accept contributions if they
579 are generally useful, well engineered, and if the contributors have signed
580 the obligatory papers with the FSF.
582 The module system is open in the sense that a package using Gnulib can
585 locally patch or override files in Gnulib,
587 locally add modules that are treated like Gnulib modules by
591 This is achieved by the @samp{--local-dir} option of @code{gnulib-tool}
592 (@pxref{Extending Gnulib}).