Standards / Extensions | C or C++ | Dependencies |
---|---|---|
XPG4 |
both | POSIX(ON) |
#define _XOPEN_SOURCE
#include <wordexp.h>
int wordexp(const char *__restrict__ words,
wordexp_t *__restrict__ pwordexp, int flags);
void wordfree(wordexp_t *pwordexp);
The wordexp() function performs word expansions as described in X/Open CAE Specification, Commands and Utilities, Issue 4, Version 2 (XCU) Topic, Word Expansions, subject to quoting as in the XCU specification, topic, Quoting, and places the list of expanded words into the structure pointed to by pwordexp.
| & ; < >
except
in the context of command substitution as specified in the XCU specification, topic,
Command Substitution. It also must not contain unquoted parentheses
or braces, except in the context of command or variable substitution. Member Type Member Name Description
size_t we_wordc Count of words matched by words.
char ** we_wordv Pointer to list of expanded words.
size_t we_offs Slots to reserve at the beginning
of pwordexp->we_wordv.
The
wordexp() function stores the number of generated words into pwordexp->we_wordc
and a pointer to a list of pointers to words in pwordexp->we_wordv.
Each individual field created during field splitting (see the XCU specification, topic,
Field Splitting) or pathname expansion (see the XCU specification, topic ,
Pathname Expansion) is a separate word in the pwordexp->we_wordv
list. The words are in order as described in the XCU specification, topic,
Word Expansions. The first pointer after the last word pointer
will be a NULL pointer. The expansion of special parameters described
in the XCU specification, topic, Special Parameters is
unspecified.It is the caller's responsibility to allocate the storage pointed to by pwordexp. The wordexp() function allocates the other space as needed, including memory pointed to by pwordexp->we_wordv. The wordfree() function frees any memory associated with pwordexp from a previous call to wordexp().
<newline> | & ; < > ( ) { }
in
an inappropriate context, wordexp() will fail, and the number of expanded
words will be 0.Unless WRDE_SHOWERR is set in flags, wordexp() will redirect stderr to /dev/null for any utilities executed as a result of command substitution while expanding words. If WRDE_SHOWERR is set, wordexp() may write messages to stderr if syntax errors are detected while expanding words.
If WRDE_DOOFFS is set, then pwordexp->we_offs must have the same value for each wordexp() call and wordfree() call using a given pwordexp.
<newline> | & ; < > ( ) { }
appears
in words in an inappropriate context.For further information about the cause of a failure, please refer to __errno2() and errno in addition to the above error return values.
If successful, wordexp() returns 0.
If unsuccessful, wordexp() returns a nonzero value, as defined in <wordexp.h> and described above, to indicate an error. If wordexp() returns the value WRDE_NOSPACE, then pwordexp->we_wordc, and pwordexp->we_wordv will be updated to reflect any words that were successfully expanded. In other cases, they will not be modified.