Function, Variable, and Macro Listing.#
-
void *alloca(size_t size)#
This function allocates memory which will be automatically reclaimed after the procedure exits. The
libibertyimplementation does not free the memory immediately but will do so eventually during subsequent calls to this function. Memory is allocated usingxmallocunder normal circumstances.The header file
alloca-conf.hcan be used in conjunction with the GNU Autoconf testAC_FUNC_ALLOCAto test for and properly make available this function. TheAC_FUNC_ALLOCAtest requires that client code use a block of preprocessor code to be safe (see the Autoconf manual for more); this header incorporates that logic and more, including the possibility of a GCC built-in function.
-
int asprintf(char **resptr, const char *format, ...)#
Like
sprintf, but instead of passing a pointer to a buffer, you pass a pointer to a pointer. This function will compute the size of the buffer needed, allocate memory withmalloc, and store a pointer to the allocated memory in*resptr. The value returned is the same assprintfwould return. If memory could not be allocated, minus one is returned andNULLis stored in*resptr.
-
int atexit(void (*f)())#
Causes function
fto be called at exit. Returns 0.
-
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.
-
int bcmp(char *x, char *y, int count)#
Compares the first
countbytes of two areas of memory. Returns zero if they are the same, nonzero otherwise. Returns zero ifcountis zero. A nonzero result only indicates a difference, it does not indicate any sorting order (say, by having a positive result meanxsorts beforey).
-
void bcopy(char *in, char *out, int length)#
Copies
lengthbytes from memory regioninto regionout. The use ofbcopyis deprecated in new programs.
-
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
nmembelements pointed to bybasefor a member that matches the object pointed to bykey. The size of each member is specified bysize. The array contents should be sorted in ascending order according to thecomparcomparison function. This routine should take two arguments pointing to thekeyand to an array member, in that order, and should return an integer less than, equal to, or greater than zero if thekeyobject is respectively less than, matching, or greater than the array member.
-
void *bsearch_r(const void *key, const void *base, size_t nmemb, size_t size, int (*compar)(const void*, const void*, void*), void *arg)#
Performs a search over an array of
nmembelements pointed to bybasefor a member that matches the object pointed to bykey. The size of each member is specified bysize. The array contents should be sorted in ascending order according to thecomparcomparison function. This routine should take three arguments: the first two point to thekeyand to an array member, and the last is passed down unchanged frombsearch_r‘s last argument. It should return an integer less than, equal to, or greater than zero if thekeyobject is respectively less than, matching, or greater than the array member.
-
char **buildargv(char *sp)#
Given a pointer to a string, parse the string extracting fields separated by whitespace and optionally enclosed within either single or double quotes (which are stripped off), and build a vector of pointers to copies of the string for each field. The input string remains unchanged. The last element of the vector is followed by a
NULLelement.All of the memory for the pointer array and copies of the string is obtained from
xmalloc. All of the memory can be returned to the system with the single function callfreeargv, which takes the returned result ofbuildargv, as it’s argument.Returns a pointer to the argument vector if successful. Returns
NULLifspisNULLor if there is insufficient memory to complete building the argument vector.If the input is a null string (as opposed to a
NULLpointer), then buildarg returns an argument vector that has one arg, a null string.
-
void bzero(char *mem, int count)#
Zeros
countbytes starting atmem. Use of this function is deprecated in favor ofmemset.
-
void *calloc(size_t nelem, size_t elsize)#
Uses
mallocto allocate storage fornelemobjects ofelsizebytes each, then zeros the memory.
-
int canonical_filename_eq(const char *a, const char *b)#
Return non-zero if file names
aandbare equivalent. This function compares the canonical versions of the filenames as returned bylrealpath(), so that so that different file names pointing to the same underlying file are treated as being identical.
-
char *choose_temp_base(void)#
Return a prefix for temporary file names or
NULLif unable to find one. The current directory is chosen if all else fails so the program is exited if a temporary directory can’t be found (mktempfails). The buffer for the result is obtained withxmalloc.This function is provided for backwards compatibility only. Its use is not recommended.
-
const char *choose_tmpdir()#
Returns a pointer to a directory path suitable for creating temporary files in.
-
long clock(void)#
Returns an approximation of the CPU time used by the process as a
clock_t; divide this number byCLOCKS_PER_SECto get the number of seconds used.
- char* concat (const char *s1, const char *s2, ..., NULL)
Concatenate zero or more of strings and return the result in freshly
xmalloced memory. The argument list is terminated by the firstNULLpointer encountered. Pointers to empty strings are ignored.
-
int countargv(char *const *argv)#
Return the number of elements in
argv. Returns zero ifargvis NULL.
-
unsigned int crc32(const unsigned char *buf, int len, unsigned int init)#
Compute the 32-bit CRC of
bufwhich has lengthlen. The starting value isinit; this may be used to compute the CRC of data split across multiple buffers by passing the return value of each call as theinitparameter of the next.This is used by the gdb remote protocol for the
qCRCcommand. In order to get the same results as gdb for a block of data, you must pass the first CRC parameter as0xffffffff.This CRC can be specified as:
- Width32
Poly : 0x04c11db7 Init : parameter, typically 0xffffffff RefIn : false RefOut : false XorOut : 0
This differs from the “standard” CRC-32 algorithm in that the values are not reflected, and there is no final XOR value. These differences make it easy to compose the values of multiple blocks.
-
char **dupargv(char *const *vector)#
Duplicate an argument vector. Simply scans through
vector, duplicating each argument until the terminatingNULLis found. Returns a pointer to the argument vector if successful. ReturnsNULLif there is insufficient memory to complete building the argument vector.
-
int errno_max(void)#
Returns the maximum
errnovalue for which a corresponding symbolic name or message is available. Note that in the case where we use thesys_errlistsupplied by the system, it is possible for there to be more symbolic names than messages, or vice versa. In fact, the manual page forperror(3C)explicitly warns that one should check the size of the table (sys_nerr) before indexing it, since new error codes may be added to the system before they are added to the table. Thussys_nerrmight be smaller than value implied by the largesterrnovalue defined in<errno.h>.We return the maximum value that can be used to obtain a meaningful symbolic name or message.
-
void expandargv(int *argcp, char ***argvp)#
The
argcpandargvparguments are pointers to the usualargcandargvarguments tomain. This function looks for arguments that begin with the character@. Any such arguments are interpreted as ‘response files’. The contents of the response file are interpreted as additional command line options. In particular, the file is separated into whitespace-separated strings; each such string is taken as a command-line option. The new options are inserted in place of the option naming the response file, and*argcpand*argvpwill be updated. If the value of*argvpis modified by this function, then the new value has been dynamically allocated and can be deallocated by the caller withfreeargv. However, most callers will simply callexpandargvnear the beginning ofmainand allow the operating system to free the memory when the program exits.
-
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 for an unnamed file, and the name of a file that we believe to correspond to that fd. This can happen when we are exec’d with an already open file (
stdoutfor example) or from the SVR4/proccalls that return open file descriptors for mapped address spaces. All we have to do is open the file by name and check the two file descriptors for a match, which is done by comparing major and minor device numbers and inode numbers.
-
FILE *fdopen_unlocked(int fildes, const char *mode)#
Opens and returns a
FILEpointer viafdopen. If the operating system supports it, ensure that the stream is setup to avoid any multi-threaded locking. Otherwise return theFILEpointer unchanged.
-
int ffs(int valu)#
Find the first (least significant) bit set in
valu. Bits are numbered from right to left, starting with bit 1 (corresponding to the value 1). Ifvaluis zero, zero is returned.
-
int filename_cmp(const char *s1, const char *s2)#
Return zero if the two file names
s1ands2are equivalent. If not equivalent, the returned value is similar to whatstrcmpwould return. In other words, it returns a negative value ifs1is less thans2, or a positive value ifs2is greater thans2.This function does not normalize file names. As a result, this function will treat filenames that are spelled differently as different even in the case when the two filenames point to the same underlying file. However, it does handle the fact that on DOS-like file systems, forward and backward slashes are equal.
-
int filename_eq(const void *s1, const void *s2)#
Return non-zero if file names
s1ands2are equivalent. This function is for use with hashtab.c hash tables.
-
hashval_t filename_hash(const void *s)#
Return the hash value for file name
sthat will be compared using filename_cmp. This function is for use with hashtab.c hash tables.
-
int filename_ncmp(const char *s1, const char *s2, size_t n)#
Return zero if the two file names
s1ands2are equivalent in rangen. If not equivalent, the returned value is similar to whatstrncmpwould return. In other words, it returns a negative value ifs1is less thans2, or a positive value ifs2is greater thans2.This function does not normalize file names. As a result, this function will treat filenames that are spelled differently as different even in the case when the two filenames point to the same underlying file. However, it does handle the fact that on DOS-like file systems, forward and backward slashes are equal.
-
int fnmatch(const char *pattern, const char *string, int flags)#
Matches
stringagainstpattern, returning zero if it matches,FNM_NOMATCHif not.patternmay contain the wildcards?to match any one character,*to match any zero or more characters, or a set of alternate characters in square brackets, like[a-gt8], which match one character (athroughg, ort, or8, in this example) if that one character is in the set. A set may be inverted (i.e., match anything except what’s in the set) by giving^or!as the first character in the set. To include those characters in the set, list them as anything other than the first character of the set. To include a dash in the set, list it last in the set. A backslash character makes the following character not special, so for example you could match against a literal asterisk with\*. To match a literal backslash, use\.flagscontrols various aspects of the matching process, and is a boolean OR of zero or more of the following values (defined in<fnmatch.h>):- FNM_PATHNAME#
stringis 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_PATHNAMEafter a slash) is not matched by*or?but must be matched explicitly.
- FNM_LEADING_DIR#
Means that
stringalso matchespatternif some initial part ofstringmatches, and is followed by/and zero or more characters. For example,foo*would match eitherfoobarorfoobar/grill.
- FNM_CASEFOLD#
Ignores case when performing the comparison.
-
FILE *fopen_unlocked(const char *path, const char *mode)#
Opens and returns a
FILEpointer viafopen. If the operating system supports it, ensure that the stream is setup to avoid any multi-threaded locking. Otherwise return theFILEpointer unchanged.
-
void freeargv(char **vector)#
Free an argument vector that was built using
buildargv. Simply scans throughvector, freeing the memory for each argument until the terminatingNULLis found, and then freesvectoritself.
-
FILE *freopen_unlocked(const char *path, const char *mode, FILE *stream)#
Opens and returns a
FILEpointer viafreopen. If the operating system supports it, ensure that the stream is setup to avoid any multi-threaded locking. Otherwise return theFILEpointer unchanged.
-
long get_run_time(void)#
Returns the time used so far, in microseconds. If possible, this is the time used by this process, else it is the elapsed time since the process started.
-
char *getcwd(char *pathname, int len)#
Copy the absolute pathname for the current working directory into
pathname, which is assumed to point to a buffer of at leastlenbytes, and return a pointer to the buffer. If the current directory’s path doesn’t fit inlencharacters, the result isNULLanderrnois set. Ifpathnameis a null pointer,getcwdwill obtainlenbytes of space usingmalloc.
-
int getpagesize(void)#
Returns the number of bytes in a page of memory. This is the granularity of many of the system memory management routines. No guarantee is made as to whether or not it is the same as the basic memory management hardware page size.
-
char *getpwd(void)#
Returns the current working directory. This implementation caches the result on the assumption that the process will not call
chdirbetween calls togetpwd.
-
int gettimeofday(struct timeval *tp, void *tz)#
Writes the current time to
tp. This implementation requires thattzbe NULL. Returns 0 on success, -1 on failure.
-
void hex_init(void)#
Initializes the array mapping the current character set to corresponding hex values. This function must be called before any call to
hex_porhex_value. If you fail to call it, a default ASCII-based table will normally be used on ASCII systems.
-
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 to
unsigned charwithin the macro.
-
unsigned int hex_value(int c)#
Returns the numeric equivalent of the given character when interpreted as a hexadecimal digit. The result is undefined if you pass an invalid hex digit. Note that the value you pass will be cast to
unsigned charwithin the macro.The
hex_valuemacro returnsunsigned int, rather than signedint, to make it easier to use in parsing addresses from hex dump files: a signedintwould be sign-extended when converted to a wider unsigned type — likebfd_vma, on some systems.
-
HOST_CHARSET#
This macro indicates the basic character set and encoding used by the host: more precisely, the encoding used for character constants in preprocessor
#ifstatements (the C “execution character set”). It is defined bysafe-ctype.h, and will be an integer constant with one of the following values:
- HOST_CHARSET_UNKNOWN#
The host character set is unknown - that is, not one of the next two possibilities.
- HOST_CHARSET_ASCII#
The host character set is ASCII.
- HOST_CHARSET_EBCDIC#
The host character set is some variant of EBCDIC. (Only one of the nineteen EBCDIC varying characters is tested; exercise caution.)
-
htab_t htab_create_typed_alloc(size_t size, htab_hash hash_f, htab_eq eq_f, htab_del del_f, htab_alloc alloc_tab_f, htab_alloc alloc_f, htab_free free_f)#
This function creates a hash table that uses two different allocators
alloc_tab_fandalloc_fto use for allocating the table itself and its entries respectively. This is useful when variables of different types need to be allocated with different allocators.The created hash table is slightly larger than
sizeand it is initially empty (all the hash table entries areHTAB_EMPTY_ENTRY). The function returns the created hash table, orNULLif memory allocation fails.
-
char *index(char *s, int c)#
Returns a pointer to the first occurrence of the character
cin the strings, orNULLif not found. The use ofindexis deprecated in new programs in favor ofstrchr.
-
void insque(struct qelem *elem, struct qelem *pred)#
-
void remque(struct qelem *elem)#
Routines to manipulate queues built from doubly linked lists. The
insqueroutine insertselemin the queue immediately afterpred. Theremqueroutine removeselemfrom its containing queue. These routines expect to be passed pointers to structures which have as their first members a forward pointer and a back pointer, like this prototype (although no prototype is provided):struct qelem { struct qelem *q_forw; struct qelem *q_back; char q_data[]; };
-
ISALPHA(c)#
-
ISALNUM(c)#
-
ISBLANK(c)#
-
ISCNTRL(c)#
-
ISDIGIT(c)#
-
ISGRAPH(c)#
-
ISLOWER(c)#
-
ISPRINT(c)#
-
ISPUNCT(c)#
-
ISSPACE(c)#
-
ISUPPER(c)#
-
ISXDIGIT(c)#
These twelve macros are defined by safe-ctype.h. Each has the
same 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 for
others. However, there are two differences between these macros and
those provided by ctype.h:
These macros are guaranteed to have well-defined behavior for all values representable by
signed charandunsigned char, and forEOF.These macros ignore the current locale; they are true for these fixed sets of characters:
ALPHAA-Za-z
ALNUMA-Za-z0-9
BLANKspace tab
CNTRL!PRINTDIGIT0-9
GRAPHALNUM || PUNCTLOWERa-z
PRINTGRAPH ||spacePUNCT`~!@#$%^&*()_-=+[{]}|;:’”,<.>/?
SPACEspace tab n r f v
UPPERA-Z
XDIGIT0-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
charoutside the range of 7-bit ASCII. In particular, both ISPRINT and ISCNTRL return false for characters with numeric values from 128 to 255.
These six macros are defined by safe-ctype.h and provide additional character classes which are useful when doing lexical analysis of C or similar languages. They are true for the following sets of characters:
|
A-Za-z0-9_ |
|
A-Za-z_ |
|
r n |
|
space tab f v 0 |
|
|
|
|
-
const char *lbasename(const char *name)#
Given a pointer to a string containing a typical pathname (
/usr/src/cmd/ls/ls.cfor example), returns a pointer to the last component of the pathname (ls.cin this case). The returned pointer is guaranteed to lie within the original string. This latter fact is not true of many vendor C libraries, which return special strings or modify the passed strings for particular input.In particular, the empty string returns the same empty string, and a path ending in
/returns the empty string after it.
-
const char *lrealpath(const char *name)#
Given a pointer to a string containing a pathname, returns a canonical version of the filename. Symlinks will be resolved, and ‘.’ and ‘..’ components will be simplified. The returned value will be allocated using
malloc, orNULLwill be returned on a memory allocation error.
-
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 asprefixis relative tobin_prefix. That is, a string starting with the directory portion ofprogname, followed by a relative pathname of the difference betweenbin_prefixandprefix.If
prognamedoes not contain any directory separators,make_relative_prefixwill searchPATHto find a program namedprogname. Also, ifprognameis a symbolic link, the symbolic link will be resolved.For example, if
bin_prefixis/alpha/beta/gamma/gcc/delta,prefixis/alpha/beta/gamma/omega/, andprognameis/red/green/blue/gcc, then this function will return/red/green/blue/../../omega/.The return value is normally allocated via
malloc. If no relative prefix can be found, returnNULL.
-
char *make_temp_file(const char *suffix)#
Return a temporary file name (as a string) or
NULLif unable to create one.suffixis a suffix to append to the file name. The string ismalloced, and the temporary file has been created.
-
void *memchr(const void *s, int c, size_t n)#
This function searches memory starting at
*sfor the characterc. The search only ends with the first occurrence ofc, or afterlengthcharacters; in particular, a null character does not terminate the search. If the charactercis found withinlengthcharacters of*s, a pointer to the character is returned. Ifcis not found, thenNULLis returned.
-
int memcmp(const void *x, const void *y, size_t count)#
Compares the first
countbytes of two areas of memory. Returns zero if they are the same, a value less than zero ifxis lexically less thany, or a value greater than zero ifxis lexically greater thany. Note that lexical order is determined as if comparing unsigned char arrays.
-
void *memcpy(void *out, const void *in, size_t length)#
Copies
lengthbytes from memory regioninto regionout. Returns a pointer toout.
-
void *memmem(const void *haystack, size_t haystack_len, const void *needle, size_t needle_len)#
Returns a pointer to the first occurrence of
needle(lengthneedle_len) inhaystack(lengthhaystack_len). ReturnsNULLif not found.
-
void *memmove(void *from, const void *to, size_t count)#
Copies
countbytes from memory areafromto memory areato, returning a pointer toto.
-
void *mempcpy(void *out, const void *in, size_t length)#
Copies
lengthbytes from memory regioninto regionout. Returns a pointer toout+length.
-
void *memset(void *s, int c, size_t count)#
Sets the first
countbytes ofsto the constant bytec, returning a pointer tos.
-
int mkstemps(char *pattern, int suffix_len)#
Generate a unique temporary file name from
pattern.patternhas the form:path/ccXXXXXXsuffix
suffix_lentells us how longsuffixis (it can be zero length). The last six characters ofpatternbeforesuffixmust beXXXXXX; they are replaced with a string that makes the filename unique. Returns a file descriptor open on the file for reading and writing.
-
void pex_free(struct pex_obj obj)#
Clean up and free all data associated with
obj. If you have not yet calledpex_get_timesorpex_get_status, this will try to kill the subprocesses.
-
int pex_get_status(struct pex_obj *obj, int count, int *vector)#
Returns the exit status of all programs run using
obj.countis the number of results expected. The results will be placed intovector. The results are in the order of the calls topex_run. Returns 0 on error, 1 on success.
-
int pex_get_times(struct pex_obj *obj, int count, struct pex_time *vector)#
Returns the process execution times of all programs run using
obj.countis the number of results expected. The results will be placed intovector. The results are in the order of the calls topex_run. Returns 0 on error, 1 on success.struct pex_timehas the following fields of the typeunsigned long:user_seconds,user_microseconds,system_seconds,system_microseconds. On systems which do not support reporting process times, all the fields will be set to0.
-
struct pex_obj *pex_init(int flags, const char *pname, const char *tempbase)#
Prepare to execute one or more programs, with standard output of each program fed to standard input of the next. This is a system independent interface to execute a pipeline.
flagsis a bitwise combination of the following:- PEX_RECORD_TIMES#
Record subprocess times if possible.
- PEX_USE_PIPES#
Use pipes for communication between processes, if possible.
- PEX_SAVE_TEMPS#
Don’t delete temporary files used for communication between processes.
pnameis the name of program to be executed, used in error messages.tempbaseis a base name to use for any required temporary files; it may beNULLto use a randomly chosen name.
-
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 in the pipeline as input.
The name of the input file is chosen according to the same rules
pex_runuses to choose output file names, based onin_name,objand thePEX_SUFFIXbit inflags.Don’t call
fcloseon the returned stream; the first call topex_runcloses it automatically.If
flagsincludesPEX_BINARY_OUTPUT, open the stream in binary mode; otherwise, open it in the default mode. IncludingPEX_BINARY_OUTPUTinflagshas no effect on Unix.
-
FILE *pex_input_pipe(struct pex_obj *obj, int binary)#
Return a stream
fpfor a pipe connected to the standard input of the first program in the pipeline;fpis opened for writing. You must have passedPEX_USE_PIPESto thepex_initcall that returnedobj.You must close
fpusingfcloseyourself when you have finished writing data to the pipeline.The file descriptor underlying
fpis marked not to be inherited by child processes.On systems that do not support pipes, this function returns
NULL, and setserrnotoEINVAL. If you would like to write code that is portable to all systems thepexfunctions support, consider usingpex_input_fileinstead.There are two opportunities for deadlock using
pex_input_pipe:Most systems’ pipes can buffer only a fixed amount of data; a process that writes to a full pipe blocks. Thus, if you write to
fpbefore starting the first process, you run the risk of blocking when there is no child process yet to read the data and allow you to continue.pex_input_pipemakes no promises about the size of the pipe’s buffer, so if you need to write any data at all before starting the first process in the pipeline, consider usingpex_input_fileinstead.Using
pex_input_pipeandpex_read_outputtogether may also cause deadlock. If the output pipe fills up, so that each program in the pipeline is waiting for the next to read more data, and you fill the input pipe by writing more data tofp, then there is no way to make progress: the only process that could read data from the output pipe is you, but you are blocked on the input pipe.
-
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 a single program. The return value and most of the parameters are as for a call to
pex_run.flagsis restricted to a combination ofPEX_SEARCH,PEX_STDERR_TO_STDOUT, andPEX_BINARY_OUTPUT.outnameis interpreted as ifPEX_LASTwere set. On a successful return,*statuswill be set to the exit status of the program.
-
FILE *pex_read_err(struct pex_obj *obj, int binary)#
Returns a
FILEpointer which may be used to read the standard error of the last program in the pipeline. When this is used,PEX_LASTshould not be used in a call topex_run. After this is called,pex_runmay no longer be called with the sameobj.binaryshould be non-zero if the file should be opened in binary mode. Don’t callfcloseon the returned file; it will be closed bypex_free.
-
FILE *pex_read_output(struct pex_obj *obj, int binary)#
Returns a
FILEpointer which may be used to read the standard output of the last program in the pipeline. When this is used,PEX_LASTshould not be used in a call topex_run. After this is called,pex_runmay no longer be called with the sameobj.binaryshould be non-zero if the file should be opened in binary mode. Don’t callfcloseon the returned file; it will be closed bypex_free.
-
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 returns
NULL. On failure it returns an error message, a statically allocated string.objis returned by a previous call topex_init.flagsis a bitwise combination of the following:- PEX_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 output of the program will be sent to
outname, or, ifoutnameisNULL, to the standard output of the calling program. Do not set this bit if you want to callpex_read_output(described below). After a call topex_runwith this bit set,pex_runmay no longer be called with the sameobj.
- PEX_SEARCH#
Search for the program using the user’s executable search path.
- PEX_SUFFIX#
outnameis a suffix. See the description ofoutname, below.
- PEX_STDERR_TO_STDOUT#
Send the program’s standard error to standard output, if possible.
- PEX_BINARY_INPUT#
The standard input (output or error) of the program should be read (written) in binary mode rather than text mode. These flags are ignored on systems which do not distinguish binary mode and text mode, such as Unix. For proper behavior these flags should match appropriately—a call to
pex_runusingPEX_BINARY_OUTPUTshould be followed by a call usingPEX_BINARY_INPUT.
- PEX_STDERR_TO_PIPE#
Send the program’s standard error to a pipe, if possible. This flag cannot be specified together with
PEX_STDERR_TO_STDOUT. This flag can be specified only on the last program in pipeline.
executableis the program to execute.argvis the set of arguments to pass to the program; normallyargv[0]will be a copy ofexecutable.outnameis used to set the name of the file to use for standard output. There are two cases in which no output file will be used:if
PEX_LASTis not set inflags, andPEX_USE_PIPESwas set in the call topex_init, and the system supports pipesif
PEX_LASTis set inflags, andoutnameisNULL
Otherwise the code will use a file to hold standard output. If
PEX_LASTis not set, this file is considered to be a temporary file, and it will be removed when no longer needed, unlessPEX_SAVE_TEMPSwas set in the call topex_init.There are two cases to consider when setting the name of the file to hold standard output.
PEX_SUFFIXis set inflags. In this caseoutnamemay not beNULL. If thetempbaseparameter topex_initwas notNULL, then the output file name is the concatenation oftempbaseandoutname. IftempbasewasNULL, then the output file name is a random file name ending inoutname.PEX_SUFFIXwas not set inflags. In this case, ifoutnameis notNULL, it is used as the output file name. IfoutnameisNULL, andtempbasewas not NULL, the output file name is randomly chosen usingtempbase. Otherwise the output file name is chosen completely at random.
errnameis the file name to use for standard error output. If it isNULL, 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
*errto anerrnovalue, or to 0 if there is no relevanterrno.
-
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 the program to be specified. Behaviour and parameters not listed below are as for
pex_run.envis the environment for the child process, specified as an array of character pointers. Each element of the array should point to a string of the formVAR=VALUE, with the exception of the last element that must beNULL.
-
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 is still supported for compatibility purposes, but is no longer documented.
-
void psignal(int signo, char *message)#
Print
messageto the standard error, followed by a colon, followed by the description of the signal specified bysigno, followed by a newline.
-
int putenv(const char *string)#
Uses
setenvorunsetenvto putstringinto the environment or remove it. Ifstringis of the formname=valuethe string is added; if no=is present the name is unset/removed.
-
int pwait(int pid, int *status, int flags)#
Another part of the old execution interface.
-
long int random(void)#
-
void srandom(unsigned int seed)#
-
void *initstate(unsigned int seed, void *arg_state, unsigned long n)#
-
void *setstate(void *arg_state)#
Random number functions.
randomreturns a random number in the range 0 toLONG_MAX.srandominitializes the random number generator to some starting point determined byseed(else, the values returned byrandomare always the same for each run of the program).initstateandsetstateallow fine-grained control over the state of the random number generator.
- char* reconcat (char *optr, const char *s1, ..., NULL)
Same as
concat, except that ifoptris notNULLit is freed after the string is created. This is intended to be useful when you’re extending an existing string or building up a string in a loop:str = reconcat (str, "pre-", str, NULL);
-
int rename(const char *old, const char *new)#
Renames a file from
oldtonew. Ifnewalready exists, it is removed.
-
char *rindex(const char *s, int c)#
Returns a pointer to the last occurrence of the character
cin the strings, orNULLif not found. The use ofrindexis deprecated in new programs in favor ofstrrchr.
-
int setenv(const char *name, const char *value, int overwrite)#
-
void unsetenv(const char *name)#
setenvaddsnameto the environment with valuevalue. If the name was already present in the environment, the new value will be stored only ifoverwriteis nonzero. The companionunsetenvfunction removesnamefrom the environment. This implementation is not safe for multithreaded code.
-
void setproctitle(const char *fmt, ...)#
Set the title of a process to
fmt. va args not supported for now, but defined for compatibility with BSD.
-
int signo_max(void)#
Returns the maximum signal value for which a corresponding symbolic name or message is available. Note that in the case where we use the
sys_siglistsupplied by the system, it is possible for there to be more symbolic names than messages, or vice versa. In fact, the manual page forpsignal(3b)explicitly warns that one should check the size of the table (NSIG) before indexing it, since new signal codes may be added to the system before they are added to the table. ThusNSIGmight be smaller than value implied by the largest signo value defined in<signal.h>.We return the maximum value that can be used to obtain a meaningful symbolic name or message.
-
int sigsetmask(int set)#
Sets the signal mask to the one provided in
setand returns the old mask (which, for libiberty’s implementation, will always be the value1).
-
const char *simple_object_attributes_compare(simple_object_attributes *attrs1, simple_object_attributes *attrs2, int *err)#
Compare
attrs1andattrs2. If they could be linked together without error, returnNULL. Otherwise, return an error message and set*errto an errno value or0if there is no relevant errno.
-
simple_object_attributes *simple_object_fetch_attributes(simple_object_read *simple_object, const char **errmsg, int *err)#
Fetch the attributes of
simple_object. The attributes are internal information such as the format of the object file, or the architecture it was compiled for. This information will persist untilsimple_object_attributes_releaseis called, even ifsimple_objectitself is released.On error this returns
NULL, sets*errmsgto an error message, and sets*errto an errno value or0if there is no relevant errno.
-
int simple_object_find_section(simple_object_read *simple_object, off_t *offset, off_t *length, const char **errmsg, int *err)#
Look for the section
nameinsimple_object. This returns information for the first section with that name.If found, return 1 and set
*offsetto the offset in the file of the section contents and set*lengthto the length of the section contents. The value in*offsetwill be relative to the offset passed tosimple_object_open_read.If the section is not found, and no error occurs,
simple_object_find_sectionreturns0and set*errmsgtoNULL.If an error occurs,
simple_object_find_sectionreturns0, sets*errmsgto an error message, and sets*errto an errno value or0if there is no relevant errno.
-
const char *simple_object_find_sections(simple_object_read *simple_object, int (*pfn)(void *data, const char *name, off_t offset, off_t length), void *data, int *err)#
This function calls
pfnfor each section insimple_object. It callspfnwith the section name, the offset within the file of the section contents, and the length of the section contents. The offset within the file is relative to the offset passed tosimple_object_open_read. Thedataargument to this function is passed along topfn.If
pfnreturns0, the loop over the sections stops andsimple_object_find_sectionsreturns. Ifpfnreturns some other value, the loop continues.On success
simple_object_find_sectionsreturns. On error it returns an error string, and sets*errto an errno value or0if there is no relevant errno.
-
simple_object_read *simple_object_open_read(int descriptor, off_t offset, const char *segment_name, const char **errmsg, int *err)#
Opens an object file for reading. Creates and returns an
simple_object_readpointer which may be passed to other functions to extract data from the object file.descriptorholds a file descriptor which permits reading.offsetis the offset into the file; this will be0in the normal case, but may be a different value when reading an object file in an archive file.segment_nameis only used with the Mach-O file format used on Darwin aka Mac OS X. It is required on that platform, and means to only look at sections within the segment with that name. The parameter is ignored on other systems.If an error occurs, this functions returns
NULLand sets*errmsgto an error string and sets*errto an errno value or0if there is no relevant errno.
-
void simple_object_release_attributes(simple_object_attributes *attrs)#
Release all resources associated with
attrs.
-
void simple_object_release_read(simple_object_read *simple_object)#
Release all resources associated with
simple_object. This does not close the file descriptor.
-
void simple_object_release_write(simple_object_write *simple_object)#
Release all resources associated with
simple_object.
-
simple_object_write *simple_object_start_write(simple_object_attributes attrs, const char *segment_name, const char **errmsg, int *err)#
Start creating a new object file using the object file format described in
attrs. You must fetch attribute information from an existing object file before you can create a new one. There is currently no support for creating an object file de novo.segment_nameis only used with Mach-O as found on Darwin aka Mac OS X. The parameter is required on that target. It means that all sections are created within the named segment. It is ignored for other object file formats.On error
simple_object_start_writereturnsNULL, sets*ERRMSGto an error message, and sets*errto an errno value or0if there is no relevant errno.
-
const char *simple_object_write_add_data(simple_object_write *simple_object, simple_object_write_section *section, const void *buffer, size_t size, int copy, int *err)#
Add data
buffer/sizetosectioninsimple_object. Ifcopyis non-zero, the data will be copied into memory if necessary. Ifcopyis zero,buffermust persist untilsimple_object_write_to_fileis called. is released.On success this returns
NULL. On error this returns an error message, and sets*errto an errno value or 0 if there is no relevant erro.
-
simple_object_write_section *simple_object_write_create_section(simple_object_write *simple_object, const char *name, unsigned int align, const char **errmsg, int *err)#
Add a section to
simple_object.nameis the name of the new section.alignis the required alignment expressed as the number of required low-order 0 bits (e.g., 2 for alignment to a 32-bit boundary).The section is created as containing data, readable, not writable, not executable, not loaded at runtime. The section is not written to the file until
simple_object_write_to_fileis called.On error this returns
NULL, sets*errmsgto an error message, and sets*errto an errno value or0if there is no relevant errno.
-
const char *simple_object_write_to_file(simple_object_write *simple_object, int descriptor, int *err)#
Write the complete object file to
descriptor, an open file descriptor. This writes out all the data accumulated by calls tosimple_object_write_create_sectionandsimple_object_write_add_data.This returns
NULLon success. On error this returns an error message and sets*errto an errno value or0if there is no relevant errno.
-
int snprintf(char *buf, size_t n, const char *format, ...)#
This function is similar to
sprintf, but it will write tobufat mostn-1bytes of text, followed by a terminating null byte, for a total ofnbytes. On error the return value is -1, otherwise it returns the number of bytes, not including the terminating null byte, that would have been written hadnbeen sufficiently large, regardless of the actual value ofn. Note some pre-C99 system libraries do not implement this correctly so users cannot generally rely on the return value if the system version of this function is used.
-
char *spaces(int count)#
Returns a pointer to a memory region filled with the specified number of spaces and null terminated. The returned pointer is valid until at least the next call.
-
splay_tree splay_tree_new_with_typed_alloc(splay_tree_compare_fn compare_fn, splay_tree_delete_key_fn delete_key_fn, splay_tree_delete_value_fn delete_value_fn, splay_tree_allocate_fn tree_allocate_fn, splay_tree_allocate_fn node_allocate_fn, splay_tree_deallocate_fn deallocate_fn, void *allocate_data)#
This function creates a splay tree that uses two different allocators
tree_allocate_fnandnode_allocate_fnto use for allocating the tree itself and its nodes respectively. This is useful when variables of different types need to be allocated with different allocators.The splay tree will use
compare_fnto compare nodes,delete_key_fnto deallocate keys, anddelete_value_fnto deallocate values. Keys and values will be deallocated when the tree is deleted using splay_tree_delete or when a node is removed using splay_tree_remove. splay_tree_insert will release the previously inserted key and value usingdelete_key_fnanddelete_value_fnif the inserted key is already found in the tree.
-
void stack_limit_increase(unsigned long pref)#
Attempt to increase stack size limit to
prefbytes if possible.
-
char *stpcpy(char *dst, const char *src)#
Copies the string
srcintodst. Returns a pointer todst+ strlen(src).
-
char *stpncpy(char *dst, const char *src, size_t len)#
Copies the string
srcintodst, copying exactlylenand padding with zeros if necessary. Iflen< strlen(src) then returndst+len, otherwise returnsdst+ strlen(src).
-
int strcasecmp(const char *s1, const char *s2)#
A case-insensitive
strcmp.
-
char *strchr(const char *s, int c)#
Returns a pointer to the first occurrence of the character
cin the strings, orNULLif not found. Ifcis itself the null character, the results are undefined.
-
char *strdup(const char *s)#
Returns a pointer to a copy of
sin memory obtained frommalloc, orNULLif insufficient memory was available.
-
const char *strerrno(int errnum)#
Given an error number returned from a system call (typically returned in
errno), returns a pointer to a string containing the symbolic name of that error number, as found in<errno.h>.If the supplied error number is within the valid range of indices for symbolic names, but no name is available for the particular error number, then returns the string
Error num, wherenumis the error number.If the supplied error number is not within the range of valid indices, then returns
NULL.The contents of the location pointed to are only guaranteed to be valid until the next call to
strerrno.
-
char *strerror(int errnoval)#
Maps an
errnonumber to an error message string, the contents of which are implementation defined. On systems which have the external variablessys_nerrandsys_errlist, these strings will be the same as the ones used byperror.If the supplied error number is within the valid range of indices for the
sys_errlist, but no message is available for the particular error number, then returns the stringError num, wherenumis the error number.If the supplied error number is not a valid index into
sys_errlist, returnsNULL.The returned string is only guaranteed to be valid only until the next call to
strerror.
-
int strncasecmp(const char *s1, const char *s2)#
A case-insensitive
strncmp.
-
int strncmp(const char *s1, const char *s2, size_t n)#
Compares the first
nbytes of two strings, returning a value asstrcmp.
-
char *strndup(const char *s, size_t n)#
Returns a pointer to a copy of
swith at mostncharacters in memory obtained frommalloc, orNULLif insufficient memory was available. The result is always NUL terminated.
-
size_t strnlen(const char *s, size_t maxlen)#
Returns the length of
s, as withstrlen, but never looks past the firstmaxlencharacters in the string. If there is no ‘0’ character in the firstmaxlencharacters, returnsmaxlen.
-
char *strrchr(const char *s, int c)#
Returns a pointer to the last occurrence of the character
cin the strings, orNULLif not found. Ifcis itself the null character, the results are undefined.
-
const char *strsignal(int signo)#
Maps an signal number to an signal message string, the contents of which are implementation defined. On systems which have the external variable
sys_siglist, these strings will be the same as the ones used bypsignal().If the supplied signal number is within the valid range of indices for the
sys_siglist, but no message is available for the particular signal number, then returns the stringSignal num, wherenumis the signal number.If the supplied signal number is not a valid index into
sys_siglist, returnsNULL.The returned string is only guaranteed to be valid only until the next call to
strsignal.
-
const char *strsigno(int signo)#
Given an signal number, returns a pointer to a string containing the symbolic name of that signal number, as found in
<signal.h>.If the supplied signal number is within the valid range of indices for symbolic names, but no name is available for the particular signal number, then returns the string
Signal num, wherenumis the signal number.If the supplied signal number is not within the range of valid indices, then returns
NULL.The contents of the location pointed to are only guaranteed to be valid until the next call to
strsigno.
-
char *strstr(const char *string, const char *sub)#
This function searches for the substring
subin the stringstring, not including the terminating null characters. A pointer to the first occurrence ofsubis returned, orNULLif the substring is absent. Ifsubpoints to a string with zero length, the function returnsstring.
-
double strtod(const char *string, char **endptr)#
This ISO C function converts the initial portion of
stringto adouble. Ifendptris notNULL, a pointer to the character after the last character used in the conversion is stored in the location referenced byendptr. If no conversion is performed, zero is returned and the value ofstringis stored in the location referenced byendptr.
-
int strtoerrno(const char *name)#
Given the symbolic name of a error number (e.g.,
EACCES), map it to an errno value. If no translation is found, returns 0.
-
long int strtol(const char *string, char **endptr, int base)#
-
unsigned long int strtoul(const char *string, char **endptr, int base)#
The
strtolfunction converts the string instringto a long integer value according to the givenbase, which must be between 2 and 36 inclusive, or be the special value 0. Ifbaseis 0,strtolwill look for the prefixes0and0xto indicate bases 8 and 16, respectively, else default to base 10. When the base is 16 (either explicitly or implicitly), a prefix of0xis allowed. The handling ofendptris as that ofstrtodabove. Thestrtoulfunction is the same, except that the converted value is unsigned.
-
long long int strtoll(const char *string, char **endptr, int base)#
-
unsigned long long int strtoull(const char *string, char **endptr, int base)#
The
strtollfunction converts the string instringto a long long integer value according to the givenbase, which must be between 2 and 36 inclusive, or be the special value 0. Ifbaseis 0,strtollwill look for the prefixes0and0xto indicate bases 8 and 16, respectively, else default to base 10. When the base is 16 (either explicitly or implicitly), a prefix of0xis allowed. The handling ofendptris as that ofstrtodabove. Thestrtoullfunction is the same, except that the converted value is unsigned.
-
int strtosigno(const char *name)#
Given the symbolic name of a signal, map it to a signal number. If no translation is found, returns 0.
-
int strverscmp(const char *s1, const char *s2)#
The
strverscmpfunction compares the strings1againsts2, considering them as holding indices/version numbers. Return value follows the same conventions as found in thestrverscmpfunction. In fact, ifs1ands2contain no digits,strverscmpbehaves likestrcmp.Basically, we compare strings normally (character by character), until we find a digit in each string - then we enter a special comparison mode, where each sequence of digits is taken as a whole. If we reach the end of these two parts without noticing a difference, we return to the standard comparison mode. There are two types of numeric parts: “integral” and “fractional” (those begin with a ‘0’). The types of 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 less than 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.
-
void timeval_add(struct timeval *a, struct timeval *b, struct timeval *result)#
Adds
atoband stores the result inresult.
-
void timeval_sub(struct timeval *a, struct timeval *b, struct timeval *result)#
Subtracts
bfromaand stores the result inresult.
-
char *tmpnam(char *s)#
This function attempts to create a name for a temporary file, which will be a valid file name yet not exist when
tmpnamchecks for it.smust point to a buffer of at leastL_tmpnambytes, or beNULL. Use of this function creates a security risk, and it must not be used in new projects. Usemkstempinstead.
-
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) when there was an error deleting the file, and a positive value if no attempt was made to unlink the file because it is special.
-
void unlock_std_streams(void)#
If the OS supports it, ensure that the standard I/O streams,
stdin,stdoutandstderrare setup to avoid any multi-threaded locking. Otherwise do nothing.
-
void unlock_stream(FILE *stream)#
If the OS supports it, ensure that the supplied stream is setup to avoid any multi-threaded locking. Otherwise leave the
FILEpointer unchanged. If thestreamisNULLdo nothing.
-
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 size of the buffer needed, allocate memory withmalloc, and store a pointer to the allocated memory in*resptr. The value returned is the same asvsprintfwould return. If memory could not be allocated, minus one is returned andNULLis stored in*resptr.
-
int vfork(void)#
Emulates
vforkby callingforkand returning its value.
-
int vprintf(const char *format, va_list ap)#
-
int vfprintf(FILE *stream, const char *format, va_list ap)#
-
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_listinstead of a variable number of arguments. Note that they do not callva_end; this is the application’s responsibility. Inlibibertythey are implemented in terms of the nonstandard but common function_doprnt.
-
int vsnprintf(char *buf, size_t n, const char *format, va_list ap)#
This function is similar to
vsprintf, but it will write tobufat mostn-1bytes of text, followed by a terminating null byte, for a total ofnbytes. On error the return value is -1, otherwise it returns the number of characters that would have been printed hadnbeen sufficiently large, regardless of the actual value ofn. Note some pre-C99 system libraries do not implement this correctly so users cannot generally rely on the return value if the system version of this function is used.
-
int waitpid(int pid, int *status, int)#
This is a wrapper around the
waitfunction. Any ‘special’ values ofpiddepend on your implementation ofwait, as does the return value. The third argument is unused inlibiberty.
-
int writeargv(char *const *argv, FILE *file)#
Write each member of ARGV, handling all necessary quoting, to the file named by FILE, separated by whitespace. Return 0 on success, non-zero if an error occurred while writing to FILE.
-
char *xasprintf(const char *format, ...)#
Print to allocated string without fail. If
xasprintffails, this will print a message tostderr(using the name set byxmalloc_set_program_name, if any) and then callxexit.
-
int xatexit(void (*fn)(void))#
Behaves as the standard
atexitfunction, but with no limit on the number of registered functions. Returns 0 on success, or -1 on failure. If you usexatexitto register functions, you must usexexitto terminate your program.
-
void *xcalloc(size_t nelem, size_t elsize)#
Allocate memory without fail, and set it to zero. This routine functions like
calloc, but will behave the same asxmallocif memory cannot be found.
-
void xexit(int code)#
Terminates the program. If any functions have been registered with the
xatexitreplacement function, they will be called first. Termination is handled via the system’s normalexitcall.
-
void *xmalloc(size_t)#
Allocate memory without fail. If
mallocfails, this will print a message tostderr(using the name set byxmalloc_set_program_name, if any) and then callxexit. Note that it is therefore safe for a program to contain#define malloc xmallocin its source.
-
void xmalloc_failed(size_t)#
This function is not meant to be called by client code, and is listed here for completeness only. If any of the allocation routines fail, this function will be called to print an error message and terminate execution.
-
void xmalloc_set_program_name(const char *name)#
You can use this to set the name of the program used by
xmalloc_failedwhen printing a failure message.
-
void *xmemdup(void *input, size_t copy_size, size_t alloc_size)#
Duplicates a region of memory without fail. First,
alloc_sizebytes are allocated, thencopy_sizebytes frominputare copied into it, and the new memory is returned. If fewer bytes are copied than were allocated, the remaining memory is zeroed.
-
void *xrealloc(void *ptr, size_t size)#
Reallocate memory without fail. This routine functions like
realloc, but will behave the same asxmallocif memory cannot be found.
-
char *xstrdup(const char *s)#
Duplicates a character string without fail, using
xmallocto obtain memory.
-
char *xstrerror(int errnum)#
Behaves exactly like the standard
strerrorfunction, but will never return aNULLpointer.
-
char *xstrndup(const char *s, size_t n)#
Returns a pointer to a copy of
swith at mostncharacters without fail, usingxmallocto obtain memory. The result is always NUL terminated.
-
char *xvasprintf(const char *format, va_list args)#
Print to allocated string without fail. If
xvasprintffails, this will print a message tostderr(using the name set byxmalloc_set_program_name, if any) and then callxexit.