summaryrefslogtreecommitdiffstats
path: root/lib/libc
diff options
context:
space:
mode:
authorgrehan <grehan@FreeBSD.org>2012-07-11 19:54:21 +0000
committergrehan <grehan@FreeBSD.org>2012-07-11 19:54:21 +0000
commitede42824618710ffa9ac08c805d8bf39bd5661ce (patch)
tree09d40ee855683606d0771d694b0686fedfe68e32 /lib/libc
parentfc13a01d538ded0843702a871a58cba4147b6037 (diff)
parentc72304b145d41338bd04103bd7e56b101261ca88 (diff)
downloadFreeBSD-src-ede42824618710ffa9ac08c805d8bf39bd5661ce.zip
FreeBSD-src-ede42824618710ffa9ac08c805d8bf39bd5661ce.tar.gz
IFC @ r238370
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/Makefile8
-rw-r--r--lib/libc/amd64/sys/Makefile.inc3
-rw-r--r--lib/libc/amd64/sys/__vdso_gettc.c49
-rw-r--r--lib/libc/arm/Symbol.map4
-rw-r--r--lib/libc/compat-43/sigpause.25
-rw-r--r--lib/libc/gen/Makefile.inc2
-rw-r--r--lib/libc/gen/Symbol.map1
-rw-r--r--lib/libc/gen/arc4random.c40
-rw-r--r--lib/libc/gen/aux.c15
-rw-r--r--lib/libc/gen/closedir.c1
-rw-r--r--lib/libc/gen/directory.317
-rw-r--r--lib/libc/gen/dirfd.c45
-rw-r--r--lib/libc/gen/err.314
-rw-r--r--lib/libc/gen/fstab.c12
-rw-r--r--lib/libc/gen/fts-compat.c4
-rw-r--r--lib/libc/gen/fts.c4
-rw-r--r--lib/libc/gen/gen-private.h59
-rw-r--r--lib/libc/gen/getcwd.c10
-rw-r--r--lib/libc/gen/getnetgrent.c184
-rw-r--r--lib/libc/gen/opendir.c1
-rw-r--r--lib/libc/gen/posix_spawnattr_getflags.32
-rw-r--r--lib/libc/gen/readdir.c1
-rw-r--r--lib/libc/gen/rewinddir.c1
-rw-r--r--lib/libc/gen/seekdir.c1
-rw-r--r--lib/libc/gen/signal.319
-rw-r--r--lib/libc/gen/sysconf.c4
-rw-r--r--lib/libc/gen/syslog.c6
-rw-r--r--lib/libc/gen/telldir.c1
-rw-r--r--lib/libc/gmon/gmon.c7
-rw-r--r--lib/libc/gmon/moncontrol.37
-rw-r--r--lib/libc/i386/gen/getcontextx.c2
-rw-r--r--lib/libc/i386/sys/Makefile.inc3
-rw-r--r--lib/libc/i386/sys/__vdso_gettc.c50
-rw-r--r--lib/libc/include/libc_private.h7
-rw-r--r--lib/libc/include/port_before.h2
-rw-r--r--lib/libc/locale/collate.c10
-rw-r--r--lib/libc/locale/ctype_l.315
-rw-r--r--lib/libc/locale/duplocale.34
-rw-r--r--lib/libc/locale/freelocale.32
-rw-r--r--lib/libc/locale/newlocale.34
-rw-r--r--lib/libc/locale/querylocale.34
-rw-r--r--lib/libc/locale/setrunelocale.c21
-rw-r--r--lib/libc/locale/toupper.c2
-rw-r--r--lib/libc/locale/uselocale.32
-rw-r--r--lib/libc/locale/xlocale.32
-rw-r--r--lib/libc/net/Makefile.inc2
-rw-r--r--lib/libc/net/Symbol.map5
-rw-r--r--lib/libc/net/getaddrinfo.c2
-rw-r--r--lib/libc/net/if_indextoname.c2
-rw-r--r--lib/libc/net/if_nameindex.c2
-rw-r--r--lib/libc/net/if_nametoindex.c2
-rw-r--r--lib/libc/net/nsdispatch.310
-rw-r--r--lib/libc/net/nsparser.y1
-rw-r--r--lib/libc/net/sctp_connectx.32
-rw-r--r--lib/libc/net/sctp_recvmsg.32
-rw-r--r--lib/libc/net/sctp_sys_calls.c6
-rw-r--r--lib/libc/net/sourcefilter.34
-rw-r--r--lib/libc/net/sourcefilter.c2
-rw-r--r--lib/libc/posix1e/acl_delete_entry.32
-rw-r--r--lib/libc/posix1e/mac_prepare.32
-rw-r--r--lib/libc/powerpc/Symbol.map4
-rw-r--r--lib/libc/powerpc/gen/Makefile.inc2
-rw-r--r--lib/libc/powerpc/gen/eabi.S33
-rw-r--r--lib/libc/rpc/auth_unix.c7
-rw-r--r--lib/libc/rpc/publickey.34
-rw-r--r--lib/libc/rpc/svc.c10
-rw-r--r--lib/libc/rpc/svc_raw.c14
-rw-r--r--lib/libc/stdio/Makefile.inc8
-rw-r--r--lib/libc/stdio/fgets.34
-rw-r--r--lib/libc/stdio/fgetwc.c24
-rw-r--r--lib/libc/stdio/fpurge.c2
-rw-r--r--lib/libc/stdio/local.h9
-rw-r--r--lib/libc/stdio/printf_l.380
-rw-r--r--lib/libc/stdio/scanf.34
-rw-r--r--lib/libc/stdio/scanf_l.370
-rw-r--r--lib/libc/stdio/setbuf.34
-rw-r--r--lib/libc/stdio/vfscanf.c210
-rw-r--r--lib/libc/stdio/vfwscanf.c61
-rw-r--r--lib/libc/stdio/wscanf.34
-rw-r--r--lib/libc/stdio/xprintf.c2
-rw-r--r--lib/libc/stdlib/Makefile.inc1
-rw-r--r--lib/libc/stdlib/getenv.33
-rw-r--r--lib/libc/stdlib/getopt_long.c9
-rw-r--r--lib/libc/stdlib/realpath.38
-rw-r--r--lib/libc/stdlib/realpath.c36
-rw-r--r--lib/libc/stdlib/strfmon.323
-rw-r--r--lib/libc/stdtime/Makefile.inc2
-rw-r--r--lib/libc/stdtime/strftime.313
-rw-r--r--lib/libc/stdtime/strftime.c2
-rw-r--r--lib/libc/stdtime/strptime.314
-rw-r--r--lib/libc/string/Makefile.inc9
-rw-r--r--lib/libc/string/strcasecmp.323
-rw-r--r--lib/libc/string/strcoll.314
-rw-r--r--lib/libc/string/strlcpy.32
-rw-r--r--lib/libc/string/strstr.310
-rw-r--r--lib/libc/string/strxfrm.314
-rw-r--r--lib/libc/sys/Makefile.inc4
-rw-r--r--lib/libc/sys/Symbol.map6
-rw-r--r--lib/libc/sys/__vdso_gettimeofday.c142
-rw-r--r--lib/libc/sys/clock_gettime.c52
-rw-r--r--lib/libc/sys/ffclock.24
-rw-r--r--lib/libc/sys/gettimeofday.c51
-rw-r--r--lib/libc/sys/jail.240
-rw-r--r--lib/libc/sys/ktrace.22
-rw-r--r--lib/libc/sys/lseek.28
-rw-r--r--lib/libc/sys/msgsnd.22
-rw-r--r--lib/libc/sys/pathconf.22
-rw-r--r--lib/libc/sys/pdfork.26
-rw-r--r--lib/libc/sys/posix_fadvise.29
-rw-r--r--lib/libc/sys/read.22
-rw-r--r--lib/libc/sys/rtprio.27
-rw-r--r--lib/libc/sys/setfib.25
-rw-r--r--lib/libc/sys/shm_open.22
-rw-r--r--lib/libc/sys/sigqueue.22
-rw-r--r--lib/libc/sys/stat.24
-rw-r--r--lib/libc/sys/timer_create.22
-rw-r--r--lib/libc/sys/timer_delete.22
-rw-r--r--lib/libc/sys/timer_settime.22
-rw-r--r--lib/libc/sys/unlink.22
119 files changed, 1303 insertions, 497 deletions
diff --git a/lib/libc/Makefile b/lib/libc/Makefile
index 2222384..ed37053 100644
--- a/lib/libc/Makefile
+++ b/lib/libc/Makefile
@@ -26,7 +26,9 @@ SHLIB_MAJOR= 7
WARNS?= 2
CFLAGS+=-I${.CURDIR}/include -I${.CURDIR}/../../include
CFLAGS+=-I${.CURDIR}/${LIBC_ARCH}
+.if ${MK_NLS} != "no"
CFLAGS+=-DNLS
+.endif
CLEANFILES+=tags
INSTALL_PIC_ARCHIVE=
PRECIOUSLIB=
@@ -41,7 +43,11 @@ CFLAGS+=${CANCELPOINTS_CFLAGS}
#
DPADD+= ${LIBGCC}
LDFLAGS+= -nodefaultlibs
-LDADD+= -lgcc -lssp_nonshared
+LDADD+= -lgcc
+
+.if ${MK_SSP} != "no"
+LDADD+= -lssp_nonshared
+.endif
# Define (empty) variables so that make doesn't give substitution
# errors if the included makefiles don't change these:
diff --git a/lib/libc/amd64/sys/Makefile.inc b/lib/libc/amd64/sys/Makefile.inc
index c7b17e0..51583d3 100644
--- a/lib/libc/amd64/sys/Makefile.inc
+++ b/lib/libc/amd64/sys/Makefile.inc
@@ -1,7 +1,8 @@
# from: Makefile.inc,v 1.1 1993/09/03 19:04:23 jtc Exp
# $FreeBSD$
-SRCS+= amd64_get_fsbase.c amd64_get_gsbase.c amd64_set_fsbase.c amd64_set_gsbase.c
+SRCS+= amd64_get_fsbase.c amd64_get_gsbase.c amd64_set_fsbase.c \
+ amd64_set_gsbase.c __vdso_gettc.c
MDASM= vfork.S brk.S cerror.S exect.S getcontext.S pipe.S ptrace.S \
reboot.S sbrk.S setlogin.S sigreturn.S
diff --git a/lib/libc/amd64/sys/__vdso_gettc.c b/lib/libc/amd64/sys/__vdso_gettc.c
new file mode 100644
index 0000000..091fe26
--- /dev/null
+++ b/lib/libc/amd64/sys/__vdso_gettc.c
@@ -0,0 +1,49 @@
+/*-
+ * Copyright (c) 2012 Konstantin Belousov <kib@FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/vdso.h>
+#include <machine/cpufunc.h>
+
+static u_int
+__vdso_gettc_low(const struct vdso_timehands *th)
+{
+ uint32_t rv;
+
+ __asm __volatile("rdtsc; shrd %%cl, %%edx, %0"
+ : "=a" (rv) : "c" (th->th_x86_shift) : "edx");
+ return (rv);
+}
+
+u_int
+__vdso_gettc(const struct vdso_timehands *th)
+{
+
+ return (th->th_x86_shift > 0 ? __vdso_gettc_low(th) : rdtsc32());
+}
diff --git a/lib/libc/arm/Symbol.map b/lib/libc/arm/Symbol.map
index dc46013..48f6747 100644
--- a/lib/libc/arm/Symbol.map
+++ b/lib/libc/arm/Symbol.map
@@ -33,6 +33,10 @@ FBSD_1.0 {
sbrk;
};
+FBSD_1.3 {
+ __flt_rounds;
+};
+
FBSDprivate_1.0 {
/* PSEUDO syscalls */
__sys_getlogin;
diff --git a/lib/libc/compat-43/sigpause.2 b/lib/libc/compat-43/sigpause.2
index 1187b52..4c24ab7 100644
--- a/lib/libc/compat-43/sigpause.2
+++ b/lib/libc/compat-43/sigpause.2
@@ -62,7 +62,7 @@
.Sy This interface is made obsolete by
.Xr sigsuspend 2
.Sy and
-.Xr sigaction 2
+.Xr sigaction 2 .
.Pp
The
.Fn sigset
@@ -172,7 +172,8 @@ returns
if the signal had been blocked and the signal's previous disposition if
it had not been blocked.
Otherwise,
-.Dv SIG_ERR is returned and
+.Dv SIG_ERR
+is returned and
.Va errno
set to indicate the error.
.Pp
diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc
index 0362ce0..98e8183 100644
--- a/lib/libc/gen/Makefile.inc
+++ b/lib/libc/gen/Makefile.inc
@@ -9,7 +9,7 @@ SRCS+= __getosreldate.c __xuname.c \
_thread_init.c \
alarm.c arc4random.c assert.c aux.c basename.c check_utility_compat.c \
clock.c closedir.c confstr.c \
- crypt.c ctermid.c daemon.c devname.c dirname.c disklabel.c \
+ crypt.c ctermid.c daemon.c devname.c dirfd.c dirname.c disklabel.c \
dlfcn.c drand48.c elf_utils.c erand48.c err.c errlst.c errno.c \
exec.c fdevname.c feature_present.c fmtcheck.c fmtmsg.c fnmatch.c \
fpclassify.c frexp.c fstab.c ftok.c fts.c fts-compat.c ftw.c \
diff --git a/lib/libc/gen/Symbol.map b/lib/libc/gen/Symbol.map
index d794c0a..356bee5 100644
--- a/lib/libc/gen/Symbol.map
+++ b/lib/libc/gen/Symbol.map
@@ -382,6 +382,7 @@ FBSD_1.2 {
};
FBSD_1.3 {
+ dirfd;
fdlopen;
__FreeBSD_libc_enter_restricted_mode;
getcontextx;
diff --git a/lib/libc/gen/arc4random.c b/lib/libc/gen/arc4random.c
index a2b235f..46059ab 100644
--- a/lib/libc/gen/arc4random.c
+++ b/lib/libc/gen/arc4random.c
@@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$");
#include <unistd.h>
#include <sys/types.h>
#include <sys/param.h>
+#include <sys/sysctl.h>
#include <sys/time.h>
#include <pthread.h>
@@ -78,6 +79,9 @@ static struct arc4_stream rs;
static pid_t arc4_stir_pid;
static int arc4_count;
+extern int __sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp,
+ void *newp, size_t newlen);
+
static inline u_int8_t arc4_getbyte(void);
static void arc4_stir(void);
@@ -109,6 +113,28 @@ arc4_addrandom(u_char *dat, int datlen)
rs.j = rs.i;
}
+static size_t
+arc4_sysctl(u_char *buf, size_t size)
+{
+ int mib[2];
+ size_t len, done;
+
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_ARND;
+ done = 0;
+
+ do {
+ len = size;
+ if (__sysctl(mib, 2, buf, &len, NULL, 0) == -1)
+ return (done);
+ done += len;
+ buf += len;
+ size -= len;
+ } while (size > 0);
+
+ return (done);
+}
+
static void
arc4_stir(void)
{
@@ -123,12 +149,16 @@ arc4_stir(void)
arc4_init();
rs_initialized = 1;
}
- fd = _open(RANDOMDEV, O_RDONLY, 0);
done = 0;
- if (fd >= 0) {
- if (_read(fd, &rdat, KEYSIZE) == KEYSIZE)
- done = 1;
- (void)_close(fd);
+ if (arc4_sysctl((u_char *)&rdat, KEYSIZE) == KEYSIZE)
+ done = 1;
+ if (!done) {
+ fd = _open(RANDOMDEV, O_RDONLY, 0);
+ if (fd >= 0) {
+ if (_read(fd, &rdat, KEYSIZE) == KEYSIZE)
+ done = 1;
+ (void)_close(fd);
+ }
}
if (!done) {
(void)gettimeofday(&rdat.tv, NULL);
diff --git a/lib/libc/gen/aux.c b/lib/libc/gen/aux.c
index 4bf8643..3767ac0 100644
--- a/lib/libc/gen/aux.c
+++ b/lib/libc/gen/aux.c
@@ -66,6 +66,7 @@ __init_elf_aux_vector(void)
static pthread_once_t aux_once = PTHREAD_ONCE_INIT;
static int pagesize, osreldate, canary_len, ncpus, pagesizes_len;
static char *canary, *pagesizes;
+static void *timekeep;
static void
init_aux(void)
@@ -101,6 +102,10 @@ init_aux(void)
case AT_NCPUS:
ncpus = aux->a_un.a_val;
break;
+
+ case AT_TIMEKEEP:
+ timekeep = aux->a_un.a_ptr;
+ break;
}
}
}
@@ -163,6 +168,16 @@ _elf_aux_info(int aux, void *buf, int buflen)
} else
res = EINVAL;
break;
+ case AT_TIMEKEEP:
+ if (buflen == sizeof(void *)) {
+ if (timekeep != NULL) {
+ *(void **)buf = timekeep;
+ res = 0;
+ } else
+ res = ENOENT;
+ } else
+ res = EINVAL;
+ break;
default:
res = ENOENT;
break;
diff --git a/lib/libc/gen/closedir.c b/lib/libc/gen/closedir.c
index 5db351b..4b520cc 100644
--- a/lib/libc/gen/closedir.c
+++ b/lib/libc/gen/closedir.c
@@ -42,6 +42,7 @@ __FBSDID("$FreeBSD$");
#include "un-namespace.h"
#include "libc_private.h"
+#include "gen-private.h"
#include "telldir.h"
/*
diff --git a/lib/libc/gen/directory.3 b/lib/libc/gen/directory.3
index 1c568fc..0fd5bba 100644
--- a/lib/libc/gen/directory.3
+++ b/lib/libc/gen/directory.3
@@ -28,7 +28,7 @@
.\" @(#)directory.3 8.1 (Berkeley) 6/4/93
.\" $FreeBSD$
.\"
-.Dd April 16, 2008
+.Dd July 5, 2012
.Dt DIRECTORY 3
.Os
.Sh NAME
@@ -153,7 +153,7 @@ returns 0 on success or an error number to indicate failure.
The
.Fn telldir
function
-returns the current location associated with the named
+returns a token representing the current location associated with the named
.Em directory stream .
Values returned by
.Fn telldir
@@ -179,6 +179,13 @@ The new position reverts to the one associated with the
when the
.Fn telldir
operation was performed.
+State associated with the token returned by
+.Fn telldir is freed when it is passed to
+.Fn seekdir .
+If you wish return to the same location again,
+then you must create a new token with another
+.Fn telldir
+call.
.Pp
The
.Fn rewinddir
@@ -245,3 +252,9 @@ The
.Fn fdopendir
function appeared in
.Fx 8.0 .
+.Sh BUGS
+The invalidation of
+.Fn telldir
+tokens when calling
+.Fn seekdir
+is non-standard.
diff --git a/lib/libc/gen/dirfd.c b/lib/libc/gen/dirfd.c
new file mode 100644
index 0000000..e29bfdc
--- /dev/null
+++ b/lib/libc/gen/dirfd.c
@@ -0,0 +1,45 @@
+/*-
+ * Copyright (c) 2011 Gleb Kurtsou <gleb@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include "namespace.h"
+#include <sys/param.h>
+
+#include <dirent.h>
+#include "un-namespace.h"
+
+#include "gen-private.h"
+
+int
+dirfd(DIR *dirp)
+{
+
+ return (_dirfd(dirp));
+}
diff --git a/lib/libc/gen/err.3 b/lib/libc/gen/err.3
index 4871bcc..8bd31c3 100644
--- a/lib/libc/gen/err.3
+++ b/lib/libc/gen/err.3
@@ -28,7 +28,7 @@
.\" From: @(#)err.3 8.1 (Berkeley) 6/9/93
.\" $FreeBSD$
.\"
-.Dd March 6, 1999
+.Dd March 29, 2012
.Dt ERR 3
.Os
.Sh NAME
@@ -212,6 +212,18 @@ if (error != 0)
.Xr printf 3 ,
.Xr strerror 3 ,
.Xr sysexits 3
+.Sh STANDARDS
+The
+.Fn err
+and
+.Fn warn
+families of functions are
+.Bx
+extensions.
+As such they should not be used in truly portable code.
+Use
+.Fn strerror
+or similar functions instead.
.Sh HISTORY
The
.Fn err
diff --git a/lib/libc/gen/fstab.c b/lib/libc/gen/fstab.c
index b2c28ad..882c57f 100644
--- a/lib/libc/gen/fstab.c
+++ b/lib/libc/gen/fstab.c
@@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$");
#include <sys/stat.h>
#include <errno.h>
+#include <fcntl.h>
#include <fstab.h>
#include <paths.h>
#include <stdio.h>
@@ -246,6 +247,8 @@ getfsfile(name)
int
setfsent()
{
+ int fd;
+
if (_fs_fp) {
rewind(_fs_fp);
LineNo = 0;
@@ -257,11 +260,18 @@ setfsent()
else
setfstab(getenv("PATH_FSTAB"));
}
- if ((_fs_fp = fopen(path_fstab, "r")) != NULL) {
+ fd = _open(path_fstab, O_RDONLY | O_CLOEXEC);
+ if (fd == -1) {
+ error(errno);
+ return (0);
+ }
+ _fs_fp = fdopen(fd, "r");
+ if (_fs_fp != NULL) {
LineNo = 0;
return(1);
}
error(errno);
+ _close(fd);
return(0);
}
diff --git a/lib/libc/gen/fts-compat.c b/lib/libc/gen/fts-compat.c
index a6ddde4..6585416 100644
--- a/lib/libc/gen/fts-compat.c
+++ b/lib/libc/gen/fts-compat.c
@@ -52,6 +52,8 @@ __FBSDID("$FreeBSD$");
#include "fts-compat.h"
#include "un-namespace.h"
+#include "gen-private.h"
+
FTSENT *__fts_children_44bsd(FTS *, int);
int __fts_close_44bsd(FTS *);
void *__fts_get_clientptr_44bsd(FTS *);
@@ -711,7 +713,7 @@ fts_build(sp, type)
*/
cderrno = 0;
if (nlinks || type == BREAD) {
- if (fts_safe_changedir(sp, cur, dirfd(dirp), NULL)) {
+ if (fts_safe_changedir(sp, cur, _dirfd(dirp), NULL)) {
if (nlinks && type == BREAD)
cur->fts_errno = errno;
cur->fts_flags |= FTS_DONTCHDIR;
diff --git a/lib/libc/gen/fts.c b/lib/libc/gen/fts.c
index 1344464..153b8da 100644
--- a/lib/libc/gen/fts.c
+++ b/lib/libc/gen/fts.c
@@ -52,6 +52,8 @@ __FBSDID("$FreeBSD$");
#include <unistd.h>
#include "un-namespace.h"
+#include "gen-private.h"
+
static FTSENT *fts_alloc(FTS *, char *, size_t);
static FTSENT *fts_build(FTS *, int);
static void fts_lfree(FTSENT *);
@@ -697,7 +699,7 @@ fts_build(FTS *sp, int type)
*/
cderrno = 0;
if (nlinks || type == BREAD) {
- if (fts_safe_changedir(sp, cur, dirfd(dirp), NULL)) {
+ if (fts_safe_changedir(sp, cur, _dirfd(dirp), NULL)) {
if (nlinks && type == BREAD)
cur->fts_errno = errno;
cur->fts_flags |= FTS_DONTCHDIR;
diff --git a/lib/libc/gen/gen-private.h b/lib/libc/gen/gen-private.h
new file mode 100644
index 0000000..e8854ad
--- /dev/null
+++ b/lib/libc/gen/gen-private.h
@@ -0,0 +1,59 @@
+/*-
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _GEN_PRIVATE_H_
+#define _GEN_PRIVATE_H_
+
+struct _telldir; /* see telldir.h */
+struct pthread_mutex;
+
+/*
+ * Structure describing an open directory.
+ *
+ * NOTE. Change structure layout with care, at least dd_fd field has to
+ * remain unchanged to guarantee backward compatibility.
+ */
+struct _dirdesc {
+ int dd_fd; /* file descriptor associated with directory */
+ long dd_loc; /* offset in current buffer */
+ long dd_size; /* amount of data returned by getdirentries */
+ char *dd_buf; /* data buffer */
+ int dd_len; /* size of data buffer */
+ long dd_seek; /* magic cookie returned by getdirentries */
+ long dd_rewind; /* magic cookie for rewinding */
+ int dd_flags; /* flags for readdir */
+ struct pthread_mutex *dd_lock; /* lock */
+ struct _telldir *dd_td; /* telldir position recording */
+};
+
+#define _dirfd(dirp) ((dirp)->dd_fd)
+
+#endif /* !_GEN_PRIVATE_H_ */
diff --git a/lib/libc/gen/getcwd.c b/lib/libc/gen/getcwd.c
index c886dde..40feedf 100644
--- a/lib/libc/gen/getcwd.c
+++ b/lib/libc/gen/getcwd.c
@@ -46,6 +46,8 @@ __FBSDID("$FreeBSD$");
#include <unistd.h>
#include "un-namespace.h"
+#include "gen-private.h"
+
#define ISDOT(dp) \
(dp->d_name[0] == '.' && (dp->d_name[1] == '\0' || \
(dp->d_name[1] == '.' && dp->d_name[2] == '\0')))
@@ -117,7 +119,7 @@ getcwd(pt, size)
for (first = 1;; first = 0) {
/* Stat the current level. */
- if (dir != NULL ? _fstat(dirfd(dir), &s) : lstat(".", &s))
+ if (dir != NULL ? _fstat(_dirfd(dir), &s) : lstat(".", &s))
goto err;
/* Save current node values. */
@@ -139,13 +141,13 @@ getcwd(pt, size)
}
/* Open and stat parent directory. */
- fd = _openat(dir != NULL ? dirfd(dir) : AT_FDCWD,
+ fd = _openat(dir != NULL ? _dirfd(dir) : AT_FDCWD,
"..", O_RDONLY);
if (fd == -1)
goto err;
if (dir)
(void) closedir(dir);
- if (!(dir = fdopendir(fd)) || _fstat(dirfd(dir), &s)) {
+ if (!(dir = fdopendir(fd)) || _fstat(_dirfd(dir), &s)) {
_close(fd);
goto err;
}
@@ -171,7 +173,7 @@ getcwd(pt, size)
continue;
/* Save the first error for later. */
- if (fstatat(dirfd(dir), dp->d_name, &s,
+ if (fstatat(_dirfd(dir), dp->d_name, &s,
AT_SYMLINK_NOFOLLOW)) {
if (!save_errno)
save_errno = errno;
diff --git a/lib/libc/gen/getnetgrent.c b/lib/libc/gen/getnetgrent.c
index ca75d9b..51b3e37 100644
--- a/lib/libc/gen/getnetgrent.c
+++ b/lib/libc/gen/getnetgrent.c
@@ -161,8 +161,7 @@ setnetgrent(const char *group)
if (group == NULL || !strlen(group))
return;
- if (grouphead.gr == (struct netgrp *)0 ||
- strcmp(group, grouphead.grname)) {
+ if (grouphead.gr == NULL || strcmp(group, grouphead.grname)) {
endnetgrent();
#ifdef YP
/* Presumed guilty until proven innocent. */
@@ -172,7 +171,7 @@ setnetgrent(const char *group)
* use NIS exclusively.
*/
if (((stat(_PATH_NETGROUP, &_yp_statp) < 0) &&
- errno == ENOENT) || _yp_statp.st_size == 0)
+ errno == ENOENT) || _yp_statp.st_size == 0)
_use_only_yp = _netgr_yp_enabled = 1;
if ((netf = fopen(_PATH_NETGROUP,"r")) != NULL ||_use_only_yp){
/*
@@ -203,9 +202,7 @@ setnetgrent(const char *group)
if (parse_netgrp(group))
endnetgrent();
else {
- grouphead.grname = (char *)
- malloc(strlen(group) + 1);
- strcpy(grouphead.grname, group);
+ grouphead.grname = strdup(group);
}
if (netf)
fclose(netf);
@@ -249,27 +246,24 @@ endnetgrent(void)
lp = lp->l_next;
free(olp->l_groupname);
free(olp->l_line);
- free((char *)olp);
+ free(olp);
}
- linehead = (struct linelist *)0;
+ linehead = NULL;
if (grouphead.grname) {
free(grouphead.grname);
- grouphead.grname = (char *)0;
+ grouphead.grname = NULL;
}
gp = grouphead.gr;
while (gp) {
ogp = gp;
gp = gp->ng_next;
- if (ogp->ng_str[NG_HOST])
- free(ogp->ng_str[NG_HOST]);
- if (ogp->ng_str[NG_USER])
- free(ogp->ng_str[NG_USER]);
- if (ogp->ng_str[NG_DOM])
- free(ogp->ng_str[NG_DOM]);
- free((char *)ogp);
+ free(ogp->ng_str[NG_HOST]);
+ free(ogp->ng_str[NG_USER]);
+ free(ogp->ng_str[NG_DOM]);
+ free(ogp);
}
- grouphead.gr = (struct netgrp *)0;
- nextgrp = (struct netgrp *)0;
+ grouphead.gr = NULL;
+ nextgrp = NULL;
#ifdef YP
_netgr_yp_enabled = 0;
#endif
@@ -284,7 +278,7 @@ _listmatch(const char *list, const char *group, int len)
int glen = strlen(group);
/* skip possible leading whitespace */
- while(isspace((unsigned char)*ptr))
+ while (isspace((unsigned char)*ptr))
ptr++;
while (ptr < list + len) {
@@ -292,12 +286,12 @@ _listmatch(const char *list, const char *group, int len)
while(*ptr != ',' && *ptr != '\0' && !isspace((unsigned char)*ptr))
ptr++;
if (strncmp(cptr, group, glen) == 0 && glen == (ptr - cptr))
- return(1);
- while(*ptr == ',' || isspace((unsigned char)*ptr))
+ return (1);
+ while (*ptr == ',' || isspace((unsigned char)*ptr))
ptr++;
}
- return(0);
+ return (0);
}
static int
@@ -311,32 +305,37 @@ _revnetgr_lookup(char* lookupdom, char* map, const char* str,
for (rot = 0; ; rot++) {
switch (rot) {
- case(0): snprintf(key, MAXHOSTNAMELEN, "%s.%s",
- str, dom?dom:lookupdom);
- break;
- case(1): snprintf(key, MAXHOSTNAMELEN, "%s.*",
- str);
- break;
- case(2): snprintf(key, MAXHOSTNAMELEN, "*.%s",
- dom?dom:lookupdom);
- break;
- case(3): snprintf(key, MAXHOSTNAMELEN, "*.*");
- break;
- default: return(0);
+ case 0:
+ snprintf(key, MAXHOSTNAMELEN, "%s.%s", str,
+ dom ? dom : lookupdom);
+ break;
+ case 1:
+ snprintf(key, MAXHOSTNAMELEN, "%s.*", str);
+ break;
+ case 2:
+ snprintf(key, MAXHOSTNAMELEN, "*.%s",
+ dom ? dom : lookupdom);
+ break;
+ case 3:
+ snprintf(key, MAXHOSTNAMELEN, "*.*");
+ break;
+ default:
+ return (0);
}
y = yp_match(lookupdom, map, key, strlen(key), &result,
- &resultlen);
+ &resultlen);
if (y == 0) {
rv = _listmatch(result, group, resultlen);
free(result);
- if (rv) return(1);
+ if (rv)
+ return (1);
} else if (y != YPERR_KEY) {
/*
* If we get an error other than 'no
* such key in map' then something is
* wrong and we should stop the search.
*/
- return(-1);
+ return (-1);
}
}
}
@@ -386,14 +385,14 @@ innetgr(const char *group, const char *host, const char *user, const char *dom)
if (_use_only_yp && (host == NULL) != (user == NULL)) {
int ret;
if(yp_get_default_domain(&_netgr_yp_domain))
- return(0);
+ return (0);
ret = _revnetgr_lookup(_netgr_yp_domain,
host?"netgroup.byhost":"netgroup.byuser",
host?host:user, dom, group);
if (ret == 1)
- return(1);
+ return (1);
else if (ret == 0 && dom != NULL)
- return(0);
+ return (0);
}
setnetgrent(group);
@@ -416,14 +415,14 @@ innetgr(const char *group, const char *host, const char *user, const char *dom)
static int
parse_netgrp(const char *group)
{
- char *spos, *epos;
- int len, strpos;
+ struct netgrp *grp;
+ struct linelist *lp = linehead;
+ char **ng;
+ char *epos, *gpos, *pos, *spos;
+ int freepos, len, strpos;
#ifdef DEBUG
int fields;
#endif
- char *pos, *gpos;
- struct netgrp *grp;
- struct linelist *lp = linehead;
/*
* First, see if the line has already been read in.
@@ -433,8 +432,7 @@ parse_netgrp(const char *group)
break;
lp = lp->l_next;
}
- if (lp == (struct linelist *)0 &&
- (lp = read_for_group(group)) == (struct linelist *)0)
+ if (lp == NULL && (lp = read_for_group(group)) == NULL)
return (1);
if (lp->l_parsed) {
#ifdef DEBUG
@@ -453,43 +451,51 @@ parse_netgrp(const char *group)
/* Watch for null pointer dereferences, dammit! */
while (pos != NULL && *pos != '\0') {
if (*pos == '(') {
- grp = (struct netgrp *)malloc(sizeof (struct netgrp));
- bzero((char *)grp, sizeof (struct netgrp));
- grp->ng_next = grouphead.gr;
- grouphead.gr = grp;
+ grp = malloc(sizeof(*grp));
+ if (grp == NULL)
+ return (1);
+ ng = grp->ng_str;
+ bzero(grp, sizeof(*grp));
pos++;
gpos = strsep(&pos, ")");
#ifdef DEBUG
fields = 0;
#endif
for (strpos = 0; strpos < 3; strpos++) {
- if ((spos = strsep(&gpos, ","))) {
-#ifdef DEBUG
- fields++;
-#endif
- while (*spos == ' ' || *spos == '\t')
- spos++;
- if ((epos = strpbrk(spos, " \t"))) {
- *epos = '\0';
- len = epos - spos;
- } else
- len = strlen(spos);
- if (len > 0) {
- grp->ng_str[strpos] = (char *)
- malloc(len + 1);
- bcopy(spos, grp->ng_str[strpos],
- len + 1);
- }
- } else {
+ if ((spos = strsep(&gpos, ",")) == NULL) {
/*
* All other systems I've tested
* return NULL for empty netgroup
* fields. It's up to user programs
* to handle the NULLs appropriately.
*/
- grp->ng_str[strpos] = NULL;
+ ng[strpos] = NULL;
+ continue;
}
+#ifdef DEBUG
+ fields++;
+#endif
+ while (*spos == ' ' || *spos == '\t')
+ spos++;
+ if ((epos = strpbrk(spos, " \t"))) {
+ *epos = '\0';
+ len = epos - spos;
+ } else
+ len = strlen(spos);
+ if (len <= 0)
+ continue;
+ ng[strpos] = malloc(len + 1);
+ if (ng[strpos] == NULL) {
+ for (freepos = 0; freepos < strpos;
+ freepos++)
+ free(ng[freepos]);
+ free(grp);
+ return (1);
+ }
+ bcopy(spos, ng[strpos], len + 1);
}
+ grp->ng_next = grouphead.gr;
+ grouphead.gr = grp;
#ifdef DEBUG
/*
* Note: on other platforms, malformed netgroup
@@ -497,14 +503,15 @@ parse_netgrp(const char *group)
* can catch bad entries and report them, we should
* stay silent by default for compatibility's sake.
*/
- if (fields < 3)
- fprintf(stderr, "Bad entry (%s%s%s%s%s) in netgroup \"%s\"\n",
- grp->ng_str[NG_HOST] == NULL ? "" : grp->ng_str[NG_HOST],
- grp->ng_str[NG_USER] == NULL ? "" : ",",
- grp->ng_str[NG_USER] == NULL ? "" : grp->ng_str[NG_USER],
- grp->ng_str[NG_DOM] == NULL ? "" : ",",
- grp->ng_str[NG_DOM] == NULL ? "" : grp->ng_str[NG_DOM],
- lp->l_groupname);
+ if (fields < 3) {
+ fprintf(stderr,
+ "Bad entry (%s%s%s%s%s) in netgroup \"%s\"\n",
+ ng[NG_HOST] == NULL ? "" : ng[NG_HOST],
+ ng[NG_USER] == NULL ? "" : ",",
+ ng[NG_USER] == NULL ? "" : ng[NG_USER],
+ ng[NG_DOM] == NULL ? "" : ",",
+ ng[NG_DOM] == NULL ? "" : ng[NG_DOM],
+ lp->l_groupname);
#endif
} else {
spos = strsep(&pos, ", \t");
@@ -526,7 +533,7 @@ parse_netgrp(const char *group)
static struct linelist *
read_for_group(const char *group)
{
- char *pos, *spos, *linep, *olinep;
+ char *linep, *olinep, *pos, *spos;
int len, olen;
int cont;
struct linelist *lp;
@@ -534,6 +541,7 @@ read_for_group(const char *group)
#ifdef YP
char *result;
int resultlen;
+ linep = NULL;
while (_netgr_yp_enabled || fgets(line, LINSIZ, netf) != NULL) {
if (_netgr_yp_enabled) {
@@ -541,7 +549,7 @@ read_for_group(const char *group)
if(yp_get_default_domain(&_netgr_yp_domain))
continue;
if (yp_match(_netgr_yp_domain, "netgroup", group,
- strlen(group), &result, &resultlen)) {
+ strlen(group), &result, &resultlen)) {
free(result);
if (_use_only_yp)
return ((struct linelist *)0);
@@ -554,6 +562,7 @@ read_for_group(const char *group)
free(result);
}
#else
+ linep = NULL;
while (fgets(line, LINSIZ, netf) != NULL) {
#endif
pos = (char *)&line;
@@ -576,8 +585,14 @@ read_for_group(const char *group)
pos++;
if (*pos != '\n' && *pos != '\0') {
lp = (struct linelist *)malloc(sizeof (*lp));
+ if (lp == NULL)
+ return (NULL);
lp->l_parsed = 0;
lp->l_groupname = (char *)malloc(len + 1);
+ if (lp->l_groupname == NULL) {
+ free(lp);
+ return (NULL);
+ }
bcopy(spos, lp->l_groupname, len);
*(lp->l_groupname + len) = '\0';
len = strlen(pos);
@@ -595,7 +610,12 @@ read_for_group(const char *group)
} else
cont = 0;
if (len > 0) {
- linep = (char *)malloc(olen + len + 1);
+ linep = malloc(olen + len + 1);
+ if (linep == NULL) {
+ free(lp->l_groupname);
+ free(lp);
+ return (NULL);
+ }
if (olen > 0) {
bcopy(olinep, linep, olen);
free(olinep);
@@ -634,5 +654,5 @@ read_for_group(const char *group)
*/
rewind(netf);
#endif
- return ((struct linelist *)0);
+ return (NULL);
}
diff --git a/lib/libc/gen/opendir.c b/lib/libc/gen/opendir.c
index 3beead7..4366399 100644
--- a/lib/libc/gen/opendir.c
+++ b/lib/libc/gen/opendir.c
@@ -46,6 +46,7 @@ __FBSDID("$FreeBSD$");
#include <unistd.h>
#include "un-namespace.h"
+#include "gen-private.h"
#include "telldir.h"
static DIR * __opendir_common(int, const char *, int);
diff --git a/lib/libc/gen/posix_spawnattr_getflags.3 b/lib/libc/gen/posix_spawnattr_getflags.3
index a2dda02..4064011 100644
--- a/lib/libc/gen/posix_spawnattr_getflags.3
+++ b/lib/libc/gen/posix_spawnattr_getflags.3
@@ -70,7 +70,7 @@ or
It is the bitwise-inclusive OR of zero or more of the following flags
(see
.Fn posix_spawn ) :
-.Bl -tag -offset indent
+.Bl -tag -width "POSIX_SPAWN_SETSCHEDPARAM" -offset indent
.It Dv POSIX_SPAWN_RESETIDS
.It Dv POSIX_SPAWN_SETPGROUP
.It Dv POSIX_SPAWN_SETSIGDEF
diff --git a/lib/libc/gen/readdir.c b/lib/libc/gen/readdir.c
index b4b4c39..324870b 100644
--- a/lib/libc/gen/readdir.c
+++ b/lib/libc/gen/readdir.c
@@ -42,6 +42,7 @@ __FBSDID("$FreeBSD$");
#include "un-namespace.h"
#include "libc_private.h"
+#include "gen-private.h"
#include "telldir.h"
/*
diff --git a/lib/libc/gen/rewinddir.c b/lib/libc/gen/rewinddir.c
index 45e450d..0eb091a 100644
--- a/lib/libc/gen/rewinddir.c
+++ b/lib/libc/gen/rewinddir.c
@@ -36,6 +36,7 @@ __FBSDID("$FreeBSD$");
#include <sys/types.h>
#include <dirent.h>
+#include "gen-private.h"
#include "telldir.h"
void
diff --git a/lib/libc/gen/seekdir.c b/lib/libc/gen/seekdir.c
index 45ed6b5..e9851a7 100644
--- a/lib/libc/gen/seekdir.c
+++ b/lib/libc/gen/seekdir.c
@@ -40,6 +40,7 @@ __FBSDID("$FreeBSD$");
#include "un-namespace.h"
#include "libc_private.h"
+#include "gen-private.h"
#include "telldir.h"
/*
diff --git a/lib/libc/gen/signal.3 b/lib/libc/gen/signal.3
index 866eee3..a41d258 100644
--- a/lib/libc/gen/signal.3
+++ b/lib/libc/gen/signal.3
@@ -38,20 +38,11 @@
.Lb libc
.Sh SYNOPSIS
.In signal.h
-.\" XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX
-.\" The prototype for signal(3) cannot be cleanly marked up in -mdoc
-.\" without the following lower-level tweak.
-.nr in-synopsis-section 0
+.\" The following is Quite Ugly, but syntactically correct.
+.\" Don't try to fix it.
+.Ft void
+.Fn \*(lp*signal "int sig" "void \*(lp*func\*(rp\*(lpint\*(rp\*(rp\*(rp\*(lpint"
.Pp
-.Ft "void \*(lp*" Ns
-.Fo signal
-.Fa "int sig"
-.Fa "void \*(lp*func\*(rp\*(lpint\*(rp"
-.Fc Ns
-.Ft "\*(rp\*(lpint\*(rp" ;
-.Pp
-.nr in-synopsis-section 1
-.\" XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX
or in
.Fx Ap s
equivalent but easier to read typedef'd version:
@@ -98,7 +89,7 @@ an interrupt.
These signals are defined in the file
.In signal.h :
.Bl -column No ".Dv SIGVTALRM" "create core image"
-.It Sy "No Name Default Action Description"
+.It Sy "Num" Ta Sy "Name" Ta Sy "Default Action" Ta Sy "Description"
.It 1 Ta Dv SIGHUP Ta "terminate process" Ta "terminal line hangup"
.It 2 Ta Dv SIGINT Ta "terminate process" Ta "interrupt program"
.It 3 Ta Dv SIGQUIT Ta "create core image" Ta "quit program"
diff --git a/lib/libc/gen/sysconf.c b/lib/libc/gen/sysconf.c
index 80ae626..2d117b7 100644
--- a/lib/libc/gen/sysconf.c
+++ b/lib/libc/gen/sysconf.c
@@ -42,6 +42,7 @@ __FBSDID("$FreeBSD$");
#include <sys/resource.h>
#include <sys/socket.h>
+#include <elf.h>
#include <errno.h>
#include <limits.h>
#include <paths.h>
@@ -51,6 +52,7 @@ __FBSDID("$FreeBSD$");
#include "../stdlib/atexit.h"
#include "tzfile.h" /* from ../../../contrib/tzcode/stdtime */
+#include "libc_private.h"
#define _PATH_ZONEINFO TZDIR /* from tzfile.h */
@@ -585,6 +587,8 @@ yesno:
case _SC_NPROCESSORS_CONF:
case _SC_NPROCESSORS_ONLN:
+ if (_elf_aux_info(AT_NCPUS, &value, sizeof(value)) == 0)
+ return ((long)value);
mib[0] = CTL_HW;
mib[1] = HW_NCPU;
break;
diff --git a/lib/libc/gen/syslog.c b/lib/libc/gen/syslog.c
index de438c4..99308e9 100644
--- a/lib/libc/gen/syslog.c
+++ b/lib/libc/gen/syslog.c
@@ -413,8 +413,10 @@ void
closelog(void)
{
THREAD_LOCK();
- (void)_close(LogFile);
- LogFile = -1;
+ if (LogFile != -1) {
+ (void)_close(LogFile);
+ LogFile = -1;
+ }
LogTag = NULL;
status = NOCONN;
THREAD_UNLOCK();
diff --git a/lib/libc/gen/telldir.c b/lib/libc/gen/telldir.c
index c217333..4954b97 100644
--- a/lib/libc/gen/telldir.c
+++ b/lib/libc/gen/telldir.c
@@ -43,6 +43,7 @@ __FBSDID("$FreeBSD$");
#include "un-namespace.h"
#include "libc_private.h"
+#include "gen-private.h"
#include "telldir.h"
/*
diff --git a/lib/libc/gmon/gmon.c b/lib/libc/gmon/gmon.c
index edf4e2f..8f508b0 100644
--- a/lib/libc/gmon/gmon.c
+++ b/lib/libc/gmon/gmon.c
@@ -157,7 +157,12 @@ _mcleanup(void)
}
moncontrol(0);
- snprintf(outname, sizeof(outname), "%s.gmon", _getprogname());
+ if (getenv("PROFIL_USE_PID"))
+ snprintf(outname, sizeof(outname), "%s.%d.gmon",
+ _getprogname(), getpid());
+ else
+ snprintf(outname, sizeof(outname), "%s.gmon", _getprogname());
+
fd = _open(outname, O_CREAT|O_TRUNC|O_WRONLY, 0666);
if (fd < 0) {
_warn("_mcleanup: %s", outname);
diff --git a/lib/libc/gmon/moncontrol.3 b/lib/libc/gmon/moncontrol.3
index 7979a71..d63035a 100644
--- a/lib/libc/gmon/moncontrol.3
+++ b/lib/libc/gmon/moncontrol.3
@@ -98,6 +98,13 @@ however, all functions in that address range will
have their execution time measured.
Profiling begins on return from
.Fn monstartup .
+.Sh ENVIRONMENT
+The following environment variables affect the execution of
+.Nm :
+.Bl -tag -width ".Ev PROFIL_USE_PID"
+.It PROFIL_USE_PID
+If set, the pid of the process is inserted into the filename.
+.El
.Sh FILES
.Bl -tag -width progname.gmon -compact
.It Pa progname.gmon
diff --git a/lib/libc/i386/gen/getcontextx.c b/lib/libc/i386/gen/getcontextx.c
index 5908ce7..2d3b562 100644
--- a/lib/libc/i386/gen/getcontextx.c
+++ b/lib/libc/i386/gen/getcontextx.c
@@ -68,7 +68,7 @@ __getcontextx_size(void)
" movl %%ebx,%1\n"
" popl %%ebx\n"
: "=a" (p[0]), "=r" (p[1]), "=c" (p[2]), "=d" (p[3])
- : "0" (0x0));
+ : "0" (0x1));
if ((p[2] & CPUID2_OSXSAVE) != 0) {
__asm __volatile(
" pushl %%ebx\n"
diff --git a/lib/libc/i386/sys/Makefile.inc b/lib/libc/i386/sys/Makefile.inc
index 98a9c9e..9eefabc 100644
--- a/lib/libc/i386/sys/Makefile.inc
+++ b/lib/libc/i386/sys/Makefile.inc
@@ -5,7 +5,8 @@
SRCS+= i386_clr_watch.c i386_set_watch.c i386_vm86.c
.endif
SRCS+= i386_get_fsbase.c i386_get_gsbase.c i386_get_ioperm.c i386_get_ldt.c \
- i386_set_fsbase.c i386_set_gsbase.c i386_set_ioperm.c i386_set_ldt.c
+ i386_set_fsbase.c i386_set_gsbase.c i386_set_ioperm.c i386_set_ldt.c \
+ __vdso_gettc.c
MDASM= Ovfork.S brk.S cerror.S exect.S getcontext.S pipe.S ptrace.S \
reboot.S sbrk.S setlogin.S sigreturn.S syscall.S
diff --git a/lib/libc/i386/sys/__vdso_gettc.c b/lib/libc/i386/sys/__vdso_gettc.c
new file mode 100644
index 0000000..4419141
--- /dev/null
+++ b/lib/libc/i386/sys/__vdso_gettc.c
@@ -0,0 +1,50 @@
+/*-
+ * Copyright (c) 2012 Konstantin Belousov <kib@FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/vdso.h>
+#include <machine/cpufunc.h>
+
+static u_int
+__vdso_gettc_low(const struct vdso_timehands *th)
+{
+ uint32_t rv;
+
+ __asm __volatile("rdtsc; shrd %%cl, %%edx, %0"
+ : "=a" (rv) : "c" (th->th_x86_shift) : "edx");
+ return (rv);
+}
+
+#pragma weak __vdso_gettc
+u_int
+__vdso_gettc(const struct vdso_timehands *th)
+{
+
+ return (th->th_x86_shift > 0 ? __vdso_gettc_low(th) : rdtsc32());
+}
diff --git a/lib/libc/include/libc_private.h b/lib/libc/include/libc_private.h
index 2182f46..faae028 100644
--- a/lib/libc/include/libc_private.h
+++ b/lib/libc/include/libc_private.h
@@ -34,6 +34,7 @@
#ifndef _LIBC_PRIVATE_H_
#define _LIBC_PRIVATE_H_
+#include <sys/_types.h>
#include <sys/_pthreadtypes.h>
/*
@@ -245,6 +246,12 @@ extern void * __sys_freebsd6_mmap(void *, __size_t, int, int, int, int, __off_t)
/* Without back-compat translation */
extern int __sys_fcntl(int, int, ...);
+struct timespec;
+struct timeval;
+struct timezone;
+int __sys_gettimeofday(struct timeval *, struct timezone *);
+int __sys_clock_gettime(__clockid_t, struct timespec *ts);
+
/* execve() with PATH processing to implement posix_spawnp() */
int _execvpe(const char *, char * const *, char * const *);
diff --git a/lib/libc/include/port_before.h b/lib/libc/include/port_before.h
index beef71d..304dd66 100644
--- a/lib/libc/include/port_before.h
+++ b/lib/libc/include/port_before.h
@@ -17,6 +17,6 @@
var = _u.v; \
} while (0)
-#define UNUSED(x) (x) = (x)
+#define UNUSED(x) (void)(x)
#endif /* _PORT_BEFORE_H_ */
diff --git a/lib/libc/locale/collate.c b/lib/libc/locale/collate.c
index 448e605..676d41c 100644
--- a/lib/libc/locale/collate.c
+++ b/lib/libc/locale/collate.c
@@ -56,11 +56,11 @@ __FBSDID("$FreeBSD$");
* We also modify the collation table test functions to search the thread-local
* table first and the global table second.
*/
-#define __collate_load_error (table->__collate_load_error)
#define __collate_substitute_nontrivial (table->__collate_substitute_nontrivial)
#define __collate_substitute_table_ptr (table->__collate_substitute_table_ptr)
#define __collate_char_pri_table_ptr (table->__collate_char_pri_table_ptr)
#define __collate_chain_pri_table (table->__collate_chain_pri_table)
+int __collate_load_error;
struct xlocale_collate __xlocale_global_collate = {
@@ -109,7 +109,9 @@ __collate_load(const char *encoding, locale_t unused)
int
__collate_load_tables(const char *encoding)
{
- return __collate_load_tables_l(encoding, &__xlocale_global_collate);
+ int ret = __collate_load_tables_l(encoding, &__xlocale_global_collate);
+ __collate_load_error = __xlocale_global_collate.__collate_load_error;
+ return ret;
}
int
@@ -123,7 +125,7 @@ __collate_load_tables_l(const char *encoding, struct xlocale_collate *table)
/* 'encoding' must be already checked. */
if (strcmp(encoding, "C") == 0 || strcmp(encoding, "POSIX") == 0) {
- __collate_load_error = 1;
+ table->__collate_load_error = 1;
return (_LDP_CACHE);
}
@@ -240,7 +242,7 @@ __collate_load_tables_l(const char *encoding, struct xlocale_collate *table)
break;
}
}
- __collate_load_error = 0;
+ table->__collate_load_error = 0;
return (_LDP_LOADED);
}
diff --git a/lib/libc/locale/ctype_l.3 b/lib/libc/locale/ctype_l.3
index 385125e..5f427de 100644
--- a/lib/libc/locale/ctype_l.3
+++ b/lib/libc/locale/ctype_l.3
@@ -135,4 +135,17 @@ See the specific manual pages for more information.
.Xr xlocale 3
.Sh STANDARDS
These functions conform to
-.St -p1003.1-2008 .
+.St -p1003.1-2008 ,
+except for
+.Fn digittoint_l ,
+.Fn isascii_l ,
+.Fn ishexnumber_l ,
+.Fn isideogram_l ,
+.Fn isnumber_l ,
+.Fn isphonogram_l ,
+.Fn isrune_l
+and
+.Fn isspecial_l
+which are
+.Fx
+extensions.
diff --git a/lib/libc/locale/duplocale.3 b/lib/libc/locale/duplocale.3
index 73c0b3e..1e149c0 100644
--- a/lib/libc/locale/duplocale.3
+++ b/lib/libc/locale/duplocale.3
@@ -44,10 +44,10 @@ Duplicates an existing
.Fa locale_t
returning a new
.Fa locale_t
-that refers to the same locale values but has independent internal state.
+that refers to the same locale values but has an independent internal state.
Various functions, such as
.Xr mblen 3
-require presistent state.
+require a persistent state.
These functions formerly used static variables and calls to them from multiple
threads had undefined behavior.
They now use fields in the
diff --git a/lib/libc/locale/freelocale.3 b/lib/libc/locale/freelocale.3
index 8401803..26060e8 100644
--- a/lib/libc/locale/freelocale.3
+++ b/lib/libc/locale/freelocale.3
@@ -34,7 +34,7 @@
.Nd Frees a locale created with
.Xr duplocale 3
or
-.Xr newlocale 3 .
+.Xr newlocale 3
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
diff --git a/lib/libc/locale/newlocale.3 b/lib/libc/locale/newlocale.3
index 599f148..e2d7ebb 100644
--- a/lib/libc/locale/newlocale.3
+++ b/lib/libc/locale/newlocale.3
@@ -51,7 +51,7 @@ Any other components will be inherited from
The
.Fa mask
is either
-.Fa LC_ALL_MASK,
+.Fa LC_ALL_MASK ,
indicating all possible locale components,
or the logical OR of some combination of the following:
.Bl -tag -width "LC_MESSAGES_MASK" -offset indent
@@ -59,7 +59,7 @@ or the logical OR of some combination of the following:
The locale for string collation routines.
This controls alphabetic ordering in
.Xr strcoll 3
- and
+and
.Xr strxfrm 3 .
.It LC_CTYPE_MASK
The locale for the
diff --git a/lib/libc/locale/querylocale.3 b/lib/libc/locale/querylocale.3
index a9d0182..4f97755 100644
--- a/lib/libc/locale/querylocale.3
+++ b/lib/libc/locale/querylocale.3
@@ -32,7 +32,7 @@
.Os
.Sh NAME
.Nm querylocale
-.Nd Look up the locale name for a specified category.
+.Nd Look up the locale name for a specified category
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
@@ -41,7 +41,7 @@
.Fn querylocale "int mask" "locale_t locale"
.Sh DESCRIPTION
Returns the name of the locale for the category specified by
-.Fa mask.
+.Fa mask .
This possible values for the mask are the same as those in
.Xr newlocale 3 .
If more than one bit in the mask is set, the returned value is undefined.
diff --git a/lib/libc/locale/setrunelocale.c b/lib/libc/locale/setrunelocale.c
index bc04e9e..3ffb649 100644
--- a/lib/libc/locale/setrunelocale.c
+++ b/lib/libc/locale/setrunelocale.c
@@ -67,7 +67,6 @@ extern _RuneLocale *_Read_RuneMagi(FILE *);
static int __setrunelocale(struct xlocale_ctype *l, const char *);
-#define __collate_load_error (table->__collate_load_error)
#define __collate_substitute_nontrivial (table->__collate_substitute_nontrivial)
#define __collate_substitute_table_ptr (table->__collate_substitute_table_ptr)
#define __collate_char_pri_table_ptr (table->__collate_char_pri_table_ptr)
@@ -89,6 +88,17 @@ const _RuneLocale *__getCurrentRuneLocale(void)
return XLOCALE_CTYPE(__get_locale())->runes;
}
+static void free_runes(_RuneLocale *rl)
+{
+ /* FIXME: The "EUC" check here is a hideous abstraction violation. */
+ if ((rl != &_DefaultRuneLocale) && (rl)) {
+ if (strcmp(rl->__encoding, "EUC") == 0) {
+ free(rl->__variable);
+ }
+ free(rl);
+ }
+}
+
static int
__setrunelocale(struct xlocale_ctype *l, const char *encoding)
{
@@ -102,6 +112,7 @@ __setrunelocale(struct xlocale_ctype *l, const char *encoding)
* The "C" and "POSIX" locale are always here.
*/
if (strcmp(encoding, "C") == 0 || strcmp(encoding, "POSIX") == 0) {
+ free_runes(saved.runes);
(void) _none_init(l, (_RuneLocale*)&_DefaultRuneLocale);
return (0);
}
@@ -153,13 +164,7 @@ __setrunelocale(struct xlocale_ctype *l, const char *encoding)
if (ret == 0) {
/* Free the old runes if it exists. */
- /* FIXME: The "EUC" check here is a hideous abstraction violation. */
- if ((saved.runes != &_DefaultRuneLocale) && (saved.runes)) {
- if (strcmp(saved.runes->__encoding, "EUC") == 0) {
- free(saved.runes->__variable);
- }
- free(saved.runes);
- }
+ free_runes(saved.runes);
} else {
/* Restore the saved version if this failed. */
memcpy(l, &saved, sizeof(struct xlocale_ctype));
diff --git a/lib/libc/locale/toupper.c b/lib/libc/locale/toupper.c
index d3a4fa3..704ac3a 100644
--- a/lib/libc/locale/toupper.c
+++ b/lib/libc/locale/toupper.c
@@ -51,7 +51,7 @@ ___toupper_l(c, l)
{
size_t lim;
FIX_LOCALE(l);
- _RuneRange *rr = &XLOCALE_CTYPE(l)->runes->__maplower_ext;
+ _RuneRange *rr = &XLOCALE_CTYPE(l)->runes->__mapupper_ext;
_RuneEntry *base, *re;
if (c < 0 || c == EOF)
diff --git a/lib/libc/locale/uselocale.3 b/lib/libc/locale/uselocale.3
index 72847b3..9b4f430 100644
--- a/lib/libc/locale/uselocale.3
+++ b/lib/libc/locale/uselocale.3
@@ -32,7 +32,7 @@
.Os
.Sh NAME
.Nm uselocale
-.Nd Sets a thread-local locale.
+.Nd Sets a thread-local locale
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
diff --git a/lib/libc/locale/xlocale.3 b/lib/libc/locale/xlocale.3
index 11a392d..9648cc7 100644
--- a/lib/libc/locale/xlocale.3
+++ b/lib/libc/locale/xlocale.3
@@ -32,7 +32,7 @@
.Os
.Sh NAME
.Nm xlocale
-.Nd Thread-safe extended locale support.
+.Nd Thread-safe extended locale support
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
diff --git a/lib/libc/net/Makefile.inc b/lib/libc/net/Makefile.inc
index 4eadf98..e61021b 100644
--- a/lib/libc/net/Makefile.inc
+++ b/lib/libc/net/Makefile.inc
@@ -36,7 +36,7 @@ LFLAGS+=-P_nsyy
CLEANFILES+=nslexer.c
-nslexer.c: nslexer.l
+nslexer.c: nslexer.l nsparser.h
${LEX} ${LFLAGS} -o/dev/stdout ${.IMPSRC} | \
sed -e '/YY_BUF_SIZE/s/16384/1024/' >${.TARGET}
diff --git a/lib/libc/net/Symbol.map b/lib/libc/net/Symbol.map
index 39ab2c7..2eddc47 100644
--- a/lib/libc/net/Symbol.map
+++ b/lib/libc/net/Symbol.map
@@ -143,6 +143,11 @@ FBSD_1.0 {
setsourcefilter;
};
+FBSD_1.3 {
+ sctp_recvv;
+ sctp_sendv;
+};
+
FBSDprivate_1.0 {
_nsdispatch;
_nsyyerror; /* generated from nslexer.l */
diff --git a/lib/libc/net/getaddrinfo.c b/lib/libc/net/getaddrinfo.c
index 8083c39..dc2641f 100644
--- a/lib/libc/net/getaddrinfo.c
+++ b/lib/libc/net/getaddrinfo.c
@@ -464,7 +464,7 @@ getaddrinfo(const char *hostname, const char *servname,
}
error = get_portmatch(pai, servname);
if (error)
- ERR(error);
+ goto bad;
*pai = ai0;
}
diff --git a/lib/libc/net/if_indextoname.c b/lib/libc/net/if_indextoname.c
index 4dadce3..4b16433 100644
--- a/lib/libc/net/if_indextoname.c
+++ b/lib/libc/net/if_indextoname.c
@@ -70,7 +70,7 @@ if_indextoname(unsigned int ifindex, char *ifname)
for (ifa = ifaddrs; ifa != NULL; ifa = ifa->ifa_next) {
if (ifa->ifa_addr &&
ifa->ifa_addr->sa_family == AF_LINK &&
- ifindex == ((struct sockaddr_dl*)ifa->ifa_addr)->sdl_index)
+ ifindex == LLINDEX((struct sockaddr_dl*)ifa->ifa_addr))
break;
}
diff --git a/lib/libc/net/if_nameindex.c b/lib/libc/net/if_nameindex.c
index 7a12d34..138289c 100644
--- a/lib/libc/net/if_nameindex.c
+++ b/lib/libc/net/if_nameindex.c
@@ -123,7 +123,7 @@ if_nameindex(void)
if (ifa->ifa_addr &&
ifa->ifa_addr->sa_family == AF_LINK) {
ifni2->if_index =
- ((struct sockaddr_dl*)ifa->ifa_addr)->sdl_index;
+ LLINDEX((struct sockaddr_dl*)ifa->ifa_addr);
ifni2->if_name = cp;
strcpy(cp, ifa->ifa_name);
ifni2++;
diff --git a/lib/libc/net/if_nametoindex.c b/lib/libc/net/if_nametoindex.c
index 9d47089..89076c0 100644
--- a/lib/libc/net/if_nametoindex.c
+++ b/lib/libc/net/if_nametoindex.c
@@ -90,7 +90,7 @@ if_nametoindex(const char *ifname)
if (ifa->ifa_addr &&
ifa->ifa_addr->sa_family == AF_LINK &&
strcmp(ifa->ifa_name, ifname) == 0) {
- ni = ((struct sockaddr_dl*)ifa->ifa_addr)->sdl_index;
+ ni = LLINDEX((struct sockaddr_dl*)ifa->ifa_addr);
break;
}
}
diff --git a/lib/libc/net/nsdispatch.3 b/lib/libc/net/nsdispatch.3
index a1da892..577bce9 100644
--- a/lib/libc/net/nsdispatch.3
+++ b/lib/libc/net/nsdispatch.3
@@ -173,11 +173,11 @@ While there is support for arbitrary sources, the following
#defines for commonly implemented sources are available:
.Bl -column NSSRC_COMPAT compat -offset indent
.It Sy "#define value"
-.It Dv NSSRC_FILES Ta """files""
-.It Dv NSSRC_DB Ta """db""
-.It Dv NSSRC_DNS Ta """dns""
-.It Dv NSSRC_NIS Ta """nis""
-.It Dv NSSRC_COMPAT Ta """compat""
+.It Dv NSSRC_FILES Ta \&"files\&"
+.It Dv NSSRC_DB Ta \&"db\&"
+.It Dv NSSRC_DNS Ta \&"dns\&"
+.It Dv NSSRC_NIS Ta \&"nis\&"
+.It Dv NSSRC_COMPAT Ta \&"compat\&"
.El
.Pp
Refer to
diff --git a/lib/libc/net/nsparser.y b/lib/libc/net/nsparser.y
index 730458a..2e57cd2 100644
--- a/lib/libc/net/nsparser.y
+++ b/lib/libc/net/nsparser.y
@@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$");
#define _NS_PRIVATE
#include <nsswitch.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include "un-namespace.h"
diff --git a/lib/libc/net/sctp_connectx.3 b/lib/libc/net/sctp_connectx.3
index 1851d4a..6ea1bb6 100644
--- a/lib/libc/net/sctp_connectx.3
+++ b/lib/libc/net/sctp_connectx.3
@@ -36,7 +36,7 @@
.Os
.Sh NAME
.Nm sctp_connectx
-.Nd connect an SCTP socket with multiple destination addresses.
+.Nd connect an SCTP socket with multiple destination addresses
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
diff --git a/lib/libc/net/sctp_recvmsg.3 b/lib/libc/net/sctp_recvmsg.3
index 37323c8..eda3e5c 100644
--- a/lib/libc/net/sctp_recvmsg.3
+++ b/lib/libc/net/sctp_recvmsg.3
@@ -66,7 +66,7 @@ For a one-to-many (SOCK_SEQPACKET) type socket, an endpoint may call
.Fn sctp_recvmsg
after having implicitly started an association via one
of the send calls including
-.Fn sctp_sendmsg
+.Fn sctp_sendmsg ,
.Fn sendto
and
.Fn sendmsg .
diff --git a/lib/libc/net/sctp_sys_calls.c b/lib/libc/net/sctp_sys_calls.c
index e9c9d64..3785a04 100644
--- a/lib/libc/net/sctp_sys_calls.c
+++ b/lib/libc/net/sctp_sys_calls.c
@@ -1,7 +1,7 @@
/*-
* Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved.
- * Copyright (c) 2008-2011, by Randall Stewart. All rights reserved.
- * Copyright (c) 2008-2011, by Michael Tuexen. All rights reserved.
+ * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
+ * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -32,6 +32,7 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
+
#include <stdio.h>
#include <string.h>
#include <errno.h>
@@ -800,7 +801,6 @@ continue_send:
}
sinfo->sinfo_assoc_id = sctp_getassocid(sd, addrs);
if (sinfo->sinfo_assoc_id == 0) {
- printf("Huh, can't get associd? TSNH!\n");
(void)setsockopt(sd, IPPROTO_SCTP, SCTP_CONNECT_X_COMPLETE, (void *)addrs,
(socklen_t) addrs->sa_len);
errno = ENOENT;
diff --git a/lib/libc/net/sourcefilter.3 b/lib/libc/net/sourcefilter.3
index c7293e0..225b020 100644
--- a/lib/libc/net/sourcefilter.3
+++ b/lib/libc/net/sourcefilter.3
@@ -158,7 +158,7 @@ For the protocol-independent functions
.Fn getsourcefilter
and
.Fn setsourcefilter ,
-the argument
+the
.Fa grouplen
argument specifies the size of the structure pointed to by
.Fa group .
@@ -220,7 +220,7 @@ operation.
.Sh SEE ALSO
.Xr ip 4 ,
.Xr ip6 4 ,
-.Xr multicast 4,
+.Xr multicast 4 ,
.Xr ifmcstat 8
.Rs
.%A D. Thaler
diff --git a/lib/libc/net/sourcefilter.c b/lib/libc/net/sourcefilter.c
index cc0f1b9..4d29d9f 100644
--- a/lib/libc/net/sourcefilter.c
+++ b/lib/libc/net/sourcefilter.c
@@ -120,7 +120,7 @@ __inaddr_to_index(in_addr_t ifaddr)
psu = (sockunion_t *)ifa->ifa_addr;
if (psu && psu->ss.ss_family == AF_LINK &&
strcmp(ifa->ifa_name, ifname) == 0) {
- ifindex = psu->sdl.sdl_index;
+ ifindex = LLINDEX(&psu->sdl);
break;
}
}
diff --git a/lib/libc/posix1e/acl_delete_entry.3 b/lib/libc/posix1e/acl_delete_entry.3
index 3705f07..b1bdc5a 100644
--- a/lib/libc/posix1e/acl_delete_entry.3
+++ b/lib/libc/posix1e/acl_delete_entry.3
@@ -30,7 +30,7 @@
.Os
.Sh NAME
.Nm acl_delete_entry ,
-.Nm acl_delete_entry_np ,
+.Nm acl_delete_entry_np
.Nd delete an ACL entry from an ACL
.Sh LIBRARY
.Lb libc
diff --git a/lib/libc/posix1e/mac_prepare.3 b/lib/libc/posix1e/mac_prepare.3
index 8e694de..e217b71 100644
--- a/lib/libc/posix1e/mac_prepare.3
+++ b/lib/libc/posix1e/mac_prepare.3
@@ -64,7 +64,7 @@ when the label was prepared.
Elements are specified in a nul-terminated string, using commas to
delimit fields.
Element names may be prefixed with the
-.Dv ?
+.Ql \&?
character to indicate that a failure by the kernel to retrieve that
element should not be considered fatal.
.Pp
diff --git a/lib/libc/powerpc/Symbol.map b/lib/libc/powerpc/Symbol.map
index 14b4811..10b7c57 100644
--- a/lib/libc/powerpc/Symbol.map
+++ b/lib/libc/powerpc/Symbol.map
@@ -38,6 +38,10 @@ FBSD_1.0 {
vfork;
};
+FBSD_1.3 {
+ __eabi;
+};
+
FBSDprivate_1.0 {
/* PSEUDO syscalls */
__sys_getlogin;
diff --git a/lib/libc/powerpc/gen/Makefile.inc b/lib/libc/powerpc/gen/Makefile.inc
index 79a2746..81c6a69 100644
--- a/lib/libc/powerpc/gen/Makefile.inc
+++ b/lib/libc/powerpc/gen/Makefile.inc
@@ -1,6 +1,6 @@
# $FreeBSD$
-SRCS += _ctx_start.S fabs.S flt_rounds.c fpgetmask.c fpgetround.c \
+SRCS += _ctx_start.S eabi.S fabs.S flt_rounds.c fpgetmask.c fpgetround.c \
fpgetsticky.c fpsetmask.c fpsetround.c getcontextx.c \
infinity.c ldexp.c makecontext.c _setjmp.S \
setjmp.S sigsetjmp.S signalcontext.c syncicache.c \
diff --git a/lib/libc/powerpc/gen/eabi.S b/lib/libc/powerpc/gen/eabi.S
new file mode 100644
index 0000000..59c2311
--- /dev/null
+++ b/lib/libc/powerpc/gen/eabi.S
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2011 Marcel Moolenaar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <machine/asm.h>
+__FBSDID("$FreeBSD$");
+
+ENTRY(__eabi)
+ blr
+
+ .section .note.GNU-stack,"",%progbits
diff --git a/lib/libc/rpc/auth_unix.c b/lib/libc/rpc/auth_unix.c
index ff3ca7b..c0d2548 100644
--- a/lib/libc/rpc/auth_unix.c
+++ b/lib/libc/rpc/auth_unix.c
@@ -185,6 +185,7 @@ authunix_create(machname, uid, gid, len, aup_gids)
AUTH *
authunix_create_default()
{
+ AUTH *auth;
int ngids;
long ngids_max;
char machname[MAXHOSTNAMELEN + 1];
@@ -207,8 +208,10 @@ authunix_create_default()
if (ngids > NGRPS)
ngids = NGRPS;
/* XXX: interface problem; those should all have been unsigned */
- return (authunix_create(machname, (int)uid, (int)gid, ngids,
- (int *)gids));
+ auth = authunix_create(machname, (int)uid, (int)gid, ngids,
+ (int *)gids);
+ free(gids);
+ return (auth);
}
/*
diff --git a/lib/libc/rpc/publickey.3 b/lib/libc/rpc/publickey.3
index d0ad6cc..ff8a615 100644
--- a/lib/libc/rpc/publickey.3
+++ b/lib/libc/rpc/publickey.3
@@ -35,14 +35,14 @@ has an extra argument,
which is used to decrypt the encrypted secret key stored in the database.
Both routines return 1 if they are successful in finding the key, 0 otherwise.
The keys are returned as
-.Dv NULL Ns \-terminated ,
+.Dv NUL Ns \-terminated ,
hexadecimal strings.
If the password supplied to
.Fn getsecretkey
fails to decrypt the secret key, the routine will return 1 but the
.Fa secretkey
argument will be a
-.Dv NULL
+.Dv NUL
string
.Pq Dq .
.Sh SEE ALSO
diff --git a/lib/libc/rpc/svc.c b/lib/libc/rpc/svc.c
index 282c2be..78a8ae1 100644
--- a/lib/libc/rpc/svc.c
+++ b/lib/libc/rpc/svc.c
@@ -108,8 +108,10 @@ xprt_register(xprt)
if (__svc_xports == NULL) {
__svc_xports = (SVCXPRT **)
mem_alloc(FD_SETSIZE * sizeof(SVCXPRT *));
- if (__svc_xports == NULL)
+ if (__svc_xports == NULL) {
+ rwlock_unlock(&svc_fd_lock);
return;
+ }
memset(__svc_xports, '\0', FD_SETSIZE * sizeof(SVCXPRT *));
}
if (sock < FD_SETSIZE) {
@@ -565,8 +567,14 @@ svc_xprt_alloc()
SVCXPRT_EXT *ext;
xprt = mem_alloc(sizeof(SVCXPRT));
+ if (xprt == NULL)
+ return (NULL);
memset(xprt, 0, sizeof(SVCXPRT));
ext = mem_alloc(sizeof(SVCXPRT_EXT));
+ if (ext == NULL) {
+ mem_free(xprt, sizeof(SVCXPRT));
+ return (NULL);
+ }
memset(ext, 0, sizeof(SVCXPRT_EXT));
xprt->xp_p3 = ext;
ext->xp_auth.svc_ah_ops = &svc_auth_null_ops;
diff --git a/lib/libc/rpc/svc_raw.c b/lib/libc/rpc/svc_raw.c
index 67bcba1..de95152 100644
--- a/lib/libc/rpc/svc_raw.c
+++ b/lib/libc/rpc/svc_raw.c
@@ -96,10 +96,22 @@ svc_raw_create()
mutex_unlock(&svcraw_lock);
return (NULL);
}
- if (__rpc_rawcombuf == NULL)
+ if (__rpc_rawcombuf == NULL) {
__rpc_rawcombuf = calloc(UDPMSGSIZE, sizeof (char));
+ if (__rpc_rawcombuf == NULL) {
+ free(srp);
+ mutex_unlock(&svcraw_lock);
+ return (NULL);
+ }
+ }
srp->raw_buf = __rpc_rawcombuf; /* Share it with the client */
srp->server = svc_xprt_alloc();
+ if (srp->server == NULL) {
+ free(__rpc_rawcombuf);
+ free(srp);
+ mutex_unlock(&svcraw_lock);
+ return (NULL);
+ }
svc_raw_private = srp;
}
srp->server->xp_fd = FD_SETSIZE;
diff --git a/lib/libc/stdio/Makefile.inc b/lib/libc/stdio/Makefile.inc
index c3b60f6..6570051 100644
--- a/lib/libc/stdio/Makefile.inc
+++ b/lib/libc/stdio/Makefile.inc
@@ -36,7 +36,8 @@ MAN+= fclose.3 ferror.3 fflush.3 fgetln.3 fgets.3 fgetwln.3 fgetws.3 \
fopen.3 fputs.3 \
fputws.3 fread.3 fseek.3 funopen.3 fwide.3 getc.3 \
getline.3 getwc.3 mktemp.3 \
- printf.3 putc.3 putwc.3 remove.3 scanf.3 setbuf.3 stdio.3 tmpnam.3 \
+ printf.3 printf_l.3 putc.3 putwc.3 remove.3 scanf.3 scanf_l.3 setbuf.3 \
+ stdio.3 tmpnam.3 \
ungetc.3 ungetwc.3 wprintf.3 wscanf.3
MLINKS+=fclose.3 fcloseall.3
@@ -63,11 +64,16 @@ MLINKS+=printf.3 asprintf.3 printf.3 dprintf.3 printf.3 fprintf.3 \
printf.3 vasprintf.3 printf.3 vdprintf.3 \
printf.3 vfprintf.3 printf.3 vprintf.3 printf.3 vsnprintf.3 \
printf.3 vsprintf.3
+MLINKS+=printf_l.3 asprintf_l.3 printf_l.3 fprintf_l.3 printf_l.3 snprintf_l.3 \
+ printf_l.3 sprintf_l.3 printf_l.3 vasprintf_l.3 printf_l.3 vfprintf_l.3 \
+ printf_l.3 vprintf_l.3 printf_l.3 vsnprintf_l.3 printf_l.3 vsprintf_l.3
MLINKS+=putc.3 fputc.3 putc.3 putc_unlocked.3 putc.3 putchar.3 \
putc.3 putchar_unlocked.3 putc.3 putw.3
MLINKS+=putwc.3 fputwc.3 putwc.3 putwchar.3
MLINKS+=scanf.3 fscanf.3 scanf.3 sscanf.3 scanf.3 vfscanf.3 scanf.3 vscanf.3 \
scanf.3 vsscanf.3
+MLINKS+=scanf_l.3 fscanf_l.3 scanf_l.3 sscanf_l.3 scanf_l.3 vfscanf_l.3 \
+ scanf_l.3 vscanf_l.3 scanf_l.3 vsscanf_l.3
MLINKS+=setbuf.3 setbuffer.3 setbuf.3 setlinebuf.3 setbuf.3 setvbuf.3
MLINKS+=tmpnam.3 tempnam.3 tmpnam.3 tmpfile.3
MLINKS+=wprintf.3 fwprintf.3 wprintf.3 swprintf.3 \
diff --git a/lib/libc/stdio/fgets.3 b/lib/libc/stdio/fgets.3
index fba7353..278e18c 100644
--- a/lib/libc/stdio/fgets.3
+++ b/lib/libc/stdio/fgets.3
@@ -32,7 +32,7 @@
.\" @(#)fgets.3 8.1 (Berkeley) 6/4/93
.\" $FreeBSD$
.\"
-.Dd June 4, 1993
+.Dd May 5, 2012
.Dt FGETS 3
.Os
.Sh NAME
@@ -154,5 +154,3 @@ a buffer overflow attack.
It is strongly suggested that the
.Fn fgets
function be used in all cases.
-(See
-the FSA.)
diff --git a/lib/libc/stdio/fgetwc.c b/lib/libc/stdio/fgetwc.c
index 0e87753..52bc988 100644
--- a/lib/libc/stdio/fgetwc.c
+++ b/lib/libc/stdio/fgetwc.c
@@ -59,6 +59,7 @@ fgetwc_l(FILE *fp, locale_t locale)
return (r);
}
+
wint_t
fgetwc(FILE *fp)
{
@@ -66,40 +67,45 @@ fgetwc(FILE *fp)
}
/*
- * Non-MT-safe version.
+ * Internal (non-MPSAFE) version of fgetwc(). This version takes an
+ * mbstate_t argument specifying the initial conversion state. For
+ * wide streams, this should always be fp->_mbstate. On return, *nread
+ * is set to the number of bytes read.
*/
-wint_t
-__fgetwc(FILE *fp, locale_t locale)
+wint_t
+__fgetwc_mbs(FILE *fp, mbstate_t *mbs, int *nread, locale_t locale)
{
wchar_t wc;
size_t nconv;
struct xlocale_ctype *l = XLOCALE_CTYPE(locale);
- if (fp->_r <= 0 && __srefill(fp))
+ if (fp->_r <= 0 && __srefill(fp)) {
+ *nread = 0;
return (WEOF);
+ }
if (MB_CUR_MAX == 1) {
/* Fast path for single-byte encodings. */
wc = *fp->_p++;
fp->_r--;
+ *nread = 1;
return (wc);
}
+ *nread = 0;
do {
- nconv = l->__mbrtowc(&wc, fp->_p, fp->_r, &fp->_mbstate);
+ nconv = l->__mbrtowc(&wc, fp->_p, fp->_r, mbs);
if (nconv == (size_t)-1)
break;
else if (nconv == (size_t)-2)
continue;
else if (nconv == 0) {
- /*
- * Assume that the only valid representation of
- * the null wide character is a single null byte.
- */
fp->_p++;
fp->_r--;
+ (*nread)++;
return (L'\0');
} else {
fp->_p += nconv;
fp->_r -= nconv;
+ *nread += nconv;
return (wc);
}
} while (__srefill(fp) == 0);
diff --git a/lib/libc/stdio/fpurge.c b/lib/libc/stdio/fpurge.c
index 6a2c70c..148e490 100644
--- a/lib/libc/stdio/fpurge.c
+++ b/lib/libc/stdio/fpurge.c
@@ -62,7 +62,7 @@ fpurge(fp)
FREEUB(fp);
fp->_p = fp->_bf._base;
fp->_r = 0;
- fp->_w = fp->_flags & (__SLBF|__SNBF) ? 0 : fp->_bf._size;
+ fp->_w = fp->_flags & (__SLBF|__SNBF|__SRD) ? 0 : fp->_bf._size;
retval = 0;
}
FUNLOCKFILE(fp);
diff --git a/lib/libc/stdio/local.h b/lib/libc/stdio/local.h
index 8b37f0d..7168f62 100644
--- a/lib/libc/stdio/local.h
+++ b/lib/libc/stdio/local.h
@@ -56,7 +56,7 @@ extern int _ftello(FILE *, fpos_t *);
extern int _fseeko(FILE *, off_t, int, int);
extern int __fflush(FILE *fp);
extern void __fcloseall(void);
-extern wint_t __fgetwc(FILE *, locale_t);
+extern wint_t __fgetwc_mbs(FILE *, mbstate_t *, int *, locale_t);
extern wint_t __fputwc(wchar_t, FILE *, locale_t);
extern int __sflush(FILE *);
extern FILE *__sfp(void);
@@ -85,6 +85,13 @@ extern size_t __fread(void * __restrict buf, size_t size, size_t count,
FILE * __restrict fp);
extern int __sdidinit;
+static inline wint_t
+__fgetwc(FILE *fp, locale_t locale)
+{
+ int nread;
+
+ return (__fgetwc_mbs(fp, &fp->_mbstate, &nread, locale));
+}
/*
* Prepare the given FILE for writing, and return 0 iff it
diff --git a/lib/libc/stdio/printf_l.3 b/lib/libc/stdio/printf_l.3
new file mode 100644
index 0000000..20c855b
--- /dev/null
+++ b/lib/libc/stdio/printf_l.3
@@ -0,0 +1,80 @@
+.\" Copyright (c) 2012 Isabell Long <issyl0@FreeBSD.org>
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd April 7, 2012
+.Dt PRINTF_L 3
+.Os
+.Sh NAME
+.Nm printf_l ,
+.Nm asprintf_l ,
+.Nm fprintf_l ,
+.Nm snprintf_l ,
+.Nm sprintf_l ,
+.Nm vasprintf_l ,
+.Nm vfprintf_l ,
+.Nm vprintf_l ,
+.Nm vsnprintf_l ,
+.Nm vsprintf_l
+.Nd formatted output conversion
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In stdio.h
+.Ft int
+.Fn printf_l "locale_t loc" "const char * restrict format" "..."
+.Ft int
+.Fn asprintf_l "char **ret" "locale_t loc" "const char * format" "..."
+.Ft int
+.Fn fprintf_l "FILE * restrict stream" "locale_t loc" "const char * restrict format" "..."
+.Ft int
+.Fn snprintf_l "char * restrict str" "size_t size" "locale_t loc" "const char * restrict format" "..."
+.Ft int
+.Fn sprintf_l "char * restrict str" "locale_t loc" "const char * restrict format" "..."
+.Ft int
+.Fn vasprintf_l "char **ret" "locale_t loc" "const char *format" "va_list ap"
+.Ft int
+.Fn vfprintf_l "FILE * restrict stream" "locale_t loc" "const char * restrict format" "va_list ap"
+.Ft int
+.Fn vprintf_l "locale_t loc" "const char * restrict format" "va_list ap"
+.Ft int
+.Fn vsnprintf_l "char * restrict str" "size_t size" "locale_t loc" "const char * restrict format" "va_list ap"
+.Ft int
+.Fn vsprintf_l "char * restrict str" "locale_t loc" "const char * restrict format" "va_list ap"
+.Sh DESCRIPTION
+The above functions are used to convert formatted output in the locale
+.Fa loc .
+They behave in the same way as the versions without the _l suffix, but use
+the specified locale rather than the global or per-thread locale.
+See the specific manual pages for more information.
+.Sh SEE ALSO
+.Xr printf 3 ,
+.Xr xlocale 3
+.Sh STANDARDS
+These functions do not conform to any specific standard so they should be
+considered as non-portable local extensions.
+.Sh HISTORY
+These functions first appeared in Darwin and were first implemented in
+.Fx 9.1 .
diff --git a/lib/libc/stdio/scanf.3 b/lib/libc/stdio/scanf.3
index 319455a..8a8666c 100644
--- a/lib/libc/stdio/scanf.3
+++ b/lib/libc/stdio/scanf.3
@@ -370,10 +370,10 @@ The string is to be made up of characters in
(or not in)
a particular set;
the set is defined by the characters between the open bracket
-.Cm [
+.Cm \&[
character
and a close bracket
-.Cm ]
+.Cm \&]
character.
The set
.Em excludes
diff --git a/lib/libc/stdio/scanf_l.3 b/lib/libc/stdio/scanf_l.3
new file mode 100644
index 0000000..04ea5d9
--- /dev/null
+++ b/lib/libc/stdio/scanf_l.3
@@ -0,0 +1,70 @@
+.\" Copyright (c) 2012 Isabell Long <issyl0@FreeBSD.org>
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd April 8, 2012
+.Dt SCANF_L 3
+.Os
+.Sh NAME
+.Nm scanf_l ,
+.Nm fscanf_l ,
+.Nm sscanf_l ,
+.Nm vfscanf_l ,
+.Nm vscanf_l ,
+.Nm vsscanf_l
+.Nd input format conversion
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In stdio.h
+.Ft int
+.Fn scanf_l "locale_t loc" "const char * restrict format" "..."
+.Ft int
+.Fn fscanf_l "FILE * restrict stream" "locale_t loc" "const char * restrict format" "..."
+.Ft int
+.Fn sscanf_l "const char * restrict str" "locale_t loc" "const char * restrict format" "..."
+.Ft int
+.Fn vfscanf_l "FILE * restrict stream" "locale_t loc" "const char * restrict format" "va_list ap"
+.Ft int
+.Fn vscanf_l "locale_t loc" "const char * restrict format" "va_list ap"
+.Ft int
+.Fn vsscanf_l "const char * restrict str" "locale_t loc" "const char * restrict format" "va_list ap"
+.Sh DESCRIPTION
+The above functions scan input according to a specified
+.Fa format
+in the locale
+.Fa loc .
+They behave in the same way as the versions without the _l suffix, but use
+the specific locale rather than the the global or per-thread locale.
+See the specific manual pages for more information.
+.Sh SEE ALSO
+.Xr scanf 3 ,
+.Xr xlocale 3
+.Sh STANDARDS
+These functions do not conform to any specific standard so they should be
+considered as non-portable local extensions.
+.Sh HISTORY
+These functions first appeared in Darwin and were first implemented in
+.Fx 9.1 .
diff --git a/lib/libc/stdio/setbuf.3 b/lib/libc/stdio/setbuf.3
index be88034..2eda0e6 100644
--- a/lib/libc/stdio/setbuf.3
+++ b/lib/libc/stdio/setbuf.3
@@ -83,6 +83,9 @@ normally does) it is line buffered.
The standard error stream
.Dv stderr
is always unbuffered.
+Note that these defaults may be altered using the
+.Xr stdbuf 1
+utility.
.Pp
The
.Fn setvbuf
@@ -177,6 +180,7 @@ function returns what the equivalent
.Fn setvbuf
would have returned.
.Sh SEE ALSO
+.Xr stdbuf 1 ,
.Xr fclose 3 ,
.Xr fopen 3 ,
.Xr fread 3 ,
diff --git a/lib/libc/stdio/vfscanf.c b/lib/libc/stdio/vfscanf.c
index 6a6b19c..8f9d3d0 100644
--- a/lib/libc/stdio/vfscanf.c
+++ b/lib/libc/stdio/vfscanf.c
@@ -125,11 +125,10 @@ static const mbstate_t initial_mbs;
*/
static __inline int
-convert_char(FILE *fp, char * __restrict p, int width)
+convert_char(FILE *fp, char * p, int width)
{
- int n, nread;
+ int n;
- nread = 0;
if (p == SUPPRESS_PTR) {
size_t sum = 0;
for (;;) {
@@ -149,63 +148,38 @@ convert_char(FILE *fp, char * __restrict p, int width)
break;
}
}
- nread += sum;
+ return (sum);
} else {
size_t r = __fread(p, 1, width, fp);
-
+
if (r == 0)
return (-1);
- nread += r;
+ return (r);
}
- return (nread);
}
static __inline int
-convert_wchar(FILE *fp, wchar_t *wcp, int width)
+convert_wchar(FILE *fp, wchar_t *wcp, int width, locale_t locale)
{
mbstate_t mbs;
- size_t nconv;
int n, nread;
- char buf[MB_CUR_MAX];
+ wint_t wi;
- nread = 0;
+ mbs = initial_mbs;
n = 0;
- while (width != 0) {
- if (n == MB_CUR_MAX) {
- fp->_flags |= __SERR;
- return (-1);
- }
- buf[n++] = *fp->_p;
- fp->_p++;
- fp->_r--;
- mbs = initial_mbs;
- nconv = mbrtowc(wcp, buf, n, &mbs);
- if (nconv == (size_t)-1) {
- fp->_flags |= __SERR;
- return (-1);
- }
- if (nconv == 0 && wcp != SUPPRESS_PTR)
- *wcp = L'\0';
- if (nconv != (size_t)-2) {
- nread += n;
- width--;
- if (wcp != SUPPRESS_PTR)
- wcp++;
- n = 0;
- }
- if (fp->_r <= 0 && __srefill(fp)) {
- if (n != 0) {
- fp->_flags |= __SERR;
- return (-1);
- }
- break;
- }
+ while (width-- != 0 &&
+ (wi = __fgetwc_mbs(fp, &mbs, &nread, locale)) != WEOF) {
+ if (wcp != SUPPRESS_PTR)
+ *wcp++ = (wchar_t)wi;
+ n += nread;
}
- return (nread);
+ if (n == 0)
+ return (-1);
+ return (n);
}
static __inline int
-convert_ccl(FILE *fp, char * __restrict p, int width, const char *ccltab)
+convert_ccl(FILE *fp, char * p, int width, const char *ccltab)
{
char *p0;
int n;
@@ -244,67 +218,38 @@ convert_ccl(FILE *fp, char * __restrict p, int width, const char *ccltab)
}
static __inline int
-convert_wccl(FILE *fp, wchar_t *wcp, int width, const char *ccltab)
+convert_wccl(FILE *fp, wchar_t *wcp, int width, const char *ccltab,
+ locale_t locale)
{
mbstate_t mbs;
- wchar_t twc;
- int n, nchars, nconv;
- char buf[MB_CUR_MAX];
+ wint_t wi;
+ int n, nread;
- if (wcp == SUPPRESS_PTR)
- wcp = &twc;
+ mbs = initial_mbs;
n = 0;
- nchars = 0;
- while (width != 0) {
- if (n == MB_CUR_MAX) {
- fp->_flags |= __SERR;
- return (-1);
- }
- buf[n++] = *fp->_p;
- fp->_p++;
- fp->_r--;
- mbs = initial_mbs;
- nconv = mbrtowc(wcp, buf, n, &mbs);
- if (nconv == (size_t)-1) {
- fp->_flags |= __SERR;
- return (-1);
- }
- if (nconv == 0)
- *wcp = L'\0';
- if (nconv != (size_t)-2) {
- if (wctob(*wcp) != EOF && !ccltab[wctob(*wcp)]) {
- while (n != 0) {
- n--;
- __ungetc(buf[n], fp);
- }
- break;
- }
- width--;
- if (wcp != &twc)
- wcp++;
- nchars++;
- n = 0;
- }
- if (fp->_r <= 0 && __srefill(fp)) {
- if (n != 0) {
- fp->_flags |= __SERR;
- return (-1);
- }
- break;
+ if (wcp == SUPPRESS_PTR) {
+ while ((wi = __fgetwc_mbs(fp, &mbs, &nread, locale)) != WEOF &&
+ width-- != 0 && ccltab[wctob(wi)])
+ n += nread;
+ if (wi != WEOF)
+ __ungetwc(wi, fp, __get_locale());
+ } else {
+ while ((wi = __fgetwc_mbs(fp, &mbs, &nread, locale)) != WEOF &&
+ width-- != 0 && ccltab[wctob(wi)]) {
+ *wcp++ = (wchar_t)wi;
+ n += nread;
}
+ if (wi != WEOF)
+ __ungetwc(wi, fp, __get_locale());
+ if (n == 0)
+ return (0);
+ *wcp = 0;
}
- if (n != 0) {
- fp->_flags |= __SERR;
- return (-1);
- }
- if (nchars == 0)
- return (0);
- *wcp = L'\0';
- return (nchars);
+ return (n);
}
static __inline int
-convert_string(FILE *fp, char * __restrict p, int width)
+convert_string(FILE *fp, char * p, int width)
{
char *p0;
int n;
@@ -335,56 +280,31 @@ convert_string(FILE *fp, char * __restrict p, int width)
}
static __inline int
-convert_wstring(FILE *fp, wchar_t *wcp, int width)
+convert_wstring(FILE *fp, wchar_t *wcp, int width, locale_t locale)
{
mbstate_t mbs;
- wchar_t twc;
- int n, nconv, nread;
- char buf[MB_CUR_MAX];
-
- if (wcp == SUPPRESS_PTR)
- wcp = &twc;
- n = nread = 0;
- while (!isspace(*fp->_p) && width != 0) {
- if (n == MB_CUR_MAX) {
- fp->_flags |= __SERR;
- return (-1);
- }
- buf[n++] = *fp->_p;
- fp->_p++;
- fp->_r--;
- mbs = initial_mbs;
- nconv = mbrtowc(wcp, buf, n, &mbs);
- if (nconv == (size_t)-1) {
- fp->_flags |= __SERR;
- return (-1);
- }
- if (nconv == 0)
- *wcp = L'\0';
- if (nconv != (size_t)-2) {
- if (iswspace(*wcp)) {
- while (n != 0) {
- n--;
- __ungetc(buf[n], fp);
- }
- break;
- }
- nread += n;
- width--;
- if (wcp != &twc)
- wcp++;
- n = 0;
- }
- if (fp->_r <= 0 && __srefill(fp)) {
- if (n != 0) {
- fp->_flags |= __SERR;
- return (-1);
- }
- break;
+ wint_t wi;
+ int n, nread;
+
+ mbs = initial_mbs;
+ n = 0;
+ if (wcp == SUPPRESS_PTR) {
+ while ((wi = __fgetwc_mbs(fp, &mbs, &nread, locale)) != WEOF &&
+ width-- != 0 && !iswspace(wi))
+ n += nread;
+ if (wi != WEOF)
+ __ungetwc(wi, fp, __get_locale());
+ } else {
+ while ((wi = __fgetwc_mbs(fp, &mbs, &nread, locale)) != WEOF &&
+ width-- != 0 && !iswspace(wi)) {
+ *wcp++ = (wchar_t)wi;
+ n += nread;
}
+ if (wi != WEOF)
+ __ungetwc(wi, fp, __get_locale());
+ *wcp = '\0';
}
- *wcp = L'\0';
- return (nread);
+ return (n);
}
/*
@@ -467,7 +387,7 @@ parseint(FILE *fp, char * __restrict buf, int width, int base, int flags)
goto ok;
}
break;
-
+
/*
* x ok iff flag still set & 2nd char (or 3rd char if
* we have a sign).
@@ -766,7 +686,7 @@ literal:
width = 1;
if (flags & LONG) {
nr = convert_wchar(fp, GETARG(wchar_t *),
- width);
+ width, locale);
} else {
nr = convert_char(fp, GETARG(char *), width);
}
@@ -780,7 +700,7 @@ literal:
width = (size_t)~0; /* `infinity' */
if (flags & LONG) {
nr = convert_wccl(fp, GETARG(wchar_t *), width,
- ccltab);
+ ccltab, locale);
} else {
nr = convert_ccl(fp, GETARG(char *), width,
ccltab);
@@ -799,7 +719,7 @@ literal:
width = (size_t)~0;
if (flags & LONG) {
nr = convert_wstring(fp, GETARG(wchar_t *),
- width);
+ width, locale);
} else {
nr = convert_string(fp, GETARG(char *), width);
}
diff --git a/lib/libc/stdio/vfwscanf.c b/lib/libc/stdio/vfwscanf.c
index 6b4d8c5..28e2c03 100644
--- a/lib/libc/stdio/vfwscanf.c
+++ b/lib/libc/stdio/vfwscanf.c
@@ -138,35 +138,22 @@ static const mbstate_t initial_mbs;
*/
static __inline int
-convert_char(FILE *fp, char * __restrict mbp, int width, locale_t locale)
+convert_char(FILE *fp, char * mbp, int width, locale_t locale)
{
mbstate_t mbs;
size_t nconv;
wint_t wi;
int n;
- char mbbuf[MB_LEN_MAX];
n = 0;
mbs = initial_mbs;
- while (width != 0 && (wi = __fgetwc(fp, locale)) != WEOF) {
- if (width >= MB_CUR_MAX && mbp != SUPPRESS_PTR) {
+ while (width-- != 0 && (wi = __fgetwc(fp, locale)) != WEOF) {
+ if (mbp != SUPPRESS_PTR) {
nconv = wcrtomb(mbp, wi, &mbs);
if (nconv == (size_t)-1)
return (-1);
- } else {
- nconv = wcrtomb(mbbuf, wi, &mbs);
- if (nconv == (size_t)-1)
- return (-1);
- if (nconv > width) {
- __ungetwc(wi, fp, locale);
- break;
- }
- if (mbp != SUPPRESS_PTR)
- memcpy(mbp, mbbuf, nconv);
- }
- if (mbp != SUPPRESS_PTR)
mbp += nconv;
- width -= nconv;
+ }
n++;
}
if (n == 0)
@@ -192,35 +179,24 @@ convert_wchar(FILE *fp, wchar_t *wcp, int width, locale_t locale)
}
static __inline int
-convert_ccl(FILE *fp, char * __restrict mbp, int width, const struct ccl *ccl,
+convert_ccl(FILE *fp, char * mbp, int width, const struct ccl *ccl,
locale_t locale)
{
mbstate_t mbs;
size_t nconv;
wint_t wi;
int n;
- char mbbuf[MB_LEN_MAX];
n = 0;
mbs = initial_mbs;
while ((wi = __fgetwc(fp, locale)) != WEOF &&
- width != 0 && inccl(ccl, wi)) {
- if (width >= MB_CUR_MAX && mbp != SUPPRESS_PTR) {
+ width-- != 0 && inccl(ccl, wi)) {
+ if (mbp != SUPPRESS_PTR) {
nconv = wcrtomb(mbp, wi, &mbs);
if (nconv == (size_t)-1)
return (-1);
- } else {
- nconv = wcrtomb(mbbuf, wi, &mbs);
- if (nconv == (size_t)-1)
- return (-1);
- if (nconv > width)
- break;
- if (mbp != SUPPRESS_PTR)
- memcpy(mbp, mbbuf, nconv);
- }
- if (mbp != SUPPRESS_PTR)
mbp += nconv;
- width -= nconv;
+ }
n++;
}
if (wi != WEOF)
@@ -261,34 +237,23 @@ convert_wccl(FILE *fp, wchar_t *wcp, int width, const struct ccl *ccl,
}
static __inline int
-convert_string(FILE *fp, char * __restrict mbp, int width, locale_t locale)
+convert_string(FILE *fp, char * mbp, int width, locale_t locale)
{
mbstate_t mbs;
size_t nconv;
wint_t wi;
int nread;
- char mbbuf[MB_LEN_MAX];
mbs = initial_mbs;
nread = 0;
- while ((wi = __fgetwc(fp, locale)) != WEOF && width != 0 &&
+ while ((wi = __fgetwc(fp, locale)) != WEOF && width-- != 0 &&
!iswspace(wi)) {
- if (width >= MB_CUR_MAX && mbp != SUPPRESS_PTR) {
+ if (mbp != SUPPRESS_PTR) {
nconv = wcrtomb(mbp, wi, &mbs);
if (nconv == (size_t)-1)
return (-1);
- } else {
- nconv = wcrtomb(mbbuf, wi, &mbs);
- if (nconv == (size_t)-1)
- return (-1);
- if (nconv > width)
- break;
- if (mbp != SUPPRESS_PTR)
- memcpy(mbp, mbbuf, nconv);
- }
- if (mbp != SUPPRESS_PTR)
mbp += nconv;
- width -= nconv;
+ }
nread++;
}
if (wi != WEOF)
@@ -407,7 +372,7 @@ parseint(FILE *fp, wchar_t *buf, int width, int base, int flags,
goto ok;
}
break;
-
+
/*
* x ok iff flag still set & 2nd char (or 3rd char if
* we have a sign).
diff --git a/lib/libc/stdio/wscanf.3 b/lib/libc/stdio/wscanf.3
index f696d3d..1dda777 100644
--- a/lib/libc/stdio/wscanf.3
+++ b/lib/libc/stdio/wscanf.3
@@ -365,10 +365,10 @@ The string is to be made up of characters in
(or not in)
a particular set;
the set is defined by the characters between the open bracket
-.Cm [
+.Cm \&[
character
and a close bracket
-.Cm ]
+.Cm \&]
character.
The set
.Em excludes
diff --git a/lib/libc/stdio/xprintf.c b/lib/libc/stdio/xprintf.c
index 0cc8571..b00b4cb 100644
--- a/lib/libc/stdio/xprintf.c
+++ b/lib/libc/stdio/xprintf.c
@@ -651,7 +651,7 @@ register_printf_render(int spec, printf_render *render, printf_arginfo_function
}
int
-register_printf_render_std(const unsigned char *specs)
+register_printf_render_std(const char *specs)
{
for (; *specs != '\0'; specs++) {
diff --git a/lib/libc/stdlib/Makefile.inc b/lib/libc/stdlib/Makefile.inc
index 7fdb6e4..75204f5 100644
--- a/lib/libc/stdlib/Makefile.inc
+++ b/lib/libc/stdlib/Makefile.inc
@@ -42,6 +42,7 @@ MLINKS+=rand.3 rand_r.3 rand.3 srand.3 rand.3 sranddev.3
MLINKS+=random.3 initstate.3 random.3 setstate.3 random.3 srandom.3 \
random.3 srandomdev.3
MLINKS+=radixsort.3 sradixsort.3
+MLINKS+=strfmon.3 strfmon_l.3
MLINKS+=strtod.3 strtof.3 strtod.3 strtold.3
MLINKS+=strtol.3 strtoll.3 strtol.3 strtoq.3 strtol.3 strtoimax.3
MLINKS+=strtoul.3 strtoull.3 strtoul.3 strtouq.3 strtoul.3 strtoumax.3
diff --git a/lib/libc/stdlib/getenv.3 b/lib/libc/stdlib/getenv.3
index bc87b9d..1949648 100644
--- a/lib/libc/stdlib/getenv.3
+++ b/lib/libc/stdlib/getenv.3
@@ -152,7 +152,8 @@ failed because
is a
.Dv NULL
pointer,
-.Fa string is without an
+.Fa string
+is without an
.Dq Li \&=
character or
.Dq Li \&=
diff --git a/lib/libc/stdlib/getopt_long.c b/lib/libc/stdlib/getopt_long.c
index bf7a04a..9f7f6d5 100644
--- a/lib/libc/stdlib/getopt_long.c
+++ b/lib/libc/stdlib/getopt_long.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: getopt_long.c,v 1.21 2006/09/22 17:22:05 millert Exp $ */
+/* $OpenBSD: getopt_long.c,v 1.22 2006/10/04 21:29:04 jmc Exp $ */
/* $NetBSD: getopt_long.c,v 1.15 2002/01/31 22:43:40 tv Exp $ */
/*
@@ -35,13 +35,6 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the NetBSD
- * Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
diff --git a/lib/libc/stdlib/realpath.3 b/lib/libc/stdlib/realpath.3
index fec5258..c7384d6 100644
--- a/lib/libc/stdlib/realpath.3
+++ b/lib/libc/stdlib/realpath.3
@@ -31,7 +31,7 @@
.\" @(#)realpath.3 8.2 (Berkeley) 2/16/94
.\" $FreeBSD$
.\"
-.Dd April 19, 2010
+.Dd May 11, 2012
.Dt REALPATH 3
.Os
.Sh NAME
@@ -40,7 +40,6 @@
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
-.In sys/param.h
.In stdlib.h
.Ft "char *"
.Fn realpath "const char *pathname" "char *resolved_path"
@@ -72,11 +71,12 @@ The
function will resolve both absolute and relative paths
and return the absolute pathname corresponding to
.Fa pathname .
-All but the last component of
+All components of
.Fa pathname
must exist when
.Fn realpath
-is called.
+is called, and all but the last component must name either directories or
+symlinks pointing to the directories.
.Sh "RETURN VALUES"
The
.Fn realpath
diff --git a/lib/libc/stdlib/realpath.c b/lib/libc/stdlib/realpath.c
index 2c9562e..aded9b2 100644
--- a/lib/libc/stdlib/realpath.c
+++ b/lib/libc/stdlib/realpath.c
@@ -54,7 +54,7 @@ realpath(const char * __restrict path, char * __restrict resolved)
char *p, *q, *s;
size_t left_len, resolved_len;
unsigned symlinks;
- int m, serrno, slen;
+ int m, slen;
char left[PATH_MAX], next_token[PATH_MAX], symlink[PATH_MAX];
if (path == NULL) {
@@ -65,7 +65,6 @@ realpath(const char * __restrict path, char * __restrict resolved)
errno = ENOENT;
return (NULL);
}
- serrno = errno;
if (resolved == NULL) {
resolved = malloc(PATH_MAX);
if (resolved == NULL)
@@ -132,8 +131,29 @@ realpath(const char * __restrict path, char * __restrict resolved)
resolved[resolved_len++] = '/';
resolved[resolved_len] = '\0';
}
- if (next_token[0] == '\0')
+ if (next_token[0] == '\0') {
+ /*
+ * Handle consequential slashes. The path
+ * before slash shall point to a directory.
+ *
+ * Only the trailing slashes are not covered
+ * by other checks in the loop, but we verify
+ * the prefix for any (rare) "//" or "/\0"
+ * occurence to not implement lookahead.
+ */
+ if (lstat(resolved, &sb) != 0) {
+ if (m)
+ free(resolved);
+ return (NULL);
+ }
+ if (!S_ISDIR(sb.st_mode)) {
+ if (m)
+ free(resolved);
+ errno = ENOTDIR;
+ return (NULL);
+ }
continue;
+ }
else if (strcmp(next_token, ".") == 0)
continue;
else if (strcmp(next_token, "..") == 0) {
@@ -151,9 +171,7 @@ realpath(const char * __restrict path, char * __restrict resolved)
}
/*
- * Append the next path component and lstat() it. If
- * lstat() fails we still can return successfully if
- * there are no more path components left.
+ * Append the next path component and lstat() it.
*/
resolved_len = strlcat(resolved, next_token, PATH_MAX);
if (resolved_len >= PATH_MAX) {
@@ -163,10 +181,8 @@ realpath(const char * __restrict path, char * __restrict resolved)
return (NULL);
}
if (lstat(resolved, &sb) != 0) {
- if (errno == ENOENT && p == NULL) {
- errno = serrno;
- return (resolved);
- }
+ if (errno != ENOENT || p != NULL)
+ errno = ENOTDIR;
if (m)
free(resolved);
return (NULL);
diff --git a/lib/libc/stdlib/strfmon.3 b/lib/libc/stdlib/strfmon.3
index 11b8e21..f82dfa3 100644
--- a/lib/libc/stdlib/strfmon.3
+++ b/lib/libc/stdlib/strfmon.3
@@ -24,7 +24,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd October 12, 2002
+.Dd June 25, 2012
.Dt STRFMON 3
.Os
.Sh NAME
@@ -36,6 +36,8 @@
.In monetary.h
.Ft ssize_t
.Fn strfmon "char * restrict s" "size_t maxsize" "const char * restrict format" "..."
+.Ft ssize_t
+.Fn strfmon_l "char * restrict s" "size_t maxsize" "locale_t loc" "const char * restrict format" "..."
.Sh DESCRIPTION
The
.Fn strfmon
@@ -47,6 +49,12 @@ No more than
.Fa maxsize
bytes are placed into the array.
.Pp
+The
+.Fn strfmon_l
+function does the same as
+.Fn strfmon
+but takes an explicit locale rather than using the current locale.
+.Pp
The format string is composed of zero or more directives:
ordinary characters (not
.Cm % ) ,
@@ -115,20 +123,25 @@ character is written.
.El
.Sh RETURN VALUES
If the total number of resulting bytes including the terminating
-.Dv NULL
+.Dv NUL
byte is not more than
.Fa maxsize ,
.Fn strfmon
returns the number of bytes placed into the array pointed to by
.Fa s ,
not including the terminating
-.Dv NULL
+.Dv NUL
byte.
Otherwise, \-1 is returned,
the contents of the array are indeterminate,
and
.Va errno
is set to indicate the error.
+.Pp
+The
+.Fn strfmon_l
+function returns the same values as
+.Fn strfmon .
.Sh ERRORS
The
.Fn strfmon
@@ -149,6 +162,10 @@ The
function
conforms to
.St -p1003.1-2001 .
+The
+.Fn strfmon_l
+function conforms to
+.St -p1003.1-2008 .
.Sh AUTHORS
.An -nosplit
The
diff --git a/lib/libc/stdtime/Makefile.inc b/lib/libc/stdtime/Makefile.inc
index a039bc9..0cc038a 100644
--- a/lib/libc/stdtime/Makefile.inc
+++ b/lib/libc/stdtime/Makefile.inc
@@ -18,4 +18,6 @@ MLINKS+=ctime.3 asctime.3 ctime.3 difftime.3 ctime.3 gmtime.3 \
ctime.3 localtime.3 ctime.3 mktime.3 ctime.3 timegm.3 \
ctime.3 ctime_r.3 ctime.3 localtime_r.3 ctime.3 gmtime_r.3 \
ctime.3 asctime_r.3
+MLINKS+=strftime.3 strftime_l.3
+MLINKS+=strptime.3 strptime_l.3
MLINKS+=time2posix.3 posix2time.3
diff --git a/lib/libc/stdtime/strftime.3 b/lib/libc/stdtime/strftime.3
index d5cdd7d..0ed023b 100644
--- a/lib/libc/stdtime/strftime.3
+++ b/lib/libc/stdtime/strftime.3
@@ -32,7 +32,7 @@
.\" @(#)strftime.3 8.1 (Berkeley) 6/4/93
.\" $FreeBSD$
.\"
-.Dd November 4, 2004
+.Dd June 25, 2012
.Dt STRFTIME 3
.Os
.Sh NAME
@@ -49,6 +49,8 @@
.Fa "const char * restrict format"
.Fa "const struct tm * restrict timeptr"
.Fc
+.Ft size_t
+.Fn strftime_l "char *restrict buf" "size_t maxsize" "const char * restrict format" "const struct tm *restrict timeptr" "locale_t loc"
.Sh DESCRIPTION
The
.Fn strftime
@@ -58,6 +60,11 @@ into the buffer
.Fa buf
according to the string pointed to by
.Fa format .
+The function
+.Fn strftime_l
+does the same as
+.Fn strftime
+but takes an explicit locale rather than using the current locale.
.Pp
The
.Fa format
@@ -268,6 +275,10 @@ The peculiar week number and year in the replacements of
and
.Ql \&%V
are defined in ISO 8601: 1988.
+The
+.Fn strftime_l
+function conforms to
+.St -p1003.1-2008 .
.Sh BUGS
There is no conversion specification for the phase of the moon.
.Pp
diff --git a/lib/libc/stdtime/strftime.c b/lib/libc/stdtime/strftime.c
index d3571ad..4ad0bc4 100644
--- a/lib/libc/stdtime/strftime.c
+++ b/lib/libc/stdtime/strftime.c
@@ -67,7 +67,7 @@ extern char * tzname[];
#define PAD_SPACE 2
#define PAD_ZERO 3
-static const char* fmt_padding[][4] = {
+static const char fmt_padding[][4][5] = {
/* DEFAULT, LESS, SPACE, ZERO */
#define PAD_FMT_MONTHDAY 0
#define PAD_FMT_HMS 0
diff --git a/lib/libc/stdtime/strptime.3 b/lib/libc/stdtime/strptime.3
index 763696b..34d2b79 100644
--- a/lib/libc/stdtime/strptime.3
+++ b/lib/libc/stdtime/strptime.3
@@ -25,7 +25,7 @@
.\"
.\" $FreeBSD$
.\" "
-.Dd January 4, 2003
+.Dd June 25, 2012
.Dt STRPTIME 3
.Os
.Sh NAME
@@ -41,6 +41,10 @@
.Fa "const char * restrict format"
.Fa "struct tm * restrict timeptr"
.Fc
+.In time.h
+.In xlocale.h
+.Ft char *
+.Fn strptime_l "const char * restrict buf" "const char * restrict format" "struct tm * restrict timeptr" "locale_t loc"
.Sh DESCRIPTION
The
.Fn strptime
@@ -53,6 +57,11 @@ and fills in the elements of the structure pointed to by
The resulting values will be relative to the local time zone.
Thus, it can be considered the reverse operation of
.Xr strftime 3 .
+The
+.Fn strptime_l
+function does the same as
+.Fn strptime ,
+but takes an explicit locale rather than using the current locale.
.Pp
The
.Fa format
@@ -104,6 +113,9 @@ that has not been required to satisfy the specified conversions in
It returns
.Dv NULL
if one of the conversions failed.
+.Fn strptime_l
+returns the same values as
+.Fn strptime .
.Sh SEE ALSO
.Xr date 1 ,
.Xr scanf 3 ,
diff --git a/lib/libc/string/Makefile.inc b/lib/libc/string/Makefile.inc
index 1dbe317..cd06fc8 100644
--- a/lib/libc/string/Makefile.inc
+++ b/lib/libc/string/Makefile.inc
@@ -42,10 +42,13 @@ MLINKS+=ffs.3 ffsl.3 \
ffs.3 flsll.3
MLINKS+=index.3 rindex.3
MLINKS+=memchr.3 memrchr.3
-MLINKS+=strcasecmp.3 strncasecmp.3
+MLINKS+=strcasecmp.3 strncasecmp.3 \
+ strcasecmp.3 strcasecmp_l.3 \
+ strcasecmp.3 strncasecmp_l.3
MLINKS+=strcat.3 strncat.3
MLINKS+=strchr.3 strrchr.3
MLINKS+=strcmp.3 strncmp.3
+MLINKS+=strcoll.3 strcoll_l.3
MLINKS+=strcpy.3 stpcpy.3 \
strcpy.3 stpncpy.3 \
strcpy.3 strncpy.3
@@ -57,8 +60,10 @@ MLINKS+=strerror.3 perror.3 \
MLINKS+=strlcpy.3 strlcat.3
MLINKS+=strlen.3 strnlen.3
MLINKS+=strstr.3 strcasestr.3 \
- strstr.3 strnstr.3
+ strstr.3 strnstr.3 \
+ strstr.3 strcasestr_l.3
MLINKS+=strtok.3 strtok_r.3
+MLINKS+=strxfrm.3 strxfrm_l.3
MLINKS+=wmemchr.3 wcpcpy.3 \
wmemchr.3 wcpncpy.3 \
wmemchr.3 wcscasecmp.3 \
diff --git a/lib/libc/string/strcasecmp.3 b/lib/libc/string/strcasecmp.3
index 2b2ef3e..760b9d4 100644
--- a/lib/libc/string/strcasecmp.3
+++ b/lib/libc/string/strcasecmp.3
@@ -45,6 +45,12 @@
.Fn strcasecmp "const char *s1" "const char *s2"
.Ft int
.Fn strncasecmp "const char *s1" "const char *s2" "size_t len"
+.In string.h
+.In xlocale.h
+.Ft int
+.Fn strcasecmp_l "const char *s1" "const char *s2" "locale_t loc"
+.Ft int
+.Fn strncasecmp_l "const char *s1" "const char *s2" "site_t len" "locale_t loc"
.Sh DESCRIPTION
The
.Fn strcasecmp
@@ -58,16 +64,22 @@ and
.Pp
The
.Fn strncasecmp
-compares at most
+function compares at most
.Fa len
characters.
-.Sh RETURN VALUES
The
+.Fn strcasecmp_l
+and
+.Fn strncasecmp_l
+functions do the same as their non-locale versions above, but take an
+explicit locale rather than using the current locale.
+.Sh RETURN VALUES
+The functions
.Fn strcasecmp
and
.Fn strncasecmp
return an integer greater than, equal to, or less than 0,
-according as
+depending on whether
.Fa s1
is lexicographically greater than, equal to, or less than
.Fa s2
@@ -77,6 +89,11 @@ The comparison is done using unsigned characters, so that
.Sq Li \e200
is greater than
.Ql \e0 .
+The functions
+.Fn strcasecmp_l
+and
+.Fn strncasecmp_l
+do the same but take explicit locales.
.Sh SEE ALSO
.Xr bcmp 3 ,
.Xr memcmp 3 ,
diff --git a/lib/libc/string/strcoll.3 b/lib/libc/string/strcoll.3
index bb8b13f..20f1888 100644
--- a/lib/libc/string/strcoll.3
+++ b/lib/libc/string/strcoll.3
@@ -44,6 +44,8 @@
.In string.h
.Ft int
.Fn strcoll "const char *s1" "const char *s2"
+.Ft int
+.Fn strcoll_l "const char *s1" "const char *s2" "locale_t loc"
.Sh DESCRIPTION
The
.Fn strcoll
@@ -54,7 +56,7 @@ and
.Fa s2
according to the current locale collation
and returns an integer greater than, equal to, or less than 0,
-according as
+depending on whether
.Fa s1
is greater than, equal to, or less than
.Fa s2 .
@@ -62,6 +64,9 @@ If information about the current locale collation is not available,
the value of
.Fn strcmp s1 s2
is returned.
+The
+.Fn strcoll_l
+function uses an explicit locale argument rather than the system locale.
.Sh SEE ALSO
.Xr setlocale 3 ,
.Xr strcmp 3 ,
@@ -70,6 +75,9 @@ is returned.
.Sh STANDARDS
The
.Fn strcoll
-function
-conforms to
+function conforms to
.St -isoC .
+The
+.Fn strcoll_l
+function conforms to
+.St -p1003.1-2008 .
diff --git a/lib/libc/string/strlcpy.3 b/lib/libc/string/strlcpy.3
index 19d3621..9ad663a 100644
--- a/lib/libc/string/strlcpy.3
+++ b/lib/libc/string/strlcpy.3
@@ -169,7 +169,7 @@ if (strlcat(pname, file, sizeof(pname)) >= sizeof(pname))
.Ed
.Pp
Since it is known how many characters were copied the first time, things
-can be sped up a bit by using a copy instead of an append
+can be sped up a bit by using a copy instead of an append.
.Bd -literal -offset indent
char *dir, *file, pname[MAXPATHLEN];
size_t n;
diff --git a/lib/libc/string/strstr.3 b/lib/libc/string/strstr.3
index 74ebdff..376def6 100644
--- a/lib/libc/string/strstr.3
+++ b/lib/libc/string/strstr.3
@@ -49,6 +49,10 @@
.Fn strcasestr "const char *big" "const char *little"
.Ft char *
.Fn strnstr "const char *big" "const char *little" "size_t len"
+.In string.h
+.In xlocale.h
+.Ft char *
+.Fn strcasestr_l "const char *big" "const char *little" "locale_t loc"
.Sh DESCRIPTION
The
.Fn strstr
@@ -65,6 +69,12 @@ function is similar to
but ignores the case of both strings.
.Pp
The
+.Fn strcasestr_l
+function does the same as
+.Fn strcasestr
+but takes an explicit locale rather than using the current locale.
+.Pp
+The
.Fn strnstr
function
locates the first occurrence of the null-terminated string
diff --git a/lib/libc/string/strxfrm.3 b/lib/libc/string/strxfrm.3
index 5f33763..da7c82a 100644
--- a/lib/libc/string/strxfrm.3
+++ b/lib/libc/string/strxfrm.3
@@ -44,6 +44,8 @@
.In string.h
.Ft size_t
.Fn strxfrm "char * restrict dst" "const char * restrict src" "size_t n"
+.Ft size_t
+.Fn strxfrm_l "char * restrict dst" "const char *restrict src" "size_t n" "locale_t loc"
.Sh DESCRIPTION
The
.Fn strxfrm
@@ -73,10 +75,16 @@ after
is equal to comparing
two original strings with
.Fn strcoll .
+.Pp
+.Fn strxfrm_l
+does the same, however takes an explicit locale rather than the global
+locale.
.Sh RETURN VALUES
Upon successful completion,
.Fn strxfrm
-returns the length of the transformed string not including
+and
+.Fn strxfrm_l
+return the length of the transformed string not including
the terminating null character.
If this value is
.Fa n
@@ -94,3 +102,7 @@ The
function
conforms to
.St -isoC .
+The
+.Fn strxfrm_l
+function conforms to
+.St -p1003.1-2008 .
diff --git a/lib/libc/sys/Makefile.inc b/lib/libc/sys/Makefile.inc
index 61d1713..df4ef42 100644
--- a/lib/libc/sys/Makefile.inc
+++ b/lib/libc/sys/Makefile.inc
@@ -15,6 +15,10 @@
#
.sinclude "${.CURDIR}/${LIBC_ARCH}/sys/Makefile.inc"
+SRCS+= clock_gettime.c gettimeofday.c __vdso_gettimeofday.c
+NOASM+= clock_gettime.o gettimeofday.o
+PSEUDO+= _clock_gettime.o _gettimeofday.o
+
# Sources common to both syscall interfaces:
SRCS+= stack_protector.c stack_protector_compat.c __error.c
.if !defined(WITHOUT_SYSCALL_COMPAT)
diff --git a/lib/libc/sys/Symbol.map b/lib/libc/sys/Symbol.map
index f1c1567..6888ea0 100644
--- a/lib/libc/sys/Symbol.map
+++ b/lib/libc/sys/Symbol.map
@@ -365,9 +365,6 @@ FBSD_1.2 {
cap_getmode;
cap_new;
cap_getrights;
- ffclock_getcounter;
- ffclock_getestimate;
- ffclock_setestimate;
getloginclass;
pdfork;
pdgetpid;
@@ -382,6 +379,9 @@ FBSD_1.2 {
};
FBSD_1.3 {
+ ffclock_getcounter;
+ ffclock_getestimate;
+ ffclock_setestimate;
posix_fadvise;
};
diff --git a/lib/libc/sys/__vdso_gettimeofday.c b/lib/libc/sys/__vdso_gettimeofday.c
new file mode 100644
index 0000000..32abb69
--- /dev/null
+++ b/lib/libc/sys/__vdso_gettimeofday.c
@@ -0,0 +1,142 @@
+/*-
+ * Copyright (c) 2012 Konstantin Belousov <kib@FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/elf.h>
+#include <sys/time.h>
+#include <sys/vdso.h>
+#include <errno.h>
+#include <time.h>
+#include <machine/atomic.h>
+#include "libc_private.h"
+
+static u_int
+tc_delta(const struct vdso_timehands *th)
+{
+
+ return ((__vdso_gettc(th) - th->th_offset_count) &
+ th->th_counter_mask);
+}
+
+static int
+binuptime(struct bintime *bt, struct vdso_timekeep *tk, int abs)
+{
+ struct vdso_timehands *th;
+ uint32_t curr, gen;
+
+ do {
+ if (!tk->tk_enabled)
+ return (ENOSYS);
+
+ /*
+ * XXXKIB. The load of tk->tk_current should use
+ * atomic_load_acq_32 to provide load barrier. But
+ * since tk points to r/o mapped page, x86
+ * implementation of atomic_load_acq faults.
+ */
+ curr = tk->tk_current;
+ rmb();
+ th = &tk->tk_th[curr];
+ if (th->th_algo != VDSO_TH_ALGO_1)
+ return (ENOSYS);
+ gen = th->th_gen;
+ *bt = th->th_offset;
+ bintime_addx(bt, th->th_scale * tc_delta(th));
+ if (abs)
+ bintime_add(bt, &th->th_boottime);
+
+ /*
+ * Barrier for load of both tk->tk_current and th->th_gen.
+ */
+ rmb();
+ } while (curr != tk->tk_current || gen == 0 || gen != th->th_gen);
+ return (0);
+}
+
+static struct vdso_timekeep *tk;
+
+int
+__vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
+{
+ struct bintime bt;
+ int error;
+
+ if (tz != NULL)
+ return (ENOSYS);
+ if (tk == NULL) {
+ error = _elf_aux_info(AT_TIMEKEEP, &tk, sizeof(tk));
+ if (error != 0 || tk == NULL)
+ return (ENOSYS);
+ }
+ if (tk->tk_ver != VDSO_TK_VER_CURR)
+ return (ENOSYS);
+ error = binuptime(&bt, tk, 1);
+ if (error != 0)
+ return (error);
+ bintime2timeval(&bt, tv);
+ return (0);
+}
+
+int
+__vdso_clock_gettime(clockid_t clock_id, struct timespec *ts)
+{
+ struct bintime bt;
+ int abs, error;
+
+ if (tk == NULL) {
+ error = _elf_aux_info(AT_TIMEKEEP, &tk, sizeof(tk));
+ if (error != 0 || tk == NULL)
+ return (ENOSYS);
+ }
+ if (tk->tk_ver != VDSO_TK_VER_CURR)
+ return (ENOSYS);
+ switch (clock_id) {
+ case CLOCK_REALTIME:
+ case CLOCK_REALTIME_PRECISE:
+ case CLOCK_REALTIME_FAST:
+ case CLOCK_SECOND:
+ abs = 1;
+ break;
+ case CLOCK_MONOTONIC:
+ case CLOCK_MONOTONIC_PRECISE:
+ case CLOCK_MONOTONIC_FAST:
+ case CLOCK_UPTIME:
+ case CLOCK_UPTIME_PRECISE:
+ case CLOCK_UPTIME_FAST:
+ abs = 0;
+ break;
+ default:
+ return (ENOSYS);
+ }
+ error = binuptime(&bt, tk, abs);
+ if (error != 0)
+ return (error);
+ bintime2timespec(&bt, ts);
+ if (clock_id == CLOCK_SECOND)
+ ts->tv_nsec = 0;
+ return (0);
+}
diff --git a/lib/libc/sys/clock_gettime.c b/lib/libc/sys/clock_gettime.c
new file mode 100644
index 0000000..e7e701b
--- /dev/null
+++ b/lib/libc/sys/clock_gettime.c
@@ -0,0 +1,52 @@
+/*-
+ * Copyright (c) 2012 Konstantin Belousov <kib@FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/syscall.h>
+#include <sys/time.h>
+#include <sys/vdso.h>
+#include <errno.h>
+#include <time.h>
+#include "libc_private.h"
+
+int __clock_gettime(clockid_t, struct timespec *ts);
+
+__weak_reference(__clock_gettime, clock_gettime);
+
+int
+__clock_gettime(clockid_t clock_id, struct timespec *ts)
+{
+ int error;
+
+ if (__vdso_clock_gettime != NULL && __vdso_gettc != NULL)
+ error = __vdso_clock_gettime(clock_id, ts);
+ else
+ error = ENOSYS;
+ if (error == ENOSYS)
+ error = __sys_clock_gettime(clock_id, ts);
+ return (error);
+}
diff --git a/lib/libc/sys/ffclock.2 b/lib/libc/sys/ffclock.2
index 0e8f09b..68ea922 100644
--- a/lib/libc/sys/ffclock.2
+++ b/lib/libc/sys/ffclock.2
@@ -34,7 +34,7 @@
.Nm ffclock_getcounter ,
.Nm ffclock_getestimate ,
.Nm ffclock_setestimate
-.Nd Retrieve feed-forward counter, get and set feed-forward clock estimates.
+.Nd Retrieve feed-forward counter, get and set feed-forward clock estimates
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
@@ -59,7 +59,7 @@ In the feed-forward context, a
.Em timestamp
is a cumulative value of the ticks of the timecounter, which can be converted
into seconds by using the feed-forward
-.Em clock estimates.
+.Em clock estimates .
.Pp
The
.Fn ffclock_getcounter
diff --git a/lib/libc/sys/gettimeofday.c b/lib/libc/sys/gettimeofday.c
new file mode 100644
index 0000000..4cc87e1
--- /dev/null
+++ b/lib/libc/sys/gettimeofday.c
@@ -0,0 +1,51 @@
+/*-
+ * Copyright (c) 2012 Konstantin Belousov <kib@FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/syscall.h>
+#include <sys/time.h>
+#include <sys/vdso.h>
+#include <errno.h>
+#include "libc_private.h"
+
+int __gettimeofday(struct timeval *tv, struct timezone *tz);
+
+__weak_reference(__gettimeofday, gettimeofday);
+
+int
+__gettimeofday(struct timeval *tv, struct timezone *tz)
+{
+ int error;
+
+ if (__vdso_gettimeofday != NULL && __vdso_gettc != NULL)
+ error = __vdso_gettimeofday(tv, tz);
+ else
+ error = ENOSYS;
+ if (error == ENOSYS)
+ error = __sys_gettimeofday(tv, tz);
+ return (error);
+}
diff --git a/lib/libc/sys/jail.2 b/lib/libc/sys/jail.2
index b0619a0..a2d692a 100644
--- a/lib/libc/sys/jail.2
+++ b/lib/libc/sys/jail.2
@@ -247,44 +247,6 @@ They return \-1 on failure, and set
to indicate the error.
.Pp
.Rv -std jail_attach jail_remove
-.Sh PRISON?
-Once a process has been put in a prison, it and its descendants cannot escape
-the prison.
-.Pp
-Inside the prison, the concept of
-.Dq superuser
-is very diluted.
-In general,
-it can be assumed that nothing can be mangled from inside a prison which
-does not exist entirely inside that prison.
-For instance the directory
-tree below
-.Dq Li path
-can be manipulated all the ways a root can normally do it, including
-.Dq Li "rm -rf /*"
-but new device special nodes cannot be created because they reference
-shared resources (the device drivers in the kernel).
-The effective
-.Dq securelevel
-for a process is the greater of the global
-.Dq securelevel
-or, if present, the per-jail
-.Dq securelevel .
-.Pp
-All IP activity will be forced to happen to/from the IP number specified,
-which should be an alias on one of the network interfaces.
-All connections to/from the loopback address
-.Pf ( Li 127.0.0.1
-for IPv4,
-.Li ::1
-for IPv6) will be changed to be to/from the primary address
-of the jail for the given address family.
-.Pp
-It is possible to identify a process as jailed by examining
-.Dq Li /proc/<pid>/status :
-it will show a field near the end of the line, either as
-a single hyphen for a process at large, or the name currently
-set for the prison for jailed processes.
.Sh ERRORS
The
.Fn jail
@@ -415,7 +377,7 @@ and
.Fn jail_attach
call
.Xr chroot 2
-internally, so it can fail for all the same reasons.
+internally, so they can fail for all the same reasons.
Please consult the
.Xr chroot 2
manual page for details.
diff --git a/lib/libc/sys/ktrace.2 b/lib/libc/sys/ktrace.2
index 1740d75..4e5d92a 100644
--- a/lib/libc/sys/ktrace.2
+++ b/lib/libc/sys/ktrace.2
@@ -127,7 +127,7 @@ field gives the time (with microsecond resolution)
that the record was generated.
The
.Va ktr_tid
-field holds a threadid.
+field holds a thread id.
.Pp
The generic header is followed by
.Va ktr_len
diff --git a/lib/libc/sys/lseek.2 b/lib/libc/sys/lseek.2
index 874c523..349940a 100644
--- a/lib/libc/sys/lseek.2
+++ b/lib/libc/sys/lseek.2
@@ -28,7 +28,7 @@
.\" @(#)lseek.2 8.3 (Berkeley) 4/19/94
.\" $FreeBSD$
.\"
-.Dd April 5, 2007
+.Dd May 26, 2012
.Dt LSEEK 2
.Os
.Sh NAME
@@ -92,9 +92,9 @@ If
.Fa whence
is
.Dv SEEK_HOLE ,
-the offset of the start of the next hole greater than or equal to the supplied
-.Fa offset
-is returned.
+the offset is set to the start of the next hole greater than or equal
+to the supplied
+.Fa offset .
The definition of a hole is provided below.
.It
If
diff --git a/lib/libc/sys/msgsnd.2 b/lib/libc/sys/msgsnd.2
index d6333bb..051c992 100644
--- a/lib/libc/sys/msgsnd.2
+++ b/lib/libc/sys/msgsnd.2
@@ -139,7 +139,7 @@ will fail if:
The
.Fa msqid
argument
-is not a valid message queue identifier
+is not a valid message queue identifier.
.Pp
The message queue was removed while
.Fn msgsnd
diff --git a/lib/libc/sys/pathconf.2 b/lib/libc/sys/pathconf.2
index 8bdd5b8..efa1338 100644
--- a/lib/libc/sys/pathconf.2
+++ b/lib/libc/sys/pathconf.2
@@ -165,7 +165,7 @@ Returns 1 if a Mandatory Access Control (MAC) label can be set on the
specified file, otherwise 0.
.It Li _PC_MIN_HOLE_SIZE
If a file system supports the reporting of holes (see
-.Xr lseek 2 ,
+.Xr lseek 2 ) ,
.Fn pathconf
and
.Fn fpathconf
diff --git a/lib/libc/sys/pdfork.2 b/lib/libc/sys/pdfork.2
index 0808fbc..ad33566 100644
--- a/lib/libc/sys/pdfork.2
+++ b/lib/libc/sys/pdfork.2
@@ -1,5 +1,5 @@
.\"
-.\" Copyright (c) 2009-2010 Robert N. M. Watson
+.\" Copyright (c) 2009-2010, 2012 Robert N. M. Watson
.\" All rights reserved.
.\"
.\" This software was developed at the University of Cambridge Computer
@@ -57,7 +57,7 @@ a variant of
.Xr fork 2 ,
which, if successful, returns a process descriptor in the integer pointed to
by
-.Fa pidp .
+.Fa fdp .
Processes created via
.Fn pdfork
will not cause
@@ -76,7 +76,7 @@ This option is not permitted in Capsicum capability mode (see
.El
.Pp
.Fn pdgetpid
-queries the process ID (PID) if the process descriptor
+queries the process ID (PID) in the process descriptor
.Fa fd .
.Pp
.Fn pdkill
diff --git a/lib/libc/sys/posix_fadvise.2 b/lib/libc/sys/posix_fadvise.2
index 37453ff..f303f42 100644
--- a/lib/libc/sys/posix_fadvise.2
+++ b/lib/libc/sys/posix_fadvise.2
@@ -28,7 +28,7 @@
.\" @(#)madvise.2 8.1 (Berkeley) 6/9/93
.\" $FreeBSD$
.\"
-.Dd February 25, 2012
+.Dd June 19, 2012
.Dt POSIX_FADVISE 2
.Os
.Sh NAME
@@ -84,10 +84,9 @@ specified range and future access to this data may require a read operation.
.It Dv POSIX_FADV_NOREUSE
Tells the system that the specified data will only be accessed once and
then not reused.
-Accesses to data within the specified range are treated as if the file
-descriptor has the
-.Dv O_DIRECT
-flag enabled.
+The system may decrease the in-memory priority of data once it has been
+read or written.
+Future access to this data may require a read operation.
.El
.Sh RETURN VALUES
.Rv -std posix_fadvise
diff --git a/lib/libc/sys/read.2 b/lib/libc/sys/read.2
index 06e0ef1..2127eda 100644
--- a/lib/libc/sys/read.2
+++ b/lib/libc/sys/read.2
@@ -164,6 +164,8 @@ argument
points outside the allocated address space.
.It Bq Er EIO
An I/O error occurred while reading from the file system.
+.It Bq Er EBUSY
+Failed to read from a file, e.g. /proc/<pid>/regs while <pid> is not stopped
.It Bq Er EINTR
A read from a slow device
(i.e.\& one that might block for an arbitrary amount of time)
diff --git a/lib/libc/sys/rtprio.2 b/lib/libc/sys/rtprio.2
index faad941..ac78b50 100644
--- a/lib/libc/sys/rtprio.2
+++ b/lib/libc/sys/rtprio.2
@@ -132,7 +132,8 @@ RTP_PRIO_NORMAL for normal priorities, and RTP_PRIO_IDLE for idle priorities.
The priority specified by the
.Va prio
field ranges between 0 and
-.Dv RTP_PRIO_MAX (usually 31) .
+.Dv RTP_PRIO_MAX
+.Pq usually 31 .
0 is the highest possible priority.
.Pp
Realtime and idle priority is inherited through fork() and exec().
@@ -149,7 +150,7 @@ Threads of equal real/idle priority are run round-robin.
The
.Fn rtprio
system call
-will fail if
+will fail if:
.Bl -tag -width Er
.It Bq Er EINVAL
The specified
@@ -175,7 +176,7 @@ The specified process or thread was not found or visible.
.Xr setpriority 2 ,
.Xr nice 3 ,
.Xr renice 8 ,
-.Xr p_cansee 9 .
+.Xr p_cansee 9
.Sh AUTHORS
.An -nosplit
The original author was
diff --git a/lib/libc/sys/setfib.2 b/lib/libc/sys/setfib.2
index ef561d2..bf23c7a 100644
--- a/lib/libc/sys/setfib.2
+++ b/lib/libc/sys/setfib.2
@@ -52,7 +52,7 @@ may be retrieved by the
sysctl.
The system maximum is set in the kernel configuration file with
.Bd -ragged -offset indent
-.Cd "options ROUTETABLES=" Ns Em N
+.Cd "options ROUTETABLES=" Ns Em N
.Ed
.Pp
or in
@@ -95,7 +95,8 @@ system call is a
.Fx
extension however similar extensions
have been added to many other
-.Ux style kernels.
+.Ux
+style kernels.
.Sh HISTORY
The
.Fn setfib
diff --git a/lib/libc/sys/shm_open.2 b/lib/libc/sys/shm_open.2
index cc12132..a521e58 100644
--- a/lib/libc/sys/shm_open.2
+++ b/lib/libc/sys/shm_open.2
@@ -88,7 +88,7 @@ already exists,
then
.Fn shm_open
will fail with
-.Er EEXIST.
+.Er EEXIST .
.Pp
Newly created objects start off with a size of zero.
If an existing shared memory object is opened with
diff --git a/lib/libc/sys/sigqueue.2 b/lib/libc/sys/sigqueue.2
index 9e6a4c5..8069e98 100644
--- a/lib/libc/sys/sigqueue.2
+++ b/lib/libc/sys/sigqueue.2
@@ -141,7 +141,7 @@ does not exist.
The
.Fn sigqueue
system call conforms to
-.St -p1003.1-2004
+.St -p1003.1-2004 .
.Sh HISTORY
Support for
.Tn POSIX
diff --git a/lib/libc/sys/stat.2 b/lib/libc/sys/stat.2
index b6c03ab..5e49b3c 100644
--- a/lib/libc/sys/stat.2
+++ b/lib/libc/sys/stat.2
@@ -28,7 +28,7 @@
.\" @(#)stat.2 8.4 (Berkeley) 5/1/95
.\" $FreeBSD$
.\"
-.Dd November 17, 2011
+.Dd June 2, 2012
.Dt STAT 2
.Os
.Sh NAME
@@ -431,7 +431,7 @@ system call appeared in
.Sh BUGS
Applying
.Fn fstat
-to a socket (and thus to a pipe)
+to a socket
returns a zeroed buffer,
except for the blocksize field,
and a unique device and inode number.
diff --git a/lib/libc/sys/timer_create.2 b/lib/libc/sys/timer_create.2
index 316cea3..3355159 100644
--- a/lib/libc/sys/timer_create.2
+++ b/lib/libc/sys/timer_create.2
@@ -157,7 +157,7 @@ memory protection fault.
The
.Fn timer_create
system call conforms to
-.St -p1003.1-2004
+.St -p1003.1-2004 .
.Sh HISTORY
Support for
.Tn POSIX
diff --git a/lib/libc/sys/timer_delete.2 b/lib/libc/sys/timer_delete.2
index a1b245a..a7f5ada 100644
--- a/lib/libc/sys/timer_delete.2
+++ b/lib/libc/sys/timer_delete.2
@@ -72,7 +72,7 @@ is not a valid timer ID.
The
.Fn timer_delete
system call conforms to
-.St -p1003.1-2004
+.St -p1003.1-2004 .
.Sh HISTORY
Support for
.Tn POSIX
diff --git a/lib/libc/sys/timer_settime.2 b/lib/libc/sys/timer_settime.2
index 4b9d938..3f7be18 100644
--- a/lib/libc/sys/timer_settime.2
+++ b/lib/libc/sys/timer_settime.2
@@ -257,7 +257,7 @@ The
and
.Fn timer_settime
system calls conform to
-.St -p1003.1-2004
+.St -p1003.1-2004 .
.Sh HISTORY
Support for
.Tn POSIX
diff --git a/lib/libc/sys/unlink.2 b/lib/libc/sys/unlink.2
index bb27085..406c77c 100644
--- a/lib/libc/sys/unlink.2
+++ b/lib/libc/sys/unlink.2
@@ -157,7 +157,7 @@ In addition to the errors returned by the
.Fn unlink ,
the
.Fn unlinkat
-may fail if
+may fail if:
.Bl -tag -width Er
.It Bq Er EBADF
The
OpenPOWER on IntegriCloud