在好例子网,分享、交流、成长!
您当前所在位置:首页C/C++ 开发实例Linux内核编程 → The GNU C Library Reference Manual

The GNU C Library Reference Manual

Linux内核编程

下载此实例
  • 开发语言:C/C++
  • 实例大小:3.85M
  • 下载次数:3
  • 浏览次数:19
  • 发布时间:2022-05-01
  • 实例类别:Linux内核编程
  • 发 布 人:好~
  • 文件格式:.pdf
  • 所需积分:2
 相关标签: lib BC ib

实例介绍

【实例简介】The GNU C Library Reference Manual

The GNU C Library, described in this document, defines all of the library functions that are specified by the ISO C standard, as well as additional features specific to POSIX and other derivatives of the Unix operating system, and extensions specific to GNU systems. The purpose of this manual is to tell you how to use the facilities of the GNU C 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.

【实例截图】

【核心代码】

Short Contents
1 Introduction .......................................... 1
2 Error Reporting ...................................... 23
3 Virtual Memory Allocation And Paging .................. 42
4 Character Handling ................................... 85
5 String and Array Utilities .............................. 95
6 Character Set Handling ............................... 138
7 Locales and Internationalization ........................ 181
8 Message Translation ................................. 201
9 Searching and Sorting ................................ 226
10 Pattern Matching ................................... 237
11 Input/Output Overview .............................. 259
12 Input/Output on Streams ............................. 264
13 Low-Level Input/Output .............................. 340
14 File System Interface ................................. 401
15 Pipes and FIFOs .................................... 449
16 Sockets ............................................ 454
17 Low-Level Terminal Interface .......................... 502
18 Syslog ............................................. 530
19 Mathematics ....................................... 538
20 Arithmetic Functions ................................. 600
21 Date and Time ...................................... 645
22 Resource Usage And Limitation ........................ 683
23 Non-Local Exits ..................................... 704
24 Signal Handling ..................................... 713
25 The Basic Program/System Interface .................... 758
26 Processes .......................................... 802
27 Inter-Process Communication .......................... 814
28 Job Control ........................................ 816
29 System Databases and Name Service Switch .............. 834
30 Users and Groups ................................... 844
31 System Management ................................. 874
32 System Configuration Parameters ....................... 889
33 Cryptographic Functions .............................. 911
ii
34 Debugging support .................................. 917
35 Threads ........................................... 920
36 Internal probes ...................................... 933
37 Tunables ........................................... 938
A C Language Facilities in the Library .................... 947
B Summary of Library Facilities .......................... 963
C Installing the GNU C Library ......................... 1086
D Library Maintenance ................................ 1098
E Platform-specific facilities ............................ 1107
F Contributors to the GNU C Library .................... 1115
G Free Software Needs Free Documentation ............... 1121
H GNU Lesser General Public License .................... 1123
I GNU Free Documentation License ..................... 1132
Concept Index ......................................... 1140
Type Index ........................................... 1153
Function and Macro Index ............................... 1156
Variable and Constant Macro Index ....................... 1172
Program and File Index ................................. 1185
iii
Table of Contents
1 Introduction ..................................... 1
1.1 Getting Started................................................. 1
1.2 Standards and Portability ...................................... 1
1.2.1 ISO C ..................................................... 2
1.2.2 POSIX (The Portable Operating System Interface)......... 2
1.2.2.1 POSIX Safety Concepts............................... 2
1.2.2.2 Unsafe Features....................................... 4
1.2.2.3 Conditionally Safe Features ........................... 5
1.2.2.4 Other Safety Remarks ................................ 9
1.2.3 Berkeley Unix ............................................ 11
1.2.4 SVID (The System V Interface Description)............... 11
1.2.5 XPG (The X/Open Portability Guide).................... 12
1.3 Using the Library ............................................. 12
1.3.1 Header Files.............................................. 12
1.3.2 Macro Definitions of Functions............................ 13
1.3.3 Reserved Names.......................................... 14
1.3.4 Feature Test Macros...................................... 15
1.4 Roadmap to the Manual....................................... 20
2 Error Reporting................................ 23
2.1 Checking for Errors............................................ 23
2.2 Error Codes................................................... 24
2.3 Error Messages................................................ 36
3 Virtual Memory Allocation And Paging ..... 42
3.1 Process Memory Concepts..................................... 42
3.2 Allocating Storage For Program Data.......................... 43
3.2.1 Memory Allocation in C Programs........................ 44
3.2.1.1 Dynamic Memory Allocation......................... 44
3.2.2 The GNU Allocator ...................................... 45
3.2.3 Unconstrained Allocation ................................. 45
3.2.3.1 Basic Memory Allocation ............................ 45
3.2.3.2 Examples of malloc ................................. 46
3.2.3.3 Freeing Memory Allocated with malloc .............. 47
3.2.3.4 Changing the Size of a Block......................... 48
3.2.3.5 Allocating Cleared Space............................. 49
3.2.3.6 Allocating Aligned Memory Blocks................... 50
3.2.3.7 Malloc Tunable Parameters .......................... 51
3.2.3.8 Heap Consistency Checking.......................... 53
3.2.3.9 Statistics for Memory Allocation with malloc ........ 55
3.2.3.10 Summary of malloc-Related Functions.............. 56
3.2.4 Allocation Debugging..................................... 57
iv
3.2.4.1 How to install the tracing functionality............... 57
3.2.4.2 Example program excerpts........................... 58
3.2.4.3 Some more or less clever ideas ....................... 58
3.2.4.4 Interpreting the traces ............................... 59
3.2.5 Replacing malloc......................................... 61
3.2.6 Obstacks ................................................. 62
3.2.6.1 Creating Obstacks ................................... 62
3.2.6.2 Preparing for Using Obstacks ........................ 62
3.2.6.3 Allocation in an Obstack............................. 63
3.2.6.4 Freeing Objects in an Obstack ....................... 65
3.2.6.5 Obstack Functions and Macros....................... 65
3.2.6.6 Growing Objects..................................... 66
3.2.6.7 Extra Fast Growing Objects ......................... 68
3.2.6.8 Status of an Obstack................................. 69
3.2.6.9 Alignment of Data in Obstacks....................... 70
3.2.6.10 Obstack Chunks.................................... 70
3.2.6.11 Summary of Obstack Functions ..................... 71
3.2.7 Automatic Storage with Variable Size..................... 73
3.2.7.1 alloca Example..................................... 73
3.2.7.2 Advantages of alloca................................ 74
3.2.7.3 Disadvantages of alloca............................. 74
3.2.7.4 GNU C Variable-Size Arrays......................... 74
3.3 Resizing the Data Segment .................................... 75
3.4 Memory Protection............................................ 76
3.4.1 Memory Protection Keys ................................. 77
3.5 Locking Pages................................................. 80
3.5.1 Why Lock Pages.......................................... 81
3.5.2 Locked Memory Details................................... 81
3.5.3 Functions To Lock And Unlock Pages..................... 82
4 Character Handling............................ 85
4.1 Classification of Characters.................................... 85
4.2 Case Conversion............................................... 87
4.3 Character class determination for wide characters.............. 88
4.4 Notes on using the wide character classes ...................... 92
4.5 Mapping of wide characters. ................................... 93
5 String and Array Utilities..................... 95
5.1 Representation of Strings...................................... 95
5.2 String and Array Conventions ................................. 96
5.3 String Length ................................................. 97
5.4 Copying Strings and Arrays ................................... 99
5.5 Concatenating Strings........................................ 104
5.6 Truncating Strings while Copying............................. 107
5.7 String/Array Comparison .................................... 111
5.8 Collation Functions........................................... 115
5.9 Search Functions ............................................. 119
v
5.9.1 Compatibility String Search Functions ................... 124
5.10 Finding Tokens in a String .................................. 124
5.11 Erasing Sensitive Data ...................................... 129
5.12 Shuffling Bytes.............................................. 130
5.13 Obfuscating Data ........................................... 130
5.14 Encode Binary Data ........................................ 131
5.15 Argz and Envz Vectors...................................... 133
5.15.1 Argz Functions......................................... 133
5.15.2 Envz Functions......................................... 136
6 Character Set Handling ...................... 138
6.1 Introduction to Extended Characters ......................... 138
6.2 Overview about Character Handling Functions................ 142
6.3 Restartable Multibyte Conversion Functions .................. 142
6.3.1 Selecting the conversion and its properties ............... 142
6.3.2 Representing the state of the conversion ................. 143
6.3.3 Converting Single Characters ............................ 144
6.3.4 Converting Multibyte and Wide Character Strings ....... 151
6.3.5 A Complete Multibyte Conversion Example.............. 154
6.4 Non-reentrant Conversion Function........................... 156
6.4.1 Non-reentrant Conversion of Single Characters........... 156
6.4.2 Non-reentrant Conversion of Strings ..................... 157
6.4.3 States in Non-reentrant Functions ....................... 159
6.5 Generic Charset Conversion .................................. 160
6.5.1 Generic Character Set Conversion Interface .............. 160
6.5.2 A complete iconv example .............................. 163
6.5.3 Some Details about other iconv Implementations ........ 166
6.5.4 The iconv Implementation in the GNU C Library ....... 167
6.5.4.1 Format of gconv-modules files...................... 168
6.5.4.2 Finding the conversion path in iconv ............... 169
6.5.4.3 iconv module data structures....................... 170
6.5.4.4 iconv module interfaces ............................ 173
7 Locales and Internationalization............. 181
7.1 What Effects a Locale Has ................................... 181
7.2 Choosing a Locale............................................ 182
7.3 Locale Categories ............................................ 182
7.4 How Programs Set the Locale ................................ 183
7.5 Standard Locales............................................. 185
7.6 Locale Names ................................................ 185
7.7 Accessing Locale Information................................. 186
7.7.1 localeconv: It is portable but . . . ...................... 187
7.7.1.1 Generic Numeric Formatting Parameters............ 187
7.7.1.2 Printing the Currency Symbol ...................... 188
7.7.1.3 Printing the Sign of a Monetary Amount............ 190
7.7.2 Pinpoint Access to Locale Data.......................... 190
7.8 A dedicated function to format numbers ...................... 196
7.9 Yes-or-No Questions.......................................... 199
vi
8 Message Translation.......................... 201
8.1 X/Open Message Catalog Handling........................... 201
8.1.1 The catgets function family ............................ 201
8.1.2 Format of the message catalog files ...................... 204
8.1.3 Generate Message Catalogs files ......................... 206
8.1.4 How to use the catgets interface........................ 208
8.1.4.1 Not using symbolic names .......................... 208
8.1.4.2 Using symbolic names .............................. 208
8.1.4.3 How does to this allow to develop................... 209
8.2 The Uniforum approach to Message Translation............... 210
8.2.1 The gettext family of functions......................... 211
8.2.1.1 What has to be done to translate a message?........ 211
8.2.1.2 How to determine which catalog to be used ......... 213
8.2.1.3 Additional functions for more complicated situations.. 215
8.2.1.4 How to specify the output character set gettext uses.. 219
8.2.1.5 How to use gettext in GUI programs............... 220
8.2.1.6 User influence on gettext .......................... 222
8.2.2 Programs to handle message catalogs for gettext........ 224
9 Searching and Sorting ........................ 226
9.1 Defining the Comparison Function............................ 226
9.2 Array Search Function........................................ 226
9.3 Array Sort Function.......................................... 227
9.4 Searching and Sorting Example............................... 228
9.5 The hsearch function. ....................................... 230
9.6 The tsearch function. ....................................... 233
10 Pattern Matching............................ 237
10.1 Wildcard Matching.......................................... 237
10.2 Globbing.................................................... 238
10.2.1 Calling glob ........................................... 238
10.2.2 Flags for Globbing ..................................... 243
10.2.3 More Flags for Globbing................................ 244
10.3 Regular Expression Matching................................ 246
10.3.1 POSIX Regular Expression Compilation ................ 247
10.3.2 Flags for POSIX Regular Expressions................... 248
10.3.3 Matching a Compiled POSIX Regular Expression ....... 249
10.3.4 Match Results with Subexpressions..................... 250
10.3.5 Complications in Subexpression Matching............... 250
10.3.6 POSIX Regexp Matching Cleanup ...................... 251
10.4 Shell-Style Word Expansion ................................. 252
10.4.1 The Stages of Word Expansion ......................... 252
10.4.2 Calling wordexp........................................ 253
10.4.3 Flags for Word Expansion .............................. 254
10.4.4 wordexp Example ...................................... 255
10.4.5 Details of Tilde Expansion.............................. 256
10.4.6 Details of Variable Substitution......................... 256
vii
11 Input/Output Overview .................... 259
11.1 Input/Output Concepts ..................................... 259
11.1.1 Streams and File Descriptors ........................... 259
11.1.2 File Position ........................................... 260
11.2 File Names.................................................. 261
11.2.1 Directories ............................................. 261
11.2.2 File Name Resolution................................... 262
11.2.3 File Name Errors....................................... 262
11.2.4 Portability of File Names............................... 263
12 Input/Output on Streams .................. 264
12.1 Streams..................................................... 264
12.2 Standard Streams ........................................... 264
12.3 Opening Streams............................................ 265
12.4 Closing Streams............................................. 269
12.5 Streams and Threads........................................ 270
12.6 Streams in Internationalized Applications.................... 273
12.7 Simple Output by Characters or Lines....................... 275
12.8 Character Input............................................. 278
12.9 Line-Oriented Input......................................... 281
12.10 Unreading ................................................. 283
12.10.1 What Unreading Means ............................... 283
12.10.2 Using ungetc To Do Unreading ....................... 284
12.11 Block Input/Output ....................................... 285
12.12 Formatted Output ......................................... 286
12.12.1 Formatted Output Basics.............................. 286
12.12.2 Output Conversion Syntax ............................ 287
12.12.3 Table of Output Conversions .......................... 288
12.12.4 Integer Conversions ................................... 289
12.12.5 Floating-Point Conversions............................ 291
12.12.6 Other Output Conversions............................. 293
12.12.7 Formatted Output Functions .......................... 294
12.12.8 Dynamically Allocating Formatted Output ............ 297
12.12.9 Variable Arguments Output Functions................. 297
12.12.10 Parsing a Template String............................ 300
12.12.11 Example of Parsing a Template String................ 302
12.13 Customizing printf ....................................... 303
12.13.1 Registering New Conversions .......................... 303
12.13.2 Conversion Specifier Options .......................... 304
12.13.3 Defining the Output Handler .......................... 305
12.13.4 printf Extension Example............................ 306
12.13.5 Predefined printf Handlers ........................... 307
12.14 Formatted Input ........................................... 309
12.14.1 Formatted Input Basics ............................... 309
12.14.2 Input Conversion Syntax .............................. 309
12.14.3 Table of Input Conversions ............................ 310
12.14.4 Numeric Input Conversions............................ 312
12.14.5 String Input Conversions .............................. 313
viii
12.14.6 Dynamically Allocating String Conversions ............ 315
12.14.7 Other Input Conversions .............................. 315
12.14.8 Formatted Input Functions............................ 316
12.14.9 Variable Arguments Input Functions................... 317
12.15 End-Of-File and Errors..................................... 318
12.16 Recovering from errors ..................................... 320
12.17 Text and Binary Streams................................... 320
12.18 File Positioning ............................................ 321
12.19 Portable File-Position Functions............................ 324
12.20 Stream Buffering........................................... 326
12.20.1 Buffering Concepts.................................... 326
12.20.2 Flushing Buffers....................................... 327
12.20.3 Controlling Which Kind of Buffering................... 328
12.21 Other Kinds of Streams .................................... 330
12.21.1 String Streams ........................................ 331
12.21.2 Programming Your Own Custom Streams ............. 333
12.21.2.1 Custom Streams and Cookies..................... 333
12.21.2.2 Custom Stream Hook Functions .................. 334
12.22 Formatted Messages........................................ 335
12.22.1 Printing Formatted Messages.......................... 335
12.22.2 Adding Severity Classes ............................... 337
12.22.3 How to use fmtmsg and addseverity.................. 338
13 Low-Level Input/Output.................... 340
13.1 Opening and Closing Files................................... 340
13.2 Input and Output Primitives ................................ 344
13.3 Setting the File Position of a Descriptor ..................... 348
13.4 Descriptors and Streams..................................... 351
13.5 Dangers of Mixing Streams and Descriptors.................. 352
13.5.1 Linked Channels ....................................... 352
13.5.2 Independent Channels.................................. 353
13.5.3 Cleaning Streams....................................... 353
13.6 Fast Scatter-Gather I/O..................................... 354
13.7 Copying data between two files.............................. 357
13.8 Memory-mapped I/O........................................ 359
13.9 Waiting for Input or Output................................. 365
13.10 Synchronizing I/O operations .............................. 368
13.11 Perform I/O Operations in Parallel......................... 369
13.11.1 Asynchronous Read and Write Operations............. 372
13.11.2 Getting the Status of AIO Operations ................. 376
13.11.3 Getting into a Consistent State........................ 377
13.11.4 Cancellation of AIO Operations ....................... 379
13.11.5 How to optimize the AIO implementation.............. 381
13.12 Control Operations on Files ................................ 382
13.13 Duplicating Descriptors .................................... 383
13.14 File Descriptor Flags....................................... 385
13.15 File Status Flags........................................... 386
13.15.1 File Access Modes..................................... 386
ix
13.15.2 Open-time Flags ...................................... 387
13.15.3 I/O Operating Modes ................................. 390
13.15.4 Getting and Setting File Status Flags.................. 391
13.16 File Locks.................................................. 392
13.17 Open File Description Locks ............................... 395
13.18 Open File Description Locks Example ...................... 397
13.19 Interrupt-Driven Input..................................... 399
13.20 Generic I/O Control operations ............................ 400
14 File System Interface........................ 401
14.1 Working Directory .......................................... 401
14.2 Accessing Directories........................................ 403
14.2.1 Format of a Directory Entry............................ 403
14.2.2 Opening a Directory Stream............................ 405
14.2.3 Reading and Closing a Directory Stream................ 406
14.2.4 Simple Program to List a Directory..................... 409
14.2.5 Random Access in a Directory Stream .................. 409
14.2.6 Scanning the Content of a Directory.................... 410
14.2.7 Simple Program to List a Directory, Mark II............ 411
14.2.8 Low-level Directory Access ............................. 412
14.3 Working with Directory Trees ............................... 413
14.4 Hard Links.................................................. 417
14.5 Symbolic Links.............................................. 418
14.6 Deleting Files ............................................... 421
14.7 Renaming Files ............................................. 422
14.8 Creating Directories......................................... 423
14.9 File Attributes .............................................. 424
14.9.1 The meaning of the File Attributes ..................... 424
14.9.2 Reading the Attributes of a File ........................ 428
14.9.3 Testing the Type of a File .............................. 430
14.9.4 File Owner............................................. 432
14.9.5 The Mode Bits for Access Permission................... 433
14.9.6 How Your Access to a File is Decided................... 435
14.9.7 Assigning File Permissions.............................. 435
14.9.8 Testing Permission to Access a File..................... 437
14.9.9 File Times ............................................. 438
14.9.10 File Size .............................................. 441
14.9.11 Storage Allocation .................................... 443
14.10 Making Special Files ....................................... 444
14.11 Temporary Files ........................................... 445
15 Pipes and FIFOs............................. 449
15.1 Creating a Pipe ............................................. 449
15.2 Pipe to a Subprocess........................................ 451
15.3 FIFO Special Files .......................................... 452
15.4 Atomicity of Pipe I/O....................................... 453
x
16 Sockets ....................................... 454
16.1 Socket Concepts............................................. 454
16.2 Communication Styles....................................... 455
16.3 Socket Addresses............................................ 456
16.3.1 Address Formats ....................................... 456
16.3.2 Setting the Address of a Socket......................... 458
16.3.3 Reading the Address of a Socket........................ 458
16.4 Interface Naming............................................ 459
16.5 The Local Namespace ....................................... 460
16.5.1 Local Namespace Concepts ............................. 460
16.5.2 Details of Local Namespace............................. 460
16.5.3 Example of Local-Namespace Sockets................... 461
16.6 The Internet Namespace .................................... 462
16.6.1 Internet Socket Address Formats ....................... 463
16.6.2 Host Addresses......................................... 464
16.6.2.1 Internet Host Addresses ........................... 464
16.6.2.2 Host Address Data Type .......................... 466
16.6.2.3 Host Address Functions............................ 467
16.6.2.4 Host Names ....................................... 468
16.6.3 Internet Ports.......................................... 472
16.6.4 The Services Database.................................. 473
16.6.5 Byte Order Conversion ................................. 475
16.6.6 Protocols Database..................................... 476
16.6.7 Internet Socket Example................................ 477
16.7 Other Namespaces .......................................... 478
16.8 Opening and Closing Sockets................................ 479
16.8.1 Creating a Socket ...................................... 479
16.8.2 Closing a Socket........................................ 479
16.8.3 Socket Pairs............................................ 480
16.9 Using Sockets with Connections ............................. 481
16.9.1 Making a Connection................................... 481
16.9.2 Listening for Connections............................... 482
16.9.3 Accepting Connections ................................. 483
16.9.4 Who is Connected to Me? .............................. 484
16.9.5 Transferring Data ...................................... 484
16.9.5.1 Sending Data...................................... 485
16.9.5.2 Receiving Data.................................... 486
16.9.5.3 Socket Data Options............................... 486
16.9.6 Byte Stream Socket Example........................... 487
16.9.7 Byte Stream Connection Server Example ............... 488
16.9.8 Out-of-Band Data...................................... 490
16.10 Datagram Socket Operations............................... 492
16.10.1 Sending Datagrams.................................... 493
16.10.2 Receiving Datagrams.................................. 493
16.10.3 Datagram Socket Example ............................ 494
16.10.4 Example of Reading Datagrams ....................... 495
16.11 The inetd Daemon ........................................ 496
16.11.1 inetd Servers ......................................... 496
xi
16.11.2 Configuring inetd..................................... 497
16.12 Socket Options............................................. 498
16.12.1 Socket Option Functions .............................. 498
16.12.2 Socket-Level Options.................................. 498
16.13 Networks Database......................................... 500
17 Low-Level Terminal Interface............... 502
17.1 Identifying Terminals........................................ 502
17.2 I/O Queues ................................................. 503
17.3 Two Styles of Input: Canonical or Not....................... 503
17.4 Terminal Modes............................................. 504
17.4.1 Terminal Mode Data Types............................. 504
17.4.2 Terminal Mode Functions............................... 505
17.4.3 Setting Terminal Modes Properly....................... 506
17.4.4 Input Modes ........................................... 507
17.4.5 Output Modes ......................................... 509
17.4.6 Control Modes ......................................... 510
17.4.7 Local Modes ........................................... 511
17.4.8 Line Speed ............................................. 514
17.4.9 Special Characters...................................... 515
17.4.9.1 Characters for Input Editing....................... 516
17.4.9.2 Characters that Cause Signals ..................... 517
17.4.9.3 Special Characters for Flow Control................ 518
17.4.9.4 Other Special Characters .......................... 519
17.4.10 Noncanonical Input ................................... 520
17.5 BSD Terminal Modes ....................................... 521
17.6 Line Control Functions...................................... 522
17.7 Noncanonical Mode Example................................ 524
17.8 Reading Passphrases ........................................ 525
17.9 Pseudo-Terminals ........................................... 526
17.9.1 Allocating Pseudo-Terminals ........................... 527
17.9.2 Opening a Pseudo-Terminal Pair ....................... 529
18 Syslog ........................................ 530
18.1 Overview of Syslog.......................................... 530
18.2 Submitting Syslog Messages ................................. 531
18.2.1 openlog ................................................ 531
18.2.2 syslog, vsyslog.......................................... 533
18.2.3 closelog ................................................ 535
18.2.4 setlogmask ............................................. 536
18.2.5 Syslog Example ........................................ 536
xii
19 Mathematics................................. 538
19.1 Predefined Mathematical Constants ......................... 538
19.2 Trigonometric Functions..................................... 539
19.3 Inverse Trigonometric Functions............................. 541
19.4 Exponentiation and Logarithms ............................. 543
19.5 Hyperbolic Functions........................................ 549
19.6 Special Functions ........................................... 552
19.7 Known Maximum Errors in Math Functions ................. 555
19.8 Pseudo-Random Numbers ................................... 590
19.8.1 ISO C Random Number Functions...................... 591
19.8.2 BSD Random Number Functions ....................... 591
19.8.3 SVID Random Number Function ....................... 593
19.9 Is Fast Code or Small Code preferred?....................... 598
20 Arithmetic Functions........................ 600
20.1 Integers..................................................... 600
20.2 Integer Division ............................................. 601
20.3 Floating Point Numbers..................................... 603
20.4 Floating-Point Number Classification Functions.............. 604
20.5 Errors in Floating-Point Calculations........................ 606
20.5.1 FP Exceptions ......................................... 606
20.5.2 Infinity and NaN ....................................... 608
20.5.3 Examining the FPU status word........................ 609
20.5.4 Error Reporting by Mathematical Functions ............ 611
20.6 Rounding Modes ............................................ 612
20.7 Floating-Point Control Functions............................ 614
20.8 Arithmetic Functions........................................ 616
20.8.1 Absolute Value......................................... 616
20.8.2 Normalization Functions................................ 617
20.8.3 Rounding Functions .................................... 619
20.8.4 Remainder Functions................................... 623
20.8.5 Setting and modifying single bits of FP values .......... 624
20.8.6 Floating-Point Comparison Functions................... 627
20.8.7 Miscellaneous FP arithmetic functions .................. 629
20.9 Complex Numbers .......................................... 632
20.10 Projections, Conjugates, and
Decomposing of Complex Numbers .............................. 633
20.11 Parsing of Numbers ........................................ 634
20.11.1 Parsing of Integers .................................... 634
20.11.2 Parsing of Floats...................................... 639
20.12 Printing of Floats .......................................... 641
20.13 Old-fashioned System V number-to-string functions......... 642
xiii
21 Date and Time............................... 645
21.1 Time Basics................................................. 645
21.2 Time Types................................................. 646
21.3 Calculating Elapsed Time ................................... 647
21.4 Processor And CPU Time................................... 648
21.4.1 CPU Time Inquiry ..................................... 648
21.4.2 Processor Time Inquiry................................. 649
21.5 Calendar Time.............................................. 650
21.5.1 Getting the Time....................................... 650
21.5.2 Setting and Adjusting the Time ........................ 652
21.5.3 Broken-down Time ..................................... 658
21.5.4 Formatting Calendar Time ............................. 661
21.5.5 Convert textual time and date information back ........ 667
21.5.5.1 Interpret string according to given format.......... 667
21.5.5.2 A More User-friendly Way to Parse Times and Dates.. 672
21.5.6 Specifying the Time Zone with TZ ...................... 675
21.5.7 Functions and Variables for Time Zones ................ 677
21.5.8 Time Functions Example ............................... 678
21.6 Setting an Alarm............................................ 678
21.7 Sleeping..................................................... 681
22 Resource Usage And Limitation............ 683
22.1 Resource Usage ............................................. 683
22.2 Limiting Resource Usage .................................... 684
22.3 Process CPU Priority And Scheduling ....................... 688
22.3.1 Absolute Priority....................................... 689
22.3.1.1 Using Absolute Priority............................ 690
22.3.2 Realtime Scheduling.................................... 690
22.3.3 Basic Scheduling Functions ............................. 691
22.3.4 Traditional Scheduling.................................. 695
22.3.4.1 Introduction To Traditional Scheduling ............ 695
22.3.4.2 Functions For Traditional Scheduling .............. 696
22.3.5 Limiting execution to certain CPUs..................... 698
22.4 Querying memory available resources ........................ 700
22.4.1 Overview about traditional Unix memory handling...... 701
22.4.2 How to get information about the memory subsystem?.. 701
22.5 Learn about the processors available......................... 703
23 Non-Local Exits ............................. 704
23.1 Introduction to Non-Local Exits............................. 704
23.2 Details of Non-Local Exits................................... 705
23.3 Non-Local Exits and Signals................................. 706
23.4 Complete Context Control................................... 707
xiv
24 Signal Handling.............................. 713
24.1 Basic Concepts of Signals.................................... 713
24.1.1 Some Kinds of Signals.................................. 713
24.1.2 Concepts of Signal Generation.......................... 713
24.1.3 How Signals Are Delivered.............................. 714
24.2 Standard Signals ............................................ 715
24.2.1 Program Error Signals.................................. 715
24.2.2 Termination Signals .................................... 718
24.2.3 Alarm Signals .......................................... 719
24.2.4 Asynchronous I/O Signals .............................. 719
24.2.5 Job Control Signals..................................... 720
24.2.6 Operation Error Signals ................................ 721
24.2.7 Miscellaneous Signals................................... 722
24.2.8 Signal Messages ........................................ 723
24.3 Specifying Signal Actions.................................... 724
24.3.1 Basic Signal Handling .................................. 724
24.3.2 Advanced Signal Handling.............................. 726
24.3.3 Interaction of signal and sigaction................... 727
24.3.4 sigaction Function Example .......................... 728
24.3.5 Flags for sigaction.................................... 729
24.3.6 Initial Signal Actions................................... 730
24.4 Defining Signal Handlers .................................... 730
24.4.1 Signal Handlers that Return............................ 730
24.4.2 Handlers That Terminate the Process................... 731
24.4.3 Nonlocal Control Transfer in Handlers .................. 732
24.4.4 Signals Arriving While a Handler Runs ................. 733
24.4.5 Signals Close Together Merge into One ................. 734
24.4.6 Signal Handling and Nonreentrant Functions............ 736
24.4.7 Atomic Data Access and Signal Handling ............... 738
24.4.7.1 Problems with Non-Atomic Access................. 738
24.4.7.2 Atomic Types ..................................... 739
24.4.7.3 Atomic Usage Patterns ............................ 739
24.5 Primitives Interrupted by Signals............................ 740
24.6 Generating Signals .......................................... 741
24.6.1 Signaling Yourself ...................................... 741
24.6.2 Signaling Another Process.............................. 742
24.6.3 Permission for using kill .............................. 743
24.6.4 Using kill for Communication ......................... 744
24.7 Blocking Signals............................................. 745
24.7.1 Why Blocking Signals is Useful ......................... 745
24.7.2 Signal Sets ............................................. 746
24.7.3 Process Signal Mask.................................... 747
24.7.4 Blocking to Test for Delivery of a Signal ................ 748
24.7.5 Blocking Signals for a Handler.......................... 749
24.7.6 Checking for Pending Signals ........................... 750
24.7.7 Remembering a Signal to Act On Later................. 751
24.8 Waiting for a Signal......................................... 752
24.8.1 Using pause............................................ 752
xv
24.8.2 Problems with pause................................... 753
24.8.3 Using sigsuspend...................................... 753
24.9 Using a Separate Signal Stack ............................... 754
24.10 BSD Signal Handling....................................... 756
25 The Basic Program/System Interface...... 758
25.1 Program Arguments......................................... 758
25.1.1 Program Argument Syntax Conventions ................ 759
25.1.2 Parsing Program Arguments............................ 759
25.2 Parsing program options using getopt....................... 760
25.2.1 Using the getopt function.............................. 760
25.2.2 Example of Parsing Arguments with getopt ............ 761
25.2.3 Parsing Long Options with getopt_long ............... 763
25.2.4 Example of Parsing Long Options with getopt_long.... 765
25.3 Parsing Program Options with Argp......................... 767
25.3.1 The argp_parse Function .............................. 767
25.3.2 Argp Global Variables.................................. 768
25.3.3 Specifying Argp Parsers ................................ 768
25.3.4 Specifying Options in an Argp Parser................... 769
25.3.4.1 Flags for Argp Options ............................ 770
25.3.5 Argp Parser Functions.................................. 771
25.3.5.1 Special Keys for Argp Parser Functions ............ 772
25.3.5.2 Argp Parsing State ................................ 774
25.3.5.3 Functions For Use in Argp Parsers................. 775
25.3.6 Combining Multiple Argp Parsers....................... 777
25.3.7 Flags for argp_parse................................... 777
25.3.8 Customizing Argp Help Output......................... 778
25.3.8.1 Special Keys for Argp Help Filter Functions........ 779
25.3.9 The argp_help Function ............................... 779
25.3.10 Flags for the argp_help Function ..................... 779
25.3.11 Argp Examples........................................ 780
25.3.11.1 A Minimal Program Using Argp.................. 781
25.3.11.2 A Program Using Argp with Only Default Options.. 781
25.3.11.3 A Program Using Argp with User Options ........ 782
25.3.11.4 A Program Using Multiple Combined Argp Parsers.. 785
25.3.12 Argp User Customization.............................. 788
25.3.12.1 Parsing of Suboptions ............................ 789
25.3.13 Parsing of Suboptions Example........................ 790
25.4 Environment Variables ...................................... 791
25.4.1 Environment Access.................................... 792
25.4.2 Standard Environment Variables........................ 794
25.5 Auxiliary Vector ............................................ 795
25.5.1 Definition of getauxval ................................ 796
25.6 System Calls................................................ 796
25.7 Program Termination ....................................... 797
25.7.1 Normal Termination.................................... 798
25.7.2 Exit Status............................................. 798
25.7.3 Cleanups on Exit....................................... 799
xvi
25.7.4 Aborting a Program.................................... 800
25.7.5 Termination Internals .................................. 800
26 Processes..................................... 802
26.1 Running a Command........................................ 802
26.2 Process Creation Concepts .................................. 803
26.3 Process Identification........................................ 803
26.4 Creating a Process .......................................... 804
26.5 Executing a File............................................. 806
26.6 Process Completion ......................................... 809
26.7 Process Completion Status .................................. 811
26.8 BSD Process Wait Function ................................. 812
26.9 Process Creation Example................................... 812
27 Inter-Process Communication .............. 814
27.1 Semaphores ................................................. 814
27.1.1 System V Semaphores.................................. 814
27.1.2 POSIX Semaphores .................................... 814
28 Job Control .................................. 816
28.1 Concepts of Job Control..................................... 816
28.2 Controlling Terminal of a Process............................ 817
28.3 Access to the Controlling Terminal .......................... 817
28.4 Orphaned Process Groups................................... 818
28.5 Implementing a Job Control Shell ........................... 818
28.5.1 Data Structures for the Shell ........................... 818
28.5.2 Initializing the Shell.................................... 820
28.5.3 Launching Jobs ........................................ 821
28.5.4 Foreground and Background............................ 824
28.5.5 Stopped and Terminated Jobs .......................... 826
28.5.6 Continuing Stopped Jobs............................... 828
28.5.7 The Missing Pieces..................................... 829
28.6 Functions for Job Control ................................... 830
28.6.1 Identifying the Controlling Terminal.................... 830
28.6.2 Process Group Functions ............................... 830
28.6.3 Functions for Controlling Terminal Access .............. 832
29 System Databases and Name Service Switch .. 834
29.1 NSS Basics.................................................. 834
29.2 The NSS Configuration File ................................. 835
29.2.1 Services in the NSS configuration File................... 835
29.2.2 Actions in the NSS configuration ....................... 836
29.2.3 Notes on the NSS Configuration File.................... 837
29.3 NSS Module Internals....................................... 838
29.3.1 The Naming Scheme of the NSS Modules ............... 838
29.3.2 The Interface of the Function in NSS Modules .......... 839
xvii
29.4 Extending NSS.............................................. 841
29.4.1 Adding another Service to NSS ......................... 841
29.4.2 Internals of the NSS Module Functions ................. 842
30 Users and Groups ........................... 844
30.1 User and Group IDs......................................... 844
30.2 The Persona of a Process.................................... 844
30.3 Why Change the Persona of a Process?...................... 845
30.4 How an Application Can Change Persona.................... 845
30.5 Reading the Persona of a Process............................ 846
30.6 Setting the User ID ......................................... 847
30.7 Setting the Group IDs....................................... 848
30.8 Enabling and Disabling Setuid Access ....................... 850
30.9 Setuid Program Example.................................... 851
30.10 Tips for Writing Setuid Programs .......................... 853
30.11 Identifying Who Logged In................................. 854
30.12 The User Accounting Database............................. 855
30.12.1 Manipulating the User Accounting Database........... 855
30.12.2 XPG User Accounting Database Functions............. 860
30.12.3 Logging In and Out ................................... 862
30.13 User Database ............................................. 863
30.13.1 The Data Structure that Describes a User ............. 863
30.13.2 Looking Up One User ................................. 864
30.13.3 Scanning the List of All Users ......................... 865
30.13.4 Writing a User Entry.................................. 866
30.14 Group Database ........................................... 867
30.14.1 The Data Structure for a Group....................... 867
30.14.2 Looking Up One Group ............................... 867
30.14.3 Scanning the List of All Groups ....................... 868
30.15 User and Group Database Example......................... 870
30.16 Netgroup Database......................................... 871
30.16.1 Netgroup Data........................................ 871
30.16.2 Looking up one Netgroup.............................. 871
30.16.3 Testing for Netgroup Membership ..................... 873
31 System Management ........................ 874
31.1 Host Identification .......................................... 874
31.2 Platform Type Identification ................................ 876
31.3 Controlling and Querying Mounts ........................... 877
31.3.1 Mount Information..................................... 878
31.3.1.1 The fstab file..................................... 878
31.3.1.2 The mtab file ...................................... 881
31.3.1.3 Other (Non-libc) Sources of Mount Information .... 884
31.3.2 Mount, Unmount, Remount ............................ 884
xviii
32 System Configuration Parameters.......... 889
32.1 General Capacity Limits..................................... 889
32.2 Overall System Options ..................................... 890
32.3 Which Version of POSIX is Supported....................... 891
32.4 Using sysconf .............................................. 892
32.4.1 Definition of sysconf................................... 892
32.4.2 Constants for sysconf Parameters...................... 892
32.4.3 Examples of sysconf................................... 901
32.5 Minimum Values for General Capacity Limits................ 901
32.6 Limits on File System Capacity ............................. 902
32.7 Optional Features in File Support ........................... 904
32.8 Minimum Values for File System Limits ..................... 904
32.9 Using pathconf............................................. 905
32.10 Utility Program Capacity Limits ........................... 907
32.11 Minimum Values for Utility Limits ......................... 908
32.12 String-Valued Parameters .................................. 909
33 Cryptographic Functions.................... 911
33.1 Passphrase Storage.......................................... 911
33.2 Generating Unpredictable Bytes............................. 915
34 Debugging support .......................... 917
34.1 Backtraces .................................................. 917
35 Threads ...................................... 920
35.1 ISO C Threads.............................................. 920
35.1.1 Return Values.......................................... 920
35.1.2 Creation and Control................................... 920
35.1.3 Call Once .............................................. 922
35.1.4 Mutexes................................................ 922
35.1.5 Condition Variables .................................... 925
35.1.6 Thread-local Storage ................................... 926
35.2 POSIX Threads............................................. 927
35.2.1 Thread-specific Data ................................... 927
35.2.2 Non-POSIX Extensions................................. 928
35.2.2.1 Setting Process-wide defaults for thread attributes.. 928
35.2.2.2 Controlling the Initial Signal Mask of a New Thread.. 928
35.2.2.3 Functions for Waiting According to a Specific Clock.. 929
35.2.2.4 Detecting Single-Threaded Execution .............. 930
36 Internal probes .............................. 933
36.1 Memory Allocation Probes .................................. 933
36.2 Non-local Goto Probes ...................................... 936
xix
37 Tunables...................................... 938
37.1 Tunable names.............................................. 939
37.2 Memory Allocation Tunables ................................ 939
37.3 Dynamic Linking Tunables .................................. 941
37.4 Elision Tunables ............................................ 942
37.5 POSIX Thread Tunables .................................... 943
37.6 Hardware Capability Tunables............................... 944
37.7 Memory Related Tunables................................... 945
Appendix A C Language
Facilities in the Library........................ 947
A.1 Explicitly Checking Internal Consistency..................... 947
A.2 Variadic Functions........................................... 948
A.2.1 Why Variadic Functions are Used ....................... 948
A.2.2 How Variadic Functions are Defined and Used........... 949
A.2.2.1 Syntax for Variable Arguments..................... 949
A.2.2.2 Receiving the Argument Values .................... 950
A.2.2.3 How Many Arguments Were Supplied .............. 950
A.2.2.4 Calling Variadic Functions ......................... 951
A.2.2.5 Argument Access Macros........................... 951
A.2.3 Example of a Variadic Function ......................... 953
A.3 Null Pointer Constant ....................................... 953
A.4 Important Data Types....................................... 954
A.5 Data Type Measurements.................................... 954
A.5.1 Width of an Integer Type............................... 955
A.5.2 Range of an Integer Type ............................... 956
A.5.3 Floating Type Macros................................... 957
A.5.3.1 Floating Point Representation Concepts ............ 957
A.5.3.2 Floating Point Parameters ......................... 959
A.5.3.3 IEEE Floating Point ............................... 961
A.5.4 Structure Field Offset Measurement..................... 962
Appendix B Summary of Library Facilities ... 963
Appendix C Installing the GNU C Library .. 1086
C.1 Configuring and compiling the GNU C Library.............. 1086
C.2 Installing the C Library..................................... 1092
C.3 Recommended Tools for Compilation........................ 1093
C.4 Specific advice for GNU/Linux systems ..................... 1095
C.5 Reporting Bugs............................................. 1096
xx
Appendix D Library Maintenance............ 1098
D.1 Adding New Functions...................................... 1098
D.1.1 Platform-specific types, macros and functions .......... 1099
D.2 Symbol handling in the GNU C Library..................... 1100
D.2.1 64-bit time symbol handling in the GNU C Library..... 1100
D.3 Porting the GNU C Library................................. 1101
D.3.1 Layout of the sysdeps Directory Hierarchy............. 1104
D.3.2 Porting the GNU C Library to Unix Systems........... 1106
Appendix E Platform-specific facilities ...... 1107
E.1 PowerPC-specific Facilities.................................. 1107
E.2 RISC-V-specific Facilities ................................... 1109
E.3 X86-specific Facilities ....................................... 1109
Appendix F Contributors to the
GNU C Library............................... 1115
Appendix G Free Software Needs
Free Documentation.......................... 1121
Appendix H GNU Lesser General
Public License................................. 1123
Appendix I GNU Free
Documentation License....................... 1132
Concept Index................................... 1140
Type Index ...................................... 1153
Function and Macro Index ..................... 1156
Variable and Constant Macro Index........... 1172
Program and File Index ........................ 1185

标签: lib BC ib

实例下载地址

The GNU C Library Reference Manual

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
;
报警