]> gnu libiberty Introduction The libiberty library is a collection of subroutines used by various GNU programs. It is available under the Library General Public License; for more information, see . This edition accompanies GCC 3, September 2001. Using using libiberty libiberty usage how to use To date, libiberty is generally not installed on its own. It has evolved over years but does not have its own version number nor release schedule. Possibly the easiest way to use libiberty in your projects is to drop the libiberty code into your project's sources, and to build the library along with your own sources; the library would then be linked in at the end. This prevents any possible version mismatches with other copies of libiberty elsewhere on the system. Passing to the configure script when building libiberty causes the header files and archive library to be installed when make install is run. This option also takes an (optional) argument to specify the installation location, in the same manner as . For your own projects, an approach which offers stability and flexibility is to include libiberty with your code, but allow the end user to optionally choose to use a previously-installed version instead. In this way the user may choose (for example) to install libiberty as part of GCC, and use that version for all software built with that compiler. (This approach has proven useful with software using the GNU readline library.) Making use of libiberty code usually requires that you include one or more header files from the libiberty distribution. (They will be named as necessary in the function descriptions.) At link time, you will need to add to your link command invocation. Overview Functions contained in libiberty can be divided into three general categories. Supplemental Functions supplemental functions functions, supplemental functions, missing Certain operating systems do not provide functions which have since become standardized, or at least common. For example, the Single Unix Specification Version 2 requires that the basename function be provided, but an OS which predates that specification might not have this function. This should not prevent well-written code from running on such a system. Similarly, some functions exist only among a particular “flavor” or “family” of operating systems. As an example, the bzero function is often not present on systems outside the BSD-derived family of systems. Many such functions are provided in libiberty. They are quickly listed here with little description, as systems which lack them become less and less common. Each function foo is implemented in foo.c but not declared in any libiberty header file; more comments and caveats for each function's implementation are often available in the source file. Generally, the function can simply be declared as extern. Replacement Functions replacement functions functions, replacement Some functions have extremely limited implementations on different platforms. Other functions are tedious to use correctly; for example, proper use of malloc calls for the return value to be checked and appropriate action taken if memory has been exhausted. A group of “replacement functions” is available in libiberty to address these issues for some of the most commonly used subroutines. All of these functions are declared in the libiberty.h header file. Many of the implementations will use preprocessor macros set by GNU Autoconf, if you decide to make use of that program. Some of these functions may call one another. Memory Allocation memory allocation The functions beginning with the letter ‘x’ are wrappers around standard functions; the functions provided by the system environment are called and their results checked before the results are passed back to client code. If the standard functions fail, these wrappers will terminate the program. Thus, these versions can be used with impunity. Exit Handlers exit handlers The existence and implementation of the atexit routine varies amongst the flavors of Unix. libiberty provides an unvarying dependable implementation via xatexit and xexit. Error Reporting error reporting These are a set of routines to facilitate programming with the system errno interface. The libiberty source file strerror.c contains a good deal of documentation for these functions. Extensions extensions functions, extension libiberty includes additional functionality above and beyond standard functions, which has proven generically useful in GNU programs, such as obstacks and regex. These functions are often copied from other projects as they gain popularity, and are included here to provide a central location from which to use, maintain, and distribute them. Obstacks obstacks An obstack is a pool of memory containing a stack of objects. You can create any number of separate obstacks, and then allocate objects in specified obstacks. Within each obstack, the last object allocated must always be the first one freed, but distinct obstacks are independent of each other. Aside from this one constraint of order of freeing, obstacks are totally general: an obstack can contain any number of objects of any size. They are implemented with macros, so allocation is usually very fast as long as the objects are usually small. And the only space overhead per object is the padding needed to start each object on a suitable boundary. Creating Obstacks The utilities for manipulating obstacks are declared in the header file obstack.h. obstack.h struct obstack — Data Type: struct obstack An obstack is represented by a data structure of type structobstack. This structure has a small fixed size; it records the statusof the obstack and how to find the space in which objects are allocated.It does not contain any of the objects themselves. You should not tryto access the contents of the structure directly; use only the functionsdescribed in this chapter. You can declare variables of type struct obstack and use them as obstacks, or you can allocate obstacks dynamically like any other kind of object. Dynamic allocation of obstacks allows your program to have a variable number of different stacks. (You can even allocate an obstack structure in another obstack, but this is rarely useful.) All the functions that work with obstacks require you to specify which obstack to use. You do this with a pointer of type struct obstack *. In the following, we often say “an obstack” when strictly speaking the object at hand is such a pointer. The objects in the obstack are packed into large blocks called chunks. The struct obstack structure points to a chain of the chunks currently in use. The obstack library obtains a new chunk whenever you allocate an object that won't fit in the previous chunk. Since the obstack library manages chunks automatically, you don't need to pay much attention to them, but you do need to supply a function which the obstack library should use to get a chunk. Usually you supply a function which uses malloc directly or indirectly. You must also supply a function to free a chunk. These matters are described in the following section. Preparing for Using Obstacks Each source file in which you plan to use the obstack functions must include the header file obstack.h, like this: #include <obstack.h> obstack_chunk_alloc obstack_chunk_free Also, if the source file uses the macro obstack_init, it must declare or define two functions or macros that will be called by the obstack library. One, obstack_chunk_alloc, is used to allocate the chunks of memory into which objects are packed. The other, obstack_chunk_free, is used to return chunks when the objects in them are freed. These macros should appear before any use of obstacks in the source file. Usually these are defined to use malloc via the intermediary xmalloc (see See section ``Unconstrained Allocation'' in The GNU C Library Reference Manual). This is done with the following pair of macro definitions: #define obstack_chunk_alloc xmalloc #define obstack_chunk_free free Though the memory you get using obstacks really comes from malloc, using obstacks is faster because malloc is called less often, for larger blocks of memory. See , for full details. At run time, before the program can use a struct obstack object as an obstack, it must initialize the obstack by calling obstack_init. obstack_init — Function: int obstack_init ( struct obstack * obstack-ptr ) Initialize obstack obstack-ptr for allocation of objects. Thisfunction calls the obstack's obstack_chunk_alloc function. Ifallocation of memory fails, the function pointed to byobstack_alloc_failed_handler is called. The obstack_initfunction always returns 1 (Compatibility notice: Former versions ofobstack returned 0 if allocation failed). Here are two examples of how to allocate the space for an obstack and initialize it. First, an obstack that is a static variable: static struct obstack myobstack; … obstack_init (&myobstack); Second, an obstack that is itself dynamically allocated: struct obstack *myobstack_ptr = (struct obstack *) xmalloc (sizeof (struct obstack)); obstack_init (myobstack_ptr); obstack_alloc_failed_handler — Variable: obstack_alloc_failed_handler The value of this variable is a pointer to a function thatobstack uses when obstack_chunk_alloc fails to allocatememory. The default action is to print a message and abort.You should supply a function that either calls exit(see See section ``Program Termination'' in The GNU C Library Reference Manual) or longjmp (see See section ``Non-Local Exits'' in The GNU C Library Reference Manual) and doesn't return. void my_obstack_alloc_failed (void) … obstack_alloc_failed_handler = &my_obstack_alloc_failed; Allocation in an Obstack allocation (obstacks) The most direct way to allocate an object in an obstack is with obstack_alloc, which is invoked almost like malloc. obstack_alloc — Function: void * obstack_alloc ( struct obstack * obstack-ptr , int size ) This allocates an uninitialized block of size bytes in an obstackand returns its address. Here obstack-ptr specifies which obstackto allocate the block in; it is the address of the struct obstackobject which represents the obstack. Each obstack function or macrorequires you to specify an obstack-ptr as the first argument.This function calls the obstack's obstack_chunk_alloc function ifit needs to allocate a new chunk of memory; it callsobstack_alloc_failed_handler if allocation of memory byobstack_chunk_alloc failed. For example, here is a function that allocates a copy of a string str in a specific obstack, which is in the variable string_obstack: struct obstack string_obstack; char * copystring (char *string) { size_t len = strlen (string) + 1; char *s = (char *) obstack_alloc (&string_obstack, len); memcpy (s, string, len); return s; } To allocate a block with specified contents, use the function obstack_copy, declared like this: obstack_copy — Function: void * obstack_copy ( struct obstack * obstack-ptr , void * address , int size ) This allocates a block and initializes it by copying sizebytes of data starting at address. It callsobstack_alloc_failed_handler if allocation of memory byobstack_chunk_alloc failed. obstack_copy0 — Function: void * obstack_copy0 ( struct obstack * obstack-ptr , void * address , int size ) Like obstack_copy, but appends an extra byte containing a nullcharacter. This extra byte is not counted in the argument size. The obstack_copy0 function is convenient for copying a sequence of characters into an obstack as a null-terminated string. Here is an example of its use: char * obstack_savestring (char *addr, int size) { return obstack_copy0 (&myobstack, addr, size); } Contrast this with the previous example of savestring using malloc (see See section ``Basic Allocation'' in The GNU C Library Reference Manual). Freeing Objects in an Obstack freeing (obstacks) To free an object allocated in an obstack, use the function obstack_free. Since the obstack is a stack of objects, freeing one object automatically frees all other objects allocated more recently in the same obstack. obstack_free — Function: void obstack_free ( struct obstack * obstack-ptr , void * object ) If object is a null pointer, everything allocated in the obstackis freed. Otherwise, object must be the address of an objectallocated in the obstack. Then object is freed, along witheverything allocated in obstack since object. Note that if object is a null pointer, the result is an uninitialized obstack. To free all memory in an obstack but leave it valid for further allocation, call obstack_free with the address of the first object allocated on the obstack: obstack_free (obstack_ptr, first_object_allocated_ptr); Recall that the objects in an obstack are grouped into chunks. When all the objects in a chunk become free, the obstack library automatically frees the chunk (see ). Then other obstacks, or non-obstack allocation, can reuse the space of the chunk. Obstack Functions and Macros macros The interfaces for using obstacks may be defined either as functions or as macros, depending on the compiler. The obstack facility works with all C compilers, including both ISO C and traditional C, but there are precautions you must take if you plan to use compilers other than GNU C. If you are using an old-fashioned non-ISO C compiler, all the obstack “functions” are actually defined only as macros. You can call these macros like functions, but you cannot use them in any other way (for example, you cannot take their address). Calling the macros requires a special precaution: namely, the first operand (the obstack pointer) may not contain any side effects, because it may be computed more than once. For example, if you write this: obstack_alloc (get_obstack (), 4); you will find that get_obstack may be called several times. If you use *obstack_list_ptr++ as the obstack pointer argument, you will get very strange results since the incrementation may occur several times. In ISO C, each function has both a macro definition and a function definition. The function definition is used if you take the address of the function without calling it. An ordinary call uses the macro definition by default, but you can request the function definition instead by writing the function name in parentheses, as shown here: char *x; void *(*funcp) (); /* Use the macro . */ x = (char *) obstack_alloc (obptr, size); /* Call the function . */ x = (char *) (obstack_alloc) (obptr, size); /* Take the address of the function . */ funcp = obstack_alloc; This is the same situation that exists in ISO C for the standard library functions. See See section ``Macro Definitions'' in The GNU C Library Reference Manual. Warning: When you do use the macros, you must observe the precaution of avoiding side effects in the first operand, even in ISO C. If you use the GNU C compiler, this precaution is not necessary, because various language extensions in GNU C permit defining the macros so as to compute each argument only once. Growing Objects growing objects (in obstacks) changing the size of a block (obstacks) Because memory in obstack chunks is used sequentially, it is possible to build up an object step by step, adding one or more bytes at a time to the end of the object. With this technique, you do not need to know how much data you will put in the object until you come to the end of it. We call this the technique of growing objects. The special functions for adding data to the growing object are described in this section. You don't need to do anything special when you start to grow an object. Using one of the functions to add data to the object automatically starts it. However, it is necessary to say explicitly when the object is finished. This is done with the function obstack_finish. The actual address of the object thus built up is not known until the object is finished. Until then, it always remains possible that you will add so much data that the object must be copied into a new chunk. While the obstack is in use for a growing object, you cannot use it for ordinary allocation of another object. If you try to do so, the space already added to the growing object will become part of the other object. obstack_blank — Function: void obstack_blank ( struct obstack * obstack-ptr , int size ) The most basic function for adding to a growing object isobstack_blank, which adds space without initializing it. obstack_grow — Function: void obstack_grow ( struct obstack * obstack-ptr , void * data , int size ) To add a block of initialized space, use obstack_grow, which isthe growing-object analogue of obstack_copy. It adds sizebytes of data to the growing object, copying the contents fromdata. obstack_grow0 — Function: void obstack_grow0 ( struct obstack * obstack-ptr , void * data , int size ) This is the growing-object analogue of obstack_copy0. It addssize bytes copied from data, followed by an additional nullcharacter. obstack_1grow — Function: void obstack_1grow ( struct obstack * obstack-ptr , char c ) To add one character at a time, use the function obstack_1grow.It adds a single byte containing c to the growing object. obstack_ptr_grow — Function: void obstack_ptr_grow ( struct obstack * obstack-ptr , void * data ) Adding the value of a pointer one can use the functionobstack_ptr_grow. It adds sizeof (void *) bytescontaining the value of data. obstack_int_grow — Function: void obstack_int_grow ( struct obstack * obstack-ptr , int data ) A single value of type int can be added by using theobstack_int_grow function. It adds sizeof (int) bytes tothe growing object and initializes them with the value of data. obstack_finish — Function: void * obstack_finish ( struct obstack * obstack-ptr ) When you are finished growing the object, use the functionobstack_finish to close it off and return its final address.Once you have finished the object, the obstack is available for ordinaryallocation or for growing another object.This function can return a null pointer under the same conditions asobstack_alloc (see ). When you build an object by growing it, you will probably need to know afterward how long it became. You need not keep track of this as you grow the object, because you can find out the length from the obstack just before finishing the object with the function obstack_object_size, declared as follows: obstack_object_size — Function: int obstack_object_size ( struct obstack * obstack-ptr ) This function returns the current size of the growing object, in bytes.Remember to call this function before finishing the object.After it is finished, obstack_object_size will return zero. If you have started growing an object and wish to cancel it, you should finish it and then free it, like this: obstack_free (obstack_ptr, obstack_finish (obstack_ptr)); This has no effect if no object was growing. shrinking objects You can use obstack_blank with a negative size argument to make the current object smaller. Just don't try to shrink it beyond zero length—there's no telling what will happen if you do that. Extra Fast Growing Objects efficiency and obstacks The usual functions for growing objects incur overhead for checking whether there is room for the new growth in the current chunk. If you are frequently constructing objects in small steps of growth, this overhead can be significant. You can reduce the overhead by using special “fast growth” functions that grow the object without checking. In order to have a robust program, you must do the checking yourself. If you do this checking in the simplest way each time you are about to add data to the object, you have not saved anything, because that is what the ordinary growth functions do. But if you can arrange to check less often, or check more efficiently, then you make the program faster. The function obstack_room returns the amount of room available in the current chunk. It is declared as follows: obstack_room — Function: int obstack_room ( struct obstack * obstack-ptr ) This returns the number of bytes that can be added safely to the currentgrowing object (or to an object about to be started) in obstackobstack using the fast growth functions. While you know there is room, you can use these fast growth functions for adding data to a growing object: obstack_1grow_fast — Function: void obstack_1grow_fast ( struct obstack * obstack-ptr , char c ) The function obstack_1grow_fast adds one byte containing thecharacter c to the growing object in obstack obstack-ptr. obstack_ptr_grow_fast — Function: void obstack_ptr_grow_fast ( struct obstack * obstack-ptr , void * data ) The function obstack_ptr_grow_fast adds sizeof (void *)bytes containing the value of data to the growing object inobstack obstack-ptr. obstack_int_grow_fast — Function: void obstack_int_grow_fast ( struct obstack * obstack-ptr , int data ) The function obstack_int_grow_fast adds sizeof (int) bytescontaining the value of data to the growing object in obstackobstack-ptr. obstack_blank_fast — Function: void obstack_blank_fast ( struct obstack * obstack-ptr , int size ) The function obstack_blank_fast adds size bytes to thegrowing object in obstack obstack-ptr without initializing them. When you check for space using obstack_room and there is not enough room for what you want to add, the fast growth functions are not safe. In this case, simply use the corresponding ordinary growth function instead. Very soon this will copy the object to a new chunk; then there will be lots of room available again. So, each time you use an ordinary growth function, check afterward for sufficient space using obstack_room. Once the object is copied to a new chunk, there will be plenty of space again, so the program will start using the fast growth functions again. Here is an example: void add_string (struct obstack *obstack, const char *ptr, int len) { while (len > 0) { int room = obstack_room (obstack); if (room == 0) { /* Not enough room. Add one character slowly, which may copy to a new chunk and make room. */ obstack_1grow (obstack, *ptr++); len--; } else { if (room > len) room = len; /* Add fast as much as we have room for. */ len -= room; while (room-- > 0) obstack_1grow_fast (obstack, *ptr++); } } } Status of an Obstack obstack status status of obstack Here are functions that provide information on the current status of allocation in an obstack. You can use them to learn about an object while still growing it. obstack_base — Function: void * obstack_base ( struct obstack * obstack-ptr ) This function returns the tentative address of the beginning of thecurrently growing object in obstack-ptr. If you finish the objectimmediately, it will have that address. If you make it larger first, itmay outgrow the current chunk—then its address will change!If no object is growing, this value says where the next object youallocate will start (once again assuming it fits in the currentchunk). obstack_next_free — Function: void * obstack_next_free ( struct obstack * obstack-ptr ) This function returns the address of the first free byte in the currentchunk of obstack obstack-ptr. This is the end of the currentlygrowing object. If no object is growing, obstack_next_freereturns the same value as obstack_base. obstack_object_size — Function: int obstack_object_size ( struct obstack * obstack-ptr ) This function returns the size in bytes of the currently growing object.This is equivalent to obstack_next_free (obstack-ptr) - obstack_base (obstack-ptr) Alignment of Data in Obstacks alignment (in obstacks) Each obstack has an alignment boundary; each object allocated in the obstack automatically starts on an address that is a multiple of the specified boundary. By default, this boundary is 4 bytes. To access an obstack's alignment boundary, use the macro obstack_alignment_mask, whose function prototype looks like this: obstack_alignment_mask — Macro: int obstack_alignment_mask ( struct obstack * obstack-ptr ) The value is a bit mask; a bit that is 1 indicates that the correspondingbit in the address of an object should be 0. The mask value should be oneless than a power of 2; the effect is that all object addresses aremultiples of that power of 2. The default value of the mask is 3, so thataddresses are multiples of 4. A mask value of 0 means an object can starton any multiple of 1 (that is, no alignment is required).The expansion of the macro obstack_alignment_mask is an lvalue,so you can alter the mask by assignment. For example, this statement: obstack_alignment_mask (obstack_ptr) = 0; has the effect of turning off alignment processing in the specified obstack. Note that a change in alignment mask does not take effect until after the next time an object is allocated or finished in the obstack. If you are not growing an object, you can make the new alignment mask take effect immediately by calling obstack_finish. This will finish a zero-length object and then do proper alignment for the next object. Obstack Chunks efficiency of chunks chunks Obstacks work by allocating space for themselves in large chunks, and then parceling out space in the chunks to satisfy your requests. Chunks are normally 4096 bytes long unless you specify a different chunk size. The chunk size includes 8 bytes of overhead that are not actually used for storing objects. Regardless of the specified size, longer chunks will be allocated when necessary for long objects. The obstack library allocates chunks by calling the function obstack_chunk_alloc, which you must define. When a chunk is no longer needed because you have freed all the objects in it, the obstack library frees the chunk by calling obstack_chunk_free, which you must also define. These two must be defined (as macros) or declared (as functions) in each source file that uses obstack_init (see ). Most often they are defined as macros like this: #define obstack_chunk_alloc malloc #define obstack_chunk_free free Note that these are simple macros (no arguments). Macro definitions with arguments will not work! It is necessary that obstack_chunk_alloc or obstack_chunk_free, alone, expand into a function name if it is not itself a function name. If you allocate chunks with malloc, the chunk size should be a power of 2. The default chunk size, 4096, was chosen because it is long enough to satisfy many typical requests on the obstack yet short enough not to waste too much memory in the portion of the last chunk not yet used. obstack_chunk_size — Macro: int obstack_chunk_size ( struct obstack * obstack-ptr ) This returns the chunk size of the given obstack. Since this macro expands to an lvalue, you can specify a new chunk size by assigning it a new value. Doing so does not affect the chunks already allocated, but will change the size of chunks allocated for that particular obstack in the future. It is unlikely to be useful to make the chunk size smaller, but making it larger might improve efficiency if you are allocating many objects whose size is comparable to the chunk size. Here is how to do so cleanly: if (obstack_chunk_size (obstack_ptr) < new-chunk-size) obstack_chunk_size (obstack_ptr) = new-chunk-size; Summary of Obstack Functions Here is a summary of all the functions associated with obstacks. Each takes the address of an obstack (struct obstack *) as its first argument. void obstack_init (struct obstack *obstack-ptr) Initialize use of an obstack. See . void *obstack_alloc (struct obstack *obstack-ptr, int size) Allocate an object of size uninitialized bytes.See . void *obstack_copy (struct obstack *obstack-ptr, void *address, int size) Allocate an object of size bytes, with contents copied fromaddress. See . void *obstack_copy0 (struct obstack *obstack-ptr, void *address, int size) Allocate an object of size+1 bytes, with size of them copiedfrom address, followed by a null character at the end.See . void obstack_free (struct obstack *obstack-ptr, void *object) Free object (and everything allocated in the specified obstackmore recently than object). See . void obstack_blank (struct obstack *obstack-ptr, int size) Add size uninitialized bytes to a growing object.See . void obstack_grow (struct obstack *obstack-ptr, void *address, int size) Add size bytes, copied from address, to a growing object.See . void obstack_grow0 (struct obstack *obstack-ptr, void *address, int size) Add size bytes, copied from address, to a growing object,and then add another byte containing a null character. See . void obstack_1grow (struct obstack *obstack-ptr, char data-char) Add one byte containing data-char to a growing object.See . void *obstack_finish (struct obstack *obstack-ptr) Finalize the object that is growing and return its permanent address.See . int obstack_object_size (struct obstack *obstack-ptr) Get the current size of the currently growing object. See . void obstack_blank_fast (struct obstack *obstack-ptr, int size) Add size uninitialized bytes to a growing object without checkingthat there is enough room. See . void obstack_1grow_fast (struct obstack *obstack-ptr, char data-char) Add one byte containing data-char to a growing object withoutchecking that there is enough room. See . int obstack_room (struct obstack *obstack-ptr) Get the amount of room now available for growing the current object.See . int obstack_alignment_mask (struct obstack *obstack-ptr) The mask used for aligning the beginning of an object. This is anlvalue. See . int obstack_chunk_size (struct obstack *obstack-ptr) The size for allocating chunks. This is an lvalue. See . void *obstack_base (struct obstack *obstack-ptr) Tentative starting address of the currently growing object.See . void *obstack_next_free (struct obstack *obstack-ptr) Address just after the end of the currently growing object.See . Function, Variable, and Macro Listing. HOST_CHARSET — Extension: HOST_CHARSET This macro indicates the basic character set and encoding used by thehost: more precisely, the encoding used for character constants inpreprocessor ‘#if’ statements (the C "execution character set").It is defined by safe-ctype.h, and will be an integer constantwith one of the following values: HOST_CHARSET_UNKNOWN The host character set is unknown - that is, not one of the next twopossibilities. HOST_CHARSET_ASCII The host character set is ASCII. HOST_CHARSET_EBCDIC The host character set is some variant of EBCDIC. (Only one of thenineteen EBCDIC varying characters is tested; exercise caution.) alloca — Replacement: void* alloca ( size_t size ) This function allocates memory which will be automatically reclaimedafter the procedure exits. The libiberty implementation does not freethe memory immediately but will do so eventually during subsequentcalls to this function. Memory is allocated using xmalloc undernormal circumstances.The header file alloca-conf.h can be used in conjunction with theGNU Autoconf test AC_FUNC_ALLOCA to test for and properly makeavailable this function. The AC_FUNC_ALLOCA test requires thatclient code use a block of preprocessor code to be safe (see the Autoconfmanual for more); this header incorporates that logic and more, includingthe possibility of a GCC built-in function. asprintf — Extension: int asprintf ( char ** resptr , const char * format , ... ) Like sprintf, but instead of passing a pointer to a buffer, youpass a pointer to a pointer. This function will compute the size ofthe buffer needed, allocate memory with malloc, and store apointer to the allocated memory in *resptr. The valuereturned is the same as sprintf would return. If memory couldnot be allocated, minus one is returned and NULL is stored in*resptr. atexit — Supplemental: int atexit ( void ( * f ) ( ) ) Causes function f to be called at exit. Returns 0. basename — Supplemental: char* basename ( const char * name ) Returns a pointer to the last component of pathname name.Behavior is undefined if the pathname ends in a directory separator. bcmp — Supplemental: int bcmp ( char * x , char * y , int count ) Compares the first count bytes of two areas of memory. Returnszero if they are the same, nonzero otherwise. Returns zero ifcount is zero. A nonzero result only indicates a difference,it does not indicate any sorting order (say, by having a positiveresult mean x sorts before y). bcopy — Supplemental: void bcopy ( char * in , char * out , int length ) Copies length bytes from memory region in to regionout. The use of bcopy is deprecated in new programs. bsearch — Supplemental: void* bsearch ( const void * key , const void * base , size_t nmemb , size_t size , int ( * compar ) ( const void * , const void * ) ) Performs a search over an array of nmemb elements pointed to bybase for a member that matches the object pointed to by key.The size of each member is specified by size. The array contentsshould be sorted in ascending order according to the comparcomparison function. This routine should take two arguments pointing tothe key and to an array member, in that order, and should return aninteger less than, equal to, or greater than zero if the key objectis respectively less than, matching, or greater than the array member. buildargv — Extension: char** buildargv ( char * sp ) Given a pointer to a string, parse the string extracting fieldsseparated by whitespace and optionally enclosed within either singleor double quotes (which are stripped off), and build a vector ofpointers to copies of the string for each field. The input stringremains unchanged. The last element of the vector is followed by aNULL element.All of the memory for the pointer array and copies of the stringis obtained from malloc. All of the memory can be returned to thesystem with the single function call freeargv, which takes thereturned result of buildargv, as it's argument.Returns a pointer to the argument vector if successful. ReturnsNULL if sp is NULL or if there is insufficientmemory to complete building the argument vector.If the input is a null string (as opposed to a NULL pointer),then buildarg returns an argument vector that has one arg, a nullstring. bzero — Supplemental: void bzero ( char * mem , int count ) Zeros count bytes starting at mem. Use of this functionis deprecated in favor of memset. calloc — Supplemental: void* calloc ( size_t nelem , size_t elsize ) Uses malloc to allocate storage for nelem objects ofelsize bytes each, then zeros the memory. choose_temp_base — Extension: char* choose_temp_base ( void ) Return a prefix for temporary file names or NULL if unable tofind one. The current directory is chosen if all else fails so theprogram is exited if a temporary directory can't be found (mktempfails). The buffer for the result is obtained with xmalloc.This function is provided for backwards compatability only. Its use isnot recommended. choose_tmpdir — Replacement: char* choose_tmpdir ( ) Returns a pointer to a directory path suitable for creating temporaryfiles in. clock — Supplemental: long clock ( void ) Returns an approximation of the CPU time used by the process as aclock_t; divide this number by ‘CLOCKS_PER_SEC’ to get thenumber of seconds used. concat — Extension: char* concat ( const char * s1 , const char * s2 , , NULL ) Concatenate zero or more of strings and return the result in freshlyxmalloced memory. Returns NULL if insufficient memory isavailable. The argument list is terminated by the first NULLpointer encountered. Pointers to empty strings are ignored. dupargv — Extension: char** dupargv ( char ** vector ) Duplicate an argument vector. Simply scans through vector,duplicating each argument until the terminating NULL is found.Returns a pointer to the argument vector if successful. ReturnsNULL if there is insufficient memory to complete building theargument vector. errno_max — Extension: int errno_max ( void ) Returns the maximum errno value for which a correspondingsymbolic name or message is available. Note that in the case where weuse the sys_errlist supplied by the system, it is possible forthere to be more symbolic names than messages, or vice versa. Infact, the manual page for perror(3C) explicitly warns that oneshould check the size of the table (sys_nerr) before indexingit, since new error codes may be added to the system before they areadded to the table. Thus sys_nerr might be smaller than valueimplied by the largest errno value defined in <errno.h>.We return the maximum value that can be used to obtain a meaningfulsymbolic name or message. expandargv — Extension: void expandargv ( int * argcp , char *** argvp ) The argcp and argvp arguments are pointers to the usualargc and argv arguments to main. This functionlooks for arguments that begin with the character ‘@’. Any sucharguments are interpreted as “response files”. The contents of theresponse file are interpreted as additional command line options. Inparticular, the file is separated into whitespace-separated strings;each such string is taken as a command-line option. The new optionsare inserted in place of the option naming the response file, and*argcp and *argvp will be updated. If the value of*argvp is modified by this function, then the new value hasbeen dynamically allocated and can be deallocated by the caller withfreeargv. However, most callers will simply callexpandargv near the beginning of main and allow theoperating system to free the memory when the program exits. fdmatch — Extension: int fdmatch ( int fd1 , int fd2 ) Check to see if two open file descriptors refer to the same file.This is useful, for example, when we have an open file descriptor foran unnamed file, and the name of a file that we believe to correspondto that fd. This can happen when we are exec'd with an already openfile (stdout for example) or from the SVR4 /proc callsthat return open file descriptors for mapped address spaces. All wehave to do is open the file by name and check the two file descriptorsfor a match, which is done by comparing major and minor device numbersand inode numbers. fdopen_unlocked — Extension: FILE * fdopen_unlocked ( int fildes , const char * mode ) Opens and returns a FILE pointer via fdopen. If theoperating system supports it, ensure that the stream is setup to avoidany multi-threaded locking. Otherwise return the FILE pointerunchanged. ffs — Supplemental: int ffs ( int valu ) Find the first (least significant) bit set in valu. Bits arenumbered from right to left, starting with bit 1 (corresponding to thevalue 1). If valu is zero, zero is returned. fnmatch — Replacement: int fnmatch ( const char * pattern , const char * string , int flags ) Matches string against pattern, returning zero if itmatches, FNM_NOMATCH if not. pattern may contain thewildcards ? to match any one character, * to match anyzero or more characters, or a set of alternate characters in squarebrackets, like ‘[a-gt8]’, which match one character (athrough g, or t, or 8, in this example) if that onecharacter is in the set. A set may be inverted (i.e., match anythingexcept what's in the set) by giving ^ or ! as the firstcharacter in the set. To include those characters in the set, list themas anything other than the first character of the set. To include adash in the set, list it last in the set. A backslash character makesthe following character not special, so for example you could matchagainst a literal asterisk with ‘\*’. To match a literalbackslash, use ‘\\’.flags controls various aspects of the matching process, and is aboolean OR of zero or more of the following values (defined in<fnmatch.h>): FNM_PATHNAMEFNM_FILE_NAME string is assumed to be a path name. No wildcard will ever match/. FNM_NOESCAPE Do not interpret backslashes as quoting the following special character. FNM_PERIOD A leading period (at the beginning of string, or ifFNM_PATHNAME after a slash) is not matched by * or? but must be matched explicitly. FNM_LEADING_DIR Means that string also matches pattern if some initial partof string matches, and is followed by / and zero or morecharacters. For example, ‘foo*’ would match either ‘foobar’or ‘foobar/grill’. FNM_CASEFOLD Ignores case when performing the comparison. fopen_unlocked — Extension: FILE * fopen_unlocked ( const char * path , const char * mode ) Opens and returns a FILE pointer via fopen. If theoperating system supports it, ensure that the stream is setup to avoidany multi-threaded locking. Otherwise return the FILE pointerunchanged. freeargv — Extension: void freeargv ( char ** vector ) Free an argument vector that was built using buildargv. Simplyscans through vector, freeing the memory for each argument untilthe terminating NULL is found, and then frees vectoritself. freopen_unlocked — Extension: FILE * freopen_unlocked ( const char * path , const char * mode , FILE * stream ) Opens and returns a FILE pointer via freopen. If theoperating system supports it, ensure that the stream is setup to avoidany multi-threaded locking. Otherwise return the FILE pointerunchanged. get_run_time — Replacement: long get_run_time ( void ) Returns the time used so far, in microseconds. If possible, this isthe time used by this process, else it is the elapsed time since theprocess started. getcwd — Supplemental: char* getcwd ( char * pathname , int len ) Copy the absolute pathname for the current working directory intopathname, which is assumed to point to a buffer of at leastlen bytes, and return a pointer to the buffer. If the currentdirectory's path doesn't fit in len characters, the result isNULL and errno is set. If pathname is a null pointer,getcwd will obtain len bytes of space usingmalloc. getpagesize — Supplemental: int getpagesize ( void ) Returns the number of bytes in a page of memory. This is thegranularity of many of the system memory management routines. Noguarantee is made as to whether or not it is the same as the basicmemory management hardware page size. getpwd — Supplemental: char* getpwd ( void ) Returns the current working directory. This implementation caches theresult on the assumption that the process will not call chdirbetween calls to getpwd. gettimeofday — Supplemental: int gettimeofday ( struct timeval * tp , void * tz ) Writes the current time to tp. This implementation requiresthat tz be NULL. Returns 0 on success, -1 on failure. hex_init — Extension: void hex_init ( void ) Initializes the array mapping the current character set tocorresponding hex values. This function must be called before anycall to hex_p or hex_value. If you fail to call it, adefault ASCII-based table will normally be used on ASCII systems. hex_p — Extension: int hex_p ( int c ) Evaluates to non-zero if the given character is a valid hex character,or zero if it is not. Note that the value you pass will be cast tounsigned char within the macro. hex_value — Extension: unsigned int hex_value ( int c ) Returns the numeric equivalent of the given character when interpretedas a hexidecimal digit. The result is undefined if you pass aninvalid hex digit. Note that the value you pass will be cast tounsigned char within the macro.The hex_value macro returns unsigned int, rather thansigned int, to make it easier to use in parsing addresses fromhex dump files: a signed int would be sign-extended whenconverted to a wider unsigned type — like bfd_vma, on somesystems. index — Supplemental: char* index ( char * s , int c ) Returns a pointer to the first occurrence of the character c inthe string s, or NULL if not found. The use of index isdeprecated in new programs in favor of strchr. insque — Supplemental: void insque ( struct qelem * elem , struct qelem * pred ) remque — Supplemental: void remque ( struct qelem * elem ) Routines to manipulate queues built from doubly linked lists. Theinsque routine inserts elem in the queue immediatelyafter pred. The remque routine removes elem fromits containing queue. These routines expect to be passed pointers tostructures which have as their first members a forward pointer and aback pointer, like this prototype (although no prototype is provided): struct qelem { struct qelem *q_forw; struct qelem *q_back; char q_data[]; }; ISALPHA — Extension: ISALPHA ( c ) ISALNUM — Extension: ISALNUM ( c ) ISBLANK — Extension: ISBLANK ( c ) ISCNTRL — Extension: ISCNTRL ( c ) ISDIGIT — Extension: ISDIGIT ( c ) ISGRAPH — Extension: ISGRAPH ( c ) ISLOWER — Extension: ISLOWER ( c ) ISPRINT — Extension: ISPRINT ( c ) ISPUNCT — Extension: ISPUNCT ( c ) ISSPACE — Extension: ISSPACE ( c ) ISUPPER — Extension: ISUPPER ( c ) ISXDIGIT — Extension: ISXDIGIT ( c ) These twelve macros are defined by safe-ctype.h. Each has thesame meaning as the corresponding macro (with name in lowercase)defined by the standard header ctype.h. For example,ISALPHA returns true for alphabetic characters and false forothers. However, there are two differences between these macros andthose provided by ctype.h: These macros are guaranteed to have well-defined behavior for allvalues representable by signed char and unsigned char, andfor EOF. These macros ignore the current locale; they are true for thesefixed sets of characters: ALPHA A-Za-z ALNUM A-Za-z0-9 BLANK space tab CNTRL !PRINT DIGIT 0-9 GRAPH ALNUM || PUNCT LOWER a-z PRINT GRAPH || space PUNCT `~!@#$%^&*()_-=+[{]}\|;:'",<.>/? SPACE space tab \n \r \f \v UPPER A-Z XDIGIT 0-9A-Fa-f Note that, if the host character set is ASCII or a superset thereof,all these macros will return false for all values of char outsidethe range of 7-bit ASCII. In particular, both ISPRINT and ISCNTRL returnfalse for characters with numeric values from 128 to 255. ISIDNUM — Extension: ISIDNUM ( c ) ISIDST — Extension: ISIDST ( c ) IS_VSPACE — Extension: IS_VSPACE ( c ) IS_NVSPACE — Extension: IS_NVSPACE ( c ) IS_SPACE_OR_NUL — Extension: IS_SPACE_OR_NUL ( c ) IS_ISOBASIC — Extension: IS_ISOBASIC ( c ) These six macros are defined by safe-ctype.h and provideadditional character classes which are useful when doing lexicalanalysis of C or similar languages. They are true for the followingsets of characters: IDNUM A-Za-z0-9_ IDST A-Za-z_ VSPACE \r \n NVSPACE space tab \f \v \0 SPACE_OR_NUL VSPACE || NVSPACE ISOBASIC VSPACE || NVSPACE || PRINT lbasename — Replacement: const char* lbasename ( const char * name ) Given a pointer to a string containing a typical pathname(‘/usr/src/cmd/ls/ls.c’ for example), returns a pointer to thelast component of the pathname (‘ls.c’ in this case). Thereturned pointer is guaranteed to lie within the originalstring. This latter fact is not true of many vendor Clibraries, which return special strings or modify the passedstrings for particular input.In particular, the empty string returns the same empty string,and a path ending in / returns the empty string after it. lrealpath — Replacement: const char* lrealpath ( const char * name ) Given a pointer to a string containing a pathname, returns a canonicalversion of the filename. Symlinks will be resolved, and “.” and “..”components will be simplified. The returned value will be allocated usingmalloc, or NULL will be returned on a memory allocation error. make_relative_prefix — Extension: const char* make_relative_prefix ( const char * progname , const char * bin_prefix , const char * prefix ) Given three paths progname, bin_prefix, prefix,return the path that is in the same position relative toprogname's directory as prefix is relative tobin_prefix. That is, a string starting with the directoryportion of progname, followed by a relative pathname of thedifference between bin_prefix and prefix.If progname does not contain any directory separators,make_relative_prefix will search PATH to find a programnamed progname. Also, if progname is a symbolic link,the symbolic link will be resolved.For example, if bin_prefix is /alpha/beta/gamma/gcc/delta,prefix is /alpha/beta/gamma/omega/, and progname is/red/green/blue/gcc, then this function will return/red/green/blue/../../omega/.The return value is normally allocated via malloc. If norelative prefix can be found, return NULL. make_temp_file — Replacement: char* make_temp_file ( const char * suffix ) Return a temporary file name (as a string) or NULL if unable tocreate one. suffix is a suffix to append to the file name. Thestring is malloced, and the temporary file has been created. memchr — Supplemental: void* memchr ( const void * s , int c , size_t n ) This function searches memory starting at *s for thecharacter c. The search only ends with the first occurrence ofc, or after length characters; in particular, a nullcharacter does not terminate the search. If the character c isfound within length characters of *s, a pointerto the character is returned. If c is not found, then NULL isreturned. memcmp — Supplemental: int memcmp ( const void * x , const void * y , size_t count ) Compares the first count bytes of two areas of memory. Returnszero if they are the same, a value less than zero if x islexically less than y, or a value greater than zero if xis lexically greater than y. Note that lexical order is determinedas if comparing unsigned char arrays. memcpy — Supplemental: void* memcpy ( void * out , const void * in , size_t length ) Copies length bytes from memory region in to regionout. Returns a pointer to out. memmove — Supplemental: void* memmove ( void * from , const void * to , size_t count ) Copies count bytes from memory area from to memory areato, returning a pointer to to. mempcpy — Supplemental: void* mempcpy ( void * out , const void * in , size_t length ) Copies length bytes from memory region in to regionout. Returns a pointer to out + length. memset — Supplemental: void* memset ( void * s , int c , size_t count ) Sets the first count bytes of s to the constant bytec, returning a pointer to s. mkstemps — Replacement: int mkstemps ( char * pattern , int suffix_len ) Generate a unique temporary file name from pattern.pattern has the form: path/ccXXXXXXsuffix suffix_len tells us how long suffix is (it can be zerolength). The last six characters of pattern before suffixmust be ‘XXXXXX’; they are replaced with a string that makes thefilename unique. Returns a file descriptor open on the file forreading and writing. pex_free — Extension: void pex_free ( struct pex_obj obj ) Clean up and free all data associated with obj. pex_get_status — Extension: int pex_get_status ( struct pex_obj * obj , int count , int * vector ) Returns the exit status of all programs run using obj.count is the number of results expected. The results will beplaced into vector. The results are in the order of the callsto pex_run. Returns 0 on error, 1 on success. pex_get_times — Extension: int pex_get_times ( struct pex_obj * obj , int count , struct pex_time * vector ) Returns the process execution times of all programs run usingobj. count is the number of results expected. Theresults will be placed into vector. The results are in theorder of the calls to pex_run. Returns 0 on error, 1 onsuccess.struct pex_time has the following fields of the typeunsigned long: user_seconds,user_microseconds, system_seconds,system_microseconds. On systems which do not support reportingprocess times, all the fields will be set to 0. pex_init — Extension: struct pex_obj * pex_init ( int flags , const char * pname , const char * tempbase ) Prepare to execute one or more programs, with standard output of eachprogram fed to standard input of the next. This is a systemindependent interface to execute a pipeline.flags is a bitwise combination of the following: PEX_RECORD_TIMESPEX_RECORD_TIMES Record subprocess times if possible. PEX_USE_PIPES PEX_USE_PIPES Use pipes for communication between processes, if possible. PEX_SAVE_TEMPS PEX_SAVE_TEMPS Don't delete temporary files used for communication betweenprocesses. pname is the name of program to be executed, used in errormessages. tempbase is a base name to use for any requiredtemporary files; it may be NULL to use a randomly chosen name. pex_input_file — Extension: FILE * pex_input_file ( struct pex_obj * obj , int flags , const char * in_name ) Return a stream for a temporary file to pass to the first program inthe pipeline as input.The name of the input file is chosen according to the same rulespex_run uses to choose output file names, based onin_name, obj and the PEX_SUFFIX bit in flags.Don't call fclose on the returned stream; the first call topex_run closes it automatically.If flags includes PEX_BINARY_OUTPUT, open the stream inbinary mode; otherwise, open it in the default mode. IncludingPEX_BINARY_OUTPUT in flags has no effect on Unix. pex_input_pipe — Extension: FILE * pex_input_pipe ( struct pex_obj * obj , int binary ) Return a stream fp for a pipe connected to the standard input ofthe first program in the pipeline; fp is opened for writing.You must have passed PEX_USE_PIPES to the pex_init callthat returned obj.You must close fp using fclose yourself when you havefinished writing data to the pipeline.The file descriptor underlying fp is marked not to be inheritedby child processes.On systems that do not support pipes, this function returnsNULL, and sets errno to EINVAL. If you wouldlike to write code that is portable to all systems the pexfunctions support, consider using pex_input_file instead.There are two opportunities for deadlock usingpex_input_pipe: Most systems' pipes can buffer only a fixed amount of data; a processthat writes to a full pipe blocks. Thus, if you write to fpbefore starting the first process, you run the risk of blocking whenthere is no child process yet to read the data and allow you tocontinue. pex_input_pipe makes no promises about thesize of the pipe's buffer, so if you need to write any data at allbefore starting the first process in the pipeline, consider usingpex_input_file instead. Using pex_input_pipe and pex_read_output togethermay also cause deadlock. If the output pipe fills up, so that eachprogram in the pipeline is waiting for the next to read more data, andyou fill the input pipe by writing more data to fp, then thereis no way to make progress: the only process that could read data fromthe output pipe is you, but you are blocked on the input pipe. pex_one — Extension: const char * pex_one ( int flags , const char * executable , char * const * argv , const char * pname , const char * outname , const char * errname , int * status , int * err ) An interface to permit the easy execution of asingle program. The return value and most of the parameters are asfor a call to pex_run. flags is restricted to acombination of PEX_SEARCH, PEX_STDERR_TO_STDOUT, andPEX_BINARY_OUTPUT. outname is interpreted as ifPEX_LAST were set. On a successful return, *status willbe set to the exit status of the program. pex_read_output — Extension: FILE * pex_read_output ( struct pex_obj * obj , int binary ) Returns a FILE pointer which may be used to read the standardoutput of the last program in the pipeline. When this is used,PEX_LAST should not be used in a call to pex_run. Afterthis is called, pex_run may no longer be called with the sameobj. binary should be non-zero if the file should beopened in binary mode. Don't call fclose on the returned file;it will be closed by pex_free. pex_run — Extension: const char * pex_run ( struct pex_obj * obj , int flags , const char * executable , char * const * argv , const char * outname , const char * errname , int * err ) Execute one program in a pipeline. On success this returnsNULL. On failure it returns an error message, a staticallyallocated string.obj is returned by a previous call to pex_init.flags is a bitwise combination of the following: PEX_LASTPEX_LAST This must be set on the last program in the pipeline. In particular,it should be set when executing a single program. The standard outputof the program will be sent to outname, or, if outname isNULL, to the standard output of the calling program. Do notset this bit if you want to call pex_read_output(described below). After a call to pex_run with this bit set,pex_run may no longer be called with the same obj. PEX_SEARCH PEX_SEARCH Search for the program using the user's executable search path. PEX_SUFFIX PEX_SUFFIX outname is a suffix. See the description of outname,below. PEX_STDERR_TO_STDOUT PEX_STDERR_TO_STDOUT Send the program's standard error to standard output, if possible. PEX_BINARY_INPUT PEX_BINARY_OUTPUT PEX_BINARY_INPUTPEX_BINARY_OUTPUT The standard input (output) of the program should be read (written) inbinary mode rather than text mode. These flags are ignored on systemswhich do not distinguish binary mode and text mode, such as Unix. Forproper behavior these flags should match appropriately—a call topex_run using PEX_BINARY_OUTPUT should be followed by acall using PEX_BINARY_INPUT. executable is the program to execute. argv is the set ofarguments to pass to the program; normally argv[0] willbe a copy of executable.outname is used to set the name of the file to use for standardoutput. There are two cases in which no output file will be used: if PEX_LAST is not set in flags, and PEX_USE_PIPESwas set in the call to pex_init, and the system supports pipes if PEX_LAST is set in flags, and outname isNULL Otherwise the code will use a file to hold standardoutput. If PEX_LAST is not set, this file is considered to bea temporary file, and it will be removed when no longer needed, unlessPEX_SAVE_TEMPS was set in the call to pex_init.There are two cases to consider when setting the name of the file tohold standard output. PEX_SUFFIX is set in flags. In this caseoutname may not be NULL. If the tempbase parameterto pex_init was not NULL, then the output file name isthe concatenation of tempbase and outname. Iftempbase was NULL, then the output file name is a randomfile name ending in outname. PEX_SUFFIX was not set in flags. In thiscase, if outname is not NULL, it is used as the outputfile name. If outname is NULL, and tempbase wasnot NULL, the output file name is randomly chosen usingtempbase. Otherwise the output file name is chosen completelyat random. errname is the file name to use for standard error output. Ifit is NULL, standard error is the same as the caller's.Otherwise, standard error is written to the named file.On an error return, the code sets *err to an errnovalue, or to 0 if there is no relevant errno. pex_run_in_environment — Extension: const char * pex_run_in_environment ( struct pex_obj * obj , int flags , const char * executable , char * const * argv , char * const * env , int env_size , const char * outname , const char * errname , int * err ) Execute one program in a pipeline, permitting the environment for theprogram to be specified. Behaviour and parameters not listed below areas for pex_run.env is the environment for the child process, specified as an array ofcharacter pointers. Each element of the array should point to a string of theform VAR=VALUE, with the exception of the last element that must beNULL. pexecute — Extension: int pexecute ( const char * program , char * const * argv , const char * this_pname , const char * temp_base , char ** errmsg_fmt , char ** errmsg_arg , int flags ) This is the old interface to execute one or more programs. It isstill supported for compatibility purposes, but is no longerdocumented. psignal — Supplemental: void psignal ( unsigned signo , char * message ) Print message to the standard error, followed by a colon,followed by the description of the signal specified by signo,followed by a newline. putenv — Supplemental: int putenv ( const char * string ) Uses setenv or unsetenv to put string intothe environment or remove it. If string is of the form‘name=value’ the string is added; if no ‘=’ is present thename is unset/removed. pwait — Extension: int pwait ( int pid , int * status , int flags ) Another part of the old execution interface. random — Supplement: long int random ( void ) srandom — Supplement: void srandom ( unsigned int seed ) initstate — Supplement: void* initstate ( unsigned int seed , void * arg_state , unsigned long n ) setstate — Supplement: void* setstate ( void * arg_state ) Random number functions. random returns a random number in therange 0 to LONG_MAX. srandom initializes the randomnumber generator to some starting point determined by seed(else, the values returned by random are always the same for eachrun of the program). initstate and setstate allow fine-grainedcontrol over the state of the random number generator. reconcat — Extension: char* reconcat ( char * optr , const char * s1 , , NULL ) Same as concat, except that if optr is not NULL itis freed after the string is created. This is intended to be usefulwhen you're extending an existing string or building up a string in aloop: str = reconcat (str, "pre-", str, NULL); rename — Supplemental: int rename ( const char * old , const char * new ) Renames a file from old to new. If new alreadyexists, it is removed. rindex — Supplemental: char* rindex ( const char * s , int c ) Returns a pointer to the last occurrence of the character c inthe string s, or NULL if not found. The use of rindex isdeprecated in new programs in favor of strrchr. setenv — Supplemental: int setenv ( const char * name , const char * value , int overwrite ) unsetenv — Supplemental: void unsetenv ( const char * name ) setenv adds name to the environment with valuevalue. If the name was already present in the environment,the new value will be stored only if overwrite is nonzero.The companion unsetenv function removes name from theenvironment. This implementation is not safe for multithreaded code. signo_max — Extension: int signo_max ( void ) Returns the maximum signal value for which a corresponding symbolicname or message is available. Note that in the case where we use thesys_siglist supplied by the system, it is possible for there tobe more symbolic names than messages, or vice versa. In fact, themanual page for psignal(3b) explicitly warns that one shouldcheck the size of the table (NSIG) before indexing it, sincenew signal codes may be added to the system before they are added tothe table. Thus NSIG might be smaller than value implied bythe largest signo value defined in <signal.h>.We return the maximum value that can be used to obtain a meaningfulsymbolic name or message. sigsetmask — Supplemental: int sigsetmask ( int set ) Sets the signal mask to the one provided in set and returnsthe old mask (which, for libiberty's implementation, will alwaysbe the value 1). snprintf — Supplemental: int snprintf ( char * buf , size_t n , const char * format , ... ) This function is similar to sprintf, but it will print at most ncharacters. On error the return value is -1, otherwise it returns thenumber of characters that would have been printed had n beensufficiently large, regardless of the actual value of n. Notesome pre-C99 system libraries do not implement this correctly so userscannot generally rely on the return value if the system version ofthis function is used. spaces — Extension: char* spaces ( int count ) Returns a pointer to a memory region filled with the specifiednumber of spaces and null terminated. The returned pointer isvalid until at least the next call. stpcpy — Supplemental: char* stpcpy ( char * dst , const char * src ) Copies the string src into dst. Returns a pointer todst + strlen(src). stpncpy — Supplemental: char* stpncpy ( char * dst , const char * src , size_t len ) Copies the string src into dst, copying exactly lenand padding with zeros if necessary. If len < strlen(src)then return dst + len, otherwise returns dst +strlen(src). strcasecmp — Supplemental: int strcasecmp ( const char * s1 , const char * s2 ) A case-insensitive strcmp. strchr — Supplemental: char* strchr ( const char * s , int c ) Returns a pointer to the first occurrence of the character c inthe string s, or NULL if not found. If c is itself thenull character, the results are undefined. strdup — Supplemental: char* strdup ( const char * s ) Returns a pointer to a copy of s in memory obtained frommalloc, or NULL if insufficient memory was available. strerrno — Replacement: const char* strerrno ( int errnum ) Given an error number returned from a system call (typically returnedin errno), returns a pointer to a string containing thesymbolic name of that error number, as found in <errno.h>.If the supplied error number is within the valid range of indices forsymbolic names, but no name is available for the particular errornumber, then returns the string ‘Error num’, where numis the error number.If the supplied error number is not within the range of validindices, then returns NULL.The contents of the location pointed to are only guaranteed to bevalid until the next call to strerrno. strerror — Supplemental: char* strerror ( int errnoval ) Maps an errno number to an error message string, the contentsof which are implementation defined. On systems which have theexternal variables sys_nerr and sys_errlist, thesestrings will be the same as the ones used by perror.If the supplied error number is within the valid range of indices forthe sys_errlist, but no message is available for the particularerror number, then returns the string ‘Error num’, wherenum is the error number.If the supplied error number is not a valid index intosys_errlist, returns NULL.The returned string is only guaranteed to be valid only until thenext call to strerror. strncasecmp — Supplemental: int strncasecmp ( const char * s1 , const char * s2 ) A case-insensitive strncmp. strncmp — Supplemental: int strncmp ( const char * s1 , const char * s2 , size_t n ) Compares the first n bytes of two strings, returning a value asstrcmp. strndup — Extension: char* strndup ( const char * s , size_t n ) Returns a pointer to a copy of s with at most n charactersin memory obtained from malloc, or NULL if insufficientmemory was available. The result is always NUL terminated. strrchr — Supplemental: char* strrchr ( const char * s , int c ) Returns a pointer to the last occurrence of the character c inthe string s, or NULL if not found. If c is itself thenull character, the results are undefined. strsignal — Supplemental: const char * strsignal ( int signo ) Maps an signal number to an signal message string, the contents ofwhich are implementation defined. On systems which have the externalvariable sys_siglist, these strings will be the same as theones used by psignal().If the supplied signal number is within the valid range of indices forthe sys_siglist, but no message is available for the particularsignal number, then returns the string ‘Signal num’, wherenum is the signal number.If the supplied signal number is not a valid index intosys_siglist, returns NULL.The returned string is only guaranteed to be valid only until the nextcall to strsignal. strsigno — Extension: const char* strsigno ( int signo ) Given an signal number, returns a pointer to a string containing thesymbolic name of that signal number, as found in <signal.h>.If the supplied signal number is within the valid range of indices forsymbolic names, but no name is available for the particular signalnumber, then returns the string ‘Signal num’, wherenum is the signal number.If the supplied signal number is not within the range of validindices, then returns NULL.The contents of the location pointed to are only guaranteed to bevalid until the next call to strsigno. strstr — Supplemental: char* strstr ( const char * string , const char * sub ) This function searches for the substring sub in the stringstring, not including the terminating null characters. A pointerto the first occurrence of sub is returned, or NULL if thesubstring is absent. If sub points to a string with zerolength, the function returns string. strtod — Supplemental: double strtod ( const char * string , char ** endptr ) This ISO C function converts the initial portion of string to adouble. If endptr is not NULL, a pointer to thecharacter after the last character used in the conversion is stored inthe location referenced by endptr. If no conversion isperformed, zero is returned and the value of string is stored inthe location referenced by endptr. strtoerrno — Extension: int strtoerrno ( const char * name ) Given the symbolic name of a error number (e.g., EACCES), map itto an errno value. If no translation is found, returns 0. strtol — Supplemental: long int strtol ( const char * string , char ** endptr , int base ) strtoul — Supplemental: unsigned long int strtoul ( const char * string , char ** endptr , int base ) The strtol function converts the string in string to along integer value according to the given base, which must bebetween 2 and 36 inclusive, or be the special value 0. If baseis 0, strtol will look for the prefixes 0 and 0xto indicate bases 8 and 16, respectively, else default to base 10.When the base is 16 (either explicitly or implicitly), a prefix of0x is allowed. The handling of endptr is as that ofstrtod above. The strtoul function is the same, exceptthat the converted value is unsigned. strtosigno — Extension: int strtosigno ( const char * name ) Given the symbolic name of a signal, map it to a signal number. If notranslation is found, returns 0. strverscmp — Function: int strverscmp ( const char * s1 , const char * s2 ) The strverscmp function compares the string s1 againsts2, considering them as holding indices/version numbers. Returnvalue follows the same conventions as found in the strverscmpfunction. In fact, if s1 and s2 contain no digits,strverscmp behaves like strcmp.Basically, we compare strings normally (character by character), untilwe find a digit in each string - then we enter a special comparisonmode, where each sequence of digits is taken as a whole. If we reach theend of these two parts without noticing a difference, we return to thestandard comparison mode. There are two types of numeric parts:"integral" and "fractional" (those begin with a '0'). The typesof the numeric parts affect the way we sort them: integral/integral: we compare values as you would expect. fractional/integral: the fractional part is less than the integral one.Again, no surprise. fractional/fractional: the things become a bit more complex.If the common prefix contains only leading zeroes, the longest part is lessthan the other one; else the comparison behaves normally. strverscmp ("no digit", "no digit") => 0 // same behavior as strcmp. strverscmp ("item#99", "item#100") => <0 // same prefix, but 99 < 100. strverscmp ("alpha1", "alpha001") => >0 // fractional part inferior to integral one. strverscmp ("part1_f012", "part1_f01") => >0 // two fractional parts. strverscmp ("foo.009", "foo.0") => <0 // idem, but with leading zeroes only. This function is especially useful when dealing with filename sorting,because filenames frequently hold indices/version numbers. tmpnam — Supplemental: char* tmpnam ( char * s ) This function attempts to create a name for a temporary file, whichwill be a valid file name yet not exist when tmpnam checks forit. s must point to a buffer of at least L_tmpnam bytes,or be NULL. Use of this function creates a security risk, and it mustnot be used in new projects. Use mkstemp instead. unlink_if_ordinary — Supplemental: int unlink_if_ordinary ( const char* ) Unlinks the named file, unless it is special (e.g. a device file).Returns 0 when the file was unlinked, a negative value (and errno set) whenthere was an error deleting the file, and a positive value if no attemptwas made to unlink the file because it is special. unlock_std_streams — Extension: void unlock_std_streams ( void ) If the OS supports it, ensure that the standard I/O streams,stdin, stdout and stderr are setup to avoid anymulti-threaded locking. Otherwise do nothing. unlock_stream — Extension: void unlock_stream ( FILE * stream ) If the OS supports it, ensure that the supplied stream is setup toavoid any multi-threaded locking. Otherwise leave the FILEpointer unchanged. If the stream is NULL do nothing. vasprintf — Extension: int vasprintf ( char ** resptr , const char * format , va_list args ) Like vsprintf, but instead of passing a pointer to a buffer,you pass a pointer to a pointer. This function will compute the sizeof the buffer needed, allocate memory with malloc, and store apointer to the allocated memory in *resptr. The valuereturned is the same as vsprintf would return. If memory couldnot be allocated, minus one is returned and NULL is stored in*resptr. vfork — Supplemental: int vfork ( void ) Emulates vfork by calling fork and returning its value. vprintf — Supplemental: int vprintf ( const char * format , va_list ap ) vfprintf — Supplemental: int vfprintf ( FILE * stream , const char * format , va_list ap ) vsprintf — Supplemental: int vsprintf ( char * str , const char * format , va_list ap ) These functions are the same as printf, fprintf, andsprintf, respectively, except that they are called with ava_list instead of a variable number of arguments. Note thatthey do not call va_end; this is the application'sresponsibility. In libiberty they are implemented in terms of thenonstandard but common function _doprnt. vsnprintf — Supplemental: int vsnprintf ( char * buf , size_t n , const char * format , va_list ap ) This function is similar to vsprintf, but it will print at mostn characters. On error the return value is -1, otherwise itreturns the number of characters that would have been printed hadn been sufficiently large, regardless of the actual value ofn. Note some pre-C99 system libraries do not implement thiscorrectly so users cannot generally rely on the return value if thesystem version of this function is used. waitpid — Supplemental: int waitpid ( int pid , int * status , int ) This is a wrapper around the wait function. Any “special”values of pid depend on your implementation of wait, asdoes the return value. The third argument is unused in libiberty. xatexit — Function: int xatexit ( void ( * fn ) ( void ) ) Behaves as the standard atexit function, but with no limit onthe number of registered functions. Returns 0 on success, or −1 onfailure. If you use xatexit to register functions, you must usexexit to terminate your program. xcalloc — Replacement: void* xcalloc ( size_t nelem , size_t elsize ) Allocate memory without fail, and set it to zero. This routine functionslike calloc, but will behave the same as xmalloc if memorycannot be found. xexit — Replacement: void xexit ( int code ) Terminates the program. If any functions have been registered withthe xatexit replacement function, they will be called first.Termination is handled via the system's normal exit call. xmalloc — Replacement: void* xmalloc ( size_t ) Allocate memory without fail. If malloc fails, this will printa message to stderr (using the name set byxmalloc_set_program_name,if any) and then call xexit. Note that it is therefore safe fora program to contain #define malloc xmalloc in its source. xmalloc_failed — Replacement: void xmalloc_failed ( size_t ) This function is not meant to be called by client code, and is listedhere for completeness only. If any of the allocation routines fail, thisfunction will be called to print an error message and terminate execution. xmalloc_set_program_name — Replacement: void xmalloc_set_program_name ( const char * name ) You can use this to set the name of the program used byxmalloc_failed when printing a failure message. xmemdup — Replacement: void* xmemdup ( void * input , size_t copy_size , size_t alloc_size ) Duplicates a region of memory without fail. First, alloc_size bytesare allocated, then copy_size bytes from input are copied intoit, and the new memory is returned. If fewer bytes are copied than wereallocated, the remaining memory is zeroed. xrealloc — Replacement: void* xrealloc ( void * ptr , size_t size ) Reallocate memory without fail. This routine functions like realloc,but will behave the same as xmalloc if memory cannot be found. xstrdup — Replacement: char* xstrdup ( const char * s ) Duplicates a character string without fail, using xmalloc toobtain memory. xstrerror — Replacement: char* xstrerror ( int errnum ) Behaves exactly like the standard strerror function, butwill never return a NULL pointer. xstrndup — Replacement: char* xstrndup ( const char * s , size_t n ) Returns a pointer to a copy of s with at most n characterswithout fail, using xmalloc to obtain memory. The result isalways NUL terminated. Licenses GNU LESSER GENERAL PUBLIC LICENSE LGPL, Lesser General Public License
Version 2.1, February 1999
Copyright © 1991, 1999 Free Software Foundation, Inc. 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software—to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software—typically libraries—of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the Lesser General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a “work based on the library” and a “work that uses the library”. The former contains code derived from the library, whereas the latter must be combined with the library in order to run. This License Agreement applies to any software library or other programwhich contains a notice placed by the copyright holder or otherauthorized party saying it may be distributed under the terms of thisLesser General Public License (also called “this License”). Eachlicensee is addressed as “you”. A “library” means a collection of software functions and/or dataprepared so as to be conveniently linked with application programs(which use some of those functions and data) to form executables. The “Library”, below, refers to any such software library or workwhich has been distributed under these terms. A “work based on theLibrary” means either the Library or any derivative work undercopyright law: that is to say, a work containing the Library or aportion of it, either verbatim or with modifications and/or translatedstraightforwardly into another language. (Hereinafter, translation isincluded without limitation in the term “modification”.) “Source code” for a work means the preferred form of the work formaking modifications to it. For a library, complete source code meansall the source code for all modules it contains, plus any associatedinterface definition files, plus the scripts used to control compilationand installation of the library. Activities other than copying, distribution and modification are notcovered by this License; they are outside its scope. The act ofrunning a program using the Library is not restricted, and output fromsuch a program is covered only if its contents constitute a work basedon the Library (independent of the use of the Library in a tool forwriting it). Whether that is true depends on what the Library doesand what the program that uses the Library does. You may copy and distribute verbatim copies of the Library'scomplete source code as you receive it, in any medium, provided thatyou conspicuously and appropriately publish on each copy anappropriate copyright notice and disclaimer of warranty; keep intactall the notices that refer to this License and to the absence of anywarranty; and distribute a copy of this License along with theLibrary. You may charge a fee for the physical act of transferring a copy,and you may at your option offer warranty protection in exchange for afee. You may modify your copy or copies of the Library or any portionof it, thus forming a work based on the Library, and copy anddistribute such modifications or work under the terms of Section 1above, provided that you also meet all of these conditions: The modified work must itself be a software library. You must cause the files modified to carry prominent noticesstating that you changed the files and the date of any change. You must cause the whole of the work to be licensed at nocharge to all third parties under the terms of this License. If a facility in the modified Library refers to a function or atable of data to be supplied by an application program that usesthe facility, other than as an argument passed when the facilityis invoked, then you must make a good faith effort to ensure that,in the event an application does not supply such function ortable, the facility still operates, and performs whatever part ofits purpose remains meaningful.(For example, a function in a library to compute square roots hasa purpose that is entirely well-defined independent of theapplication. Therefore, Subsection 2d requires that anyapplication-supplied function or table used by this function mustbe optional: if the application does not supply it, the squareroot function must still compute square roots.) These requirements apply to the modified work as a whole. Ifidentifiable sections of that work are not derived from the Library,and can be reasonably considered independent and separate works inthemselves, then this License, and its terms, do not apply to thosesections when you distribute them as separate works. But when youdistribute the same sections as part of a whole which is a work basedon the Library, the distribution of the whole must be on the terms ofthis License, whose permissions for other licensees extend to theentire whole, and thus to each and every part regardless of who wroteit.Thus, it is not the intent of this section to claim rights or contestyour rights to work written entirely by you; rather, the intent is toexercise the right to control the distribution of derivative orcollective works based on the Library.In addition, mere aggregation of another work not based on the Librarywith the Library (or with a work based on the Library) on a volume ofa storage or distribution medium does not bring the other work underthe scope of this License. You may opt to apply the terms of the ordinary GNU General PublicLicense instead of this License to a given copy of the Library. To dothis, you must alter all the notices that refer to this License, sothat they refer to the ordinary GNU General Public License, version 2,instead of to this License. (If a newer version than version 2 of theordinary GNU General Public License has appeared, then you can specifythat version instead if you wish.) Do not make any other change inthese notices. Once this change is made in a given copy, it is irreversible forthat copy, so the ordinary GNU General Public License applies to allsubsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code ofthe Library into a program that is not a library. You may copy and distribute the Library (or a portion orderivative of it, under Section 2) in object code or executable formunder the terms of Sections 1 and 2 above provided that you accompanyit with the complete corresponding machine-readable source code, whichmust be distributed under the terms of Sections 1 and 2 above on amedium customarily used for software interchange. If distribution of object code is made by offering access to copyfrom a designated place, then offering equivalent access to copy thesource code from the same place satisfies the requirement todistribute the source code, even though third parties are notcompelled to copy the source along with the object code. A program that contains no derivative of any portion of theLibrary, but is designed to work with the Library by being compiled orlinked with it, is called a “work that uses the Library”. Such awork, in isolation, is not a derivative work of the Library, andtherefore falls outside the scope of this License. However, linking a “work that uses the Library” with the Librarycreates an executable that is a derivative of the Library (because itcontains portions of the Library), rather than a “work that uses thelibrary”. The executable is therefore covered by this License.Section 6 states terms for distribution of such executables. When a “work that uses the Library” uses material from a header filethat is part of the Library, the object code for the work may be aderivative work of the Library even though the source code is not.Whether this is true is especially significant if the work can belinked without the Library, or if the work is itself a library. Thethreshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, datastructure layouts and accessors, and small macros and small inlinefunctions (ten lines or less in length), then the use of the objectfile is unrestricted, regardless of whether it is legally a derivativework. (Executables containing this object code plus portions of theLibrary will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you maydistribute the object code for the work under the terms of Section 6.Any executables containing that work also fall under Section 6,whether or not they are linked directly with the Library itself. As an exception to the Sections above, you may also combine orlink a “work that uses the Library” with the Library to produce awork containing portions of the Library, and distribute that workunder terms of your choice, provided that the terms permitmodification of the work for the customer's own use and reverseengineering for debugging such modifications. You must give prominent notice with each copy of the work that theLibrary is used in it and that the Library and its use are covered bythis License. You must supply a copy of this License. If the workduring execution displays copyright notices, you must include thecopyright notice for the Library among them, as well as a referencedirecting the user to the copy of this License. Also, you must do oneof these things: Accompany the work with the complete correspondingmachine-readable source code for the Library including whateverchanges were used in the work (which must be distributed underSections 1 and 2 above); and, if the work is an executable linkedwith the Library, with the complete machine-readable “work thatuses the Library”, as object code and/or source code, so that theuser can modify the Library and then relink to produce a modifiedexecutable containing the modified Library. (It is understoodthat the user who changes the contents of definitions files in theLibrary will not necessarily be able to recompile the applicationto use the modified definitions.) Use a suitable shared library mechanism for linking with the Library. Asuitable mechanism is one that (1) uses at run time a copy of thelibrary already present on the user's computer system, rather thancopying library functions into the executable, and (2) will operateproperly with a modified version of the library, if the user installsone, as long as the modified version is interface-compatible with theversion that the work was made with. Accompany the work with a written offer, valid for atleast three years, to give the same user the materialsspecified in Subsection 6a, above, for a charge no morethan the cost of performing this distribution. If distribution of the work is made by offering access to copyfrom a designated place, offer equivalent access to copy the abovespecified materials from the same place. Verify that the user has already received a copy of thesematerials or that you have already sent this user a copy. For an executable, the required form of the “work that uses theLibrary” must include any data and utility programs needed forreproducing the executable from it. However, as a special exception,the materials to be distributed need not include anything that isnormally distributed (in either source or binary form) with the majorcomponents (compiler, kernel, and so on) of the operating system onwhich the executable runs, unless that component itself accompanies theexecutable. It may happen that this requirement contradicts the licenserestrictions of other proprietary libraries that do not normallyaccompany the operating system. Such a contradiction means you cannotuse both them and the Library together in an executable that youdistribute. You may place library facilities that are a work based on theLibrary side-by-side in a single library together with other libraryfacilities not covered by this License, and distribute such a combinedlibrary, provided that the separate distribution of the work based onthe Library and of the other library facilities is otherwisepermitted, and provided that you do these two things: Accompany the combined library with a copy of the same workbased on the Library, uncombined with any other libraryfacilities. This must be distributed under the terms of theSections above. Give prominent notice with the combined library of the factthat part of it is a work based on the Library, and explainingwhere to find the accompanying uncombined form of the same work. You may not copy, modify, sublicense, link with, or distributethe Library except as expressly provided under this License. Anyattempt otherwise to copy, modify, sublicense, link with, ordistribute the Library is void, and will automatically terminate yourrights under this License. However, parties who have received copies,or rights, from you under this License will not have their licensesterminated so long as such parties remain in full compliance. You are not required to accept this License, since you have notsigned it. However, nothing else grants you permission to modify ordistribute the Library or its derivative works. These actions areprohibited by law if you do not accept this License. Therefore, bymodifying or distributing the Library (or any work based on theLibrary), you indicate your acceptance of this License to do so, andall its terms and conditions for copying, distributing or modifyingthe Library or works based on it. Each time you redistribute the Library (or any work based on theLibrary), the recipient automatically receives a license from theoriginal licensor to copy, distribute, link with or modify the Librarysubject to these terms and conditions. You may not impose any furtherrestrictions on the recipients' exercise of the rights granted herein.You are not responsible for enforcing compliance by third parties withthis License. If, as a consequence of a court judgment or allegation of patentinfringement or for any other reason (not limited to patent issues),conditions are imposed on you (whether by court order, agreement orotherwise) that contradict the conditions of this License, they do notexcuse you from the conditions of this License. If you cannotdistribute so as to satisfy simultaneously your obligations under thisLicense and any other pertinent obligations, then as a consequence youmay not distribute the Library at all. For example, if a patentlicense would not permit royalty-free redistribution of the Library byall those who receive copies directly or indirectly through you, thenthe only way you could satisfy both it and this License would be torefrain entirely from distribution of the Library.If any portion of this section is held invalid or unenforceable under anyparticular circumstance, the balance of the section is intended to apply,and the section as a whole is intended to apply in other circumstances.It is not the purpose of this section to induce you to infringe anypatents or other property right claims or to contest validity of anysuch claims; this section has the sole purpose of protecting theintegrity of the free software distribution system which isimplemented by public license practices. Many people have madegenerous contributions to the wide range of software distributedthrough that system in reliance on consistent application of thatsystem; it is up to the author/donor to decide if he or she is willingto distribute software through any other system and a licensee cannotimpose that choice.This section is intended to make thoroughly clear what is believed tobe a consequence of the rest of this License. If the distribution and/or use of the Library is restricted incertain countries either by patents or by copyrighted interfaces, theoriginal copyright holder who places the Library under this License may addan explicit geographical distribution limitation excluding those countries,so that distribution is permitted only in or among countries not thusexcluded. In such case, this License incorporates the limitation as ifwritten in the body of this License. The Free Software Foundation may publish revised and/or newversions of the Lesser General Public License from time to time.Such new versions will be similar in spirit to the present version,but may differ in detail to address new problems or concerns.Each version is given a distinguishing version number. If the Libraryspecifies a version number of this License which applies to it and“any later version”, you have the option of following the terms andconditions either of that version or of any later version published bythe Free Software Foundation. If the Library does not specify alicense version number, you may choose any version ever published bythe Free Software Foundation. If you wish to incorporate parts of the Library into other freeprograms whose distribution conditions are incompatible with these,write to the author to ask for permission. For software which iscopyrighted by the Free Software Foundation, write to the FreeSoftware Foundation; we sometimes make exceptions for this. Ourdecision will be guided by the two goals of preserving the free statusof all derivatives of our free software and of promoting the sharingand reuse of software generally. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NOWARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OROTHER PARTIES PROVIDE THE LIBRARY “AS IS” WITHOUT WARRANTY OF ANYKIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THEIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULARPURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THELIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUMETHE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO INWRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFYAND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOUFOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL ORCONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THELIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEINGRENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR AFAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IFSUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCHDAMAGES. How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found. one line to give the library's name and an idea of what it does. Copyright (C) year name of author This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a “copyright disclaimer” for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. signature of Ty Coon, 1 April 1990 Ty Coon, President of Vice That's all there is to it!
BSD Copyright © 1990 Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyrightnotice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyrightnotice, this list of conditions and the following disclaimer in thedocumentation and/or other materials provided with the distribution. [rescinded 22 July 1999] Neither the name of the University nor the names of its contributorsmay be used to endorse or promote products derived from this softwarewithout specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
xreflabel="Index" id="Index"> Index A alignment (in obstacks), see alloca, see allocation (obstacks), see asprintf, see atexit, see B basename, see bcmp, see bcopy, see bsearch, see buildargv, see bzero, see C calloc, see changing the size of a block (obstacks), see choose_temp_base, see choose_tmpdir, see chunks, see clock, see concat, see D dupargv, see E efficiency and obstacks, see efficiency of chunks, see errno_max, see error reporting, see exit handlers, see expandargv, see extensions, see F fdmatch, see fdopen_unlocked, see ffs, see fnmatch, see fopen_unlocked, see freeargv, see freeing (obstacks), see freopen_unlocked, see functions, extension, see functions, missing, see functions, replacement, see functions, supplemental, see G get_run_time, see getcwd, see getpagesize, see getpwd, see gettimeofday, see growing objects (in obstacks), see H hex_init, see hex_p, see hex_value, see HOST_CHARSET, see how to use, see I index, see initstate, see insque, see IS_ISOBASIC, see IS_NVSPACE, see IS_SPACE_OR_NUL, see IS_VSPACE, see ISALNUM, see ISALPHA, see ISBLANK, see ISCNTRL, see ISDIGIT, see ISGRAPH, see ISIDNUM, see ISIDST, see ISLOWER, see ISPRINT, see ISPUNCT, see ISSPACE, see ISUPPER, see ISXDIGIT, see L lbasename, see LGPL, Lesser General Public License, see libiberty usage, see lrealpath, see M macros, see make_relative_prefix, see make_temp_file, see memchr, see memcmp, see memcpy, see memmove, see memory allocation, see mempcpy, see memset, see mkstemps, see O obstack status, see obstack.h, see obstack_1grow, see obstack_1grow_fast, see obstack_alignment_mask, see obstack_alloc, see obstack_alloc_failed_handler, see obstack_base, see obstack_blank, see obstack_blank_fast, see obstack_chunk_alloc, see obstack_chunk_free, see obstack_chunk_size, see obstack_copy, see obstack_copy0, see obstack_finish, see obstack_free, see obstack_grow, see obstack_grow0, see obstack_init, see obstack_int_grow, see obstack_int_grow_fast, see obstack_next_free, see obstack_object_size, see obstack_object_size, see obstack_ptr_grow, see obstack_ptr_grow_fast, see obstack_room, see obstacks, see P PEX_BINARY_INPUT, see PEX_BINARY_OUTPUT, see pex_free, see pex_get_status, see pex_get_times, see pex_init, see pex_input_file, see pex_input_pipe, see PEX_LAST, see pex_one, see pex_read_output, see PEX_RECORD_TIMES, see pex_run, see pex_run_in_environment, see PEX_SAVE_TEMPS, see PEX_SEARCH, see PEX_STDERR_TO_STDOUT, see PEX_SUFFIX, see PEX_USE_PIPES, see pexecute, see psignal, see putenv, see pwait, see R random, see reconcat, see remque, see rename, see replacement functions, see rindex, see S setenv, see setstate, see shrinking objects, see signo_max, see sigsetmask, see snprintf, see spaces, see srandom, see status of obstack, see stpcpy, see stpncpy, see strcasecmp, see strchr, see strdup, see strerrno, see strerror, see strncasecmp, see strncmp, see strndup, see strrchr, see strsignal, see strsigno, see strstr, see strtod, see strtoerrno, see strtol, see strtosigno, see strtoul, see strverscmp, see supplemental functions, see T tmpnam, see U unlink_if_ordinary, see unlock_std_streams, see unlock_stream, see unsetenv, see using libiberty, see V vasprintf, see vfork, see vfprintf, see vprintf, see vsnprintf, see vsprintf, see W waitpid, see X xatexit, see xcalloc, see xexit, see xmalloc, see xmalloc_failed, see xmalloc_set_program_name, see xmemdup, see xrealloc, see xstrdup, see xstrerror, see xstrndup, see