1 \input texinfo @c -*-texinfo-*-
2 @comment $Id: gnulib.texi,v 1.26 2006-07-19 21:48:14 dprice Exp $
3 @comment %**start of header
4 @setfilename gnulib.info
8 @comment %**end of header
10 @set UPDATED $Date: 2006-07-19 21:48:14 $
13 This manual is for GNU Gnulib (updated @value{UPDATED}),
14 which is a library of common routines intended to be shared at the
17 Copyright @copyright{} 2004, 2005, 2006 Free Software Foundation, Inc.
20 Permission is granted to copy, distribute and/or modify this document
21 under the terms of the GNU Free Documentation License, Version 1.1 or
22 any later version published by the Free Software Foundation; with no
23 Invariant Sections, with the Front-Cover Texts being ``A GNU Manual,''
24 and with the Back-Cover Texts as in (a) below. A copy of the
25 license is included in the section entitled ``GNU Free Documentation
28 (a) The FSF's Back-Cover Text is: ``You have freedom to copy and modify
29 this GNU Manual, like GNU software. Copies published by the Free
30 Software Foundation raise funds for GNU development.''
34 @dircategory Software development
36 * Gnulib: (gnulib). Source files to share among distributions.
41 @subtitle updated @value{UPDATED}
42 @author @email{bug-gnulib@@gnu.org}
44 @vskip 0pt plus 1filll
59 * Invoking gnulib-tool::
60 * Copying This Manual::
68 This manual contains some bare-bones documentation, but not much more.
69 It's mostly been a place to store notes until someone (you?)@ gets
70 around to writing a coherent manual.
75 @item Gnulib is hosted at Savannah:
76 @url{http://savannah.gnu.org/projects/gnulib}. Get the sources
77 through CVS from there.
78 @item The Gnulib home page:
79 @url{http://www.gnu.org/software/gnulib/}.
89 * Out of memory handling::
90 * Library version handling::
91 * Regular expressions::
93 * Libtool and Windows::
100 @cindex comments describing functions
101 @cindex describing functions, locating
102 Where to put comments describing functions: Because of risk of
103 divergence, we prefer to keep most function describing comments in
104 only one place: just above the actual function definition. Some
105 people prefer to put that documentation in the .h file. In any case,
106 it should appear in just one place unless you can ensure that the
107 multiple copies will always remain identical.
111 @section Header files
113 @cindex double inclusion of header files
114 @cindex header file include protection
115 It is a tradition to use CPP tricks to avoid parsing the same header
116 file more than once, which might cause warnings. The trick is to wrap
117 the content of the header file (say, @file{foo.h}) in a block, as in:
123 body of header file goes here
128 Whether to use @code{FOO_H} or @code{_FOO_H} is a matter of taste and
129 style. The C89 and C99 standards reserve all identifiers that begin with an
130 underscore and either an uppercase letter or another underscore, for
131 any use. Thus, in theory, an application might not safely assume that
132 @code{_FOO_H} has not already been defined by a library. On the other
133 hand, using @code{FOO_H} will likely lead the higher risk of
134 collisions with other symbols (e.g., @code{KEY_H}, @code{XK_H}, @code{BPF_H},
135 which are CPP macro constants, or @code{COFF_LONG_H}, which is a CPP
136 macro function). Your preference may depend on whether you consider
137 the header file under discussion as part of the application (which has
138 its own namespace for CPP symbols) or a supporting library (that
139 shouldn't interfere with the application's CPP symbol namespace).
141 @cindex C++ header files
142 @cindex Header files and C++
143 Adapting C header files for use in C++ applications can use another
152 body of header file goes here
159 The idea here is that @code{__cplusplus} is defined only by C++
160 implementations, which will wrap the header file in an @samp{extern "C"}
161 block. Again, whether to use this trick is a matter of taste and
162 style. While the above can be seen as harmless, it could be argued
163 that the header file is written in C, and any C++ application using it
164 should explicitly use the @samp{extern "C"} block itself. Your
165 preference might depend on whether you consider the API exported by
166 your header file as something available for C programs only, or for C
167 and C++ programs alike.
169 @subheading Include ordering
171 When writing a gnulib module, or even in general, a good way to order
172 the @samp{#include} directives is the following.
175 @item First comes the #include "..." specifying the module being implemented.
176 @item Then come all the #include <...> of system or system-replacement headers,
178 @item Then come all the #include "..." of gnulib and private headers, in
189 @include inet_ntoa.texi
192 @node Out of memory handling
193 @section Out of memory handling
195 @cindex Out of Memory handling
196 @cindex Memory allocation failure
197 The GSS API does not have a standard error code for the out of memory
198 error condition. Instead of adding a non-standard error code, this
199 library has chosen to adopt a different strategy. Out of memory
200 handling happens in rare situations, but performing the out of memory
201 error handling after almost all API function invocations pollute your
202 source code and might make it harder to spot more serious problems.
203 The strategy chosen improve code readability and robustness.
205 @cindex Aborting execution
206 For most applications, aborting the application with an error message
207 when the out of memory situation occur is the best that can be wished
208 for. This is how the library behaves by default.
210 @vindex xalloc_fail_func
211 However, we realize that some applications may not want to have the
212 GSS library abort execution in any situation. The GSS library support
213 a hook to let the application regain control and perform its own
214 cleanups when an out of memory situation has occurred. The application
215 can define a function (having a @code{void} prototype, i.e., no return
216 value and no parameters) and set the library variable
217 @code{xalloc_fail_func} to that function. The variable should be
221 extern void (*xalloc_fail_func) (void);
224 The GSS library will invoke this function if an out of memory error
225 occurs. Note that after this the GSS library is in an undefined
226 state, so you must unload or restart the application to continue call
227 GSS library functions. The hook is only intended to allow the
228 application to log the situation in a special way. Of course, care
229 must be taken to not allocate more memory, as that will likely also
233 @node Library version handling
234 @section Library version handling
236 The module @samp{check-version} can be useful when your gnulib
237 application is a system library. You will typically wrap the call to
238 the @code{check_version} function through a library API, your library
239 header file may contain:
242 #define STRINGPREP_VERSION "0.5.18"
244 extern const char *stringprep_check_version (const char *req_version);
247 To avoid ELF symbol collisions with other libraries that use the
248 @samp{check-version} module, add to @file{config.h} through a
249 AC_DEFINE something like:
252 AC_DEFINE(check_version, stringprep_check_version,
253 [Rename check_version.])
256 The @code{stringprep_check_version} function will thus be implemented
257 by the @code{check_version} module.
259 There are two uses of the interface. The first is a way to provide
260 for applications to find out the version number of the library it
261 uses. The application may contain diagnostic code such as:
264 printf ("Stringprep version: header %s library %s",
266 stringprep_check_version (NULL));
269 Separating the library and header file version can be useful when
270 searching for version mismatch related problems.
272 The second uses is as a rudimentary test of proper library version, by
273 making sure the application get a library version that is the same, or
274 newer, than the header file used when building the application. This
275 doesn't catch all problems, libraries may change backwards incompatibly
276 in later versions, but enable applications to require a certain
277 minimum version before it may proceed.
279 Typical uses look like:
282 /* Check version of libgcrypt. */
283 if (!gcry_check_version (GCRYPT_VERSION))
284 die ("version mismatch\n");
288 @node Regular expressions
289 @section Regular expressions
291 Gnulib supports many different types of regular expressions; although
292 the underlying features are the same or identical, the syntax used
293 varies. The descriptions given here for the different types are
294 generated automatically.
296 @include regexprops-generic.texi
299 @node Windows sockets
300 @section Windows sockets
302 There are several issues when building applications that should work
303 under Windows. The most problematic part is for applications that use
306 Hopefully, we can add helpful notes to this section that will help you
307 port your application to Windows using gnulib.
309 @subsection Getaddrinfo and WINVER
311 This was written for the getaddrinfo module, but may be applicable to
314 The getaddrinfo function exists in ws2tcpip.h and -lws2_32 on Windows
315 XP. The function declaration is present if @code{WINVER >= 0x0501}.
316 Windows 2000 does not have getaddrinfo in its @file{WS2_32.dll}.
318 Thus, if you want to assume Windows XP or later, you can add
319 AC_DEFINE(WINVER, 0x0501) to avoid compiling to (partial) getaddrinfo
322 If you want to support Windows 2000, don't do anything, but be aware
323 that gnulib will use its own (partial) getaddrinfo implementation even
324 on Windows XP. Currently the code does not attempt to determine if
325 the getaddrinfo function is available during runtime.
327 Todo: Make getaddrinfo.c open the WS2_32.DLL and check for the
328 getaddrinfo symbol and use it if present, otherwise fall back to our
331 @node Libtool and Windows
332 @section Libtool and Windows
334 If you want it to be possible to cross-compile your program to MinGW
335 and you use Libtool, you need to put:
341 in your @file{configure.ac}. This sets the correct names for the
342 @code{OBJDUMP}, @code{DLLTOOL}, and @code{AS} tools for the build.
344 If you are building a library, you will also need to pass
345 @code{-no-undefined} to make sure Libtool produces a DLL for your
346 library. From a @file{Makefile.am}:
349 libgsasl_la_LDFLAGS += -no-undefined
352 @include gnulib-tool.texi
355 @node Copying This Manual
356 @appendix Copying This Manual
359 * GNU Free Documentation License:: License for copying this manual.