Changeset View
Changeset View
Standalone View
Standalone View
lib/libc/gen/wordexp.c
Show First 20 Lines • Show All 123 Lines • ▼ Show 20 Lines | |||||
static int | static int | ||||
we_askshell(const char *words, wordexp_t *we, int flags) | we_askshell(const char *words, wordexp_t *we, int flags) | ||||
{ | { | ||||
int pdesw[2]; /* Pipe for writing words */ | int pdesw[2]; /* Pipe for writing words */ | ||||
int pdes[2]; /* Pipe for reading output */ | int pdes[2]; /* Pipe for reading output */ | ||||
char wfdstr[sizeof(int) * 3 + 1]; | char wfdstr[sizeof(int) * 3 + 1]; | ||||
char buf[35]; /* Buffer for byte and word count */ | char buf[35]; /* Buffer for byte and word count */ | ||||
long nwords, nbytes; /* Number of words, bytes from child */ | long nwords, nbytes; /* Number of words, bytes from child */ | ||||
long i; /* Handy integer */ | size_t i; /* Handy integer */ | ||||
size_t sofs; /* Offset into we->we_strings */ | size_t sofs; /* Offset into we->we_strings */ | ||||
size_t vofs; /* Offset into we->we_wordv */ | size_t vofs; /* Offset into we->we_wordv */ | ||||
pid_t pid; /* Process ID of child */ | pid_t pid; /* Process ID of child */ | ||||
pid_t wpid; /* waitpid return value */ | pid_t wpid; /* waitpid return value */ | ||||
int status; /* Child exit status */ | int status; /* Child exit status */ | ||||
int error; /* Our return value */ | int error; /* Our return value */ | ||||
int serrno; /* errno to return */ | int serrno; /* errno to return */ | ||||
char *np, *p; /* Handy pointers */ | char *np, *p; /* Handy pointers */ | ||||
▲ Show 20 Lines • Show All 106 Lines • ▼ Show 20 Lines | if ((nstrings = realloc(we->we_strings, we->we_nbytes)) == NULL) { | ||||
error = WRDE_NOSPACE; | error = WRDE_NOSPACE; | ||||
goto cleanup; | goto cleanup; | ||||
} | } | ||||
for (i = 0; i < vofs; i++) | for (i = 0; i < vofs; i++) | ||||
if (we->we_wordv[i] != NULL) | if (we->we_wordv[i] != NULL) | ||||
we->we_wordv[i] += nstrings - we->we_strings; | we->we_wordv[i] += nstrings - we->we_strings; | ||||
we->we_strings = nstrings; | we->we_strings = nstrings; | ||||
if (we_read_fully(pdes[0], we->we_strings + sofs, nbytes) != nbytes) { | if (we_read_fully(pdes[0], we->we_strings + sofs, nbytes) != (size_t)nbytes) { | ||||
error = WRDE_NOSPACE; /* abort for unknown reason */ | error = WRDE_NOSPACE; /* abort for unknown reason */ | ||||
serrno = errno; | serrno = errno; | ||||
goto cleanup; | goto cleanup; | ||||
} | } | ||||
error = 0; | error = 0; | ||||
cleanup: | cleanup: | ||||
_close(pdes[0]); | _close(pdes[0]); | ||||
▲ Show 20 Lines • Show All 149 Lines • Show Last 20 Lines |