summaryrefslogtreecommitdiffstats
path: root/lib/libc/gen
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/gen')
-rw-r--r--lib/libc/gen/alarm.c3
-rw-r--r--lib/libc/gen/assert.c5
-rw-r--r--lib/libc/gen/clock.c2
-rw-r--r--lib/libc/gen/dlfcn.c4
-rw-r--r--lib/libc/gen/dup3.c2
-rw-r--r--lib/libc/gen/elf_utils.c3
-rw-r--r--lib/libc/gen/err.c5
-rw-r--r--lib/libc/gen/exec.c4
-rw-r--r--lib/libc/gen/feature_present.c1
-rw-r--r--lib/libc/gen/fmtcheck.c1
-rw-r--r--lib/libc/gen/fnmatch.c95
-rw-r--r--lib/libc/gen/ftok.c4
-rw-r--r--lib/libc/gen/fts-compat.c67
-rw-r--r--lib/libc/gen/fts.c9
-rw-r--r--lib/libc/gen/getbsize.c4
-rw-r--r--lib/libc/gen/getcwd.c4
-rw-r--r--lib/libc/gen/getdomainname.c4
-rw-r--r--lib/libc/gen/getgrent.c5
-rw-r--r--lib/libc/gen/gethostname.c4
-rw-r--r--lib/libc/gen/getloadavg.c4
-rw-r--r--lib/libc/gen/getmntinfo.c4
-rw-r--r--lib/libc/gen/getpagesize.c2
-rw-r--r--lib/libc/gen/getpwent.c5
-rw-r--r--lib/libc/gen/getusershell.c17
-rw-r--r--lib/libc/gen/getvfsbyname.c4
-rw-r--r--lib/libc/gen/glob.c16
-rw-r--r--lib/libc/gen/initgroups.c4
-rw-r--r--lib/libc/gen/isatty.c3
-rw-r--r--lib/libc/gen/nlist.c26
-rw-r--r--lib/libc/gen/pause.c2
-rw-r--r--lib/libc/gen/popen.c6
-rw-r--r--lib/libc/gen/psignal.c4
-rw-r--r--lib/libc/gen/raise.c1
-rw-r--r--lib/libc/gen/readdir.c12
-rw-r--r--lib/libc/gen/rewinddir.c3
-rw-r--r--lib/libc/gen/seekdir.c4
-rw-r--r--lib/libc/gen/semctl.c1
-rw-r--r--lib/libc/gen/setjmperr.c2
-rw-r--r--lib/libc/gen/sigsetops.c18
-rw-r--r--lib/libc/gen/sleep.c2
-rw-r--r--lib/libc/gen/strtofflags.c9
-rw-r--r--lib/libc/gen/sysconf.c3
-rw-r--r--lib/libc/gen/telldir.c10
-rw-r--r--lib/libc/gen/tls.c2
-rw-r--r--lib/libc/gen/ttyslot.c2
-rw-r--r--lib/libc/gen/ualarm.c4
-rw-r--r--lib/libc/gen/uname.c2
-rw-r--r--lib/libc/gen/unvis-compat.c2
-rw-r--r--lib/libc/gen/usleep.c2
-rw-r--r--lib/libc/gen/utime.c4
-rw-r--r--lib/libc/gen/wait.c2
-rw-r--r--lib/libc/gen/wait3.c2
-rw-r--r--lib/libc/gen/waitid.c2
-rw-r--r--lib/libc/gen/waitpid.c2
-rw-r--r--lib/libc/gen/wordexp.330
-rw-r--r--lib/libc/gen/wordexp.c212
56 files changed, 319 insertions, 337 deletions
diff --git a/lib/libc/gen/alarm.c b/lib/libc/gen/alarm.c
index 318be4c..439a9e1 100644
--- a/lib/libc/gen/alarm.c
+++ b/lib/libc/gen/alarm.c
@@ -40,8 +40,7 @@ __FBSDID("$FreeBSD$");
#include <unistd.h>
unsigned int
-alarm(secs)
- unsigned int secs;
+alarm(unsigned int secs)
{
struct itimerval it, oitv;
struct itimerval *itp = &it;
diff --git a/lib/libc/gen/assert.c b/lib/libc/gen/assert.c
index 73e199c..ccbc7a4 100644
--- a/lib/libc/gen/assert.c
+++ b/lib/libc/gen/assert.c
@@ -38,10 +38,7 @@ __FBSDID("$FreeBSD$");
#include <stdlib.h>
void
-__assert(func, file, line, failedexpr)
- const char *func, *file;
- int line;
- const char *failedexpr;
+__assert(const char *func, const char *file, int line, const char *failedexpr)
{
if (func == NULL)
(void)fprintf(stderr,
diff --git a/lib/libc/gen/clock.c b/lib/libc/gen/clock.c
index b405cda..435e0f8 100644
--- a/lib/libc/gen/clock.c
+++ b/lib/libc/gen/clock.c
@@ -45,7 +45,7 @@ __FBSDID("$FreeBSD$");
+ (r).tv_usec / (1000000 / CLOCKS_PER_SEC))
clock_t
-clock()
+clock(void)
{
struct rusage ru;
diff --git a/lib/libc/gen/dlfcn.c b/lib/libc/gen/dlfcn.c
index 7d28797..53c9d67 100644
--- a/lib/libc/gen/dlfcn.c
+++ b/lib/libc/gen/dlfcn.c
@@ -41,6 +41,10 @@ __FBSDID("$FreeBSD$");
static char sorry[] = "Service unavailable";
+void _rtld_thread_init(void *);
+void _rtld_atfork_pre(int *);
+void _rtld_atfork_post(int *);
+
/*
* For ELF, the dynamic linker directly resolves references to its
* services to functions inside the dynamic linker itself. These
diff --git a/lib/libc/gen/dup3.c b/lib/libc/gen/dup3.c
index ac8877c..ff3431a 100644
--- a/lib/libc/gen/dup3.c
+++ b/lib/libc/gen/dup3.c
@@ -35,6 +35,8 @@ __FBSDID("$FreeBSD$");
#include <errno.h>
#include "un-namespace.h"
+int __dup3(int, int, int);
+
int
__dup3(int oldfd, int newfd, int flags)
{
diff --git a/lib/libc/gen/elf_utils.c b/lib/libc/gen/elf_utils.c
index 7bd7511..069f62e 100644
--- a/lib/libc/gen/elf_utils.c
+++ b/lib/libc/gen/elf_utils.c
@@ -33,6 +33,9 @@
#include <link.h>
#include <stddef.h>
+int __elf_phdr_match_addr(struct dl_phdr_info *, void *);
+void __pthread_map_stacks_exec(void);
+
int
__elf_phdr_match_addr(struct dl_phdr_info *phdr_info, void *addr)
{
diff --git a/lib/libc/gen/err.c b/lib/libc/gen/err.c
index 0ba584c..a536e5a 100644
--- a/lib/libc/gen/err.c
+++ b/lib/libc/gen/err.c
@@ -79,10 +79,7 @@ _err(int eval, const char *fmt, ...)
}
void
-verr(eval, fmt, ap)
- int eval;
- const char *fmt;
- va_list ap;
+verr(int eval, const char *fmt, va_list ap)
{
verrc(eval, errno, fmt, ap);
}
diff --git a/lib/libc/gen/exec.c b/lib/libc/gen/exec.c
index 4998ee8..c6731f7 100644
--- a/lib/libc/gen/exec.c
+++ b/lib/libc/gen/exec.c
@@ -131,9 +131,7 @@ execlp(const char *name, const char *arg, ...)
}
int
-execv(name, argv)
- const char *name;
- char * const *argv;
+execv(const char *name, char * const *argv)
{
(void)_execve(name, argv, environ);
return (-1);
diff --git a/lib/libc/gen/feature_present.c b/lib/libc/gen/feature_present.c
index 7a2c282..a230c8a 100644
--- a/lib/libc/gen/feature_present.c
+++ b/lib/libc/gen/feature_present.c
@@ -35,6 +35,7 @@ __FBSDID("$FreeBSD$");
#include <sys/sysctl.h>
#include <stdio.h>
#include <stdlib.h>
+#include <unistd.h>
/*
* Returns true if the named feature is present in the currently
diff --git a/lib/libc/gen/fmtcheck.c b/lib/libc/gen/fmtcheck.c
index 5b3f2c4..7929f1f 100644
--- a/lib/libc/gen/fmtcheck.c
+++ b/lib/libc/gen/fmtcheck.c
@@ -36,6 +36,7 @@ __FBSDID("$FreeBSD$");
#include <ctype.h>
__weak_reference(__fmtcheck, fmtcheck);
+const char * __fmtcheck(const char *, const char *);
enum __e_fmtcheck_types {
FMTCHECK_START,
diff --git a/lib/libc/gen/fnmatch.c b/lib/libc/gen/fnmatch.c
index 47d0a41..2f240a8 100644
--- a/lib/libc/gen/fnmatch.c
+++ b/lib/libc/gen/fnmatch.c
@@ -76,9 +76,7 @@ static int fnmatch1(const char *, const char *, const char *, int, mbstate_t,
mbstate_t);
int
-fnmatch(pattern, string, flags)
- const char *pattern, *string;
- int flags;
+fnmatch(const char *pattern, const char *string, int flags)
{
static const mbstate_t initial;
@@ -86,16 +84,17 @@ fnmatch(pattern, string, flags)
}
static int
-fnmatch1(pattern, string, stringstart, flags, patmbs, strmbs)
- const char *pattern, *string, *stringstart;
- int flags;
- mbstate_t patmbs, strmbs;
+fnmatch1(const char *pattern, const char *string, const char *stringstart,
+ int flags, mbstate_t patmbs, mbstate_t strmbs)
{
+ const char *bt_pattern, *bt_string;
+ mbstate_t bt_patmbs, bt_strmbs;
char *newp;
char c;
wchar_t pc, sc;
size_t pclen, sclen;
+ bt_pattern = bt_string = NULL;
for (;;) {
pclen = mbrtowc(&pc, pattern, MB_LEN_MAX, &patmbs);
if (pclen == (size_t)-1 || pclen == (size_t)-2)
@@ -111,16 +110,18 @@ fnmatch1(pattern, string, stringstart, flags, patmbs, strmbs)
case EOS:
if ((flags & FNM_LEADING_DIR) && sc == '/')
return (0);
- return (sc == EOS ? 0 : FNM_NOMATCH);
+ if (sc == EOS)
+ return (0);
+ goto backtrack;
case '?':
if (sc == EOS)
return (FNM_NOMATCH);
if (sc == '/' && (flags & FNM_PATHNAME))
- return (FNM_NOMATCH);
+ goto backtrack;
if (sc == '.' && (flags & FNM_PERIOD) &&
(string == stringstart ||
((flags & FNM_PATHNAME) && *(string - 1) == '/')))
- return (FNM_NOMATCH);
+ goto backtrack;
string += sclen;
break;
case '*':
@@ -132,7 +133,7 @@ fnmatch1(pattern, string, stringstart, flags, patmbs, strmbs)
if (sc == '.' && (flags & FNM_PERIOD) &&
(string == stringstart ||
((flags & FNM_PATHNAME) && *(string - 1) == '/')))
- return (FNM_NOMATCH);
+ goto backtrack;
/* Optimize for pattern with * at end or before /. */
if (c == EOS)
@@ -148,33 +149,24 @@ fnmatch1(pattern, string, stringstart, flags, patmbs, strmbs)
break;
}
- /* General case, use recursion. */
- while (sc != EOS) {
- if (!fnmatch1(pattern, string, stringstart,
- flags, patmbs, strmbs))
- return (0);
- sclen = mbrtowc(&sc, string, MB_LEN_MAX,
- &strmbs);
- if (sclen == (size_t)-1 ||
- sclen == (size_t)-2) {
- sc = (unsigned char)*string;
- sclen = 1;
- memset(&strmbs, 0, sizeof(strmbs));
- }
- if (sc == '/' && flags & FNM_PATHNAME)
- break;
- string += sclen;
- }
- return (FNM_NOMATCH);
+ /*
+ * First try the shortest match for the '*' that
+ * could work. We can forget any earlier '*' since
+ * there is no way having it match more characters
+ * can help us, given that we are already here.
+ */
+ bt_pattern = pattern, bt_patmbs = patmbs;
+ bt_string = string, bt_strmbs = strmbs;
+ break;
case '[':
if (sc == EOS)
return (FNM_NOMATCH);
if (sc == '/' && (flags & FNM_PATHNAME))
- return (FNM_NOMATCH);
+ goto backtrack;
if (sc == '.' && (flags & FNM_PERIOD) &&
(string == stringstart ||
((flags & FNM_PATHNAME) && *(string - 1) == '/')))
- return (FNM_NOMATCH);
+ goto backtrack;
switch (rangematch(pattern, sc, flags, &newp,
&patmbs)) {
@@ -184,7 +176,7 @@ fnmatch1(pattern, string, stringstart, flags, patmbs, strmbs)
pattern = newp;
break;
case RANGE_NOMATCH:
- return (FNM_NOMATCH);
+ goto backtrack;
}
string += sclen;
break;
@@ -199,14 +191,39 @@ fnmatch1(pattern, string, stringstart, flags, patmbs, strmbs)
/* FALLTHROUGH */
default:
norm:
+ string += sclen;
if (pc == sc)
;
else if ((flags & FNM_CASEFOLD) &&
(towlower(pc) == towlower(sc)))
;
- else
- return (FNM_NOMATCH);
- string += sclen;
+ else {
+ backtrack:
+ /*
+ * If we have a mismatch (other than hitting
+ * the end of the string), go back to the last
+ * '*' seen and have it match one additional
+ * character.
+ */
+ if (bt_pattern == NULL)
+ return (FNM_NOMATCH);
+ sclen = mbrtowc(&sc, bt_string, MB_LEN_MAX,
+ &bt_strmbs);
+ if (sclen == (size_t)-1 ||
+ sclen == (size_t)-2) {
+ sc = (unsigned char)*bt_string;
+ sclen = 1;
+ memset(&bt_strmbs, 0,
+ sizeof(bt_strmbs));
+ }
+ if (sc == EOS)
+ return (FNM_NOMATCH);
+ if (sc == '/' && flags & FNM_PATHNAME)
+ return (FNM_NOMATCH);
+ bt_string += sclen;
+ pattern = bt_pattern, patmbs = bt_patmbs;
+ string = bt_string, strmbs = bt_strmbs;
+ }
break;
}
}
@@ -214,12 +231,8 @@ fnmatch1(pattern, string, stringstart, flags, patmbs, strmbs)
}
static int
-rangematch(pattern, test, flags, newp, patmbs)
- const char *pattern;
- wchar_t test;
- int flags;
- char **newp;
- mbstate_t *patmbs;
+rangematch(const char *pattern, wchar_t test, int flags, char **newp,
+ mbstate_t *patmbs)
{
int negate, ok;
wchar_t c, c2;
diff --git a/lib/libc/gen/ftok.c b/lib/libc/gen/ftok.c
index 4269e37..2fad66e 100644
--- a/lib/libc/gen/ftok.c
+++ b/lib/libc/gen/ftok.c
@@ -33,9 +33,7 @@ __FBSDID("$FreeBSD$");
#include <sys/ipc.h>
key_t
-ftok(path, id)
- const char *path;
- int id;
+ftok(const char *path, int id)
{
struct stat st;
diff --git a/lib/libc/gen/fts-compat.c b/lib/libc/gen/fts-compat.c
index 1be41da..51b6c26 100644
--- a/lib/libc/gen/fts-compat.c
+++ b/lib/libc/gen/fts-compat.c
@@ -120,10 +120,8 @@ static const char *ufslike_filesystems[] = {
};
FTS *
-__fts_open_44bsd(argv, options, compar)
- char * const *argv;
- int options;
- int (*compar)(const FTSENT * const *, const FTSENT * const *);
+__fts_open_44bsd(char * const *argv, int options,
+ int (*compar)(const FTSENT * const *, const FTSENT * const *))
{
struct _fts_private *priv;
FTS *sp;
@@ -139,9 +137,8 @@ __fts_open_44bsd(argv, options, compar)
}
/* Allocate/initialize the stream. */
- if ((priv = malloc(sizeof(*priv))) == NULL)
+ if ((priv = calloc(1, sizeof(*priv))) == NULL)
return (NULL);
- memset(priv, 0, sizeof(*priv));
sp = &priv->ftsp_fts;
sp->fts_compar = compar;
sp->fts_options = options;
@@ -234,9 +231,7 @@ mem1: free(sp);
}
static void
-fts_load(sp, p)
- FTS *sp;
- FTSENT *p;
+fts_load(FTS *sp, FTSENT *p)
{
int len;
char *cp;
@@ -260,8 +255,7 @@ fts_load(sp, p)
}
int
-__fts_close_44bsd(sp)
- FTS *sp;
+__fts_close_44bsd(FTS *sp)
{
FTSENT *freep, *p;
int saved_errno;
@@ -315,8 +309,7 @@ __fts_close_44bsd(sp)
? p->fts_pathlen - 1 : p->fts_pathlen)
FTSENT *
-__fts_read_44bsd(sp)
- FTS *sp;
+__fts_read_44bsd(FTS *sp)
{
FTSENT *p, *tmp;
int instr;
@@ -510,10 +503,7 @@ name: t = sp->fts_path + NAPPEND(p->fts_parent);
*/
/* ARGSUSED */
int
-__fts_set_44bsd(sp, p, instr)
- FTS *sp;
- FTSENT *p;
- int instr;
+__fts_set_44bsd(FTS *sp, FTSENT *p, int instr)
{
if (instr != 0 && instr != FTS_AGAIN && instr != FTS_FOLLOW &&
instr != FTS_NOINSTR && instr != FTS_SKIP) {
@@ -525,9 +515,7 @@ __fts_set_44bsd(sp, p, instr)
}
FTSENT *
-__fts_children_44bsd(sp, instr)
- FTS *sp;
- int instr;
+__fts_children_44bsd(FTS *sp, int instr)
{
FTSENT *p;
int fd;
@@ -635,9 +623,7 @@ __fts_set_clientptr_44bsd(FTS *sp, void *clientptr)
* been found, cutting the stat calls by about 2/3.
*/
static FTSENT *
-fts_build(sp, type)
- FTS *sp;
- int type;
+fts_build(FTS *sp, int type)
{
struct dirent *dp;
FTSENT *p, *head;
@@ -901,10 +887,7 @@ mem1: saved_errno = errno;
}
static u_short
-fts_stat(sp, p, follow)
- FTS *sp;
- FTSENT *p;
- int follow;
+fts_stat(FTS *sp, FTSENT *p, int follow)
{
FTSENT *t;
dev_t dev;
@@ -999,10 +982,7 @@ fts_compar(const void *a, const void *b)
}
static FTSENT *
-fts_sort(sp, head, nitems)
- FTS *sp;
- FTSENT *head;
- int nitems;
+fts_sort(FTS *sp, FTSENT *head, int nitems)
{
FTSENT **ap, *p;
@@ -1031,10 +1011,7 @@ fts_sort(sp, head, nitems)
}
static FTSENT *
-fts_alloc(sp, name, namelen)
- FTS *sp;
- char *name;
- int namelen;
+fts_alloc(FTS *sp, char *name, int namelen)
{
FTSENT *p;
size_t len;
@@ -1081,8 +1058,7 @@ fts_alloc(sp, name, namelen)
}
static void
-fts_lfree(head)
- FTSENT *head;
+fts_lfree(FTSENT *head)
{
FTSENT *p;
@@ -1100,9 +1076,7 @@ fts_lfree(head)
* plus 256 bytes so don't realloc the path 2 bytes at a time.
*/
static int
-fts_palloc(sp, more)
- FTS *sp;
- size_t more;
+fts_palloc(FTS *sp, size_t more)
{
sp->fts_pathlen += more + 256;
@@ -1127,9 +1101,7 @@ fts_palloc(sp, more)
* already returned.
*/
static void
-fts_padjust(sp, head)
- FTS *sp;
- FTSENT *head;
+fts_padjust(FTS *sp, FTSENT *head)
{
FTSENT *p;
char *addr = sp->fts_path;
@@ -1153,8 +1125,7 @@ fts_padjust(sp, head)
}
static size_t
-fts_maxarglen(argv)
- char * const *argv;
+fts_maxarglen(char * const *argv)
{
size_t len, max;
@@ -1170,11 +1141,7 @@ fts_maxarglen(argv)
* Assumes p->fts_dev and p->fts_ino are filled in.
*/
static int
-fts_safe_changedir(sp, p, fd, path)
- FTS *sp;
- FTSENT *p;
- int fd;
- char *path;
+fts_safe_changedir(FTS *sp, FTSENT *p, int fd, char *path)
{
int ret, oerrno, newfd;
struct stat sb;
diff --git a/lib/libc/gen/fts.c b/lib/libc/gen/fts.c
index 8083a88..03ef5c8 100644
--- a/lib/libc/gen/fts.c
+++ b/lib/libc/gen/fts.c
@@ -110,10 +110,8 @@ static const char *ufslike_filesystems[] = {
};
FTS *
-fts_open(argv, options, compar)
- char * const *argv;
- int options;
- int (*compar)(const FTSENT * const *, const FTSENT * const *);
+fts_open(char * const *argv, int options,
+ int (*compar)(const FTSENT * const *, const FTSENT * const *))
{
struct _fts_private *priv;
FTS *sp;
@@ -1105,8 +1103,7 @@ fts_padjust(FTS *sp, FTSENT *head)
}
static size_t
-fts_maxarglen(argv)
- char * const *argv;
+fts_maxarglen(char * const *argv)
{
size_t len, max;
diff --git a/lib/libc/gen/getbsize.c b/lib/libc/gen/getbsize.c
index 7e88e3f..bbf5b1e 100644
--- a/lib/libc/gen/getbsize.c
+++ b/lib/libc/gen/getbsize.c
@@ -39,9 +39,7 @@ __FBSDID("$FreeBSD$");
#include <string.h>
char *
-getbsize(headerlenp, blocksizep)
- int *headerlenp;
- long *blocksizep;
+getbsize(int *headerlenp, long *blocksizep)
{
static char header[20];
long n, max, mul, blocksize;
diff --git a/lib/libc/gen/getcwd.c b/lib/libc/gen/getcwd.c
index da76d56..6884897 100644
--- a/lib/libc/gen/getcwd.c
+++ b/lib/libc/gen/getcwd.c
@@ -55,9 +55,7 @@ __FBSDID("$FreeBSD$");
extern int __getcwd(char *, size_t);
char *
-getcwd(pt, size)
- char *pt;
- size_t size;
+getcwd(char *pt, size_t size)
{
struct dirent *dp;
DIR *dir = NULL;
diff --git a/lib/libc/gen/getdomainname.c b/lib/libc/gen/getdomainname.c
index 21eb66d..5a38857 100644
--- a/lib/libc/gen/getdomainname.c
+++ b/lib/libc/gen/getdomainname.c
@@ -39,9 +39,7 @@ __FBSDID("$FreeBSD$");
#include <unistd.h>
int
-getdomainname(name, namelen)
- char *name;
- int namelen;
+getdomainname(char *name, int namelen)
{
int mib[2];
size_t size;
diff --git a/lib/libc/gen/getgrent.c b/lib/libc/gen/getgrent.c
index 1f4d7e9..31d2af1 100644
--- a/lib/libc/gen/getgrent.c
+++ b/lib/libc/gen/getgrent.c
@@ -75,6 +75,7 @@ static const ns_src defaultsrc[] = {
{ NULL, 0 }
};
+int __getgroupmembership(const char *, gid_t, gid_t *, int, int *);
int __gr_match_entry(const char *, size_t, enum nss_lookup_type,
const char *, gid_t);
int __gr_parse_entry(char *, size_t, struct group *, char *, size_t,
@@ -1238,7 +1239,7 @@ compat_setgrent(void *retval, void *mdata, va_list ap)
int rv, stayopen;
#define set_setent(x, y) do { \
- int i; \
+ unsigned int i; \
\
for (i = 0; i < (sizeof(x)/sizeof(x[0])) - 1; i++) \
x[i].mdata = (void *)y; \
@@ -1308,7 +1309,7 @@ compat_group(void *retval, void *mdata, va_list ap)
int rv, stayopen, *errnop;
#define set_lookup_type(x, y) do { \
- int i; \
+ unsigned int i; \
\
for (i = 0; i < (sizeof(x)/sizeof(x[0])) - 1; i++) \
x[i].mdata = (void *)y; \
diff --git a/lib/libc/gen/gethostname.c b/lib/libc/gen/gethostname.c
index c83805e..dc2b372 100644
--- a/lib/libc/gen/gethostname.c
+++ b/lib/libc/gen/gethostname.c
@@ -40,9 +40,7 @@ __FBSDID("$FreeBSD$");
#include <unistd.h>
int
-gethostname(name, namelen)
- char *name;
- size_t namelen;
+gethostname(char *name, size_t namelen)
{
int mib[2];
diff --git a/lib/libc/gen/getloadavg.c b/lib/libc/gen/getloadavg.c
index 127d3e8..9c06d0a 100644
--- a/lib/libc/gen/getloadavg.c
+++ b/lib/libc/gen/getloadavg.c
@@ -48,9 +48,7 @@ __FBSDID("$FreeBSD$");
* Return number of samples retrieved, or -1 on error.
*/
int
-getloadavg(loadavg, nelem)
- double loadavg[];
- int nelem;
+getloadavg(double loadavg[], int nelem)
{
struct loadavg loadinfo;
int i, mib[2];
diff --git a/lib/libc/gen/getmntinfo.c b/lib/libc/gen/getmntinfo.c
index 2b532f6..99f82aa 100644
--- a/lib/libc/gen/getmntinfo.c
+++ b/lib/libc/gen/getmntinfo.c
@@ -42,9 +42,7 @@ __FBSDID("$FreeBSD$");
* Return information about mounted filesystems.
*/
int
-getmntinfo(mntbufp, flags)
- struct statfs **mntbufp;
- int flags;
+getmntinfo(struct statfs **mntbufp, int flags)
{
static struct statfs *mntbuf;
static int mntsize;
diff --git a/lib/libc/gen/getpagesize.c b/lib/libc/gen/getpagesize.c
index f4b8128..da2eb69 100644
--- a/lib/libc/gen/getpagesize.c
+++ b/lib/libc/gen/getpagesize.c
@@ -51,7 +51,7 @@ __FBSDID("$FreeBSD$");
*/
int
-getpagesize()
+getpagesize(void)
{
int mib[2];
static int value;
diff --git a/lib/libc/gen/getpwent.c b/lib/libc/gen/getpwent.c
index 09a6247..6546f587 100644
--- a/lib/libc/gen/getpwent.c
+++ b/lib/libc/gen/getpwent.c
@@ -1607,7 +1607,8 @@ compat_redispatch(struct compat_state *st, enum nss_lookup_type how,
{ NULL, NULL, NULL }
};
void *discard;
- int rv, e, i;
+ int rv, e;
+ unsigned int i;
for (i = 0; i < sizeof(dtab)/sizeof(dtab[0]) - 1; i++)
dtab[i].mdata = (void *)lookup_how;
@@ -1702,7 +1703,7 @@ compat_setpwent(void *retval, void *mdata, va_list ap)
int rv, stayopen;
#define set_setent(x, y) do { \
- int i; \
+ unsigned int i; \
\
for (i = 0; i < (sizeof(x)/sizeof(x[0])) - 1; i++) \
x[i].mdata = (void *)y; \
diff --git a/lib/libc/gen/getusershell.c b/lib/libc/gen/getusershell.c
index 53536e1..6e78286 100644
--- a/lib/libc/gen/getusershell.c
+++ b/lib/libc/gen/getusershell.c
@@ -102,10 +102,7 @@ static int _local_initshells(void *, void *, va_list);
/*ARGSUSED*/
static int
-_local_initshells(rv, cb_data, ap)
- void *rv;
- void *cb_data;
- va_list ap;
+_local_initshells(void *rv, void *cb_data, va_list ap)
{
char *sp, *cp;
FILE *fp;
@@ -139,10 +136,7 @@ static int _dns_initshells(void *, void *, va_list);
/*ARGSUSED*/
static int
-_dns_initshells(rv, cb_data, ap)
- void *rv;
- void *cb_data;
- va_list ap;
+_dns_initshells(void *rv, void *cb_data, va_list ap)
{
char shellname[] = "shells-XXXXX";
int hsindex, hpi, r;
@@ -183,10 +177,7 @@ static int _nis_initshells(void *, void *, va_list);
/*ARGSUSED*/
static int
-_nis_initshells(rv, cb_data, ap)
- void *rv;
- void *cb_data;
- va_list ap;
+_nis_initshells(void *rv, void *cb_data, va_list ap)
{
static char *ypdomain;
char *key, *data;
@@ -239,7 +230,7 @@ _nis_initshells(rv, cb_data, ap)
#endif /* YP */
static const char *const *
-initshells()
+initshells(void)
{
static const ns_dtab dtab[] = {
NS_FILES_CB(_local_initshells, NULL)
diff --git a/lib/libc/gen/getvfsbyname.c b/lib/libc/gen/getvfsbyname.c
index 0d896bb..c90c5ee 100644
--- a/lib/libc/gen/getvfsbyname.c
+++ b/lib/libc/gen/getvfsbyname.c
@@ -45,9 +45,7 @@ __FBSDID("$FreeBSD$");
* and if it is resident, return its xvfsconf structure.
*/
int
-getvfsbyname(fsname, vfcp)
- const char *fsname;
- struct xvfsconf *vfcp;
+getvfsbyname(const char *fsname, struct xvfsconf *vfcp)
{
struct xvfsconf *xvfsp;
size_t buflen;
diff --git a/lib/libc/gen/glob.c b/lib/libc/gen/glob.c
index 95a3a06..971d616 100644
--- a/lib/libc/gen/glob.c
+++ b/lib/libc/gen/glob.c
@@ -650,13 +650,7 @@ glob3(Char *pathbuf, Char *pathend, Char *pathend_last,
int err;
char buf[MAXPATHLEN];
- /*
- * The readdirfunc declaration can't be prototyped, because it is
- * assigned, below, to two functions which are prototyped in glob.h
- * and dirent.h as taking pointers to differently typed opaque
- * structures.
- */
- struct dirent *(*readdirfunc)();
+ struct dirent *(*readdirfunc)(DIR *);
if (pathend > pathend_last)
return (GLOB_ABORTED);
@@ -677,12 +671,14 @@ glob3(Char *pathbuf, Char *pathend, Char *pathend_last,
err = 0;
- /* Search directory for matching names. */
+ /* pglob->gl_readdir takes a void *, fix this manually */
if (pglob->gl_flags & GLOB_ALTDIRFUNC)
- readdirfunc = pglob->gl_readdir;
+ readdirfunc = (struct dirent *(*)(DIR *))pglob->gl_readdir;
else
readdirfunc = readdir;
- while ((dp = (*readdirfunc)(dirp))) {
+
+ /* Search directory for matching names. */
+ while ((dp = (*readdirfunc)(dirp)) != NULL) {
char *sc;
Char *dc;
wchar_t wc;
diff --git a/lib/libc/gen/initgroups.c b/lib/libc/gen/initgroups.c
index aacaf7e..d6a644c 100644
--- a/lib/libc/gen/initgroups.c
+++ b/lib/libc/gen/initgroups.c
@@ -44,9 +44,7 @@ __FBSDID("$FreeBSD$");
#include <unistd.h>
int
-initgroups(uname, agroup)
- const char *uname;
- gid_t agroup;
+initgroups(const char *uname, gid_t agroup)
{
int ngroups, ret;
long ngroups_max;
diff --git a/lib/libc/gen/isatty.c b/lib/libc/gen/isatty.c
index 076b824..02b0ffd 100644
--- a/lib/libc/gen/isatty.c
+++ b/lib/libc/gen/isatty.c
@@ -37,8 +37,7 @@ __FBSDID("$FreeBSD$");
#include <unistd.h>
int
-isatty(fd)
- int fd;
+isatty(int fd)
{
int retval;
struct termios t;
diff --git a/lib/libc/gen/nlist.c b/lib/libc/gen/nlist.c
index ec878c5..e93f89b 100644
--- a/lib/libc/gen/nlist.c
+++ b/lib/libc/gen/nlist.c
@@ -61,11 +61,10 @@ __FBSDID("$FreeBSD$");
int __fdnlist(int, struct nlist *);
int __aout_fdnlist(int, struct nlist *);
int __elf_fdnlist(int, struct nlist *);
+int __elf_is_okay__(Elf_Ehdr *);
int
-nlist(name, list)
- const char *name;
- struct nlist *list;
+nlist(const char *name, struct nlist *list)
{
int fd, n;
@@ -89,11 +88,10 @@ static struct nlist_handlers {
};
int
-__fdnlist(fd, list)
- int fd;
- struct nlist *list;
+__fdnlist(int fd, struct nlist *list)
{
- int n = -1, i;
+ int n = -1;
+ unsigned int i;
for (i = 0; i < sizeof(nlist_fn) / sizeof(nlist_fn[0]); i++) {
n = (nlist_fn[i].fn)(fd, list);
@@ -107,9 +105,7 @@ __fdnlist(fd, list)
#ifdef _NLIST_DO_AOUT
int
-__aout_fdnlist(fd, list)
- int fd;
- struct nlist *list;
+__aout_fdnlist(int fd, struct nlist *list)
{
struct nlist *p, *symtab;
caddr_t strtab, a_out_mmap;
@@ -235,9 +231,7 @@ __elf_is_okay__(Elf_Ehdr *ehdr)
}
int
-__elf_fdnlist(fd, list)
- int fd;
- struct nlist *list;
+__elf_fdnlist(int fd, struct nlist *list)
{
struct nlist *p;
Elf_Off symoff = 0, symstroff = 0;
@@ -377,11 +371,7 @@ __elf_fdnlist(fd, list)
* n_value and n_type members.
*/
static void
-elf_sym_to_nlist(nl, s, shdr, shnum)
- struct nlist *nl;
- Elf_Sym *s;
- Elf_Shdr *shdr;
- int shnum;
+elf_sym_to_nlist(struct nlist *nl, Elf_Sym *s, Elf_Shdr *shdr, int shnum)
{
nl->n_value = s->st_value;
diff --git a/lib/libc/gen/pause.c b/lib/libc/gen/pause.c
index ef48c1c..8e7a638 100644
--- a/lib/libc/gen/pause.c
+++ b/lib/libc/gen/pause.c
@@ -38,6 +38,8 @@ __FBSDID("$FreeBSD$");
#include "libc_private.h"
+int __pause(void);
+
/*
* Backwards compatible pause.
*/
diff --git a/lib/libc/gen/popen.c b/lib/libc/gen/popen.c
index e54bb5c..a7a9708 100644
--- a/lib/libc/gen/popen.c
+++ b/lib/libc/gen/popen.c
@@ -67,8 +67,7 @@ static pthread_mutex_t pidlist_mutex = PTHREAD_MUTEX_INITIALIZER;
#define THREAD_UNLOCK() if (__isthreaded) _pthread_mutex_unlock(&pidlist_mutex)
FILE *
-popen(command, type)
- const char *command, *type;
+popen(const char *command, const char *type)
{
struct pid *cur;
FILE *iop;
@@ -179,8 +178,7 @@ popen(command, type)
* if already `pclosed', or waitpid returns an error.
*/
int
-pclose(iop)
- FILE *iop;
+pclose(FILE *iop)
{
struct pid *cur, *last = NULL;
int pstat;
diff --git a/lib/libc/gen/psignal.c b/lib/libc/gen/psignal.c
index 6fca4b1..5c5aada 100644
--- a/lib/libc/gen/psignal.c
+++ b/lib/libc/gen/psignal.c
@@ -44,9 +44,7 @@ __FBSDID("$FreeBSD$");
#include "un-namespace.h"
void
-psignal(sig, s)
- unsigned int sig;
- const char *s;
+psignal(unsigned int sig, const char *s)
{
const char *c;
diff --git a/lib/libc/gen/raise.c b/lib/libc/gen/raise.c
index 994fea5..4bc895e 100644
--- a/lib/libc/gen/raise.c
+++ b/lib/libc/gen/raise.c
@@ -40,6 +40,7 @@ __FBSDID("$FreeBSD$");
__weak_reference(__raise, raise);
__weak_reference(__raise, _raise);
+int __raise(int);
int
__raise(int s)
diff --git a/lib/libc/gen/readdir.c b/lib/libc/gen/readdir.c
index c6f5d3f..b5162ed 100644
--- a/lib/libc/gen/readdir.c
+++ b/lib/libc/gen/readdir.c
@@ -49,9 +49,7 @@ __FBSDID("$FreeBSD$");
* get next entry in a directory.
*/
struct dirent *
-_readdir_unlocked(dirp, skip)
- DIR *dirp;
- int skip;
+_readdir_unlocked(DIR *dirp, int skip)
{
struct dirent *dp;
long initial_seek;
@@ -91,8 +89,7 @@ _readdir_unlocked(dirp, skip)
}
struct dirent *
-readdir(dirp)
- DIR *dirp;
+readdir(DIR *dirp)
{
struct dirent *dp;
@@ -107,10 +104,7 @@ readdir(dirp)
}
int
-readdir_r(dirp, entry, result)
- DIR *dirp;
- struct dirent *entry;
- struct dirent **result;
+readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result)
{
struct dirent *dp;
int saved_errno;
diff --git a/lib/libc/gen/rewinddir.c b/lib/libc/gen/rewinddir.c
index e157cd6..2421c47 100644
--- a/lib/libc/gen/rewinddir.c
+++ b/lib/libc/gen/rewinddir.c
@@ -45,8 +45,7 @@ __FBSDID("$FreeBSD$");
#include "telldir.h"
void
-rewinddir(dirp)
- DIR *dirp;
+rewinddir(DIR *dirp)
{
if (__isthreaded)
diff --git a/lib/libc/gen/seekdir.c b/lib/libc/gen/seekdir.c
index e9851a7..699de46 100644
--- a/lib/libc/gen/seekdir.c
+++ b/lib/libc/gen/seekdir.c
@@ -48,9 +48,7 @@ __FBSDID("$FreeBSD$");
* _seekdir is in telldir.c so that it can share opaque data structures.
*/
void
-seekdir(dirp, loc)
- DIR *dirp;
- long loc;
+seekdir(DIR *dirp, long loc)
{
if (__isthreaded)
_pthread_mutex_lock(&dirp->dd_lock);
diff --git a/lib/libc/gen/semctl.c b/lib/libc/gen/semctl.c
index 156d18c..c68734d 100644
--- a/lib/libc/gen/semctl.c
+++ b/lib/libc/gen/semctl.c
@@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$");
int __semctl(int semid, int semnum, int cmd, union semun *arg);
int freebsd7___semctl(int semid, int semnum, int cmd, union semun_old *arg);
+int freebsd7_semctl(int semid, int semnum, int cmd, ...);
int
semctl(int semid, int semnum, int cmd, ...)
diff --git a/lib/libc/gen/setjmperr.c b/lib/libc/gen/setjmperr.c
index 3cfeb55..90fa4aa 100644
--- a/lib/libc/gen/setjmperr.c
+++ b/lib/libc/gen/setjmperr.c
@@ -46,7 +46,7 @@ __FBSDID("$FreeBSD$");
#include "un-namespace.h"
void
-longjmperror()
+longjmperror(void)
{
#define ERRMSG "longjmp botch.\n"
(void)_write(STDERR_FILENO, ERRMSG, sizeof(ERRMSG) - 1);
diff --git a/lib/libc/gen/sigsetops.c b/lib/libc/gen/sigsetops.c
index cf7e688..cbcbfec 100644
--- a/lib/libc/gen/sigsetops.c
+++ b/lib/libc/gen/sigsetops.c
@@ -39,9 +39,7 @@ __FBSDID("$FreeBSD$");
#include <signal.h>
int
-sigaddset(set, signo)
- sigset_t *set;
- int signo;
+sigaddset(sigset_t *set, int signo)
{
if (signo <= 0 || signo > _SIG_MAXSIG) {
@@ -53,9 +51,7 @@ sigaddset(set, signo)
}
int
-sigdelset(set, signo)
- sigset_t *set;
- int signo;
+sigdelset(sigset_t *set, int signo)
{
if (signo <= 0 || signo > _SIG_MAXSIG) {
@@ -67,8 +63,7 @@ sigdelset(set, signo)
}
int
-sigemptyset(set)
- sigset_t *set;
+sigemptyset(sigset_t *set)
{
int i;
@@ -78,8 +73,7 @@ sigemptyset(set)
}
int
-sigfillset(set)
- sigset_t *set;
+sigfillset(sigset_t *set)
{
int i;
@@ -89,9 +83,7 @@ sigfillset(set)
}
int
-sigismember(set, signo)
- const sigset_t *set;
- int signo;
+sigismember(const sigset_t *set, int signo)
{
if (signo <= 0 || signo > _SIG_MAXSIG) {
diff --git a/lib/libc/gen/sleep.c b/lib/libc/gen/sleep.c
index 6bb4ecd..6c33c35 100644
--- a/lib/libc/gen/sleep.c
+++ b/lib/libc/gen/sleep.c
@@ -42,6 +42,8 @@ __FBSDID("$FreeBSD$");
#include "libc_private.h"
+unsigned int __sleep(unsigned int);
+
unsigned int
__sleep(unsigned int seconds)
{
diff --git a/lib/libc/gen/strtofflags.c b/lib/libc/gen/strtofflags.c
index 55e9945..dba9cd2 100644
--- a/lib/libc/gen/strtofflags.c
+++ b/lib/libc/gen/strtofflags.c
@@ -94,14 +94,13 @@ static struct {
* are set, return the empty string.
*/
char *
-fflagstostr(flags)
- u_long flags;
+fflagstostr(u_long flags)
{
char *string;
const char *sp;
char *dp;
u_long setflags;
- int i;
+ u_int i;
if ((string = (char *)malloc(nmappings * (longestflaglen + 1))) == NULL)
return (NULL);
@@ -128,9 +127,7 @@ fflagstostr(flags)
* to the offending token.
*/
int
-strtofflags(stringp, setp, clrp)
- char **stringp;
- u_long *setp, *clrp;
+strtofflags(char **stringp, u_long *setp, u_long *clrp)
{
char *string, *p;
int i;
diff --git a/lib/libc/gen/sysconf.c b/lib/libc/gen/sysconf.c
index 2b3acfb..be3d4af 100644
--- a/lib/libc/gen/sysconf.c
+++ b/lib/libc/gen/sysconf.c
@@ -69,8 +69,7 @@ __FBSDID("$FreeBSD$");
* less useful than returning up-to-date values, however.
*/
long
-sysconf(name)
- int name;
+sysconf(int name)
{
struct rlimit rl;
size_t len;
diff --git a/lib/libc/gen/telldir.c b/lib/libc/gen/telldir.c
index 19cd6ee..3e5678c 100644
--- a/lib/libc/gen/telldir.c
+++ b/lib/libc/gen/telldir.c
@@ -50,8 +50,7 @@ __FBSDID("$FreeBSD$");
* return a pointer into a directory
*/
long
-telldir(dirp)
- DIR *dirp;
+telldir(DIR *dirp)
{
struct ddloc *lp;
long idx;
@@ -86,9 +85,7 @@ telldir(dirp)
* Only values returned by "telldir" should be passed to seekdir.
*/
void
-_seekdir(dirp, loc)
- DIR *dirp;
- long loc;
+_seekdir(DIR *dirp, long loc)
{
struct ddloc *lp;
struct dirent *dp;
@@ -152,8 +149,7 @@ _fixtelldir(DIR *dirp, long oldseek, long oldloc)
* Reclaim memory for telldir cookies which weren't used.
*/
void
-_reclaim_telldir(dirp)
- DIR *dirp;
+_reclaim_telldir(DIR *dirp)
{
struct ddloc *lp;
struct ddloc *templp;
diff --git a/lib/libc/gen/tls.c b/lib/libc/gen/tls.c
index 73eb9a2..ca4d696 100644
--- a/lib/libc/gen/tls.c
+++ b/lib/libc/gen/tls.c
@@ -270,7 +270,7 @@ __libc_free_tls(void *tcb __unused, size_t tcbsize __unused,
extern char **environ;
void
-_init_tls()
+_init_tls(void)
{
#ifndef PIC
Elf_Addr *sp;
diff --git a/lib/libc/gen/ttyslot.c b/lib/libc/gen/ttyslot.c
index 1de0837..397e3ad 100644
--- a/lib/libc/gen/ttyslot.c
+++ b/lib/libc/gen/ttyslot.c
@@ -33,6 +33,8 @@ static char sccsid[] = "@(#)ttyslot.c 8.1 (Berkeley) 6/4/93";
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
+int __ttyslot(void);
+
int
__ttyslot(void)
{
diff --git a/lib/libc/gen/ualarm.c b/lib/libc/gen/ualarm.c
index bf75775..6a1dca7 100644
--- a/lib/libc/gen/ualarm.c
+++ b/lib/libc/gen/ualarm.c
@@ -44,9 +44,7 @@ __FBSDID("$FreeBSD$");
* every ``reload'' microseconds after the first signal.
*/
useconds_t
-ualarm(usecs, reload)
- useconds_t usecs;
- useconds_t reload;
+ualarm(useconds_t usecs, useconds_t reload)
{
struct itimerval new, old;
diff --git a/lib/libc/gen/uname.c b/lib/libc/gen/uname.c
index 5a7baf7..499f761 100644
--- a/lib/libc/gen/uname.c
+++ b/lib/libc/gen/uname.c
@@ -40,6 +40,8 @@ __FBSDID("$FreeBSD$");
#include <errno.h>
#undef uname
+int uname(struct utsname *);
+
int
uname(struct utsname *name)
{
diff --git a/lib/libc/gen/unvis-compat.c b/lib/libc/gen/unvis-compat.c
index 080143e..5fa5ca9 100644
--- a/lib/libc/gen/unvis-compat.c
+++ b/lib/libc/gen/unvis-compat.c
@@ -34,6 +34,8 @@
#define _UNVIS_END 1
+int __unvis_44bsd(char *, int, int *, int);
+
int
__unvis_44bsd(char *cp, int c, int *astate, int flag)
{
diff --git a/lib/libc/gen/usleep.c b/lib/libc/gen/usleep.c
index 7c35f6c..90be6d4 100644
--- a/lib/libc/gen/usleep.c
+++ b/lib/libc/gen/usleep.c
@@ -40,6 +40,8 @@ __FBSDID("$FreeBSD$");
#include "libc_private.h"
+int __usleep(useconds_t);
+
int
__usleep(useconds_t useconds)
{
diff --git a/lib/libc/gen/utime.c b/lib/libc/gen/utime.c
index 97bf878..0250a7a 100644
--- a/lib/libc/gen/utime.c
+++ b/lib/libc/gen/utime.c
@@ -38,9 +38,7 @@ __FBSDID("$FreeBSD$");
#include <utime.h>
int
-utime(path, times)
- const char *path;
- const struct utimbuf *times;
+utime(const char *path, const struct utimbuf *times)
{
struct timeval tv[2], *tvp;
diff --git a/lib/libc/gen/wait.c b/lib/libc/gen/wait.c
index 46a3fdd..7cede6e 100644
--- a/lib/libc/gen/wait.c
+++ b/lib/libc/gen/wait.c
@@ -42,6 +42,8 @@ __FBSDID("$FreeBSD$");
#include "libc_private.h"
+pid_t __wait(int *);
+
pid_t
__wait(int *istat)
{
diff --git a/lib/libc/gen/wait3.c b/lib/libc/gen/wait3.c
index 965effe..b50e3dd 100644
--- a/lib/libc/gen/wait3.c
+++ b/lib/libc/gen/wait3.c
@@ -42,6 +42,8 @@ __FBSDID("$FreeBSD$");
#include "libc_private.h"
+pid_t __wait3(int *, int, struct rusage *);
+
pid_t
__wait3(int *istat, int options, struct rusage *rup)
{
diff --git a/lib/libc/gen/waitid.c b/lib/libc/gen/waitid.c
index 17a2dd6..8bdd652 100644
--- a/lib/libc/gen/waitid.c
+++ b/lib/libc/gen/waitid.c
@@ -39,6 +39,8 @@ __FBSDID("$FreeBSD$");
#include "un-namespace.h"
#include "libc_private.h"
+int __waitid(idtype_t, id_t, siginfo_t *, int);
+
int
__waitid(idtype_t idtype, id_t id, siginfo_t *info, int flags)
{
diff --git a/lib/libc/gen/waitpid.c b/lib/libc/gen/waitpid.c
index 5177591..5dc4fa8 100644
--- a/lib/libc/gen/waitpid.c
+++ b/lib/libc/gen/waitpid.c
@@ -42,6 +42,8 @@ __FBSDID("$FreeBSD$");
#include "libc_private.h"
+pid_t __waitpid(pid_t, int *, int);
+
pid_t
__waitpid(pid_t pid, int *istat, int options)
{
diff --git a/lib/libc/gen/wordexp.3 b/lib/libc/gen/wordexp.3
index 2fc20ef..dd4605f 100644
--- a/lib/libc/gen/wordexp.3
+++ b/lib/libc/gen/wordexp.3
@@ -25,7 +25,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd August 18, 2015
+.Dd September 30, 2015
.Dt WORDEXP 3
.Os
.Sh NAME
@@ -108,8 +108,9 @@ function frees the memory allocated by
.Sh IMPLEMENTATION NOTES
The
.Fn wordexp
-function is implemented by executing
-.Xr sh 1 .
+function is implemented using the undocumented
+.Ic freebsd_wordexp
+shell built-in command.
.Sh RETURN VALUES
The
.Fn wordexp
@@ -191,18 +192,19 @@ and
functions conform to
.St -p1003.1-2001 .
.Sh BUGS
-Do not pass untrusted user data to
-.Fn wordexp ,
-regardless of whether the
-.Dv WRDE_NOCMD
-flag is set.
-The
-.Fn wordexp
-function attempts to detect input that would cause commands to be
-executed before passing it to the shell
-but it does not use the same parser so it may be fooled.
-.Pp
The current
.Fn wordexp
implementation does not recognize multibyte characters other than UTF-8, since
the shell (which it invokes to perform expansions) does not.
+.Sh SECURITY CONSIDERATIONS
+Pathname generation may create output that is exponentially larger than the
+input size.
+.Pp
+Although this implementation detects command substitution reliably for
+.Dv WRDE_NOCMD ,
+the attack surface remains fairly large.
+Also, some other implementations
+(such as older versions of this one)
+may execute command substitutions even if
+.Dv WRDE_NOCMD
+is set.
diff --git a/lib/libc/gen/wordexp.c b/lib/libc/gen/wordexp.c
index 859ca50..3791e1e 100644
--- a/lib/libc/gen/wordexp.c
+++ b/lib/libc/gen/wordexp.c
@@ -32,6 +32,7 @@
#include <fcntl.h>
#include <paths.h>
#include <signal.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -43,7 +44,7 @@
__FBSDID("$FreeBSD$");
static int we_askshell(const char *, wordexp_t *, int);
-static int we_check(const char *, int);
+static int we_check(const char *);
/*
* wordexp --
@@ -65,7 +66,7 @@ wordexp(const char * __restrict words, wordexp_t * __restrict we, int flags)
we->we_strings = NULL;
we->we_nbytes = 0;
}
- if ((error = we_check(words, flags)) != 0) {
+ if ((error = we_check(words)) != 0) {
wordfree(we);
return (error);
}
@@ -94,17 +95,37 @@ we_read_fully(int fd, char *buffer, size_t len)
return done;
}
+static bool
+we_write_fully(int fd, const char *buffer, size_t len)
+{
+ size_t done;
+ ssize_t nwritten;
+
+ done = 0;
+ do {
+ nwritten = _write(fd, buffer + done, len - done);
+ if (nwritten == -1 && errno == EINTR)
+ continue;
+ if (nwritten <= 0)
+ return (false);
+ done += nwritten;
+ } while (done != len);
+ return (true);
+}
+
/*
* we_askshell --
- * Use the `wordexp' /bin/sh builtin function to do most of the work
- * in expanding the word string. This function is complicated by
+ * Use the `freebsd_wordexp' /bin/sh builtin function to do most of the
+ * work in expanding the word string. This function is complicated by
* memory management.
*/
static int
we_askshell(const char *words, wordexp_t *we, int flags)
{
- int pdes[2]; /* Pipe to child */
- char buf[18]; /* Buffer for byte and word count */
+ int pdesw[2]; /* Pipe for writing words */
+ int pdes[2]; /* Pipe for reading output */
+ char wfdstr[sizeof(int) * 3 + 1];
+ char buf[35]; /* Buffer for byte and word count */
long nwords, nbytes; /* Number of words, bytes from child */
long i; /* Handy integer */
size_t sofs; /* Offset into we->we_strings */
@@ -119,18 +140,25 @@ we_askshell(const char *words, wordexp_t *we, int flags)
char **nwv; /* Temporary for realloc() */
sigset_t newsigblock, oldsigblock;
const char *ifs;
- char save;
serrno = errno;
ifs = getenv("IFS");
- if (pipe2(pdes, O_CLOEXEC) < 0)
+ if (pipe2(pdesw, O_CLOEXEC) < 0)
+ return (WRDE_NOSPACE); /* XXX */
+ snprintf(wfdstr, sizeof(wfdstr), "%d", pdesw[0]);
+ if (pipe2(pdes, O_CLOEXEC) < 0) {
+ _close(pdesw[0]);
+ _close(pdesw[1]);
return (WRDE_NOSPACE); /* XXX */
+ }
(void)sigemptyset(&newsigblock);
(void)sigaddset(&newsigblock, SIGCHLD);
(void)__libc_sigprocmask(SIG_BLOCK, &newsigblock, &oldsigblock);
if ((pid = fork()) < 0) {
serrno = errno;
+ _close(pdesw[0]);
+ _close(pdesw[1]);
_close(pdes[0]);
_close(pdes[1]);
(void)__libc_sigprocmask(SIG_SETMASK, &oldsigblock, NULL);
@@ -146,43 +174,54 @@ we_askshell(const char *words, wordexp_t *we, int flags)
_dup2(pdes[1], STDOUT_FILENO) :
_fcntl(pdes[1], F_SETFD, 0)) < 0)
_exit(1);
+ if (_fcntl(pdesw[0], F_SETFD, 0) < 0)
+ _exit(1);
execl(_PATH_BSHELL, "sh", flags & WRDE_UNDEF ? "-u" : "+u",
- "-c", "IFS=$1;eval \"$2\";eval \"echo;set -- $3\";"
- "IFS=;a=\"$*\";printf '%08x' \"$#\" \"${#a}\";"
- "printf '%s\\0' \"$@\"",
+ "-c", "IFS=$1;eval \"$2\";"
+ "freebsd_wordexp -f \"$3\" ${4:+\"$4\"}",
"",
ifs != NULL ? ifs : " \t\n",
- flags & WRDE_SHOWERR ? "" : "exec 2>/dev/null", words,
+ flags & WRDE_SHOWERR ? "" : "exec 2>/dev/null",
+ wfdstr,
+ flags & WRDE_NOCMD ? "-p" : "",
(char *)NULL);
_exit(1);
}
/*
- * We are the parent; read the output of the shell wordexp function,
- * which is a byte indicating that the words were parsed successfully,
- * a 32-bit hexadecimal word count, a 32-bit hexadecimal byte count
- * (not including terminating null bytes), followed by the expanded
- * words separated by nulls.
+ * We are the parent; write the words.
*/
_close(pdes[1]);
- switch (we_read_fully(pdes[0], buf, 17)) {
+ _close(pdesw[0]);
+ if (!we_write_fully(pdesw[1], words, strlen(words))) {
+ _close(pdesw[1]);
+ error = WRDE_SYNTAX;
+ goto cleanup;
+ }
+ _close(pdesw[1]);
+ /*
+ * Read the output of the shell wordexp function,
+ * which is a byte indicating that the words were parsed successfully,
+ * a 64-bit hexadecimal word count, a dummy byte, a 64-bit hexadecimal
+ * byte count (not including terminating null bytes), followed by the
+ * expanded words separated by nulls.
+ */
+ switch (we_read_fully(pdes[0], buf, 34)) {
case 1:
- error = WRDE_BADVAL;
+ error = buf[0] == 'C' ? WRDE_CMDSUB : WRDE_BADVAL;
serrno = errno;
goto cleanup;
- case 17:
+ case 34:
break;
default:
error = WRDE_SYNTAX;
serrno = errno;
goto cleanup;
}
- save = buf[9];
- buf[9] = '\0';
- nwords = strtol(buf + 1, NULL, 16);
- buf[9] = save;
buf[17] = '\0';
- nbytes = strtol(buf + 9, NULL, 16) + nwords;
+ nwords = strtol(buf + 1, NULL, 16);
+ buf[34] = '\0';
+ nbytes = strtol(buf + 18, NULL, 16) + nwords;
/*
* Allocate or reallocate (when flags & WRDE_APPEND) the word vector
@@ -255,83 +294,96 @@ cleanup:
* we_check --
* Check that the string contains none of the following unquoted
* special characters: <newline> |&;<>(){}
- * or command substitutions when WRDE_NOCMD is set in flags.
+ * This mainly serves for {} which are normally legal in sh.
+ * It deliberately does not attempt to model full sh syntax.
*/
static int
-we_check(const char *words, int flags)
+we_check(const char *words)
{
char c;
- int dquote, level, quote, squote;
+ /* Saw \ or $, possibly not special: */
+ bool quote = false, dollar = false;
+ /* Saw ', ", ${, ` or $(, possibly not special: */
+ bool have_sq = false, have_dq = false, have_par_begin = false;
+ bool have_cmd = false;
+ /* Definitely saw a ', ", ${, ` or $(, need a closing character: */
+ bool need_sq = false, need_dq = false, need_par_end = false;
+ bool need_cmd_old = false, need_cmd_new = false;
- quote = squote = dquote = 0;
while ((c = *words++) != '\0') {
switch (c) {
case '\\':
- if (squote == 0)
- quote ^= 1;
+ quote = !quote;
+ continue;
+ case '$':
+ if (quote)
+ quote = false;
+ else
+ dollar = !dollar;
continue;
case '\'':
- if (quote + dquote == 0)
- squote ^= 1;
+ if (!quote && !have_sq && !have_dq)
+ need_sq = true;
+ else
+ need_sq = false;
+ have_sq = true;
break;
case '"':
- if (quote + squote == 0)
- dquote ^= 1;
+ if (!quote && !have_sq && !have_dq)
+ need_dq = true;
+ else
+ need_dq = false;
+ have_dq = true;
break;
case '`':
- if (quote + squote == 0 && flags & WRDE_NOCMD)
- return (WRDE_CMDSUB);
- while ((c = *words++) != '\0' && c != '`')
- if (c == '\\' && (c = *words++) == '\0')
- break;
- if (c == '\0')
- return (WRDE_SYNTAX);
+ if (!quote && !have_sq && !have_cmd)
+ need_cmd_old = true;
+ else
+ need_cmd_old = false;
+ have_cmd = true;
break;
- case '|': case '&': case ';': case '<': case '>':
- case '{': case '}': case '(': case ')': case '\n':
- if (quote + squote + dquote == 0)
+ case '{':
+ if (!quote && !dollar && !have_sq && !have_dq &&
+ !have_cmd)
return (WRDE_BADCHAR);
+ if (dollar) {
+ if (!quote && !have_sq)
+ need_par_end = true;
+ have_par_begin = true;
+ }
break;
- case '$':
- if ((c = *words++) == '\0')
- break;
- else if (quote + squote == 0 && c == '(') {
- if (flags & WRDE_NOCMD && *words != '(')
- return (WRDE_CMDSUB);
- level = 1;
- while ((c = *words++) != '\0') {
- if (c == '\\') {
- if ((c = *words++) == '\0')
- break;
- } else if (c == '(')
- level++;
- else if (c == ')' && --level == 0)
- break;
- }
- if (c == '\0' || level != 0)
- return (WRDE_SYNTAX);
- } else if (quote + squote == 0 && c == '{') {
- level = 1;
- while ((c = *words++) != '\0') {
- if (c == '\\') {
- if ((c = *words++) == '\0')
- break;
- } else if (c == '{')
- level++;
- else if (c == '}' && --level == 0)
- break;
- }
- if (c == '\0' || level != 0)
- return (WRDE_SYNTAX);
- } else
- --words;
+ case '}':
+ if (!quote && !have_sq && !have_dq && !have_par_begin &&
+ !have_cmd)
+ return (WRDE_BADCHAR);
+ need_par_end = false;
+ break;
+ case '(':
+ if (!quote && !dollar && !have_sq && !have_dq &&
+ !have_cmd)
+ return (WRDE_BADCHAR);
+ if (dollar) {
+ if (!quote && !have_sq)
+ need_cmd_new = true;
+ have_cmd = true;
+ }
+ break;
+ case ')':
+ if (!quote && !have_sq && !have_dq && !have_cmd)
+ return (WRDE_BADCHAR);
+ need_cmd_new = false;
+ break;
+ case '|': case '&': case ';': case '<': case '>': case '\n':
+ if (!quote && !have_sq && !have_dq && !have_cmd)
+ return (WRDE_BADCHAR);
break;
default:
break;
}
- quote = 0;
+ quote = dollar = false;
}
- if (quote + squote + dquote != 0)
+ if (quote || dollar || need_sq || need_dq || need_par_end ||
+ need_cmd_old || need_cmd_new)
return (WRDE_SYNTAX);
return (0);
OpenPOWER on IntegriCloud