write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-#define mempcpy __mempcpy
-#define stpcpy __stpcpy
-#define strndup __strndup
-#define strspn __strspn
-#define unsetenv __unsetenv
-#define waitpid __waitpid
-#define kill __kill
-
-#define _GNU_SOURCE
-#include <sys/cdefs.h>
+#include <features.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <glob.h>
#include <wordexp.h>
+/* Experimentally off - libc_hidden_proto(mempcpy) */
+/* Experimentally off - libc_hidden_proto(stpcpy) */
+/* Experimentally off - libc_hidden_proto(strchr) */
+/* Experimentally off - libc_hidden_proto(strcpy) */
+/* Experimentally off - libc_hidden_proto(strdup) */
+/* Experimentally off - libc_hidden_proto(strlen) */
+/* Experimentally off - libc_hidden_proto(strndup) */
+/* Experimentally off - libc_hidden_proto(strspn) */
+/* Experimentally off - libc_hidden_proto(strcspn) */
+libc_hidden_proto(setenv)
+libc_hidden_proto(unsetenv)
+libc_hidden_proto(waitpid)
+libc_hidden_proto(kill)
+libc_hidden_proto(getuid)
+libc_hidden_proto(getpwnam_r)
+libc_hidden_proto(getpwuid_r)
+libc_hidden_proto(execve)
+libc_hidden_proto(dup2)
+libc_hidden_proto(atoi)
+libc_hidden_proto(fnmatch)
+libc_hidden_proto(pipe)
+libc_hidden_proto(fork)
+libc_hidden_proto(open)
+libc_hidden_proto(close)
+libc_hidden_proto(read)
+libc_hidden_proto(getenv)
+libc_hidden_proto(getpid)
+libc_hidden_proto(sprintf)
+libc_hidden_proto(fprintf)
+libc_hidden_proto(abort)
+libc_hidden_proto(glob)
+libc_hidden_proto(globfree)
+libc_hidden_proto(wordfree)
+#ifdef __UCLIBC_HAS_XLOCALE__
+libc_hidden_proto(__ctype_b_loc)
+#elif defined __UCLIBC_HAS_CTYPE_TABLES__
+libc_hidden_proto(__ctype_b)
+#endif
+
#define __WORDEXP_FULL
//#undef __WORDEXP_FULL
//extern char **__libc_argv;
/* FIXME!!!! */
-int __libc_argc;
-char **__libc_argv;
+int attribute_hidden __libc_argc;
+char attribute_hidden **__libc_argv;
/* Some forward declarations */
static int parse_dollars(char **word, size_t * word_length,
#define W_CHUNK (100)
/* Result of w_newword will be ignored if it's the last word. */
-static inline char *w_newword(size_t * actlen, size_t * maxlen)
+static __inline__ char *w_newword(size_t * actlen, size_t * maxlen)
{
*actlen = *maxlen = 0;
return NULL;
}
/* Add a character to the buffer, allocating room for it if needed. */
-static inline char *w_addchar(char *buffer, size_t * actlen,
+static __inline__ char *w_addchar(char *buffer, size_t * actlen,
size_t * maxlen, char ch)
/* (lengths exclude trailing zero) */
{
{
size_t len;
assert(str != NULL); /* w_addstr only called from this file */
- len = __strlen(str);
+ len = strlen(str);
return w_addmem(buffer, actlen, maxlen, str, len);
}
* the caller sees them.
*/
if (word == NULL) {
- word = __strdup("");
+ word = strdup("");
if (word == NULL)
goto no_space;
}
if (*word_length != 0) {
if (!((*word)[*word_length - 1] == '=' && wordc == 0)) {
if (!((*word)[*word_length - 1] == ':'
- && __strchr(*word, '=') && wordc == 0)) {
+ && strchr(*word, '=') && wordc == 0)) {
*word = w_addchar(*word, word_length, max_length, '~');
return *word ? 0 : WRDE_NOSPACE;
}
results are unspecified. We do a lookup on the uid if
HOME is unset. */
- home = __getenv("HOME");
+ home = getenv("HOME");
if (home != NULL) {
*word = w_addstr(*word, word_length, max_length, home);
if (*word == NULL)
uid = getuid();
buffer = alloca(buflen);
- while ((result = getpwuid_r(uid, &pwd, buffer, buflen, &tpwd))
- != 0 && errno == ERANGE)
+ while ((result = getpwuid_r(uid, &pwd, buffer, buflen, &tpwd))
+ != 0 && errno == ERANGE)
{
buflen += 1000;
buffer = alloca(buflen);
}
for (match = 0; match < globbuf.gl_pathc; ++match) {
- char *matching_word = __strdup(globbuf.gl_pathv[match]);
+ char *matching_word = strdup(globbuf.gl_pathv[match]);
if (matching_word == NULL || w_addword(pwordexp, matching_word)) {
globfree(&globbuf);
glob_list.we_wordv = NULL;
glob_list.we_offs = 0;
for (; words[*offset] != '\0'; ++*offset) {
- if ((ifs && __strchr(ifs, words[*offset])) ||
- (!ifs && __strchr(" \t\n", words[*offset])))
+ if ((ifs && strchr(ifs, words[*offset])) ||
+ (!ifs && strchr(" \t\n", words[*offset])))
/* Reached IFS */
break;
/* Redirect output. */
dup2(fildes[1], 1);
- __close(fildes[1]);
+ close(fildes[1]);
/* Redirect stderr to /dev/null if we have to. */
if (showerr == 0) {
int fd;
- __close(2);
- fd = __open(_PATH_DEVNULL, O_WRONLY);
+ close(2);
+ fd = open(_PATH_DEVNULL, O_WRONLY);
if (fd >= 0 && fd != 2) {
dup2(fd, 2);
- __close(fd);
+ close(fd);
}
}
/* Make sure the subshell doesn't field-split on our behalf. */
unsetenv("IFS");
- __close(fildes[0]);
+ close(fildes[0]);
execve(_PATH_BSHELL, (char *const *) args, __environ);
/* Bad. What now? */
if ((pid = fork()) < 0) {
/* Bad */
- __close(fildes[0]);
- __close(fildes[1]);
+ close(fildes[0]);
+ close(fildes[1]);
return WRDE_NOSPACE;
}
/* Parent */
- __close(fildes[1]);
+ close(fildes[1]);
buffer = alloca(bufsize);
if (!pwordexp)
/* Quoted - no field splitting */
{
while (1) {
- if ((buflen = __read(fildes[0], buffer, bufsize)) < 1) {
+ if ((buflen = read(fildes[0], buffer, bufsize)) < 1) {
if (waitpid(pid, &status, WNOHANG) == 0)
continue;
- if ((buflen = __read(fildes[0], buffer, bufsize)) < 1)
+ if ((buflen = read(fildes[0], buffer, bufsize)) < 1)
break;
}
*/
while (1) {
- if ((buflen = __read(fildes[0], buffer, bufsize)) < 1) {
+ if ((buflen = read(fildes[0], buffer, bufsize)) < 1) {
if (waitpid(pid, &status, WNOHANG) == 0)
continue;
- if ((buflen = __read(fildes[0], buffer, bufsize)) < 1)
+ if ((buflen = read(fildes[0], buffer, bufsize)) < 1)
break;
}
for (i = 0; i < buflen; ++i) {
- if (__strchr(ifs, buffer[i]) != NULL) {
+ if (strchr(ifs, buffer[i]) != NULL) {
/* Current character is IFS */
- if (__strchr(ifs_white, buffer[i]) == NULL) {
+ if (strchr(ifs_white, buffer[i]) == NULL) {
/* Current character is IFS but not whitespace */
if (copying == 2) {
/* current character
}
}
- __close(fildes[0]);
+ close(fildes[0]);
/* Check for syntax error (re-execute but with "-n" flag) */
if (buflen < 1 && status != 0) {
no_space:
kill(pid, SIGKILL);
waitpid(pid, NULL, 0);
- __close(fildes[0]);
+ close(fildes[0]);
return WRDE_NOSPACE;
}
}
/* Premature end */
- if (comm)
- free(comm);
+ free(comm);
return WRDE_SYNTAX;
}
goto envsubst;
}
while (isdigit(words[++*offset]));
- } else if (__strchr("*@$", words[*offset]) != NULL) {
+ } else if (strchr("*@$", words[*offset]) != NULL) {
/* Special parameter. */
special = 1;
env = w_addchar(env, &env_length, &env_maxlen, words[*offset]);
break;
case ':':
- if (__strchr("-=?+", words[1 + *offset]) == NULL)
+ if (strchr("-=?+", words[1 + *offset]) == NULL)
goto syntax;
colon_seen = 1;
/* Is it `$$'? */
if (*env == '$') {
buffer[20] = '\0';
- value = _itoa(__getpid(), &buffer[20]);
+ value = _itoa(getpid(), &buffer[20]);
}
/* Is it `${#*}' or `${#@}'? */
else if ((*env == '*' || *env == '@') && seen_hash) {
&buffer[20]);
*word = w_addstr(*word, word_length, max_length, value);
free(env);
- if (pattern)
- free(pattern);
+ free(pattern);
return *word ? 0 : WRDE_NOSPACE;
}
/* Is it `$*' or `$@' (unquoted) ? */
/* Build up value parameter by parameter (copy them) */
for (p = 1; __libc_argv[p]; ++p)
- plist_len += __strlen(__libc_argv[p]) + 1; /* for space */
+ plist_len += strlen(__libc_argv[p]) + 1; /* for space */
value = malloc(plist_len);
if (value == NULL)
goto no_space;
goto no_space;
for (p = 2; __libc_argv[p + 1]; p++) {
- char *newword = __strdup(__libc_argv[p]);
+ char *newword = strdup(__libc_argv[p]);
if (newword == NULL || w_addword(pwordexp, newword))
goto no_space;
}
}
} else
- value = __getenv(env);
+ value = getenv(env);
if (value == NULL && (flags & WRDE_UNDEF)) {
/* Variable not defined. */
if (free_value)
free(value);
- if (expanded)
- free(expanded);
+ free(expanded);
goto do_error;
}
if (free_value)
free(value);
- if (expanded)
- free(expanded);
+ free(expanded);
goto do_error;
}
goto no_space;
}
- if (pattern)
- free(pattern);
+ free(pattern);
pattern = expanded;
}
if (value == NULL || pattern == NULL || *pattern == '\0')
break;
- end = value + __strlen(value);
+ end = value + strlen(value);
switch (action) {
case ACT_RP_SHORT_LEFT:
if (fnmatch(pattern, value, 0) != FNM_NOMATCH) {
*p = c;
if (free_value) {
- char *newval = __strdup(p);
+ char *newval = strdup(p);
if (newval == NULL) {
free(value);
if (fnmatch(pattern, value, 0) != FNM_NOMATCH) {
*p = c;
if (free_value) {
- char *newval = __strdup(p);
+ char *newval = strdup(p);
if (newval == NULL) {
free(value);
/* Substitute parameter */
break;
- if (free_value && value)
+ if (free_value)
free(value);
if (!colon_seen && value)
/* Substitute NULL */
goto success;
- value = pattern ? __strdup(pattern) : pattern;
+ value = pattern ? strdup(pattern) : pattern;
free_value = 1;
if (pattern && !value)
case ACT_NONNULL_SUBST:
if (value && (*value || !colon_seen)) {
- if (free_value && value)
+ if (free_value)
free(value);
- value = pattern ? __strdup(pattern) : pattern;
+ value = pattern ? strdup(pattern) : pattern;
free_value = 1;
if (pattern && !value)
goto success;
}
- if (free_value && value)
+ if (free_value)
free(value);
- value = pattern ? __strdup(pattern) : pattern;
+ value = pattern ? strdup(pattern) : pattern;
free_value = 1;
if (pattern && !value)
param_length[20] = '\0';
*word = w_addstr(*word, word_length, max_length,
- _itoa(value ? __strlen(value) : 0,
+ _itoa(value ? strlen(value) : 0,
¶m_length[20]));
if (free_value) {
assert(value != NULL);
return *word ? 0 : WRDE_NOSPACE;
} else {
/* Need to field-split */
- char *value_copy = __strdup(value); /* Don't modify value */
+ char *value_copy = strdup(value); /* Don't modify value */
char *field_begin = value_copy;
int seen_nonws_ifs = 0;
/* Skip at most one non-whitespace IFS character after the field */
seen_nonws_ifs = 0;
- if (*next_field && __strchr(ifs, *next_field)) {
+ if (*next_field && strchr(ifs, *next_field)) {
seen_nonws_ifs = 1;
next_field++;
}
error = WRDE_SYNTAX;
do_error:
- if (env)
- free(env);
+ free(env);
- if (pattern)
- free(pattern);
+ free(pattern);
return error;
}
#else
-static inline int
+static __inline__ int
parse_backtick(char **word, size_t * word_length, size_t * max_length,
const char *words, size_t * offset, int flags,
wordexp_t * pwordexp, const char *ifs,
pwordexp->we_wordv = NULL;
}
}
+libc_hidden_def(wordfree)
/*
* wordexp()
/* Find out what the field separators are.
* There are two types: whitespace and non-whitespace.
*/
- ifs = __getenv("IFS");
+ ifs = getenv("IFS");
if (!ifs)
/* IFS unset - use <space><tab><newline>. */
- ifs = __strcpy(ifs_white, " \t\n");
+ ifs = strcpy(ifs_white, " \t\n");
else {
char *ifsch = ifs;
char *whch = ifs_white;
default:
/* Is it a word separator? */
- if (__strchr(" \t", words[words_offset]) == NULL) {
+ if (strchr(" \t", words[words_offset]) == NULL) {
char ch = words[words_offset];
/* Not a word separator -- but is it a valid word char? */
- if (__strchr("\n|&;<>(){}", ch)) {
+ if (strchr("\n|&;<>(){}", ch)) {
/* Fail */
error = WRDE_BADCHAR;
goto do_error;
* set we members back to what they were.
*/
- if (word != NULL)
- free(word);
+ free(word);
if (error == WRDE_NOSPACE)
return WRDE_NOSPACE;