1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
|
@node Introduction, Error Reporting, Top, Top
@chapter Introduction
@c %MENU% Purpose of the GNU C Library
The C language provides no built-in facilities for performing such
common operations as input/output, memory management, string
manipulation, and the like. Instead, these facilities are defined
in a standard @dfn{library}, which you compile and link with your
programs.
@cindex library
The GNU C library, described in this document, defines all of the
library functions that are specified by the @w{ISO C} standard, as well as
additional features specific to POSIX and other derivatives of the Unix
operating system, and extensions specific to the GNU system.
The purpose of this manual is to tell you how to use the facilities
of the GNU library. We have mentioned which features belong to which
standards to help you identify things that are potentially non-portable
to other systems. But the emphasis in this manual is not on strict
portability.
@menu
* Getting Started:: What this manual is for and how to use it.
* Standards and Portability:: Standards and sources upon which the GNU
C library is based.
* Using the Library:: Some practical uses for the library.
* Roadmap to the Manual:: Overview of the remaining chapters in
this manual.
@end menu
@node Getting Started, Standards and Portability, , Introduction
@section Getting Started
This manual is written with the assumption that you are at least
somewhat familiar with the C programming language and basic programming
concepts. Specifically, familiarity with ISO standard C
(@pxref{ISO C}), rather than ``traditional'' pre-ISO C dialects, is
assumed.
The GNU C library includes several @dfn{header files}, each of which
provides definitions and declarations for a group of related facilities;
this information is used by the C compiler when processing your program.
For example, the header file @file{stdio.h} declares facilities for
performing input and output, and the header file @file{string.h}
declares string processing utilities. The organization of this manual
generally follows the same division as the header files.
If you are reading this manual for the first time, you should read all
of the introductory material and skim the remaining chapters. There are
a @emph{lot} of functions in the GNU C library and it's not realistic to
expect that you will be able to remember exactly @emph{how} to use each
and every one of them. It's more important to become generally familiar
with the kinds of facilities that the library provides, so that when you
are writing your programs you can recognize @emph{when} to make use of
library functions, and @emph{where} in this manual you can find more
specific information about them.
@node Standards and Portability, Using the Library, Getting Started, Introduction
@section Standards and Portability
@cindex standards
This section discusses the various standards and other sources that the
GNU C library is based upon. These sources include the @w{ISO C} and
POSIX standards, and the System V and Berkeley Unix implementations.
The primary focus of this manual is to tell you how to make effective
use of the GNU library facilities. But if you are concerned about
making your programs compatible with these standards, or portable to
operating systems other than GNU, this can affect how you use the
library. This section gives you an overview of these standards, so that
you will know what they are when they are mentioned in other parts of
the manual.
@xref{Library Summary}, for an alphabetical list of the functions and
other symbols provided by the library. This list also states which
standards each function or symbol comes from.
@menu
* ISO C:: The international standard for the C
programming language.
* POSIX:: The ISO/IEC 9945 (aka IEEE 1003) standards
for operating systems.
* Berkeley Unix:: BSD and SunOS.
* SVID:: The System V Interface Description.
* XPG:: The X/Open Portability Guide.
@end menu
@node ISO C, POSIX, , Standards and Portability
@subsection ISO C
@cindex ISO C
The GNU C library is compatible with the C standard adopted by the
American National Standards Institute (ANSI):
@cite{American National Standard X3.159-1989---``ANSI C''} and later
by the International Standardization Organization (ISO):
@cite{ISO/IEC 9899:1990, ``Programming languages---C''}.
We here refer to the standard as @w{ISO C} since this is the more
general standard in respect of ratification.
The header files and library facilities that make up the GNU library are
a superset of those specified by the @w{ISO C} standard.@refill
@pindex gcc
If you are concerned about strict adherence to the @w{ISO C} standard, you
should use the @samp{-ansi} option when you compile your programs with
the GNU C compiler. This tells the compiler to define @emph{only} ISO
standard features from the library header files, unless you explicitly
ask for additional features. @xref{Feature Test Macros}, for
information on how to do this.
Being able to restrict the library to include only @w{ISO C} features is
important because @w{ISO C} puts limitations on what names can be defined
by the library implementation, and the GNU extensions don't fit these
limitations. @xref{Reserved Names}, for more information about these
restrictions.
This manual does not attempt to give you complete details on the
differences between @w{ISO C} and older dialects. It gives advice on how
to write programs to work portably under multiple C dialects, but does
not aim for completeness.
@node POSIX, Berkeley Unix, ISO C, Standards and Portability
@subsection POSIX (The Portable Operating System Interface)
@cindex POSIX
@cindex POSIX.1
@cindex IEEE Std 1003.1
@cindex ISO/IEC 9945-1
@cindex POSIX.2
@cindex IEEE Std 1003.2
@cindex ISO/IEC 9945-2
The GNU library is also compatible with the ISO @dfn{POSIX} family of
standards, known more formally as the @dfn{Portable Operating System
Interface for Computer Environments} (ISO/IEC 9945). They were also
published as ANSI/IEEE Std 1003. POSIX is derived mostly from various
versions of the Unix operating system.
The library facilities specified by the POSIX standards are a superset
of those required by @w{ISO C}; POSIX specifies additional features for
@w{ISO C} functions, as well as specifying new additional functions. In
general, the additional requirements and functionality defined by the
POSIX standards are aimed at providing lower-level support for a
particular kind of operating system environment, rather than general
programming language support which can run in many diverse operating
system environments.@refill
The GNU C library implements all of the functions specified in
@cite{ISO/IEC 9945-1:1996, the POSIX System Application Program
Interface}, commonly referred to as POSIX.1. The primary extensions to
the @w{ISO C} facilities specified by this standard include file system
interface primitives (@pxref{File System Interface}), device-specific
terminal control functions (@pxref{Low-Level Terminal Interface}), and
process control functions (@pxref{Processes}).
Some facilities from @cite{ISO/IEC 9945-2:1993, the POSIX Shell and
Utilities standard} (POSIX.2) are also implemented in the GNU library.
These include utilities for dealing with regular expressions and other
pattern matching facilities (@pxref{Pattern Matching}).
@comment Roland sez:
@comment The GNU C library as it stands conforms to 1003.2 draft 11, which
@comment specifies:
@comment
@comment Several new macros in <limits.h>.
@comment popen, pclose
@comment <regex.h> (which is not yet fully implemented--wait on this)
@comment fnmatch
@comment getopt
@comment <glob.h>
@comment <wordexp.h> (not yet implemented)
@comment confstr
@node Berkeley Unix, SVID, POSIX, Standards and Portability
@subsection Berkeley Unix
@cindex BSD Unix
@cindex 4.@var{n} BSD Unix
@cindex Berkeley Unix
@cindex SunOS
@cindex Unix, Berkeley
The GNU C library defines facilities from some versions of Unix which
are not formally standardized, specifically from the 4.2 BSD, 4.3 BSD,
and 4.4 BSD Unix systems (also known as @dfn{Berkeley Unix}) and from
@dfn{SunOS} (a popular 4.2 BSD derivative that includes some Unix System
V functionality). These systems support most of the @w{ISO C} and POSIX
facilities, and 4.4 BSD and newer releases of SunOS in fact support them all.
The BSD facilities include symbolic links (@pxref{Symbolic Links}), the
@code{select} function (@pxref{Waiting for I/O}), the BSD signal
functions (@pxref{BSD Signal Handling}), and sockets (@pxref{Sockets}).
@node SVID, XPG, Berkeley Unix, Standards and Portability
@subsection SVID (The System V Interface Description)
@cindex SVID
@cindex System V Unix
@cindex Unix, System V
The @dfn{System V Interface Description} (SVID) is a document describing
the AT&T Unix System V operating system. It is to some extent a
superset of the POSIX standard (@pxref{POSIX}).
The GNU C library defines most of the facilities required by the SVID
that are not also required by the @w{ISO C} or POSIX standards, for
compatibility with System V Unix and other Unix systems (such as
SunOS) which include these facilities. However, many of the more
obscure and less generally useful facilities required by the SVID are
not included. (In fact, Unix System V itself does not provide them all.)
The supported facilities from System V include the methods for
inter-process communication and shared memory, the @code{hsearch} and
@code{drand48} families of functions, @code{fmtmsg} and several of the
mathematical functions.
@node XPG, , SVID, Standards and Portability
@subsection XPG (The X/Open Portability Guide)
The X/Open Portability Guide, published by the X/Open Company, Ltd., is
a more general standard than POSIX. X/Open owns the Unix copyright and
the XPG specifies the requirements for systems which are intended to be
a Unix system.
The GNU C library complies to the X/Open Portability Guide, Issue 4.2,
with all extensions common to XSI (X/Open System Interface)
compliant systems and also all X/Open UNIX extensions.
The additions on top of POSIX are mainly derived from functionality
available in @w{System V} and BSD systems. Some of the really bad
mistakes in @w{System V} systems were corrected, though. Since
fulfilling the XPG standard with the Unix extensions is a
precondition for getting the Unix brand chances are good that the
functionality is available on commercial systems.
@node Using the Library, Roadmap to the Manual, Standards and Portability, Introduction
@section Using the Library
This section describes some of the practical issues involved in using
the GNU C library.
@menu
* Header Files:: How to include the header files in your
programs.
* Macro Definitions:: Some functions in the library may really
be implemented as macros.
* Reserved Names:: The C standard reserves some names for
the library, and some for users.
* Feature Test Macros:: How to control what names are defined.
@end menu
@node Header Files, Macro Definitions, , Using the Library
@subsection Header Files
@cindex header files
Libraries for use by C programs really consist of two parts: @dfn{header
files} that define types and macros and declare variables and
functions; and the actual library or @dfn{archive} that contains the
definitions of the variables and functions.
(Recall that in C, a @dfn{declaration} merely provides information that
a function or variable exists and gives its type. For a function
declaration, information about the types of its arguments might be
provided as well. The purpose of declarations is to allow the compiler
to correctly process references to the declared variables and functions.
A @dfn{definition}, on the other hand, actually allocates storage for a
variable or says what a function does.)
@cindex definition (compared to declaration)
@cindex declaration (compared to definition)
In order to use the facilities in the GNU C library, you should be sure
that your program source files include the appropriate header files.
This is so that the compiler has declarations of these facilities
available and can correctly process references to them. Once your
program
|