summaryrefslogtreecommitdiffstats
path: root/lib
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
parentfc13a01d538ded0843702a871a58cba4147b6037 (diff)
parentc72304b145d41338bd04103bd7e56b101261ca88 (diff)
downloadFreeBSD-src-ede42824618710ffa9ac08c805d8bf39bd5661ce.zip
FreeBSD-src-ede42824618710ffa9ac08c805d8bf39bd5661ce.tar.gz
IFC @ r238370
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile6
-rw-r--r--lib/bind/dns/code.h19
-rw-r--r--lib/bind/dns/dns/enumtype.h2
-rw-r--r--lib/bind/dns/dns/rdatastruct.h35
-rw-r--r--lib/clang/Makefile1
-rw-r--r--lib/clang/clang.build.mk4
-rw-r--r--lib/clang/include/Makefile8
-rw-r--r--lib/clang/include/clang/Basic/Version.inc4
-rw-r--r--lib/clang/include/clang/Config/config.h12
-rw-r--r--lib/clang/include/llvm/Config/config.h7
-rw-r--r--lib/clang/libclangindex/Makefile23
-rw-r--r--lib/clang/libclangsema/Makefile1
-rw-r--r--lib/clang/libllvmruntimedyld/Makefile3
-rw-r--r--lib/clang/libllvmsupport/Makefile1
-rw-r--r--lib/libbluetooth/bluetooth.33
-rw-r--r--lib/libc++/Makefile283
-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
-rw-r--r--lib/libcompiler_rt/Makefile2
-rw-r--r--lib/libcrypt/Makefile6
-rw-r--r--lib/libcrypt/crypt.310
-rw-r--r--lib/libcrypt/crypt.c14
-rw-r--r--lib/libcxxrt/Makefile32
-rw-r--r--lib/libcxxrt/Version.map18
-rw-r--r--lib/libedit/chared.c33
-rw-r--r--lib/libedit/chared.h4
-rw-r--r--lib/libedit/common.c2
-rw-r--r--lib/libedit/editline.3107
-rw-r--r--lib/libedit/editrc.532
-rw-r--r--lib/libedit/el.c46
-rw-r--r--lib/libedit/histedit.h6
-rw-r--r--lib/libedit/history.c109
-rw-r--r--lib/libedit/key.c35
-rw-r--r--lib/libedit/key.h4
-rw-r--r--lib/libedit/prompt.c50
-rw-r--r--lib/libedit/prompt.h6
-rw-r--r--lib/libedit/read.c42
-rw-r--r--lib/libedit/refresh.c213
-rw-r--r--lib/libedit/search.c4
-rw-r--r--lib/libedit/sig.c76
-rw-r--r--lib/libedit/sig.h10
-rw-r--r--lib/libedit/term.c184
-rw-r--r--lib/libedit/term.h6
-rw-r--r--lib/libedit/tty.c2
-rw-r--r--lib/libedit/vi.c40
-rw-r--r--lib/libelf/Makefile17
-rw-r--r--lib/libelf/elf.316
-rw-r--r--lib/libelf/elf_begin.32
-rw-r--r--lib/libelf/elf_getdata.32
-rw-r--r--lib/libelf/elf_strptr.32
-rw-r--r--lib/libelf/gelf.314
-rw-r--r--lib/libelf/gelf_getphdr.32
-rw-r--r--lib/libelf/gelf_newehdr.33
-rw-r--r--lib/libfetch/common.c32
-rw-r--r--lib/libfetch/http.c4
-rw-r--r--lib/libgpib/gpib.312
-rw-r--r--lib/libgssapi/gss_accept_sec_context.36
-rw-r--r--lib/libgssapi/gss_acquire_cred.36
-rw-r--r--lib/libgssapi/gss_add_cred.36
-rw-r--r--lib/libgssapi/gss_add_oid_set_member.36
-rw-r--r--lib/libgssapi/gss_canonicalize_name.36
-rw-r--r--lib/libgssapi/gss_compare_name.38
-rw-r--r--lib/libgssapi/gss_context_time.36
-rw-r--r--lib/libgssapi/gss_create_empty_oid_set.36
-rw-r--r--lib/libgssapi/gss_delete_sec_context.36
-rw-r--r--lib/libgssapi/gss_display_name.36
-rw-r--r--lib/libgssapi/gss_display_status.38
-rw-r--r--lib/libgssapi/gss_duplicate_name.36
-rw-r--r--lib/libgssapi/gss_export_name.36
-rw-r--r--lib/libgssapi/gss_export_sec_context.36
-rw-r--r--lib/libgssapi/gss_get_mic.36
-rw-r--r--lib/libgssapi/gss_import_name.36
-rw-r--r--lib/libgssapi/gss_import_sec_context.36
-rw-r--r--lib/libgssapi/gss_indicate_mechs.36
-rw-r--r--lib/libgssapi/gss_init_sec_context.36
-rw-r--r--lib/libgssapi/gss_inquire_context.36
-rw-r--r--lib/libgssapi/gss_inquire_cred.36
-rw-r--r--lib/libgssapi/gss_inquire_cred_by_mech.36
-rw-r--r--lib/libgssapi/gss_inquire_mechs_for_name.36
-rw-r--r--lib/libgssapi/gss_inquire_names_for_mech.36
-rw-r--r--lib/libgssapi/gss_process_context_token.36
-rw-r--r--lib/libgssapi/gss_release_buffer.36
-rw-r--r--lib/libgssapi/gss_release_cred.36
-rw-r--r--lib/libgssapi/gss_release_name.36
-rw-r--r--lib/libgssapi/gss_release_oid_set.36
-rw-r--r--lib/libgssapi/gss_test_oid_set_member.36
-rw-r--r--lib/libgssapi/gss_unwrap.38
-rw-r--r--lib/libgssapi/gss_verify_mic.36
-rw-r--r--lib/libgssapi/gss_wrap.312
-rw-r--r--lib/libgssapi/gss_wrap_size_limit.36
-rw-r--r--lib/libgssapi/gssapi.32
-rw-r--r--lib/libgssapi/mech.510
-rw-r--r--lib/libjail/jail.c58
-rw-r--r--lib/libkiconv/Makefile9
-rw-r--r--lib/libkiconv/xlat16_iconv.c10
-rw-r--r--lib/libkvm/kvm_getpcpu.34
-rw-r--r--lib/libmagic/Makefile5
-rw-r--r--lib/libmagic/config.h2
-rw-r--r--lib/libmd/Makefile29
-rw-r--r--lib/libmd/md2.copyright17
-rw-r--r--lib/libmd/md2.h46
-rw-r--r--lib/libmd/md2c.c211
-rw-r--r--lib/libmd/mdX.312
-rw-r--r--lib/libnandfs/Makefile9
-rw-r--r--lib/libnandfs/libnandfs.h65
-rw-r--r--lib/libnandfs/nandfs.c247
-rw-r--r--lib/libncp/ncpl_nls.c76
-rw-r--r--lib/libpam/libpam/Makefile17
-rw-r--r--lib/libpam/modules/pam_exec/pam_exec.84
-rw-r--r--lib/libpam/modules/pam_ssh/pam_ssh.c2
-rw-r--r--lib/libpcap/Makefile9
-rw-r--r--lib/libpcap/config.h34
-rw-r--r--lib/libpmc/pmc.322
-rw-r--r--lib/libprocstat/cd9660.c4
-rw-r--r--lib/libprocstat/common_kvm.c4
-rw-r--r--lib/libprocstat/libprocstat.32
-rw-r--r--lib/libprocstat/libprocstat.c17
-rw-r--r--lib/libradius/libradius.38
-rw-r--r--lib/librpcsec_gss/rpc_gss_get_error.32
-rw-r--r--lib/librpcsec_gss/rpc_gss_get_mech_info.32
-rw-r--r--lib/librpcsec_gss/rpc_gss_get_principal_name.32
-rw-r--r--lib/librpcsec_gss/rpc_gss_get_versions.32
-rw-r--r--lib/librpcsec_gss/rpc_gss_getcred.32
-rw-r--r--lib/librpcsec_gss/rpc_gss_is_installed.32
-rw-r--r--lib/librpcsec_gss/rpc_gss_max_data_length.32
-rw-r--r--lib/librpcsec_gss/rpc_gss_mech_to_oid.32
-rw-r--r--lib/librpcsec_gss/rpc_gss_oid_to_mech.32
-rw-r--r--lib/librpcsec_gss/rpc_gss_qop_to_num.32
-rw-r--r--lib/librpcsec_gss/rpc_gss_seccreate.34
-rw-r--r--lib/librpcsec_gss/rpc_gss_set_callback.32
-rw-r--r--lib/librpcsec_gss/rpc_gss_set_defaults.32
-rw-r--r--lib/librpcsec_gss/rpc_gss_set_svc_name.32
-rw-r--r--lib/librpcsec_gss/rpc_gss_svc_max_data_length.32
-rw-r--r--lib/libstand/Makefile21
-rw-r--r--lib/libstand/bswap.c2
-rw-r--r--lib/libstand/nandfs.c1041
-rw-r--r--lib/libstand/stand.h1
-rw-r--r--lib/libstdbuf/Makefile12
-rw-r--r--lib/libstdbuf/libstdbuf.3102
-rw-r--r--lib/libstdbuf/stdbuf.c115
-rw-r--r--lib/libtacplus/libtacplus.32
-rw-r--r--lib/libthr/thread/thr_init.c4
-rw-r--r--lib/libthr/thread/thr_mutex.c1
-rw-r--r--lib/libthr/thread/thr_private.h1
-rw-r--r--lib/libthr/thread/thr_sleepq.c22
-rw-r--r--lib/libusb/Makefile4
-rw-r--r--lib/libusb/libusb.334
-rw-r--r--lib/libusb/libusb.h1
-rw-r--r--lib/libusb/libusb10.c25
-rw-r--r--lib/libusb/libusb10_desc.c19
-rw-r--r--lib/libusb/libusb10_io.c10
-rw-r--r--lib/libusb/libusb20.319
-rw-r--r--lib/libusbhid/parse.c2
-rw-r--r--lib/libutil/Makefile5
-rw-r--r--lib/libutil/auth.356
-rw-r--r--lib/libutil/auth.c36
-rw-r--r--lib/libutil/auth.conf.535
-rw-r--r--lib/libutil/login.conf.59
-rw-r--r--lib/libutil/property.32
-rw-r--r--lib/libutil/pw_util.c19
-rw-r--r--lib/libz/ChangeLog203
-rw-r--r--lib/libz/FAQ12
-rw-r--r--lib/libz/FREEBSD-upgrade2
-rw-r--r--lib/libz/Makefile14
-rw-r--r--lib/libz/README24
-rw-r--r--lib/libz/Symbol.map9
-rw-r--r--lib/libz/Versions.def5
-rw-r--r--lib/libz/adler32.c68
-rw-r--r--lib/libz/contrib/asm686/match.S16
-rw-r--r--lib/libz/crc32.c83
-rw-r--r--lib/libz/crc32.h2
-rw-r--r--lib/libz/deflate.c259
-rw-r--r--lib/libz/deflate.h10
-rw-r--r--lib/libz/doc/algorithm.txt2
-rw-r--r--lib/libz/gzguts.h87
-rw-r--r--lib/libz/gzlib.c165
-rw-r--r--lib/libz/gzread.c418
-rw-r--r--lib/libz/gzwrite.c148
-rw-r--r--lib/libz/infback.c14
-rw-r--r--lib/libz/inffixed.h6
-rw-r--r--lib/libz/inflate.c90
-rw-r--r--lib/libz/inftrees.c46
-rw-r--r--lib/libz/test/example.c (renamed from lib/libz/example.c)82
-rw-r--r--lib/libz/test/infcover.c671
-rw-r--r--lib/libz/test/minigzip.c (renamed from lib/libz/minigzip.c)193
-rw-r--r--lib/libz/trees.c40
-rw-r--r--lib/libz/zconf.h196
-rw-r--r--lib/libz/zlib.318
-rw-r--r--lib/libz/zlib.h309
-rw-r--r--lib/libz/zopen.c12
-rw-r--r--lib/libz/zutil.c24
-rw-r--r--lib/libz/zutil.h98
-rw-r--r--lib/msun/man/cexp.32
-rw-r--r--lib/msun/man/complex.32
-rw-r--r--lib/msun/src/math.h79
312 files changed, 6821 insertions, 2782 deletions
diff --git a/lib/Makefile b/lib/Makefile
index 0c47d08..989ea23 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -88,6 +88,7 @@ SUBDIR= ${SUBDIR_ORDERED} \
libmemstat \
${_libmilter} \
${_libmp} \
+ ${_libnandfs} \
${_libncp} \
${_libngatm} \
libopie \
@@ -104,6 +105,7 @@ SUBDIR= ${SUBDIR_ORDERED} \
${_libsmdb} \
${_libsmutil} \
libstand \
+ libstdbuf \
libstdthreads \
${_libtelnet} \
${_libthr} \
@@ -175,6 +177,10 @@ _libipx= libipx
_libthr= libthr
.endif
+.if ${MK_NAND} != "no"
+_libnandfs= libnandfs
+.endif
+
.if ${MK_NETGRAPH} != "no"
_libnetgraph= libnetgraph
.endif
diff --git a/lib/bind/dns/code.h b/lib/bind/dns/code.h
index ad9e11e..a451eeb 100644
--- a/lib/bind/dns/code.h
+++ b/lib/bind/dns/code.h
@@ -83,6 +83,7 @@
#include "rdata/in_1/dhcid_49.c"
#include "rdata/generic/nsec3_50.c"
#include "rdata/generic/nsec3param_51.c"
+#include "rdata/generic/tlsa_52.c"
#include "rdata/generic/hip_55.c"
#include "rdata/generic/spf_99.c"
#include "rdata/generic/unspec_103.c"
@@ -192,6 +193,7 @@
break; \
case 50: result = fromtext_nsec3(rdclass, type, lexer, origin, options, target, callbacks); break; \
case 51: result = fromtext_nsec3param(rdclass, type, lexer, origin, options, target, callbacks); break; \
+ case 52: result = fromtext_tlsa(rdclass, type, lexer, origin, options, target, callbacks); break; \
case 55: result = fromtext_hip(rdclass, type, lexer, origin, options, target, callbacks); break; \
case 99: result = fromtext_spf(rdclass, type, lexer, origin, options, target, callbacks); break; \
case 103: result = fromtext_unspec(rdclass, type, lexer, origin, options, target, callbacks); break; \
@@ -305,6 +307,7 @@
break; \
case 50: result = totext_nsec3(rdata, tctx, target); break; \
case 51: result = totext_nsec3param(rdata, tctx, target); break; \
+ case 52: result = totext_tlsa(rdata, tctx, target); break; \
case 55: result = totext_hip(rdata, tctx, target); break; \
case 99: result = totext_spf(rdata, tctx, target); break; \
case 103: result = totext_unspec(rdata, tctx, target); break; \
@@ -418,6 +421,7 @@
break; \
case 50: result = fromwire_nsec3(rdclass, type, source, dctx, options, target); break; \
case 51: result = fromwire_nsec3param(rdclass, type, source, dctx, options, target); break; \
+ case 52: result = fromwire_tlsa(rdclass, type, source, dctx, options, target); break; \
case 55: result = fromwire_hip(rdclass, type, source, dctx, options, target); break; \
case 99: result = fromwire_spf(rdclass, type, source, dctx, options, target); break; \
case 103: result = fromwire_unspec(rdclass, type, source, dctx, options, target); break; \
@@ -531,6 +535,7 @@
break; \
case 50: result = towire_nsec3(rdata, cctx, target); break; \
case 51: result = towire_nsec3param(rdata, cctx, target); break; \
+ case 52: result = towire_tlsa(rdata, cctx, target); break; \
case 55: result = towire_hip(rdata, cctx, target); break; \
case 99: result = towire_spf(rdata, cctx, target); break; \
case 103: result = towire_unspec(rdata, cctx, target); break; \
@@ -644,6 +649,7 @@
break; \
case 50: result = compare_nsec3(rdata1, rdata2); break; \
case 51: result = compare_nsec3param(rdata1, rdata2); break; \
+ case 52: result = compare_tlsa(rdata1, rdata2); break; \
case 55: result = compare_hip(rdata1, rdata2); break; \
case 99: result = compare_spf(rdata1, rdata2); break; \
case 103: result = compare_unspec(rdata1, rdata2); break; \
@@ -757,6 +763,7 @@
break; \
case 50: result = casecompare_nsec3(rdata1, rdata2); break; \
case 51: result = casecompare_nsec3param(rdata1, rdata2); break; \
+ case 52: result = casecompare_tlsa(rdata1, rdata2); break; \
case 55: result = casecompare_hip(rdata1, rdata2); break; \
case 99: result = casecompare_spf(rdata1, rdata2); break; \
case 103: result = casecompare_unspec(rdata1, rdata2); break; \
@@ -870,6 +877,7 @@
break; \
case 50: result = fromstruct_nsec3(rdclass, type, source, target); break; \
case 51: result = fromstruct_nsec3param(rdclass, type, source, target); break; \
+ case 52: result = fromstruct_tlsa(rdclass, type, source, target); break; \
case 55: result = fromstruct_hip(rdclass, type, source, target); break; \
case 99: result = fromstruct_spf(rdclass, type, source, target); break; \
case 103: result = fromstruct_unspec(rdclass, type, source, target); break; \
@@ -983,6 +991,7 @@
break; \
case 50: result = tostruct_nsec3(rdata, target, mctx); break; \
case 51: result = tostruct_nsec3param(rdata, target, mctx); break; \
+ case 52: result = tostruct_tlsa(rdata, target, mctx); break; \
case 55: result = tostruct_hip(rdata, target, mctx); break; \
case 99: result = tostruct_spf(rdata, target, mctx); break; \
case 103: result = tostruct_unspec(rdata, target, mctx); break; \
@@ -1096,6 +1105,7 @@
break; \
case 50: freestruct_nsec3(source); break; \
case 51: freestruct_nsec3param(source); break; \
+ case 52: freestruct_tlsa(source); break; \
case 55: freestruct_hip(source); break; \
case 99: freestruct_spf(source); break; \
case 103: freestruct_unspec(source); break; \
@@ -1209,6 +1219,7 @@
break; \
case 50: result = additionaldata_nsec3(rdata, add, arg); break; \
case 51: result = additionaldata_nsec3param(rdata, add, arg); break; \
+ case 52: result = additionaldata_tlsa(rdata, add, arg); break; \
case 55: result = additionaldata_hip(rdata, add, arg); break; \
case 99: result = additionaldata_spf(rdata, add, arg); break; \
case 103: result = additionaldata_unspec(rdata, add, arg); break; \
@@ -1322,6 +1333,7 @@
break; \
case 50: result = digest_nsec3(rdata, digest, arg); break; \
case 51: result = digest_nsec3param(rdata, digest, arg); break; \
+ case 52: result = digest_tlsa(rdata, digest, arg); break; \
case 55: result = digest_hip(rdata, digest, arg); break; \
case 99: result = digest_spf(rdata, digest, arg); break; \
case 103: result = digest_unspec(rdata, digest, arg); break; \
@@ -1435,6 +1447,7 @@
break; \
case 50: result = checkowner_nsec3(name, rdclass, type, wildcard); break; \
case 51: result = checkowner_nsec3param(name, rdclass, type, wildcard); break; \
+ case 52: result = checkowner_tlsa(name, rdclass, type, wildcard); break; \
case 55: result = checkowner_hip(name, rdclass, type, wildcard); break; \
case 99: result = checkowner_spf(name, rdclass, type, wildcard); break; \
case 103: result = checkowner_unspec(name, rdclass, type, wildcard); break; \
@@ -1548,6 +1561,7 @@
break; \
case 50: result = checknames_nsec3(rdata, owner, bad); break; \
case 51: result = checknames_nsec3param(rdata, owner, bad); break; \
+ case 52: result = checknames_tlsa(rdata, owner, bad); break; \
case 55: result = checknames_hip(rdata, owner, bad); break; \
case 99: result = checknames_spf(rdata, owner, bad); break; \
case 103: result = checknames_unspec(rdata, owner, bad); break; \
@@ -1718,6 +1732,9 @@
case 233: \
RDATATYPE_COMPARE("nsec3", 50, _typename, _length, _typep); \
break; \
+ case 120: \
+ RDATATYPE_COMPARE("tlsa", 52, _typename, _length, _typep); \
+ break; \
case 208: \
RDATATYPE_COMPARE("hip", 55, _typename, _length, _typep); \
break; \
@@ -1806,6 +1823,7 @@
case 49: return (RRTYPE_DHCID_ATTRIBUTES); \
case 50: return (RRTYPE_NSEC3_ATTRIBUTES); \
case 51: return (RRTYPE_NSEC3PARAM_ATTRIBUTES); \
+ case 52: return (RRTYPE_TLSA_ATTRIBUTES); \
case 55: return (RRTYPE_HIP_ATTRIBUTES); \
case 99: return (RRTYPE_SPF_ATTRIBUTES); \
case 100: return (DNS_RDATATYPEATTR_RESERVED); \
@@ -1875,6 +1893,7 @@
case 49: return (str_totext("DHCID", target)); \
case 50: return (str_totext("NSEC3", target)); \
case 51: return (str_totext("NSEC3PARAM", target)); \
+ case 52: return (str_totext("TLSA", target)); \
case 55: return (str_totext("HIP", target)); \
case 99: return (str_totext("SPF", target)); \
case 100: return (str_totext("UINFO", target)); \
diff --git a/lib/bind/dns/dns/enumtype.h b/lib/bind/dns/dns/enumtype.h
index bc64f69..4c9a2f9 100644
--- a/lib/bind/dns/dns/enumtype.h
+++ b/lib/bind/dns/dns/enumtype.h
@@ -78,6 +78,7 @@ enum {
dns_rdatatype_dhcid = 49,
dns_rdatatype_nsec3 = 50,
dns_rdatatype_nsec3param = 51,
+ dns_rdatatype_tlsa = 52,
dns_rdatatype_hip = 55,
dns_rdatatype_spf = 99,
dns_rdatatype_unspec = 103,
@@ -140,6 +141,7 @@ enum {
#define dns_rdatatype_dhcid ((dns_rdatatype_t)dns_rdatatype_dhcid)
#define dns_rdatatype_nsec3 ((dns_rdatatype_t)dns_rdatatype_nsec3)
#define dns_rdatatype_nsec3param ((dns_rdatatype_t)dns_rdatatype_nsec3param)
+#define dns_rdatatype_tlsa ((dns_rdatatype_t)dns_rdatatype_tlsa)
#define dns_rdatatype_hip ((dns_rdatatype_t)dns_rdatatype_hip)
#define dns_rdatatype_spf ((dns_rdatatype_t)dns_rdatatype_spf)
#define dns_rdatatype_unspec ((dns_rdatatype_t)dns_rdatatype_unspec)
diff --git a/lib/bind/dns/dns/rdatastruct.h b/lib/bind/dns/dns/rdatastruct.h
index 4b50b57..9504fa8 100644
--- a/lib/bind/dns/dns/rdatastruct.h
+++ b/lib/bind/dns/dns/rdatastruct.h
@@ -1840,6 +1840,41 @@ typedef struct dns_rdata_nsec3param {
#endif /* GENERIC_NSEC3PARAM_51_H */
/*
+ * Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/* $Id$ */
+
+#ifndef GENERIC_TLSA_52_H
+#define GENERIC_TLSA_52_H 1
+
+/*!
+ * \brief per draft-ietf-dane-protocol-19.txt
+ */
+typedef struct dns_rdata_tlsa {
+ dns_rdatacommon_t common;
+ isc_mem_t *mctx;
+ isc_uint8_t usage;
+ isc_uint8_t selector;
+ isc_uint8_t match;
+ isc_uint16_t length;
+ unsigned char *data;
+} dns_rdata_tlsa_t;
+
+#endif /* GENERIC_TLSA_52_H */
+/*
* Copyright (C) 2009 Internet Systems Consortium, Inc. ("ISC")
*
* Permission to use, copy, modify, and/or distribute this software for any
diff --git a/lib/clang/Makefile b/lib/clang/Makefile
index d6e9457..2d77383 100644
--- a/lib/clang/Makefile
+++ b/lib/clang/Makefile
@@ -12,7 +12,6 @@ SUBDIR= libclanganalysis \
libclangedit \
libclangfrontend \
libclangfrontendtool \
- libclangindex \
libclanglex \
libclangparse \
libclangrewrite \
diff --git a/lib/clang/clang.build.mk b/lib/clang/clang.build.mk
index a14918d..67868f1 100644
--- a/lib/clang/clang.build.mk
+++ b/lib/clang/clang.build.mk
@@ -25,9 +25,7 @@ LLVM_REQUIRES_RTTI=
CXXFLAGS+=-fno-rtti
.endif
-.ifdef TOOLS_PREFIX
-CFLAGS+=-DCLANG_PREFIX=\"${TOOLS_PREFIX}\"
-.endif
+CFLAGS+=-DDEFAULT_SYSROOT=\"${TOOLS_PREFIX}\"
.PATH: ${LLVM_SRCS}/${SRCDIR}
diff --git a/lib/clang/include/Makefile b/lib/clang/include/Makefile
index 73a6120..05b43cf 100644
--- a/lib/clang/include/Makefile
+++ b/lib/clang/include/Makefile
@@ -5,17 +5,23 @@
INCSDIR=${INCLUDEDIR}/clang/3.1
INCS= altivec.h \
+ avx2intrin.h \
avxintrin.h \
+ bmi2intrin.h \
+ bmiintrin.h \
cpuid.h \
emmintrin.h \
+ fma4intrin.h \
immintrin.h \
+ lzcntintrin.h \
mm3dnow.h \
mm_malloc.h \
mmintrin.h \
+ module.map \
nmmintrin.h \
pmmintrin.h \
+ popcntintrin.h \
smmintrin.h \
- stdalign.h \
tmmintrin.h \
unwind.h \
wmmintrin.h \
diff --git a/lib/clang/include/clang/Basic/Version.inc b/lib/clang/include/clang/Basic/Version.inc
index 55d4ea6..b263857 100644
--- a/lib/clang/include/clang/Basic/Version.inc
+++ b/lib/clang/include/clang/Basic/Version.inc
@@ -5,6 +5,6 @@
#define CLANG_VERSION_MINOR 1
#define CLANG_VENDOR "FreeBSD "
-#define CLANG_VENDOR_SUFFIX " 20120413"
+#define CLANG_VENDOR_SUFFIX " 20120523"
-#define SVN_REVISION "154661"
+#define SVN_REVISION "156863"
diff --git a/lib/clang/include/clang/Config/config.h b/lib/clang/include/clang/Config/config.h
index 7348308..8a7936b 100644
--- a/lib/clang/include/clang/Config/config.h
+++ b/lib/clang/include/clang/Config/config.h
@@ -11,10 +11,16 @@
/* Relative directory for resource files */
#define CLANG_RESOURCE_DIR ""
-/* Directory where gcc is installed. */
-#define GCC_INSTALL_PREFIX ""
-
/* Directories clang will search for headers */
#define C_INCLUDE_DIRS ""
+/* Linker version detected at compile time. */
+/* #undef HOST_LINK_VERSION */
+
+/* Default <path> to all compiler invocations for --sysroot=<path>. */
+/* #undef DEFAULT_SYSROOT */
+
+/* Directory where gcc is installed. */
+#define GCC_INSTALL_PREFIX ""
+
#endif
diff --git a/lib/clang/include/llvm/Config/config.h b/lib/clang/include/llvm/Config/config.h
index f6001e9..90bee6e 100644
--- a/lib/clang/include/llvm/Config/config.h
+++ b/lib/clang/include/llvm/Config/config.h
@@ -14,6 +14,9 @@
/* Directories clang will search for headers */
#define C_INCLUDE_DIRS ""
+/* Default <path> to all compiler invocations for --sysroot=<path>. */
+/* #undef DEFAULT_SYSROOT */
+
/* Define if position independent code is enabled */
#define ENABLE_PIC 0
@@ -660,13 +663,13 @@
#define PACKAGE_NAME "LLVM"
/* Define to the full name and version of this package. */
-#define PACKAGE_STRING "LLVM 3.1svn"
+#define PACKAGE_STRING "LLVM 3.1"
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "llvm"
/* Define to the version of this package. */
-#define PACKAGE_VERSION "3.1svn"
+#define PACKAGE_VERSION "3.1"
/* Define as the return type of signal handlers (`int' or `void'). */
#define RETSIGTYPE void
diff --git a/lib/clang/libclangindex/Makefile b/lib/clang/libclangindex/Makefile
deleted file mode 100644
index 63b532c..0000000
--- a/lib/clang/libclangindex/Makefile
+++ /dev/null
@@ -1,23 +0,0 @@
-# $FreeBSD$
-
-LIB= clangindex
-
-SRCDIR= tools/clang/lib/Index
-SRCS= ASTLocation.cpp \
- Analyzer.cpp \
- DeclReferenceMap.cpp \
- Entity.cpp \
- GlobalSelector.cpp \
- Handlers.cpp \
- IndexProvider.cpp \
- Indexer.cpp \
- Program.cpp \
- SelectorMap.cpp \
-
-TGHDRS= AttrList \
- Attrs \
- DeclNodes \
- DiagnosticCommonKinds \
- StmtNodes
-
-.include "../clang.lib.mk"
diff --git a/lib/clang/libclangsema/Makefile b/lib/clang/libclangsema/Makefile
index e40a756..3b2b331 100644
--- a/lib/clang/libclangsema/Makefile
+++ b/lib/clang/libclangsema/Makefile
@@ -36,6 +36,7 @@ SRCS= AnalysisBasedWarnings.cpp \
SemaOverload.cpp \
SemaPseudoObject.cpp \
SemaStmt.cpp \
+ SemaStmtAttr.cpp \
SemaTemplate.cpp \
SemaTemplateDeduction.cpp \
SemaTemplateInstantiate.cpp \
diff --git a/lib/clang/libllvmruntimedyld/Makefile b/lib/clang/libllvmruntimedyld/Makefile
index 7280e1d..d5d5447 100644
--- a/lib/clang/libllvmruntimedyld/Makefile
+++ b/lib/clang/libllvmruntimedyld/Makefile
@@ -3,7 +3,8 @@
LIB= llvmruntimedyld
SRCDIR= lib/ExecutionEngine/RuntimeDyld
-SRCS= RuntimeDyld.cpp \
+SRCS= GDBRegistrar.cpp \
+ RuntimeDyld.cpp \
RuntimeDyldELF.cpp \
RuntimeDyldMachO.cpp
diff --git a/lib/clang/libllvmsupport/Makefile b/lib/clang/libllvmsupport/Makefile
index 19afb44..5fcff88 100644
--- a/lib/clang/libllvmsupport/Makefile
+++ b/lib/clang/libllvmsupport/Makefile
@@ -30,6 +30,7 @@ SRCS= APFloat.cpp \
IntervalMap.cpp \
IntEqClasses.cpp \
IntrusiveRefCntPtr.cpp \
+ Locale.cpp \
LockFileManager.cpp \
ManagedStatic.cpp \
Memory.cpp \
diff --git a/lib/libbluetooth/bluetooth.3 b/lib/libbluetooth/bluetooth.3
index aa738d4..e011094 100644
--- a/lib/libbluetooth/bluetooth.3
+++ b/lib/libbluetooth/bluetooth.3
@@ -494,7 +494,8 @@ previously obtained with
.Xr bt_devopen 3 .
Filtering can be done on packet types, i.e.
.Dv ACL ,
-.Dv SCO or
+.Dv SCO
+or
.Dv HCI ,
command and event packets, and, in addition, on
.Dv HCI
diff --git a/lib/libc++/Makefile b/lib/libc++/Makefile
index fc35ea5..1c65cc3 100644
--- a/lib/libc++/Makefile
+++ b/lib/libc++/Makefile
@@ -1,156 +1,163 @@
# $FreeBSD$
-LIBCXXRTDIR= ${.CURDIR}/../../contrib/libcxxrt
-HDRDIR= ${.CURDIR}/../../contrib/libc++/include
-SRCDIR= ${.CURDIR}/../../contrib/libc++/src
-CXXINCLUDEDIR= ${INCLUDEDIR}/c++/v${SHLIB_MAJOR}
+LIBCXXRTDIR= ${.CURDIR}/../../contrib/libcxxrt
+HDRDIR= ${.CURDIR}/../../contrib/libc++/include
+SRCDIR= ${.CURDIR}/../../contrib/libc++/src
+CXXINCLUDEDIR= ${INCLUDEDIR}/c++/v${SHLIB_MAJOR}
.PATH: ${SRCDIR}
-LIB= c++
-SHLIB_MAJOR= 1
+LIB= c++
+SHLIB_MAJOR= 1
-SRCS+= algorithm.cpp\
- bind.cpp\
- chrono.cpp\
- condition_variable.cpp\
- debug.cpp\
- exception.cpp\
- future.cpp\
- hash.cpp\
- ios.cpp\
- iostream.cpp\
- locale.cpp\
- memory.cpp\
- mutex.cpp\
- new.cpp\
- random.cpp\
- regex.cpp\
- stdexcept.cpp\
- string.cpp\
- strstream.cpp\
- system_error.cpp\
- thread.cpp\
- typeinfo.cpp\
- utility.cpp\
- valarray.cpp
+SRCS+= algorithm.cpp\
+ bind.cpp\
+ chrono.cpp\
+ condition_variable.cpp\
+ debug.cpp\
+ exception.cpp\
+ future.cpp\
+ hash.cpp\
+ ios.cpp\
+ iostream.cpp\
+ locale.cpp\
+ memory.cpp\
+ mutex.cpp\
+ new.cpp\
+ random.cpp\
+ regex.cpp\
+ stdexcept.cpp\
+ string.cpp\
+ strstream.cpp\
+ system_error.cpp\
+ thread.cpp\
+ typeinfo.cpp\
+ utility.cpp\
+ valarray.cpp
-WARNS= 0
-CXXFLAGS+= -I${HDRDIR} -I${LIBCXXRTDIR} -std=c++0x -nostdlib -DLIBCXXRT
+WARNS= 0
+CXXFLAGS+= -I${HDRDIR} -I${LIBCXXRTDIR} -std=c++0x -nostdlib -DLIBCXXRT
-DPADD= ${LIBCXXRT}
-LDADD= -lcxxrt
-LDFLAGS+= --verbose
-INCSGROUPS= STD EXT
+DPADD= ${LIBCXXRT}
+LDADD= -lcxxrt
+LDFLAGS+= --verbose
+INCSGROUPS= STD EXT
-STD_HEADERS= __bit_reference\
- __config\
- __debug\
- __functional_03\
- __functional_base\
- __functional_base_03\
- __hash_table\
- __locale\
- __mutex_base\
- __split_buffer\
- __sso_allocator\
- __std_stream\
- __tree\
- __tuple\
- __tuple_03\
- __undef_min_max\
- algorithm\
- array\
- atomic\
- bitset\
- cassert\
- ccomplex\
- cctype\
- cerrno\
- cfenv\
- cfloat\
- chrono\
- cinttypes\
- ciso646\
- climits\
- clocale\
- cmath\
- codecvt\
- complex\
- complex.h\
- condition_variable\
- csetjmp\
- csignal\
- cstdarg\
- cstdbool\
- cstddef\
- cstdint\
- cstdio\
- cstdlib\
- cstring\
- ctgmath\
- ctime\
- cwchar\
- cwctype\
- deque\
- exception\
- forward_list\
- fstream\
- functional\
- future\
- initializer_list\
- iomanip\
- ios\
- iosfwd\
- iostream\
- istream\
- iterator\
- limits\
- list\
- locale\
- map\
- memory\
- mutex\
- new\
- numeric\
- ostream\
- queue\
- random\
- ratio\
- regex\
- scoped_allocator\
- set\
- sstream\
- stack\
- stdexcept\
- streambuf\
- string\
- strstream\
- system_error\
- tgmath.h\
- thread\
- tuple\
- type_traits\
- typeindex\
- typeinfo\
- unordered_map\
- unordered_set\
- utility\
- valarray\
- vector
+STD_HEADERS= __bit_reference\
+ __config\
+ __debug\
+ __functional_03\
+ __functional_base\
+ __functional_base_03\
+ __hash_table\
+ __locale\
+ __mutex_base\
+ __split_buffer\
+ __sso_allocator\
+ __std_stream\
+ __tree\
+ __tuple\
+ __tuple_03\
+ __undef_min_max\
+ algorithm\
+ array\
+ atomic\
+ bitset\
+ cassert\
+ ccomplex\
+ cctype\
+ cerrno\
+ cfenv\
+ cfloat\
+ chrono\
+ cinttypes\
+ ciso646\
+ climits\
+ clocale\
+ cmath\
+ codecvt\
+ complex\
+ complex.h\
+ condition_variable\
+ csetjmp\
+ csignal\
+ cstdarg\
+ cstdbool\
+ cstddef\
+ cstdint\
+ cstdio\
+ cstdlib\
+ cstring\
+ ctgmath\
+ ctime\
+ cwchar\
+ cwctype\
+ deque\
+ exception\
+ forward_list\
+ fstream\
+ functional\
+ future\
+ initializer_list\
+ iomanip\
+ ios\
+ iosfwd\
+ iostream\
+ istream\
+ iterator\
+ limits\
+ list\
+ locale\
+ map\
+ memory\
+ mutex\
+ new\
+ numeric\
+ ostream\
+ queue\
+ random\
+ ratio\
+ regex\
+ scoped_allocator\
+ set\
+ sstream\
+ stack\
+ stdexcept\
+ streambuf\
+ string\
+ strstream\
+ system_error\
+ tgmath.h\
+ thread\
+ tuple\
+ type_traits\
+ typeindex\
+ typeinfo\
+ unordered_map\
+ unordered_set\
+ utility\
+ valarray\
+ vector
+RT_HEADERS= cxxabi.h\
+ unwind.h\
+ unwind-arm.h\
+ unwind-itanium.h
.for hdr in ${STD_HEADERS}
-STD+= ${HDRDIR}/${hdr}
+STD+= ${HDRDIR}/${hdr}
.endfor
-STDDIR= ${CXXINCLUDEDIR}
+.for hdr in ${RT_HEADERS}
+STD+= ${LIBCXXRTDIR}/${hdr}
+.endfor
+STDDIR= ${CXXINCLUDEDIR}
-EXT_HEADERS= __hash\
- hash_map\
- hash_set
+EXT_HEADERS= __hash\
+ hash_map\
+ hash_set
.for hdr in ${EXT_HEADERS}
-EXT+= ${HDRDIR}/ext/${hdr}
+EXT+= ${HDRDIR}/ext/${hdr}
.endfor
-EXTDIR= ${CXXINCLUDEDIR}/ext
+EXTDIR= ${CXXINCLUDEDIR}/ext
.include <bsd.lib.mk>
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
diff --git a/lib/libcompiler_rt/Makefile b/lib/libcompiler_rt/Makefile
index ff9daad..84f9b36 100644
--- a/lib/libcompiler_rt/Makefile
+++ b/lib/libcompiler_rt/Makefile
@@ -176,7 +176,7 @@ SRCS+= ${file}.c
. endif
.endfor
-.if ${MACHINE_CPUARCH} != "sparc64" && ${MACHINE_CPUARCH} != "mips"
+.if ${MACHINE_CPUARCH} != "mips"
. if ${MK_INSTALLLIB} != "no"
SYMLINKS+=libcompiler_rt.a ${LIBDIR}/libgcc.a
. endif
diff --git a/lib/libcrypt/Makefile b/lib/libcrypt/Makefile
index eea5572..7274e28 100644
--- a/lib/libcrypt/Makefile
+++ b/lib/libcrypt/Makefile
@@ -26,11 +26,7 @@ SRCS+= crypt-des.c crypt-blowfish.c blowfish.c
CFLAGS+= -I${.CURDIR} -DHAS_DES -DHAS_BLOWFISH
.endif
-# And the auth_getval() code and support.
-.PATH: ${.CURDIR}/../libutil
-SRCS+= auth.c property.c
-.for sym in auth_getval property_find properties_read properties_free \
- MD4Init MD4Final MD4Update MD4Pad \
+.for sym in MD4Init MD4Final MD4Update MD4Pad \
MD5Init MD5Final MD5Update MD5Pad \
SHA256_Init SHA256_Final SHA256_Update \
SHA512_Init SHA512_Final SHA512_Update
diff --git a/lib/libcrypt/crypt.3 b/lib/libcrypt/crypt.3
index 949a7a7..f14a6eb 100644
--- a/lib/libcrypt/crypt.3
+++ b/lib/libcrypt/crypt.3
@@ -196,7 +196,7 @@ SHA-512
.Pp
Other crypt formats may be easily added.
An example salt would be:
-.Bl -tag -offset indent
+.Bl -tag -width 6n -offset indent
.It Cm "$4$thesalt$rest"
.El
.Ss "Traditional" crypt:
@@ -238,12 +238,6 @@ The
.Fn crypt_set_format
function sets the default encoding format according to the supplied
.Fa string .
-.Pp
-The global default format can be set using the
-.Pa /etc/auth.conf
-file using the
-.Va crypt_default
-property.
.Sh RETURN VALUES
The
.Fn crypt
@@ -260,9 +254,7 @@ Otherwise, a value of 0 is returned.
.Sh SEE ALSO
.Xr login 1 ,
.Xr passwd 1 ,
-.Xr auth_getval 3 ,
.Xr getpass 3 ,
-.Xr auth.conf 5 ,
.Xr passwd 5
.Sh HISTORY
A rotor-based
diff --git a/lib/libcrypt/crypt.c b/lib/libcrypt/crypt.c
index b949a48..bfcbb20 100644
--- a/lib/libcrypt/crypt.c
+++ b/lib/libcrypt/crypt.c
@@ -79,23 +79,23 @@ static const struct {
}
};
+#ifdef HAS_DES
+#define CRYPT_DEFAULT "des"
+#else
+#define CRYPT_DEFAULT "md5"
+#endif
+
static int crypt_type = -1;
static void
crypt_setdefault(void)
{
- char *def;
size_t i;
if (crypt_type != -1)
return;
- def = auth_getval("crypt_default");
- if (def == NULL) {
- crypt_type = 0;
- return;
- }
for (i = 0; i < sizeof(crypt_types) / sizeof(crypt_types[0]) - 1; i++) {
- if (strcmp(def, crypt_types[i].name) == 0) {
+ if (strcmp(CRYPT_DEFAULT, crypt_types[i].name) == 0) {
crypt_type = (int)i;
return;
}
diff --git a/lib/libcxxrt/Makefile b/lib/libcxxrt/Makefile
index e710546..d197361 100644
--- a/lib/libcxxrt/Makefile
+++ b/lib/libcxxrt/Makefile
@@ -1,26 +1,26 @@
# $FreeBSD$
-SRCDIR= ${.CURDIR}/../../contrib/libcxxrt
+SRCDIR= ${.CURDIR}/../../contrib/libcxxrt
-SHLIB_MAJOR= 1
-SHLIBDIR?= /lib
+SHLIB_MAJOR= 1
+SHLIBDIR?= /lib
.PATH: ${SRCDIR}
-LIB= cxxrt
+LIB= cxxrt
-SRCS+= libelftc_dem_gnu3.c\
- terminate.cc\
- dynamic_cast.cc\
- memory.cc\
- auxhelper.cc\
- exception.cc\
- stdexcept.cc\
- typeinfo.cc\
- guard.cc
+SRCS+= libelftc_dem_gnu3.c\
+ terminate.cc\
+ dynamic_cast.cc\
+ memory.cc\
+ auxhelper.cc\
+ exception.cc\
+ stdexcept.cc\
+ typeinfo.cc\
+ guard.cc
-WARNS= 0
-CFLAGS+= -I${SRCDIR}
-VERSION_MAP= ${.CURDIR}/Version.map
+WARNS= 0
+CFLAGS+= -I${SRCDIR}
+VERSION_MAP= ${.CURDIR}/Version.map
.include <bsd.lib.mk>
diff --git a/lib/libcxxrt/Version.map b/lib/libcxxrt/Version.map
index b5be60e..ca990a0 100644
--- a/lib/libcxxrt/Version.map
+++ b/lib/libcxxrt/Version.map
@@ -306,11 +306,6 @@ CXXRT_1.0 {
"std::type_info::__is_pointer_p() const";
- "operator delete[](void*)";
- "operator delete(void*)";
- "operator new[](unsigned long)";
- "operator new(unsigned long)";
- "operator new(unsigned long, std::nothrow_t const&)";
};
__cxa_allocate_dependent_exception;
@@ -321,3 +316,16 @@ CXXRT_1.0 {
__cxa_rethrow_primary_exception;
} CXXABI_1.3.1;
+
+GLIBCXX_3.4 {
+ extern "C++" {
+ "operator delete[](void*)";
+ "operator delete(void*)";
+ "operator new[](unsigned int)";
+ "operator new(unsigned int)";
+ "operator new(unsigned int, std::nothrow_t const&)";
+ "operator new[](unsigned long)";
+ "operator new(unsigned long)";
+ "operator new(unsigned long, std::nothrow_t const&)";
+ };
+};
diff --git a/lib/libedit/chared.c b/lib/libedit/chared.c
index ffaaaa7..6a4f3f6 100644
--- a/lib/libedit/chared.c
+++ b/lib/libedit/chared.c
@@ -29,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $NetBSD: chared.c,v 1.25 2005/08/08 01:41:30 christos Exp $
+ * $NetBSD: chared.c,v 1.27 2009/02/15 21:55:23 christos Exp $
*/
#if !defined(lint) && !defined(SCCSID)
@@ -59,12 +59,12 @@ cv_undo(EditLine *el)
{
c_undo_t *vu = &el->el_chared.c_undo;
c_redo_t *r = &el->el_chared.c_redo;
- unsigned int size;
+ size_t size;
/* Save entire line for undo */
size = el->el_line.lastchar - el->el_line.buffer;
vu->len = size;
- vu->cursor = el->el_line.cursor - el->el_line.buffer;
+ vu->cursor = (int)(el->el_line.cursor - el->el_line.buffer);
memcpy(vu->buf, el->el_line.buffer, size);
/* save command info for redo */
@@ -83,7 +83,7 @@ cv_yank(EditLine *el, const char *ptr, int size)
{
c_kill_t *k = &el->el_chared.c_kill;
- memcpy(k->buf, ptr, size +0u);
+ memcpy(k->buf, ptr, (size_t)size);
k->last = k->buf + size;
}
@@ -97,7 +97,7 @@ c_insert(EditLine *el, int num)
char *cp;
if (el->el_line.lastchar + num >= el->el_line.limit) {
- if (!ch_enlargebufs(el, num +0u))
+ if (!ch_enlargebufs(el, (size_t)num))
return; /* can't go past end of buffer */
}
@@ -118,7 +118,7 @@ c_delafter(EditLine *el, int num)
{
if (el->el_line.cursor + num > el->el_line.lastchar)
- num = el->el_line.lastchar - el->el_line.cursor;
+ num = (int)(el->el_line.lastchar - el->el_line.cursor);
if (el->el_map.current != el->el_map.emacs) {
cv_undo(el);
@@ -159,7 +159,7 @@ c_delbefore(EditLine *el, int num)
{
if (el->el_line.cursor - num < el->el_line.buffer)
- num = el->el_line.cursor - el->el_line.buffer;
+ num = (int)(el->el_line.cursor - el->el_line.buffer);
if (el->el_map.current != el->el_map.emacs) {
cv_undo(el);
@@ -375,7 +375,7 @@ cv_delfini(EditLine *el)
/* sanity */
return;
- size = el->el_line.cursor - el->el_chared.c_vcmd.pos;
+ size = (int)(el->el_line.cursor - el->el_chared.c_vcmd.pos);
if (size == 0)
size = 1;
el->el_line.cursor = el->el_chared.c_vcmd.pos;
@@ -529,8 +529,7 @@ ch_reset(EditLine *el, int mclear)
}
private void
-ch__clearmacro(el)
- EditLine *el;
+ch__clearmacro(EditLine *el)
{
c_macro_t *ma = &el->el_chared.c_macro;
while (ma->level >= 0)
@@ -542,9 +541,7 @@ ch__clearmacro(el)
* Returns 1 if successful, 0 if not.
*/
protected int
-ch_enlargebufs(el, addlen)
- EditLine *el;
- size_t addlen;
+ch_enlargebufs(EditLine *el, size_t addlen)
{
size_t sz, newsz;
char *newbuffer, *oldbuf, *oldkbuf;
@@ -695,12 +692,12 @@ protected int
c_gets(EditLine *el, char *buf, const char *prompt)
{
char ch;
- int len;
+ ssize_t len;
char *cp = el->el_line.buffer;
if (prompt) {
len = strlen(prompt);
- memcpy(cp, prompt, len + 0u);
+ memcpy(cp, prompt, (size_t)len);
cp += len;
}
len = 0;
@@ -721,7 +718,7 @@ c_gets(EditLine *el, char *buf, const char *prompt)
case '\010': /* Delete and backspace */
case '\177':
- if (len <= 0) {
+ if (len == 0) {
len = -1;
break;
}
@@ -749,7 +746,7 @@ c_gets(EditLine *el, char *buf, const char *prompt)
el->el_line.buffer[0] = '\0';
el->el_line.lastchar = el->el_line.buffer;
el->el_line.cursor = el->el_line.buffer;
- return len;
+ return (int)len;
}
@@ -771,6 +768,6 @@ c_hpos(EditLine *el)
ptr >= el->el_line.buffer && *ptr != '\n';
ptr--)
continue;
- return (el->el_line.cursor - ptr - 1);
+ return (int)(el->el_line.cursor - ptr - 1);
}
}
diff --git a/lib/libedit/chared.h b/lib/libedit/chared.h
index 6636fc7..153fceb 100644
--- a/lib/libedit/chared.h
+++ b/lib/libedit/chared.h
@@ -30,7 +30,7 @@
* SUCH DAMAGE.
*
* @(#)chared.h 8.1 (Berkeley) 6/4/93
- * $NetBSD: chared.h,v 1.17 2006/03/06 21:11:56 christos Exp $
+ * $NetBSD: chared.h,v 1.18 2009/02/15 21:55:23 christos Exp $
* $FreeBSD$
*/
@@ -70,7 +70,7 @@ typedef struct c_macro_t {
* Undo information for vi - no undo in emacs (yet)
*/
typedef struct c_undo_t {
- int len; /* length of saved line */
+ ssize_t len; /* length of saved line */
int cursor; /* position of saved cursor */
char *buf; /* full saved text */
} c_undo_t;
diff --git a/lib/libedit/common.c b/lib/libedit/common.c
index d314eef..0599554 100644
--- a/lib/libedit/common.c
+++ b/lib/libedit/common.c
@@ -905,7 +905,7 @@ ed_command(EditLine *el, int c __unused)
int tmplen;
tmplen = c_gets(el, tmpbuf, "\n: ");
- term__putc('\n');
+ term__putc(el, '\n');
if (tmplen < 0 || (tmpbuf[tmplen] = 0, parse_line(el, tmpbuf)) == -1)
term_beep(el);
diff --git a/lib/libedit/editline.3 b/lib/libedit/editline.3
index 9661d66..dd4c874 100644
--- a/lib/libedit/editline.3
+++ b/lib/libedit/editline.3
@@ -1,4 +1,4 @@
-.\" $NetBSD: editline.3,v 1.55 2007/01/12 16:31:13 christos Exp $
+.\" $NetBSD: editline.3,v 1.70 2009/07/05 21:55:24 perry Exp $
.\"
.\" Copyright (c) 1997-2003 The NetBSD Foundation, Inc.
.\" All rights reserved.
@@ -28,7 +28,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd January 12, 2007
+.Dd July 5, 2009
.Dt EDITLINE 3
.Os
.Sh NAME
@@ -162,6 +162,9 @@ is modified to contain the number of characters read.
Returns the line read if successful, or
.Dv NULL
if no characters were read or if an error occurred.
+The return value may not remain valid across calls to
+.Fn el_gets
+and must be copied if the data is to be retained.
.It Fn el_getc
Read a character from the tty.
.Fa ch
@@ -222,10 +225,30 @@ are supported, along with the required argument list:
Define prompt printing function as
.Fa f ,
which is to return a string that contains the prompt.
+.It Dv EL_PROMPT_ESC , Fa "char *(*f)(EditLine *)" , Fa "char c"
+Same as
+.Dv EL_PROMPT ,
+but the
+.Fa c
+argument indicates the start/stop literal prompt character.
+.Pp
+If a start/stop literal character is found in the prompt, the
+character itself
+is not printed, but characters after it are printed directly to the
+terminal without affecting the state of the current line.
+A subsequent second start/stop literal character ends this behavior.
+This is typically used to embed literal escape sequences that change the
+color/style of the terminal in the prompt.
+.Dv 0
+unsets it.
+.It Dv EL_REFRESH
+Re-display the current line on the next terminal line.
.It Dv EL_RPROMPT , Fa "char *(*f)(EditLine *)"
Define right side prompt printing function as
.Fa f ,
which is to return a string that contains the prompt.
+.It Dv EL_RPROMPT_ESC , Fa "char *(*f)(EditLine *)" , Fa "char c"
+Define the right prompt printing function but with a literal escape character.
.It Dv EL_TERMINAL , Fa "const char *type"
Define terminal type of the tty to be
.Fa type ,
@@ -259,66 +282,43 @@ reading command input:
and
.Dv SIGWINCH .
Otherwise, the current signal handlers will be used.
-.It Dv EL_BIND , Xo
-.Fa "const char *" ,
-.Fa "..." ,
-.Dv NULL
-.Xc
+.It Dv EL_BIND , Fa "const char *" , Fa "..." , Dv NULL
Perform the
.Ic bind
builtin command.
Refer to
.Xr editrc 5
for more information.
-.It Dv EL_ECHOTC , Xo
-.Fa "const char *" ,
-.Fa "..." ,
-.Dv NULL
-.Xc
+.It Dv EL_ECHOTC , Fa "const char *" , Fa "..." , Dv NULL
Perform the
.Ic echotc
builtin command.
Refer to
.Xr editrc 5
for more information.
-.It Dv EL_SETTC , Xo
-.Fa "const char *" ,
-.Fa "..." ,
-.Dv NULL
-.Xc
+.It Dv EL_SETTC , Fa "const char *" , Fa "..." , Dv NULL
Perform the
.Ic settc
builtin command.
Refer to
.Xr editrc 5
for more information.
-.It Dv EL_SETTY , Xo
-.Fa "const char *" ,
-.Fa "..." ,
-.Dv NULL
-.Xc
+.It Dv EL_SETTY , Fa "const char *" , Fa "..." , Dv NULL
Perform the
.Ic setty
builtin command.
Refer to
.Xr editrc 5
for more information.
-.It Dv EL_TELLTC , Xo
-.Fa "const char *" ,
-.Fa "..." ,
-.Dv NULL
-.Xc
+.It Dv EL_TELLTC , Fa "const char *" , Fa "..." , Dv NULL
Perform the
.Ic telltc
builtin command.
Refer to
.Xr editrc 5
for more information.
-.It Dv EL_ADDFN , Xo
-.Fa "const char *name" ,
-.Fa "const char *help" ,
-.Fa "unsigned char (*func)(EditLine *e, int ch)"
-.Xc
+.It Dv EL_ADDFN , Fa "const char *name" , Fa "const char *help" , \
+Fa "unsigned char (*func)(EditLine *e, int ch)"
Add a user defined function,
.Fn func ,
referred to as
@@ -360,10 +360,8 @@ Beep, and flush tty.
.It Dv CC_FATAL
Fatal error, reset tty to known state.
.El
-.It Dv EL_HIST , Xo
-.Fa "History *(*func)(History *, int op, ...)" ,
-.Fa "const char *ptr"
-.Xc
+.It Dv EL_HIST , Fa "History *(*func)(History *, int op, ...)" , \
+Fa "const char *ptr"
Defines which history function to use, which is usually
.Fn history .
.Fa ptr
@@ -435,10 +433,22 @@ The following values for
are supported, along with actual type of
.Fa result :
.Bl -tag -width 4n
-.It Dv EL_PROMPT , Fa "char *(*f)(EditLine *)"
-Return a pointer to the function that displays the prompt.
-.It Dv EL_RPROMPT , Fa "char *(*f)(EditLine *)"
-Return a pointer to the function that displays the rightside prompt.
+.It Dv EL_PROMPT , Fa "char *(*f)(EditLine *)" , Fa "char *c"
+Return a pointer to the function that displays the prompt in
+.Fa f .
+If
+.Fa c
+is not
+.Dv NULL ,
+return the start/stop literal prompt character in it.
+.It Dv EL_RPROMPT , Fa "char *(*f)(EditLine *)" , Fa "char *c"
+Return a pointer to the function that displays the prompt in
+.Fa f .
+If
+.Fa c
+is not
+.Dv NULL ,
+return the start/stop literal prompt character in it.
.It Dv EL_EDITOR , Fa "const char *"
Return the name of the editor, which will be one of
.Dq emacs
@@ -603,18 +613,11 @@ assumed to be created with
.Fn history_init .
.It Dv H_CLEAR
Clear the history.
-.It Dv H_FUNC , Xo
-.Fa "void *ptr" ,
-.Fa "history_gfun_t first" ,
-.Fa "history_gfun_t next" ,
-.Fa "history_gfun_t last" ,
-.Fa "history_gfun_t prev" ,
-.Fa "history_gfun_t curr" ,
-.Fa "history_sfun_t set" ,
-.Fa "history_vfun_t clear" ,
-.Fa "history_efun_t enter" ,
-.Fa "history_efun_t add"
-.Xc
+.It Dv H_FUNC , Fa "void *ptr" , Fa "history_gfun_t first" , \
+Fa "history_gfun_t next" , Fa "history_gfun_t last" , \
+Fa "history_gfun_t prev" , Fa "history_gfun_t curr" , \
+Fa "history_sfun_t set" , Fa "history_vfun_t clear" , \
+Fa "history_efun_t enter" , Fa "history_efun_t add"
Define functions to perform various history operations.
.Fa ptr
is the argument given to a function when it is invoked.
diff --git a/lib/libedit/editrc.5 b/lib/libedit/editrc.5
index 2fa1a63..f46b874 100644
--- a/lib/libedit/editrc.5
+++ b/lib/libedit/editrc.5
@@ -1,4 +1,4 @@
-.\" $NetBSD: editrc.5,v 1.20 2006/08/21 12:45:30 christos Exp $
+.\" $NetBSD: editrc.5,v 1.24 2009/04/11 22:17:52 wiz Exp $
.\"
.\" Copyright (c) 1997-2000 The NetBSD Foundation, Inc.
.\" All rights reserved.
@@ -89,16 +89,8 @@ shell.
.Pp
The following builtin commands are available:
.Bl -tag -width 4n
-.It Ic bind Xo
-.Op Fl a
-.Op Fl e
-.Op Fl k
-.Op Fl l
-.Op Fl r
-.Op Fl s
-.Op Fl v
-.Op Ar key Op Ar command
-.Xc
+.It Ic bind Oo Fl a Oc Oo Fl e Oc Oo Fl k Oc Oo Fl l Oc Oo Fl r Oc \
+Oo Fl s Oc Oo Fl v Oc Oo Ar key Oo Ar command Oc Oc
Without options, list all bound keys, and the editor command to which
each is bound.
If
@@ -192,11 +184,7 @@ if it has any, notably
.Sq \e
and
.Sq ^ .
-.It Ic echotc Xo
-.Op Fl sv
-.Ar arg
-.Ar ...
-.Xc
+.It Ic echotc Oo Fl sv Oc Ar arg Ar ...
Exercise terminal capabilities given in
.Ar arg Ar ... .
If
@@ -252,16 +240,8 @@ to
as defined in
.Xr termcap 5 .
No sanity checking is done.
-.It Ic setty Xo
-.Op Fl a
-.Op Fl d
-.Op Fl q
-.Op Fl x
-.Op Ar +mode
-.Op Ar -mode
-.Op Ar mode
-.Op Ar char=c
-.Xc
+.It Ic setty Oo Fl a Oc Oo Fl d Oc Oo Fl q Oc Oo Fl x Oc Oo Ar +mode Oc \
+Oo Ar -mode Oc Oo Ar mode Oc Oo Ar char=c Oc
Control which tty modes that
.Nm
will not allow the user to change.
diff --git a/lib/libedit/el.c b/lib/libedit/el.c
index 3b4036f..8dcd698 100644
--- a/lib/libedit/el.c
+++ b/lib/libedit/el.c
@@ -29,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $NetBSD: el.c,v 1.44 2006/12/15 22:13:33 christos Exp $
+ * $NetBSD: el.c,v 1.55 2009/07/25 21:19:23 christos Exp $
*/
#if !defined(lint) && !defined(SCCSID)
@@ -48,6 +48,7 @@ __FBSDID("$FreeBSD$");
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
+#include <ctype.h>
#include "el.h"
#define HAVE_ISSETUGID
@@ -156,9 +157,21 @@ el_set(EditLine *el, int op, ...)
switch (op) {
case EL_PROMPT:
- case EL_RPROMPT:
- rv = prompt_set(el, va_arg(ap, el_pfunc_t), op);
+ case EL_RPROMPT: {
+ el_pfunc_t p = va_arg(ap, el_pfunc_t);
+
+ rv = prompt_set(el, p, 0, op);
break;
+ }
+
+ case EL_PROMPT_ESC:
+ case EL_RPROMPT_ESC: {
+ el_pfunc_t p = va_arg(ap, el_pfunc_t);
+ char c = va_arg(ap, int);
+
+ rv = prompt_set(el, p, c, op);
+ break;
+ }
case EL_TERMINAL:
rv = term_set(el, va_arg(ap, char *));
@@ -309,6 +322,12 @@ el_set(EditLine *el, int op, ...)
break;
}
+ case EL_REFRESH:
+ re_clear_display(el);
+ re_refresh(el);
+ term__flush(el);
+ break;
+
default:
rv = -1;
break;
@@ -335,9 +354,13 @@ el_get(EditLine *el, int op, ...)
switch (op) {
case EL_PROMPT:
- case EL_RPROMPT:
- rv = prompt_get(el, va_arg(ap, el_pfunc_t *), op);
+ case EL_RPROMPT: {
+ el_pfunc_t *p = va_arg(ap, el_pfunc_t *);
+ char *c = va_arg(ap, char *);
+
+ rv = prompt_get(el, p, c, op);
break;
+ }
case EL_EDITOR:
rv = map_get_editor(el, va_arg(ap, const char **));
@@ -364,7 +387,7 @@ el_get(EditLine *el, int op, ...)
char *argv[20];
int i;
- for (i = 1; i < sizeof(argv) / sizeof(argv[0]); i++)
+ for (i = 1; i < (int)(sizeof(argv) / sizeof(argv[0])); i++)
if ((argv[i] = va_arg(ap, char *)) == NULL)
break;
@@ -495,12 +518,14 @@ el_source(EditLine *el, const char *fname)
FILE *fp;
size_t len;
char *ptr;
+#ifdef HAVE_ISSETUGID
+ char path[MAXPATHLEN];
+#endif
fp = NULL;
if (fname == NULL) {
#ifdef HAVE_ISSETUGID
static const char elpath[] = "/.editrc";
- char path[MAXPATHLEN];
if (issetugid())
return (-1);
@@ -529,6 +554,13 @@ el_source(EditLine *el, const char *fname)
if (len > 0 && ptr[len - 1] == '\n')
--len;
ptr[len] = '\0';
+
+ /* loop until first non-space char or EOL */
+ while (*ptr != '\0' && isspace((unsigned char)*ptr))
+ ptr++;
+ if (*ptr == '#')
+ continue; /* ignore, this is a comment line */
+
if (parse_line(el, ptr) == -1) {
(void) fclose(fp);
return (-1);
diff --git a/lib/libedit/histedit.h b/lib/libedit/histedit.h
index 8417bb3..24af1d5 100644
--- a/lib/libedit/histedit.h
+++ b/lib/libedit/histedit.h
@@ -131,10 +131,10 @@ unsigned char _el_fn_sh_complete(EditLine *, int);
#define EL_GETCFN 13 /* , el_rfunc_t); */
#define EL_CLIENTDATA 14 /* , void *); */
#define EL_UNBUFFERED 15 /* , int); */
-#define EL_PREP_TERM 16 /* , int); */
+#define EL_PREP_TERM 16 /* , int); */
#define EL_GETTC 17 /* , const char *, ..., NULL); */
-#define EL_GETFP 18 /* , int, FILE **) */
-#define EL_SETFP 19 /* , int, FILE *) */
+#define EL_GETFP 18 /* , int, FILE **); */
+#define EL_SETFP 19 /* , int, FILE *); */
#define EL_REFRESH 20 /* , void); set */
#define EL_PROMPT_ESC 21 /* , prompt_func, Char); set/get */
#define EL_RPROMPT_ESC 22 /* , prompt_func, Char); set/get */
diff --git a/lib/libedit/history.c b/lib/libedit/history.c
index 76b3b07..8f30a05 100644
--- a/lib/libedit/history.c
+++ b/lib/libedit/history.c
@@ -29,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $NetBSD: history.c,v 1.32 2006/09/28 13:52:51 christos Exp $
+ * $NetBSD: history.c,v 1.34 2009/09/07 21:24:33 christos Exp $
*/
#if !defined(lint) && !defined(SCCSID)
@@ -116,6 +116,7 @@ private int history_prev_string(History *, HistEvent *, const char *);
*/
typedef struct hentry_t {
HistEvent ev; /* What we return */
+ void *data; /* data */
struct hentry_t *next; /* Next entry */
struct hentry_t *prev; /* Previous entry */
} hentry_t;
@@ -145,6 +146,9 @@ private int history_def_init(ptr_t *, HistEvent *, int);
private int history_def_insert(history_t *, HistEvent *, const char *);
private void history_def_delete(history_t *, HistEvent *, hentry_t *);
+private int history_deldata_nth(history_t *, HistEvent *, int, void **);
+private int history_set_nth(ptr_t, HistEvent *, int);
+
#define history_def_setsize(p, num)(void) (((history_t *)p)->max = (num))
#define history_def_getsize(p) (((history_t *)p)->cur)
#define history_def_getunique(p) (((((history_t *)p)->flags) & H_UNIQUE) != 0)
@@ -335,6 +339,31 @@ history_def_set(ptr_t p, HistEvent *ev, const int n)
}
+/* history_set_nth():
+ * Default function to set the current event in the history to the
+ * n-th one.
+ */
+private int
+history_set_nth(ptr_t p, HistEvent *ev, int n)
+{
+ history_t *h = (history_t *) p;
+
+ if (h->cur == 0) {
+ he_seterrev(ev, _HE_EMPTY_LIST);
+ return (-1);
+ }
+ for (h->cursor = h->list.prev; h->cursor != &h->list;
+ h->cursor = h->cursor->prev)
+ if (n-- <= 0)
+ break;
+ if (h->cursor == &h->list) {
+ he_seterrev(ev, _HE_NOT_FOUND);
+ return (-1);
+ }
+ return (0);
+}
+
+
/* history_def_add():
* Append string to element
*/
@@ -363,6 +392,24 @@ history_def_add(ptr_t p, HistEvent *ev, const char *str)
}
+private int
+history_deldata_nth(history_t *h, HistEvent *ev,
+ int num, void **data)
+{
+ if (history_set_nth(h, ev, num) != 0)
+ return (-1);
+ /* magic value to skip delete (just set to n-th history) */
+ if (data == (void **)-1)
+ return (0);
+ ev->str = strdup(h->cursor->ev.str);
+ ev->num = h->cursor->ev.num;
+ if (data)
+ *data = h->cursor->data;
+ history_def_delete(h, ev, h->cursor);
+ return (0);
+}
+
+
/* history_def_del():
* Delete element hp of the h list
*/
@@ -392,8 +439,11 @@ history_def_delete(history_t *h,
HistEventPrivate *evp = (void *)&hp->ev;
if (hp == &h->list)
abort();
- if (h->cursor == hp)
+ if (h->cursor == hp) {
h->cursor = hp->prev;
+ if (h->cursor == &h->list)
+ h->cursor = hp->next;
+ }
hp->prev->next = hp->next;
hp->next->prev = hp->prev;
h_free((ptr_t) evp->str);
@@ -416,6 +466,7 @@ history_def_insert(history_t *h, HistEvent *ev, const char *str)
h_free((ptr_t)h->cursor);
goto oomem;
}
+ h->cursor->data = NULL;
h->cursor->ev.num = ++h->eventid;
h->cursor->next = h->list.next;
h->cursor->prev = &h->list;
@@ -711,8 +762,8 @@ history_load(History *h, const char *fname)
(void) strunvis(ptr, line);
line[sz] = c;
if (HENTER(h, &ev, ptr) == -1) {
- h_free((ptr_t)ptr);
- return -1;
+ i = -1;
+ goto oomem;
}
}
oomem:
@@ -787,6 +838,23 @@ history_prev_event(History *h, HistEvent *ev, int num)
}
+private int
+history_next_evdata(History *h, HistEvent *ev, int num, void **d)
+{
+ int retval;
+
+ for (retval = HCURR(h, ev); retval != -1; retval = HPREV(h, ev))
+ if (num-- <= 0) {
+ if (d)
+ *d = ((history_t *)h->h_ref)->cursor->data;
+ return (0);
+ }
+
+ he_seterrev(ev, _HE_NOT_FOUND);
+ return (-1);
+}
+
+
/* history_next_event():
* Find the next event, with number given
*/
@@ -976,11 +1044,42 @@ history(History *h, HistEvent *ev, int fun, ...)
retval = 0;
break;
+ case H_NEXT_EVDATA:
+ {
+ int num = va_arg(va, int);
+ void **d = va_arg(va, void **);
+ retval = history_next_evdata(h, ev, num, d);
+ break;
+ }
+
+ case H_DELDATA:
+ {
+ int num = va_arg(va, int);
+ void **d = va_arg(va, void **);
+ retval = history_deldata_nth((history_t *)h->h_ref, ev, num, d);
+ break;
+ }
+
+ case H_REPLACE: /* only use after H_NEXT_EVDATA */
+ {
+ const char *line = va_arg(va, const char *);
+ void *d = va_arg(va, void *);
+ const char *s;
+ if(!line || !(s = strdup(line))) {
+ retval = -1;
+ break;
+ }
+ ((history_t *)h->h_ref)->cursor->ev.str = s;
+ ((history_t *)h->h_ref)->cursor->data = d;
+ retval = 0;
+ break;
+ }
+
default:
retval = -1;
he_seterrev(ev, _HE_UNKNOWN);
break;
}
va_end(va);
- return (retval);
+ return retval;
}
diff --git a/lib/libedit/key.c b/lib/libedit/key.c
index 0b9d05d..5a0b779 100644
--- a/lib/libedit/key.c
+++ b/lib/libedit/key.c
@@ -29,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $NetBSD: key.c,v 1.19 2006/03/23 20:22:51 christos Exp $
+ * $NetBSD: key.c,v 1.20 2009/02/15 21:55:23 christos Exp $
*/
#if !defined(lint) && !defined(SCCSID)
@@ -86,8 +86,8 @@ private void node__free(key_node_t *);
private void node__put(EditLine *, key_node_t *);
private int node__delete(EditLine *, key_node_t **, const char *);
private int node_lookup(EditLine *, const char *, key_node_t *,
- int);
-private int node_enum(EditLine *, key_node_t *, int);
+ size_t);
+private int node_enum(EditLine *, key_node_t *, size_t);
#define KEY_BUFSIZ EL_BUFSIZ
@@ -478,9 +478,9 @@ node__free(key_node_t *k)
* Print if last node
*/
private int
-node_lookup(EditLine *el, const char *str, key_node_t *ptr, int cnt)
+node_lookup(EditLine *el, const char *str, key_node_t *ptr, size_t cnt)
{
- int ncnt;
+ size_t ncnt;
if (ptr == NULL)
return (-1); /* cannot have null ptr */
@@ -493,7 +493,8 @@ node_lookup(EditLine *el, const char *str, key_node_t *ptr, int cnt)
/* If match put this char into el->el_key.buf. Recurse */
if (ptr->ch == *str) {
/* match found */
- ncnt = key__decode_char(el->el_key.buf, KEY_BUFSIZ, cnt,
+ ncnt = key__decode_char(el->el_key.buf,
+ (size_t)KEY_BUFSIZ, cnt,
(unsigned char) ptr->ch);
if (ptr->next != NULL)
/* not yet at leaf */
@@ -527,9 +528,9 @@ node_lookup(EditLine *el, const char *str, key_node_t *ptr, int cnt)
* Traverse the node printing the characters it is bound in buffer
*/
private int
-node_enum(EditLine *el, key_node_t *ptr, int cnt)
+node_enum(EditLine *el, key_node_t *ptr, size_t cnt)
{
- int ncnt;
+ size_t ncnt;
if (cnt >= KEY_BUFSIZ - 5) { /* buffer too small */
el->el_key.buf[++cnt] = '"';
@@ -547,7 +548,7 @@ node_enum(EditLine *el, key_node_t *ptr, int cnt)
return (-1);
}
/* put this char at end of str */
- ncnt = key__decode_char(el->el_key.buf, KEY_BUFSIZ, cnt,
+ ncnt = key__decode_char(el->el_key.buf, (size_t)KEY_BUFSIZ, cnt,
(unsigned char)ptr->ch);
if (ptr->next == NULL) {
/* print this key and function */
@@ -615,8 +616,8 @@ key_kprint(EditLine *el, const char *key, key_value_t *val, int ntype)
/* key__decode_char():
* Put a printable form of char in buf.
*/
-protected int
-key__decode_char(char *buf, int cnt, int off, int ch)
+protected size_t
+key__decode_char(char *buf, size_t cnt, size_t off, int ch)
{
char *sb = buf + off;
char *eb = buf + cnt;
@@ -626,7 +627,7 @@ key__decode_char(char *buf, int cnt, int off, int ch)
if (ch == 0) {
ADDC('^');
ADDC('@');
- return b - sb;
+ return (int)(b - sb);
}
if (iscntrl(ch)) {
ADDC('^');
@@ -648,15 +649,15 @@ key__decode_char(char *buf, int cnt, int off, int ch)
ADDC((((unsigned int) ch >> 3) & 7) + '0');
ADDC((ch & 7) + '0');
}
- return b - sb;
+ return (size_t)(b - sb);
}
/* key__decode_str():
* Make a printable version of the ey
*/
-protected int
-key__decode_str(const char *str, char *buf, int len, const char *sep)
+protected size_t
+key__decode_str(const char *str, char *buf, size_t len, const char *sep)
{
char *b = buf, *eb = b + len;
const char *p;
@@ -699,7 +700,7 @@ key__decode_str(const char *str, char *buf, int len, const char *sep)
}
done:
ADDC('\0');
- if (b - buf >= len)
+ if ((size_t)(b - buf) >= len)
buf[len - 1] = '\0';
- return b - buf;
+ return (size_t)(b - buf);
}
diff --git a/lib/libedit/key.h b/lib/libedit/key.h
index 3a21292..1997adc 100644
--- a/lib/libedit/key.h
+++ b/lib/libedit/key.h
@@ -76,8 +76,8 @@ protected int key_delete(EditLine *, const char *);
protected void key_print(EditLine *, const char *);
protected void key_kprint(EditLine *, const char *, key_value_t *,
int);
-protected int key__decode_str(const char *, char *, int,
+protected size_t key__decode_str(const char *, char *, size_t,
const char *);
-protected int key__decode_char(char *, int, int, int);
+protected size_t key__decode_char(char *, size_t, size_t, int);
#endif /* _h_el_key */
diff --git a/lib/libedit/prompt.c b/lib/libedit/prompt.c
index 3d72da7..76d2d64 100644
--- a/lib/libedit/prompt.c
+++ b/lib/libedit/prompt.c
@@ -85,14 +85,23 @@ prompt_print(EditLine *el, int op)
{
el_prompt_t *elp;
char *p;
+ int ignore = 0;
if (op == EL_PROMPT)
elp = &el->el_prompt;
else
elp = &el->el_rprompt;
- p = (elp->p_func) (el);
- while (*p)
- re_putc(el, *p++, 1);
+
+ for (p = (*elp->p_func)(el); *p; p++) {
+ if (elp->p_ignore == *p) {
+ ignore = !ignore;
+ continue;
+ }
+ if (ignore)
+ term__putc(el, *p);
+ else
+ re_putc(el, *p, 1);
+ }
elp->p_pos.v = el->el_refresh.r_cursor.v;
elp->p_pos.h = el->el_refresh.r_cursor.h;
@@ -109,10 +118,12 @@ prompt_init(EditLine *el)
el->el_prompt.p_func = prompt_default;
el->el_prompt.p_pos.v = 0;
el->el_prompt.p_pos.h = 0;
+ el->el_prompt.p_ignore = '\0';
el->el_rprompt.p_func = prompt_default_r;
el->el_rprompt.p_pos.v = 0;
el->el_rprompt.p_pos.h = 0;
- return (0);
+ el->el_rprompt.p_ignore = '\0';
+ return 0;
}
@@ -130,24 +141,29 @@ prompt_end(EditLine *el __unused)
* Install a prompt printing function
*/
protected int
-prompt_set(EditLine *el, el_pfunc_t prf, int op)
+prompt_set(EditLine *el, el_pfunc_t prf, char c, int op)
{
el_prompt_t *p;
- if (op == EL_PROMPT)
+ if (op == EL_PROMPT || op == EL_PROMPT_ESC)
p = &el->el_prompt;
else
p = &el->el_rprompt;
+
if (prf == NULL) {
- if (op == EL_PROMPT)
+ if (op == EL_PROMPT || op == EL_PROMPT_ESC)
p->p_func = prompt_default;
else
p->p_func = prompt_default_r;
} else
p->p_func = prf;
+
+ p->p_ignore = c;
+
p->p_pos.v = 0;
p->p_pos.h = 0;
- return (0);
+
+ return 0;
}
@@ -155,14 +171,22 @@ prompt_set(EditLine *el, el_pfunc_t prf, int op)
* Retrieve the prompt printing function
*/
protected int
-prompt_get(EditLine *el, el_pfunc_t *prf, int op)
+prompt_get(EditLine *el, el_pfunc_t *prf, char *c, int op)
{
+ el_prompt_t *p;
if (prf == NULL)
- return (-1);
+ return -1;
+
if (op == EL_PROMPT)
- *prf = el->el_prompt.p_func;
+ p = &el->el_prompt;
else
- *prf = el->el_rprompt.p_func;
- return (0);
+ p = &el->el_rprompt;
+
+ *prf = el->el_rprompt.p_func;
+
+ if (c)
+ *c = p->p_ignore;
+
+ return 0;
}
diff --git a/lib/libedit/prompt.h b/lib/libedit/prompt.h
index 6523add..fe69ca4 100644
--- a/lib/libedit/prompt.h
+++ b/lib/libedit/prompt.h
@@ -47,11 +47,13 @@ typedef char * (*el_pfunc_t)(EditLine*);
typedef struct el_prompt_t {
el_pfunc_t p_func; /* Function to return the prompt */
coord_t p_pos; /* position in the line after prompt */
+ char p_ignore; /* character to start/end literal
+*/
} el_prompt_t;
protected void prompt_print(EditLine *, int);
-protected int prompt_set(EditLine *, el_pfunc_t, int);
-protected int prompt_get(EditLine *, el_pfunc_t *, int);
+protected int prompt_set(EditLine *, el_pfunc_t, char, int);
+protected int prompt_get(EditLine *, el_pfunc_t *, char *, int);
protected int prompt_init(EditLine *);
protected void prompt_end(EditLine *);
diff --git a/lib/libedit/read.c b/lib/libedit/read.c
index 0caba5d..ea40e50 100644
--- a/lib/libedit/read.c
+++ b/lib/libedit/read.c
@@ -29,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $NetBSD: read.c,v 1.40 2007/03/01 21:41:45 christos Exp $
+ * $NetBSD: read.c,v 1.52 2009/07/22 15:57:00 christos Exp $
*/
#if !defined(lint) && !defined(SCCSID)
@@ -222,7 +222,7 @@ el_push(EditLine *el, const char *str)
ma->level--;
}
term_beep(el);
- term__flush();
+ term__flush(el);
}
@@ -286,7 +286,7 @@ read_getcmd(EditLine *el, el_action_t *cmdnum, char *ch)
private int
read_char(EditLine *el, char *cp)
{
- int num_read;
+ ssize_t num_read;
int tried = 0;
while ((num_read = read(el->el_infd, cp, 1)) == -1)
@@ -297,7 +297,7 @@ read_char(EditLine *el, char *cp)
return (-1);
}
- return (num_read);
+ return (int)num_read;
}
/* read_pop():
@@ -309,8 +309,9 @@ read_pop(c_macro_t *ma)
int i;
el_free(ma->macro[0]);
- for (i = ma->level--; i > 0; i--)
- ma->macro[i - 1] = ma->macro[i];
+ for (i = 0; i < ma->level; i++)
+ ma->macro[i] = ma->macro[i + 1];
+ ma->level--;
ma->offset = 0;
}
@@ -323,7 +324,7 @@ el_getc(EditLine *el, char *cp)
int num_read;
c_macro_t *ma = &el->el_chared.c_macro;
- term__flush();
+ term__flush(el);
for (;;) {
if (ma->level < 0) {
if (!read_preread(el))
@@ -382,7 +383,7 @@ read_prepare(EditLine *el)
re_refresh(el); /* print the prompt */
if (el->el_flags & UNBUFFERED)
- term__flush();
+ term__flush(el);
}
protected void
@@ -406,6 +407,8 @@ el_gets(EditLine *el, int *nread)
c_macro_t *ma = &el->el_chared.c_macro;
#endif /* FIONREAD */
+ *nread = 0;
+
if (el->el_flags & NO_TTY) {
char *cp = el->el_line.buffer;
size_t idx;
@@ -428,8 +431,8 @@ el_gets(EditLine *el, int *nread)
el->el_line.cursor = el->el_line.lastchar = cp;
*cp = '\0';
if (nread)
- *nread = el->el_line.cursor - el->el_line.buffer;
- return (el->el_line.buffer);
+ *nread = (int)(el->el_line.cursor - el->el_line.buffer);
+ return (*nread ? el->el_line.buffer : NULL);
}
@@ -459,7 +462,7 @@ el_gets(EditLine *el, int *nread)
else
cp = el->el_line.lastchar;
- term__flush();
+ term__flush(el);
while ((*el->el_read.read_char)(el, cp) == 1) {
/* make sure there is space next character */
@@ -469,8 +472,6 @@ el_gets(EditLine *el, int *nread)
break;
cp = &el->el_line.buffer[idx];
}
- if (*cp == 4) /* ought to be stty eof */
- break;
cp++;
crlf = cp[-1] == '\r' || cp[-1] == '\n';
if (el->el_flags & UNBUFFERED)
@@ -482,8 +483,8 @@ el_gets(EditLine *el, int *nread)
el->el_line.cursor = el->el_line.lastchar = cp;
*cp = '\0';
if (nread)
- *nread = el->el_line.cursor - el->el_line.buffer;
- return (el->el_line.buffer);
+ *nread = (int)(el->el_line.cursor - el->el_line.buffer);
+ return (*nread ? el->el_line.buffer : NULL);
}
for (num = OKCMD; num == OKCMD;) { /* while still editing this
@@ -499,7 +500,7 @@ el_gets(EditLine *el, int *nread)
#endif /* DEBUG_READ */
break;
}
- if ((unsigned int)cmdnum >= el->el_map.nfunc) { /* BUG CHECK command */
+ if ((unsigned int)cmdnum >= (unsigned int)el->el_map.nfunc) { /* BUG CHECK command */
#ifdef DEBUG_EDIT
(void) fprintf(el->el_errfile,
"ERROR: illegal command from key 0%o\r\n", ch);
@@ -581,7 +582,7 @@ el_gets(EditLine *el, int *nread)
break;
case CC_NEWLINE: /* normal end of line */
- num = el->el_line.lastchar - el->el_line.buffer;
+ num = (int)(el->el_line.lastchar - el->el_line.buffer);
break;
case CC_FATAL: /* fatal error, reset to known state */
@@ -602,7 +603,7 @@ el_gets(EditLine *el, int *nread)
"*** editor ERROR ***\r\n\n");
#endif /* DEBUG_READ */
term_beep(el);
- term__flush();
+ term__flush(el);
break;
}
el->el_state.argument = 1;
@@ -612,7 +613,7 @@ el_gets(EditLine *el, int *nread)
break;
}
- term__flush(); /* flush any buffered output */
+ term__flush(el); /* flush any buffered output */
/* make sure the tty is set up correctly */
if ((el->el_flags & UNBUFFERED) == 0) {
read_finish(el);
@@ -620,7 +621,8 @@ el_gets(EditLine *el, int *nread)
*nread = num;
} else {
if (nread)
- *nread = el->el_line.lastchar - el->el_line.buffer;
+ *nread =
+ (int)(el->el_line.lastchar - el->el_line.buffer);
}
return (num ? el->el_line.buffer : NULL);
}
diff --git a/lib/libedit/refresh.c b/lib/libedit/refresh.c
index 22e1de4..8fe8229 100644
--- a/lib/libedit/refresh.c
+++ b/lib/libedit/refresh.c
@@ -29,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $NetBSD: refresh.c,v 1.27 2005/11/09 22:11:10 christos Exp $
+ * $NetBSD: refresh.c,v 1.34 2009/12/28 22:15:36 christos Exp $
*/
#if !defined(lint) && !defined(SCCSID)
@@ -49,6 +49,7 @@ __FBSDID("$FreeBSD$");
#include "el.h"
+private void re_nextline(EditLine *);
private void re_addc(EditLine *, int);
private void re_update_line(EditLine *, char *, char *, int);
private void re_insert (EditLine *, char *, int, int, char *, int);
@@ -86,6 +87,37 @@ re_printstr(EditLine *el, const char *str, char *f, char *t)
#define ELRE_DEBUG(a, b)
#endif
+/* re_nextline():
+ * Move to the next line or scroll
+ */
+private void
+re_nextline(EditLine *el)
+{
+ el->el_refresh.r_cursor.h = 0; /* reset it. */
+
+ /*
+ * If we would overflow (input is longer than terminal size),
+ * emulate scroll by dropping first line and shuffling the rest.
+ * We do this via pointer shuffling - it's safe in this case
+ * and we avoid memcpy().
+ */
+ if (el->el_refresh.r_cursor.v + 1 >= el->el_term.t_size.v) {
+ int i, lins = el->el_term.t_size.v;
+ char *firstline = el->el_vdisplay[0];
+
+ for(i = 1; i < lins; i++)
+ el->el_vdisplay[i - 1] = el->el_vdisplay[i];
+
+ firstline[0] = '\0'; /* empty the string */
+ el->el_vdisplay[i - 1] = firstline;
+ } else
+ el->el_refresh.r_cursor.v++;
+
+ ELRE_ASSERT(el->el_refresh.r_cursor.v >= el->el_term.t_size.v,
+ (__F, "\r\nre_putc: overflow! r_cursor.v == %d > %d\r\n",
+ el->el_refresh.r_cursor.v, el->el_term.t_size.v),
+ abort());
+}
/* re_addc():
* Draw c, expanding tabs, control chars etc.
@@ -101,10 +133,8 @@ re_addc(EditLine *el, int c)
if (c == '\n') { /* expand the newline */
int oldv = el->el_refresh.r_cursor.v;
re_putc(el, '\0', 0); /* assure end of line */
- if (oldv == el->el_refresh.r_cursor.v) { /* XXX */
- el->el_refresh.r_cursor.h = 0; /* reset cursor pos */
- el->el_refresh.r_cursor.v++;
- }
+ if (oldv == el->el_refresh.r_cursor.v) /* XXX */
+ re_nextline(el);
return;
}
if (c == '\t') { /* expand the tab */
@@ -144,33 +174,12 @@ re_putc(EditLine *el, int c, int shift)
el->el_refresh.r_cursor.h++; /* advance to next place */
if (el->el_refresh.r_cursor.h >= el->el_term.t_size.h) {
- el->el_vdisplay[el->el_refresh.r_cursor.v][el->el_term.t_size.h] = '\0';
/* assure end of line */
- el->el_refresh.r_cursor.h = 0; /* reset it. */
-
- /*
- * If we would overflow (input is longer than terminal size),
- * emulate scroll by dropping first line and shuffling the rest.
- * We do this via pointer shuffling - it's safe in this case
- * and we avoid memcpy().
- */
- if (el->el_refresh.r_cursor.v + 1 >= el->el_term.t_size.v) {
- int i, lins = el->el_term.t_size.v;
- char *firstline = el->el_vdisplay[0];
-
- for(i=1; i < lins; i++)
- el->el_vdisplay[i-1] = el->el_vdisplay[i];
-
- firstline[0] = '\0'; /* empty the string */
- el->el_vdisplay[i-1] = firstline;
- } else
- el->el_refresh.r_cursor.v++;
-
- ELRE_ASSERT(el->el_refresh.r_cursor.v >= el->el_term.t_size.v,
- (__F, "\r\nre_putc: overflow! r_cursor.v == %d > %d\r\n",
- el->el_refresh.r_cursor.v, el->el_term.t_size.v),
- abort());
+ el->el_vdisplay[el->el_refresh.r_cursor.v][el->el_term.t_size.h]
+ = '\0';
+ re_nextline(el);
}
+
}
@@ -298,7 +307,7 @@ re_refresh(EditLine *el)
term_move_to_char(el, 0);
term_clear_EOL(el, (int) strlen(el->el_display[i]));
#ifdef DEBUG_REFRESH
- term_overwrite(el, "C\b", 2);
+ term_overwrite(el, "C\b", (size_t)2);
#endif /* DEBUG_REFRESH */
el->el_display[i][0] = '\0';
}
@@ -321,9 +330,9 @@ re_goto_bottom(EditLine *el)
{
term_move_to_line(el, el->el_refresh.r_oldcv);
- term__putc('\n');
+ term__putc(el, '\n');
re_clear_display(el);
- term__flush();
+ term__flush(el);
}
@@ -475,6 +484,7 @@ re_update_line(EditLine *el, char *old, char *new, int i)
char *ofd, *ols, *oe, *nfd, *nls, *ne;
char *osb, *ose, *nsb, *nse;
int fx, sx;
+ size_t len;
/*
* find first diff
@@ -601,12 +611,12 @@ re_update_line(EditLine *el, char *old, char *new, int i)
* fx is the number of characters we need to insert/delete: in the
* beginning to bring the two same begins together
*/
- fx = (nsb - nfd) - (osb - ofd);
+ fx = (int)((nsb - nfd) - (osb - ofd));
/*
* sx is the number of characters we need to insert/delete: in the
* end to bring the two same last parts together
*/
- sx = (nls - nse) - (ols - ose);
+ sx = (int)((nls - nse) - (ols - ose));
if (!EL_CAN_INSERT) {
if (fx > 0) {
@@ -655,8 +665,8 @@ re_update_line(EditLine *el, char *old, char *new, int i)
/*
* Now that we are done with pragmatics we recompute fx, sx
*/
- fx = (nsb - nfd) - (osb - ofd);
- sx = (nls - nse) - (ols - ose);
+ fx = (int)((nsb - nfd) - (osb - ofd));
+ sx = (int)((nls - nse) - (ols - ose));
ELRE_DEBUG(1, (__F, "fx %d, sx %d\n", fx, sx));
ELRE_DEBUG(1, (__F, "ofd %d, osb %d, ose %d, ols %d, oe %d\n",
@@ -739,7 +749,7 @@ re_update_line(EditLine *el, char *old, char *new, int i)
/*
* Move to the first char to insert, where the first diff is.
*/
- term_move_to_char(el, nfd - new);
+ term_move_to_char(el, (int)(nfd - new));
/*
* Check if we have stuff to keep at end
*/
@@ -752,20 +762,21 @@ re_update_line(EditLine *el, char *old, char *new, int i)
ELRE_DEBUG(!EL_CAN_INSERT, (__F,
"ERROR: cannot insert in early first diff\n"));
term_insertwrite(el, nfd, fx);
- re_insert(el, old, ofd - old,
+ re_insert(el, old, (int)(ofd - old),
el->el_term.t_size.h, nfd, fx);
}
/*
* write (nsb-nfd) - fx chars of new starting at
* (nfd + fx)
*/
- term_overwrite(el, nfd + fx, (nsb - nfd) - fx);
- re__strncopy(ofd + fx, nfd + fx,
- (size_t) ((nsb - nfd) - fx));
+ len = (size_t) ((nsb - nfd) - fx);
+ term_overwrite(el, (nfd + fx), len);
+ re__strncopy(ofd + fx, nfd + fx, len);
} else {
ELRE_DEBUG(1, (__F, "without anything to save\r\n"));
- term_overwrite(el, nfd, (nsb - nfd));
- re__strncopy(ofd, nfd, (size_t) (nsb - nfd));
+ len = (size_t)(nsb - nfd);
+ term_overwrite(el, nfd, len);
+ re__strncopy(ofd, nfd, len);
/*
* Done
*/
@@ -777,7 +788,7 @@ re_update_line(EditLine *el, char *old, char *new, int i)
/*
* move to the first char to delete where the first diff is
*/
- term_move_to_char(el, ofd - old);
+ term_move_to_char(el, (int)(ofd - old));
/*
* Check if we have stuff to save
*/
@@ -791,14 +802,15 @@ re_update_line(EditLine *el, char *old, char *new, int i)
ELRE_DEBUG(!EL_CAN_DELETE, (__F,
"ERROR: cannot delete in first diff\n"));
term_deletechars(el, -fx);
- re_delete(el, old, ofd - old,
+ re_delete(el, old, (int)(ofd - old),
el->el_term.t_size.h, -fx);
}
/*
* write (nsb-nfd) chars of new starting at nfd
*/
- term_overwrite(el, nfd, (nsb - nfd));
- re__strncopy(ofd, nfd, (size_t) (nsb - nfd));
+ len = (size_t) (nsb - nfd);
+ term_overwrite(el, nfd, len);
+ re__strncopy(ofd, nfd, len);
} else {
ELRE_DEBUG(1, (__F,
@@ -806,8 +818,9 @@ re_update_line(EditLine *el, char *old, char *new, int i)
/*
* write (nsb-nfd) chars of new starting at nfd
*/
- term_overwrite(el, nfd, (nsb - nfd));
- re_clear_eol(el, fx, sx, (oe - old) - (ne - new));
+ term_overwrite(el, nfd, (size_t)(nsb - nfd));
+ re_clear_eol(el, fx, sx,
+ (int)((oe - old) - (ne - new)));
/*
* Done
*/
@@ -826,7 +839,7 @@ re_update_line(EditLine *el, char *old, char *new, int i)
* fx is the number of characters inserted (+) or deleted (-)
*/
- term_move_to_char(el, (ose - old) + fx);
+ term_move_to_char(el, (int)((ose - old) + fx));
/*
* Check if we have stuff to save
*/
@@ -843,12 +856,13 @@ re_update_line(EditLine *el, char *old, char *new, int i)
/*
* write (nls-nse) chars of new starting at nse
*/
- term_overwrite(el, nse, (nls - nse));
+ term_overwrite(el, nse, (size_t)(nls - nse));
} else {
ELRE_DEBUG(1, (__F,
"but with nothing left to save\r\n"));
- term_overwrite(el, nse, (nls - nse));
- re_clear_eol(el, fx, sx, (oe - old) - (ne - new));
+ term_overwrite(el, nse, (size_t)(nls - nse));
+ re_clear_eol(el, fx, sx,
+ (int)((oe - old) - (ne - new)));
}
}
/*
@@ -858,7 +872,7 @@ re_update_line(EditLine *el, char *old, char *new, int i)
ELRE_DEBUG(1, (__F, "late first diff insert at %d...\r\n",
nfd - new));
- term_move_to_char(el, nfd - new);
+ term_move_to_char(el, (int)(nfd - new));
/*
* Check if we have stuff to keep at the end
*/
@@ -869,7 +883,7 @@ re_update_line(EditLine *el, char *old, char *new, int i)
* to zero above as a flag saying that we hadn't done
* an early first insert.
*/
- fx = (nsb - nfd) - (osb - ofd);
+ fx = (int)((nsb - nfd) - (osb - ofd));
if (fx > 0) {
/*
* insert fx chars of new starting at nfd
@@ -877,20 +891,21 @@ re_update_line(EditLine *el, char *old, char *new, int i)
ELRE_DEBUG(!EL_CAN_INSERT, (__F,
"ERROR: cannot insert in late first diff\n"));
term_insertwrite(el, nfd, fx);
- re_insert(el, old, ofd - old,
+ re_insert(el, old, (int)(ofd - old),
el->el_term.t_size.h, nfd, fx);
}
/*
* write (nsb-nfd) - fx chars of new starting at
* (nfd + fx)
*/
- term_overwrite(el, nfd + fx, (nsb - nfd) - fx);
- re__strncopy(ofd + fx, nfd + fx,
- (size_t) ((nsb - nfd) - fx));
+ len = (size_t) ((nsb - nfd) - fx);
+ term_overwrite(el, (nfd + fx), len);
+ re__strncopy(ofd + fx, nfd + fx, len);
} else {
ELRE_DEBUG(1, (__F, "without anything to save\r\n"));
- term_overwrite(el, nfd, (nsb - nfd));
- re__strncopy(ofd, nfd, (size_t) (nsb - nfd));
+ len = (size_t) (nsb - nfd);
+ term_overwrite(el, nfd, len);
+ re__strncopy(ofd, nfd, len);
}
}
/*
@@ -898,8 +913,8 @@ re_update_line(EditLine *el, char *old, char *new, int i)
*/
if (sx >= 0) {
ELRE_DEBUG(1, (__F,
- "second diff insert at %d...\r\n", nse - new));
- term_move_to_char(el, nse - new);
+ "second diff insert at %d...\r\n", (int)(nse - new)));
+ term_move_to_char(el, (int)(nse - new));
if (ols != oe) {
ELRE_DEBUG(1, (__F, "with stuff to keep at end\r\n"));
if (sx > 0) {
@@ -912,10 +927,11 @@ re_update_line(EditLine *el, char *old, char *new, int i)
* write (nls-nse) - sx chars of new starting at
* (nse + sx)
*/
- term_overwrite(el, nse + sx, (nls - nse) - sx);
+ term_overwrite(el, (nse + sx),
+ (size_t)((nls - nse) - sx));
} else {
ELRE_DEBUG(1, (__F, "without anything to save\r\n"));
- term_overwrite(el, nse, (nls - nse));
+ term_overwrite(el, nse, (size_t)(nls - nse));
/*
* No need to do a clear-to-end here because we were
@@ -974,34 +990,28 @@ re_refresh_cursor(EditLine *el)
/* do input buffer to el->el_line.cursor */
for (cp = el->el_line.buffer; cp < el->el_line.cursor; cp++) {
c = *cp;
- h++; /* all chars at least this long */
- if (c == '\n') {/* handle newline in data part too */
+ switch (c) {
+ case '\n': /* handle newline in data part too */
h = 0;
v++;
- } else {
- if (c == '\t') { /* if a tab, to next tab stop */
- while (h & 07) {
- h++;
- }
- } else if (iscntrl((unsigned char) c)) {
- /* if control char */
+ break;
+ case '\t': /* if a tab, to next tab stop */
+ while (++h & 07)
+ continue;
+ break;
+ default:
+ if (iscntrl((unsigned char) c))
+ h += 2; /* ^x */
+ else if (!isprint((unsigned char) c))
+ h += 4; /* octal \xxx */
+ else
h++;
- if (h > th) { /* if overflow, compensate */
- h = 1;
- v++;
- }
- } else if (!isprint((unsigned char) c)) {
- h += 3;
- if (h > th) { /* if overflow, compensate */
- h = h - th;
- v++;
- }
- }
+ break;
}
if (h >= th) { /* check, extra long tabs picked up here also */
- h = 0;
+ h -= th;
v++;
}
}
@@ -1009,7 +1019,7 @@ re_refresh_cursor(EditLine *el)
/* now go there */
term_move_to_line(el, v);
term_move_to_char(el, h);
- term__flush();
+ term__flush(el);
}
@@ -1020,7 +1030,7 @@ private void
re_fastputc(EditLine *el, int c)
{
- term__putc(c);
+ term__putc(el, c);
el->el_display[el->el_cursor.v][el->el_cursor.h++] = c;
if (el->el_cursor.h >= el->el_term.t_size.h) {
/* if we must overflow */
@@ -1036,23 +1046,23 @@ re_fastputc(EditLine *el, int c)
int i, lins = el->el_term.t_size.v;
char *firstline = el->el_display[0];
- for(i=1; i < lins; i++)
- el->el_display[i-1] = el->el_display[i];
+ for(i = 1; i < lins; i++)
+ el->el_display[i - 1] = el->el_display[i];
re__copy_and_pad(firstline, "", 0);
- el->el_display[i-1] = firstline;
+ el->el_display[i - 1] = firstline;
} else {
el->el_cursor.v++;
el->el_refresh.r_oldcv++;
}
if (EL_HAS_AUTO_MARGINS) {
if (EL_HAS_MAGIC_MARGINS) {
- term__putc(' ');
- term__putc('\b');
+ term__putc(el, ' ');
+ term__putc(el, '\b');
}
} else {
- term__putc('\r');
- term__putc('\n');
+ term__putc(el, '\r');
+ term__putc(el, '\n');
}
}
}
@@ -1092,7 +1102,7 @@ re_fastaddc(EditLine *el)
re_fastputc(el, (int)(((((unsigned int)c) >> 3) & 7) + '0'));
re_fastputc(el, (c & 7) + '0');
}
- term__flush();
+ term__flush(el);
}
@@ -1121,17 +1131,16 @@ re_clear_lines(EditLine *el)
if (EL_CAN_CEOL) {
int i;
- term_move_to_char(el, 0);
- for (i = 0; i <= el->el_refresh.r_oldcv; i++) {
+ for (i = el->el_refresh.r_oldcv; i >= 0; i--) {
/* for each line on the screen */
term_move_to_line(el, i);
+ term_move_to_char(el, 0);
term_clear_EOL(el, el->el_term.t_size.h);
}
- term_move_to_line(el, 0);
} else {
term_move_to_line(el, el->el_refresh.r_oldcv);
/* go to last line */
- term__putc('\r'); /* go to BOL */
- term__putc('\n'); /* go to new line */
+ term__putc(el, '\r'); /* go to BOL */
+ term__putc(el, '\n'); /* go to new line */
}
}
diff --git a/lib/libedit/search.c b/lib/libedit/search.c
index 991bad2..af3da8c 100644
--- a/lib/libedit/search.c
+++ b/lib/libedit/search.c
@@ -29,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $NetBSD: search.c,v 1.20 2004/11/04 01:16:03 christos Exp $
+ * $NetBSD: search.c,v 1.21 2009/02/15 21:55:23 christos Exp $
*/
#if !defined(lint) && !defined(SCCSID)
@@ -207,7 +207,7 @@ ce_inc_search(EditLine *el, int dir)
el_action_t ret = CC_NORM;
int ohisteventno = el->el_history.eventno;
- int oldpatlen = el->el_search.patlen;
+ size_t oldpatlen = el->el_search.patlen;
int newdir = dir;
int done, redo;
diff --git a/lib/libedit/sig.c b/lib/libedit/sig.c
index a895aea..218a32e 100644
--- a/lib/libedit/sig.c
+++ b/lib/libedit/sig.c
@@ -29,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $NetBSD: sig.c,v 1.11 2003/08/07 16:44:33 agc Exp $
+ * $NetBSD: sig.c,v 1.14 2009/02/18 15:04:40 christos Exp $
*/
#if !defined(lint) && !defined(SCCSID)
@@ -78,7 +78,7 @@ sig_handler(int signo)
tty_rawmode(sel);
if (ed_redisplay(sel, 0) == CC_REFRESH)
re_refresh(sel);
- term__flush();
+ term__flush(sel);
break;
case SIGWINCH:
@@ -94,7 +94,10 @@ sig_handler(int signo)
if (signo == sighdl[i])
break;
- (void) signal(signo, sel->el_signal[i]);
+ (void) sigaction(signo, &sel->el_signal->sig_action[i], NULL);
+ sel->el_signal->sig_action[i].sa_handler = SIG_ERR;
+ sel->el_signal->sig_action[i].sa_flags = 0;
+ sigemptyset(&sel->el_signal->sig_action[i].sa_mask);
(void) sigprocmask(SIG_SETMASK, &oset, NULL);
(void) kill(0, signo);
}
@@ -106,26 +109,29 @@ sig_handler(int signo)
protected int
sig_init(EditLine *el)
{
- int i;
- sigset_t nset, oset;
+ size_t i;
+ sigset_t *nset, oset;
- (void) sigemptyset(&nset);
-#define _DO(a) (void) sigaddset(&nset, a);
+ el->el_signal = el_malloc(sizeof(*el->el_signal));
+ if (el->el_signal == NULL)
+ return -1;
+
+ nset = &el->el_signal->sig_set;
+ (void) sigemptyset(nset);
+#define _DO(a) (void) sigaddset(nset, a);
ALLSIGS
#undef _DO
- (void) sigprocmask(SIG_BLOCK, &nset, &oset);
-
-#define SIGSIZE (sizeof(sighdl) / sizeof(sighdl[0]) * sizeof(el_signalhandler_t))
+ (void) sigprocmask(SIG_BLOCK, nset, &oset);
- el->el_signal = (el_signalhandler_t *) el_malloc(SIGSIZE);
- if (el->el_signal == NULL)
- return (-1);
- for (i = 0; sighdl[i] != -1; i++)
- el->el_signal[i] = SIG_ERR;
+ for (i = 0; sighdl[i] != -1; i++) {
+ el->el_signal->sig_action[i].sa_handler = SIG_ERR;
+ el->el_signal->sig_action[i].sa_flags = 0;
+ sigemptyset(&el->el_signal->sig_action[i].sa_mask);
+ }
(void) sigprocmask(SIG_SETMASK, &oset, NULL);
- return (0);
+ return 0;
}
@@ -147,20 +153,21 @@ sig_end(EditLine *el)
protected void
sig_set(EditLine *el)
{
- int i;
- sigset_t nset, oset;
+ size_t i;
+ sigset_t oset;
+ struct sigaction osa, nsa;
- (void) sigemptyset(&nset);
-#define _DO(a) (void) sigaddset(&nset, a);
- ALLSIGS
-#undef _DO
- (void) sigprocmask(SIG_BLOCK, &nset, &oset);
+ nsa.sa_handler = sig_handler;
+ sigemptyset(&nsa.sa_mask);
+
+ (void) sigprocmask(SIG_BLOCK, &el->el_signal->sig_set, &oset);
for (i = 0; sighdl[i] != -1; i++) {
- el_signalhandler_t s;
+ nsa.sa_flags = SIGINT ? 0 : SA_RESTART;
/* This could happen if we get interrupted */
- if ((s = signal(sighdl[i], sig_handler)) != sig_handler)
- el->el_signal[i] = s;
+ if (sigaction(sighdl[i], &nsa, &osa) != -1 &&
+ osa.sa_handler != sig_handler)
+ el->el_signal->sig_action[i] = osa;
}
sel = el;
(void) sigprocmask(SIG_SETMASK, &oset, NULL);
@@ -173,20 +180,17 @@ sig_set(EditLine *el)
protected void
sig_clr(EditLine *el)
{
- int i;
- sigset_t nset, oset;
+ size_t i;
+ sigset_t oset;
- (void) sigemptyset(&nset);
-#define _DO(a) (void) sigaddset(&nset, a);
- ALLSIGS
-#undef _DO
- (void) sigprocmask(SIG_BLOCK, &nset, &oset);
+ (void) sigprocmask(SIG_BLOCK, &el->el_signal->sig_set, &oset);
for (i = 0; sighdl[i] != -1; i++)
- if (el->el_signal[i] != SIG_ERR)
- (void) signal(sighdl[i], el->el_signal[i]);
+ if (el->el_signal->sig_action[i].sa_handler != SIG_ERR)
+ (void)sigaction(sighdl[i],
+ &el->el_signal->sig_action[i], NULL);
sel = NULL; /* we are going to die if the handler is
* called */
- (void) sigprocmask(SIG_SETMASK, &oset, NULL);
+ (void)sigprocmask(SIG_SETMASK, &oset, NULL);
}
diff --git a/lib/libedit/sig.h b/lib/libedit/sig.h
index b1ce14b..8773ddc 100644
--- a/lib/libedit/sig.h
+++ b/lib/libedit/sig.h
@@ -30,7 +30,7 @@
* SUCH DAMAGE.
*
* @(#)sig.h 8.1 (Berkeley) 6/4/93
- * $NetBSD: sig.h,v 1.5 2003/08/07 16:44:33 agc Exp $
+ * $NetBSD: sig.h,v 1.7 2009/02/15 21:25:01 christos Exp $
* $FreeBSD$
*/
@@ -51,15 +51,17 @@
#define ALLSIGS \
_DO(SIGINT) \
_DO(SIGTSTP) \
- _DO(SIGSTOP) \
_DO(SIGQUIT) \
_DO(SIGHUP) \
_DO(SIGTERM) \
_DO(SIGCONT) \
_DO(SIGWINCH)
+#define ALLSIGSNO 7
-typedef void (*el_signalhandler_t)(int);
-typedef el_signalhandler_t *el_signal_t;
+typedef struct {
+ struct sigaction sig_action[ALLSIGSNO];
+ sigset_t sig_set;
+} *el_signal_t;
protected void sig_end(EditLine*);
protected int sig_init(EditLine*);
diff --git a/lib/libedit/term.c b/lib/libedit/term.c
index 1d89279..4899193 100644
--- a/lib/libedit/term.c
+++ b/lib/libedit/term.c
@@ -29,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $NetBSD: term.c,v 1.46 2006/11/24 00:01:17 christos Exp $
+ * $NetBSD: term.c,v 1.56 2009/12/28 21:54:21 christos Exp $
*/
#if !defined(lint) && !defined(SCCSID)
@@ -261,9 +261,13 @@ private int term_alloc_display(EditLine *);
private void term_alloc(EditLine *, const struct termcapstr *, const char *);
private void term_init_arrow(EditLine *);
private void term_reset_arrow(EditLine *);
+private int term_putc(int);
+private void term_tputs(EditLine *, const char *, int);
-
-private FILE *term_outfile = NULL; /* XXX: How do we fix that? */
+#ifdef _REENTRANT
+private pthread_mutex_t term_mutex = PTHREAD_MUTEX_INITIALIZER;
+#endif
+private FILE *term_outfile = NULL;
/* term_setflags():
@@ -311,7 +315,6 @@ term_setflags(EditLine *el)
#endif /* DEBUG_SCREEN */
}
-
/* term_init():
* Initialize the terminal stuff
*/
@@ -337,7 +340,6 @@ term_init(EditLine *el)
if (el->el_term.t_val == NULL)
return (-1);
(void) memset(el->el_term.t_val, 0, T_val * sizeof(int));
- term_outfile = el->el_outfile;
term_init_arrow(el);
(void) term_set(el, NULL);
return (0);
@@ -372,7 +374,7 @@ private void
term_alloc(EditLine *el, const struct termcapstr *t, const char *cap)
{
char termbuf[TC_BUFSIZE];
- int tlen, clen;
+ size_t tlen, clen;
char **tlist = el->el_term.t_str;
char **tmp, **str = &tlist[t - tstr];
@@ -399,7 +401,7 @@ term_alloc(EditLine *el, const struct termcapstr *t, const char *cap)
/* XXX strcpy is safe */
(void) strcpy(*str = &el->el_term.t_buf[el->el_term.t_loc],
cap);
- el->el_term.t_loc += clen + 1; /* one for \0 */
+ el->el_term.t_loc += (int)clen + 1; /* one for \0 */
return;
}
/*
@@ -416,7 +418,7 @@ term_alloc(EditLine *el, const struct termcapstr *t, const char *cap)
termbuf[tlen++] = '\0';
}
memcpy(el->el_term.t_buf, termbuf, TC_BUFSIZE);
- el->el_term.t_loc = tlen;
+ el->el_term.t_loc = (int)tlen;
if (el->el_term.t_loc + 3 >= TC_BUFSIZE) {
(void) fprintf(el->el_errfile,
"Out of termcap string space.\n");
@@ -424,7 +426,7 @@ term_alloc(EditLine *el, const struct termcapstr *t, const char *cap)
}
/* XXX strcpy is safe */
(void) strcpy(*str = &el->el_term.t_buf[el->el_term.t_loc], cap);
- el->el_term.t_loc += clen + 1; /* one for \0 */
+ el->el_term.t_loc += (int)clen + 1; /* one for \0 */
return;
}
@@ -542,19 +544,20 @@ term_move_to_line(EditLine *el, int where)
el->el_display[el->el_cursor.v][0] != '\0') {
/* move without newline */
term_move_to_char(el, el->el_term.t_size.h - 1);
- term_overwrite(el,
- &el->el_display[el->el_cursor.v][el->el_cursor.h],
- 1);
+ term_overwrite(el, &el->el_display
+ [el->el_cursor.v][el->el_cursor.h],
+ (size_t)(el->el_term.t_size.h -
+ el->el_cursor.h));
/* updates Cursor */
del--;
} else {
if ((del > 1) && GoodStr(T_DO)) {
- (void) tputs(tgoto(Str(T_DO), del, del),
- del, term__putc);
+ term_tputs(el, tgoto(Str(T_DO), del,
+ del), del);
del = 0;
} else {
for (; del > 0; del--)
- term__putc('\n');
+ term__putc(el, '\n');
/* because the \n will become \r\n */
el->el_cursor.h = 0;
}
@@ -562,12 +565,11 @@ term_move_to_line(EditLine *el, int where)
}
} else { /* del < 0 */
if (GoodStr(T_UP) && (-del > 1 || !GoodStr(T_up)))
- (void) tputs(tgoto(Str(T_UP), -del, -del), -del,
- term__putc);
+ term_tputs(el, tgoto(Str(T_UP), -del, -del), -del);
else {
if (GoodStr(T_up))
for (; del < 0; del++)
- (void) tputs(Str(T_up), 1, term__putc);
+ term_tputs(el, Str(T_up), 1);
}
}
el->el_cursor.v = where;/* now where is here */
@@ -594,7 +596,7 @@ mc_again:
return;
}
if (!where) { /* if where is first column */
- term__putc('\r'); /* do a CR */
+ term__putc(el, '\r'); /* do a CR */
el->el_cursor.h = 0;
return;
}
@@ -602,25 +604,24 @@ mc_again:
if ((del < -4 || del > 4) && GoodStr(T_ch))
/* go there directly */
- (void) tputs(tgoto(Str(T_ch), where, where), where, term__putc);
+ term_tputs(el, tgoto(Str(T_ch), where, where), where);
else {
if (del > 0) { /* moving forward */
if ((del > 4) && GoodStr(T_RI))
- (void) tputs(tgoto(Str(T_RI), del, del),
- del, term__putc);
+ term_tputs(el, tgoto(Str(T_RI), del, del), del);
else {
/* if I can do tabs, use them */
if (EL_CAN_TAB) {
if ((el->el_cursor.h & 0370) !=
- (where & 0370)) {
+ (where & ~0x7)) {
/* if not within tab stop */
for (i =
(el->el_cursor.h & 0370);
- i < (where & 0370);
+ i < (where & ~0x7);
i += 8)
- term__putc('\t');
+ term__putc(el, '\t');
/* then tab over */
- el->el_cursor.h = where & 0370;
+ el->el_cursor.h = where & ~0x7;
}
}
/*
@@ -631,15 +632,15 @@ mc_again:
* NOTE THAT term_overwrite() WILL CHANGE
* el->el_cursor.h!!!
*/
- term_overwrite(el,
- &el->el_display[el->el_cursor.v][el->el_cursor.h],
- where - el->el_cursor.h);
+ term_overwrite(el, &el->el_display[
+ el->el_cursor.v][el->el_cursor.h],
+ (size_t)(where - el->el_cursor.h));
}
} else { /* del < 0 := moving backward */
if ((-del > 4) && GoodStr(T_LE))
- (void) tputs(tgoto(Str(T_LE), -del, -del),
- -del, term__putc);
+ term_tputs(el, tgoto(Str(T_LE), -del, -del),
+ -del);
else { /* can't go directly there */
/*
* if the "cost" is greater than the "cost"
@@ -650,12 +651,12 @@ mc_again:
(((unsigned int) where >> 3) +
(where & 07)))
: (-del > where)) {
- term__putc('\r'); /* do a CR */
+ term__putc(el, '\r'); /* do a CR */
el->el_cursor.h = 0;
goto mc_again; /* and try again */
}
for (i = 0; i < -del; i++)
- term__putc('\b');
+ term__putc(el, '\b');
}
}
}
@@ -667,20 +668,21 @@ mc_again:
* Overstrike num characters
*/
protected void
-term_overwrite(EditLine *el, const char *cp, int n)
+term_overwrite(EditLine *el, const char *cp, size_t n)
{
- if (n <= 0)
- return; /* catch bugs */
+ if (n == 0)
+ return;
- if (n > el->el_term.t_size.h) {
+ if (n > (size_t)el->el_term.t_size.h) {
#ifdef DEBUG_SCREEN
(void) fprintf(el->el_errfile,
"term_overwrite: n is riduculous: %d\r\n", n);
#endif /* DEBUG_SCREEN */
return;
}
+
do {
- term__putc(*cp++);
+ term__putc(el, *cp++);
el->el_cursor.h++;
} while (--n);
@@ -695,12 +697,13 @@ term_overwrite(EditLine *el, const char *cp, int n)
if ((c = el->el_display[el->el_cursor.v][el->el_cursor.h])
!= '\0')
term_overwrite(el, &c, 1);
- else
- term__putc(' ');
- el->el_cursor.h = 1;
+ else {
+ term__putc(el, ' ');
+ el->el_cursor.h = 1;
+ }
}
} else /* no wrap, but cursor stays on screen */
- el->el_cursor.h = el->el_term.t_size.h;
+ el->el_cursor.h = el->el_term.t_size.h - 1;
}
}
@@ -730,19 +733,18 @@ term_deletechars(EditLine *el, int num)
if (GoodStr(T_DC)) /* if I have multiple delete */
if ((num > 1) || !GoodStr(T_dc)) { /* if dc would be more
* expen. */
- (void) tputs(tgoto(Str(T_DC), num, num),
- num, term__putc);
+ term_tputs(el, tgoto(Str(T_DC), num, num), num);
return;
}
if (GoodStr(T_dm)) /* if I have delete mode */
- (void) tputs(Str(T_dm), 1, term__putc);
+ term_tputs(el, Str(T_dm), 1);
if (GoodStr(T_dc)) /* else do one at a time */
while (num--)
- (void) tputs(Str(T_dc), 1, term__putc);
+ term_tputs(el, Str(T_dc), 1);
if (GoodStr(T_ed)) /* if I have delete mode */
- (void) tputs(Str(T_ed), 1, term__putc);
+ term_tputs(el, Str(T_ed), 1);
}
@@ -771,37 +773,35 @@ term_insertwrite(EditLine *el, char *cp, int num)
if (GoodStr(T_IC)) /* if I have multiple insert */
if ((num > 1) || !GoodStr(T_ic)) {
/* if ic would be more expensive */
- (void) tputs(tgoto(Str(T_IC), num, num),
- num, term__putc);
- term_overwrite(el, cp, num);
+ term_tputs(el, tgoto(Str(T_IC), num, num), num);
+ term_overwrite(el, cp, (size_t)num);
/* this updates el_cursor.h */
return;
}
if (GoodStr(T_im) && GoodStr(T_ei)) { /* if I have insert mode */
- (void) tputs(Str(T_im), 1, term__putc);
+ term_tputs(el, Str(T_im), 1);
el->el_cursor.h += num;
do
- term__putc(*cp++);
+ term__putc(el, *cp++);
while (--num);
if (GoodStr(T_ip)) /* have to make num chars insert */
- (void) tputs(Str(T_ip), 1, term__putc);
+ term_tputs(el, Str(T_ip), 1);
- (void) tputs(Str(T_ei), 1, term__putc);
+ term_tputs(el, Str(T_ei), 1);
return;
}
do {
if (GoodStr(T_ic)) /* have to make num chars insert */
- (void) tputs(Str(T_ic), 1, term__putc);
- /* insert a char */
+ term_tputs(el, Str(T_ic), 1);
- term__putc(*cp++);
+ term__putc(el, *cp++);
el->el_cursor.h++;
if (GoodStr(T_ip)) /* have to make num chars insert */
- (void) tputs(Str(T_ip), 1, term__putc);
+ term_tputs(el, Str(T_ip), 1);
/* pad the inserted char */
} while (--num);
@@ -817,10 +817,10 @@ term_clear_EOL(EditLine *el, int num)
int i;
if (EL_CAN_CEOL && GoodStr(T_ce))
- (void) tputs(Str(T_ce), 1, term__putc);
+ term_tputs(el, Str(T_ce), 1);
else {
for (i = 0; i < num; i++)
- term__putc(' ');
+ term__putc(el, ' ');
el->el_cursor.h += num; /* have written num spaces */
}
}
@@ -835,14 +835,14 @@ term_clear_screen(EditLine *el)
if (GoodStr(T_cl))
/* send the clear screen code */
- (void) tputs(Str(T_cl), Val(T_li), term__putc);
+ term_tputs(el, Str(T_cl), Val(T_li));
else if (GoodStr(T_ho) && GoodStr(T_cd)) {
- (void) tputs(Str(T_ho), Val(T_li), term__putc); /* home */
+ term_tputs(el, Str(T_ho), Val(T_li)); /* home */
/* clear to bottom of screen */
- (void) tputs(Str(T_cd), Val(T_li), term__putc);
+ term_tputs(el, Str(T_cd), Val(T_li));
} else {
- term__putc('\r');
- term__putc('\n');
+ term__putc(el, '\r');
+ term__putc(el, '\n');
}
}
@@ -855,9 +855,9 @@ term_beep(EditLine *el)
{
if (GoodStr(T_bl))
/* what termcap says we should use */
- (void) tputs(Str(T_bl), 1, term__putc);
+ term_tputs(el, Str(T_bl), 1);
else
- term__putc('\007'); /* an ASCII bell; ^G */
+ term__putc(el, '\007'); /* an ASCII bell; ^G */
}
@@ -869,9 +869,9 @@ protected void
term_clear_to_bottom(EditLine *el)
{
if (GoodStr(T_cd))
- (void) tputs(Str(T_cd), Val(T_li), term__putc);
+ term_tputs(el, Str(T_cd), Val(T_li));
else if (GoodStr(T_ce))
- (void) tputs(Str(T_ce), Val(T_li), term__putc);
+ term_tputs(el, Str(T_ce), Val(T_li));
}
#endif
@@ -1238,26 +1238,49 @@ term_bind_arrow(EditLine *el)
}
}
+/* term_putc():
+ * Add a character
+ */
+private int
+term_putc(int c)
+{
+
+ if (term_outfile == NULL)
+ return -1;
+ return fputc(c, term_outfile);
+}
+
+private void
+term_tputs(EditLine *el, const char *cap, int affcnt)
+{
+#ifdef _REENTRANT
+ pthread_mutex_lock(&term_mutex);
+#endif
+ term_outfile = el->el_outfile;
+ (void)tputs(cap, affcnt, term_putc);
+#ifdef _REENTRANT
+ pthread_mutex_unlock(&term_mutex);
+#endif
+}
/* term__putc():
* Add a character
*/
protected int
-term__putc(int c)
+term__putc(EditLine *el, int c)
{
- return (fputc(c, term_outfile));
+ return fputc(c, el->el_outfile);
}
-
/* term__flush():
* Flush output
*/
protected void
-term__flush(void)
+term__flush(EditLine *el)
{
- (void) fflush(term_outfile);
+ (void) fflush(el->el_outfile);
}
/* term_writec():
@@ -1267,10 +1290,10 @@ protected void
term_writec(EditLine *el, int c)
{
char buf[8];
- int cnt = key__decode_char(buf, sizeof(buf), 0, c);
+ size_t cnt = key__decode_char(buf, sizeof(buf), 0, c);
buf[cnt] = '\0';
- term_overwrite(el, buf, cnt);
- term__flush();
+ term_overwrite(el, buf, (size_t)cnt);
+ term__flush(el);
}
@@ -1585,7 +1608,7 @@ term_echotc(EditLine *el, int argc __unused,
*argv);
return (-1);
}
- (void) tputs(scap, 1, term__putc);
+ term_tputs(el, scap, 1);
break;
case 1:
argv++;
@@ -1613,7 +1636,7 @@ term_echotc(EditLine *el, int argc __unused,
*argv);
return (-1);
}
- (void) tputs(tgoto(scap, arg_cols, arg_rows), 1, term__putc);
+ term_tputs(el, tgoto(scap, arg_cols, arg_rows), 1);
break;
default:
/* This is wrong, but I will ignore it... */
@@ -1669,8 +1692,7 @@ term_echotc(EditLine *el, int argc __unused,
*argv);
return (-1);
}
- (void) tputs(tgoto(scap, arg_cols, arg_rows), arg_rows,
- term__putc);
+ term_tputs(el, tgoto(scap, arg_cols, arg_rows), arg_rows);
break;
}
return (0);
diff --git a/lib/libedit/term.h b/lib/libedit/term.h
index 15d393c..4bf4685 100644
--- a/lib/libedit/term.h
+++ b/lib/libedit/term.h
@@ -85,7 +85,7 @@ typedef struct {
protected void term_move_to_line(EditLine *, int);
protected void term_move_to_char(EditLine *, int);
protected void term_clear_EOL(EditLine *, int);
-protected void term_overwrite(EditLine *, const char *, int);
+protected void term_overwrite(EditLine *, const char *, size_t);
protected void term_insertwrite(EditLine *, char *, int);
protected void term_deletechars(EditLine *, int);
protected void term_clear_screen(EditLine *);
@@ -105,8 +105,8 @@ protected int term_gettc(EditLine *, int, char **);
protected int term_telltc(EditLine *, int, const char **);
protected int term_echotc(EditLine *, int, const char **);
protected void term_writec(EditLine *, int);
-protected int term__putc(int);
-protected void term__flush(void);
+protected int term__putc(EditLine *, int);
+protected void term__flush(EditLine *);
/*
* Easy access macros
diff --git a/lib/libedit/tty.c b/lib/libedit/tty.c
index fca3c2b..c0b4638 100644
--- a/lib/libedit/tty.c
+++ b/lib/libedit/tty.c
@@ -29,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $NetBSD: tty.c,v 1.24 2006/03/18 09:07:05 christos Exp $
+ * $NetBSD: tty.c,v 1.25 2006/03/18 09:09:41 christos Exp $
*/
#if !defined(lint) && !defined(SCCSID)
diff --git a/lib/libedit/vi.c b/lib/libedit/vi.c
index ae57e07..4826901 100644
--- a/lib/libedit/vi.c
+++ b/lib/libedit/vi.c
@@ -29,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $NetBSD: vi.c,v 1.25 2006/03/06 21:11:56 christos Exp $
+ * $NetBSD: vi.c,v 1.30 2009/02/21 23:31:56 christos Exp $
*/
#if !defined(lint) && !defined(SCCSID)
@@ -63,7 +63,7 @@ cv_action(EditLine *el, int c)
if (!(c & YANK))
cv_undo(el);
cv_yank(el, el->el_line.buffer,
- el->el_line.lastchar - el->el_line.buffer);
+ (int)(el->el_line.lastchar - el->el_line.buffer));
el->el_chared.c_vcmd.action = NOP;
el->el_chared.c_vcmd.pos = 0;
if (!(c & YANK)) {
@@ -87,12 +87,12 @@ private el_action_t
cv_paste(EditLine *el, int c)
{
c_kill_t *k = &el->el_chared.c_kill;
- int len = k->last - k->buf;
+ size_t len = (size_t)(k->last - k->buf);
if (k->buf == NULL || len == 0)
return (CC_ERROR);
#ifdef DEBUG_PASTE
- (void) fprintf(el->el_errfile, "Paste: \"%.*s\"\n", len, k->buf);
+ (void) fprintf(el->el_errfile, "Paste: \"%.*s\"\n", (int)len, k->buf);
#endif
cv_undo(el);
@@ -100,10 +100,10 @@ cv_paste(EditLine *el, int c)
if (!c && el->el_line.cursor < el->el_line.lastchar)
el->el_line.cursor++;
- c_insert(el, len);
+ c_insert(el, (int)len);
if (el->el_line.cursor + len > el->el_line.lastchar)
return (CC_ERROR);
- (void) memcpy(el->el_line.cursor, k->buf, len +0u);
+ (void) memcpy(el->el_line.cursor, k->buf, len);
return (CC_REFRESH);
}
@@ -358,7 +358,7 @@ vi_substitute_line(EditLine *el, int c __unused)
cv_undo(el);
cv_yank(el, el->el_line.buffer,
- el->el_line.lastchar - el->el_line.buffer);
+ (int)(el->el_line.lastchar - el->el_line.buffer));
(void) em_kill_line(el, 0);
el->el_map.current = el->el_map.key;
return (CC_REFRESH);
@@ -376,7 +376,7 @@ vi_change_to_eol(EditLine *el, int c __unused)
cv_undo(el);
cv_yank(el, el->el_line.cursor,
- el->el_line.lastchar - el->el_line.cursor);
+ (int)(el->el_line.lastchar - el->el_line.cursor));
(void) ed_kill_line(el, 0);
el->el_map.current = el->el_map.key;
return (CC_REFRESH);
@@ -516,7 +516,8 @@ vi_undo(EditLine *el, int c __unused)
/* switch line buffer and undo buffer */
el->el_chared.c_undo.buf = el->el_line.buffer;
el->el_chared.c_undo.len = el->el_line.lastchar - el->el_line.buffer;
- el->el_chared.c_undo.cursor = el->el_line.cursor - el->el_line.buffer;
+ el->el_chared.c_undo.cursor =
+ (int)(el->el_line.cursor - el->el_line.buffer);
el->el_line.limit = un.buf + (el->el_line.limit - el->el_line.buffer);
el->el_line.buffer = un.buf;
el->el_line.cursor = un.buf + un.cursor;
@@ -641,7 +642,7 @@ vi_kill_line_prev(EditLine *el, int c __unused)
while (cp < el->el_line.cursor)
*kp++ = *cp++; /* copy it */
el->el_chared.c_kill.last = kp;
- c_delbefore(el, el->el_line.cursor - el->el_line.buffer);
+ c_delbefore(el, (int)(el->el_line.cursor - el->el_line.buffer));
el->el_line.cursor = el->el_line.buffer; /* zap! */
return (CC_REFRESH);
}
@@ -797,7 +798,7 @@ vi_match(EditLine *el, int c)
{
const char match_chars[] = "()[]{}";
char *cp;
- int delta, i, count;
+ size_t delta, i, count;
char o_ch, c_ch;
*el->el_line.lastchar = '\0'; /* just in case */
@@ -872,7 +873,7 @@ vi_yank_end(EditLine *el, int c)
{
cv_yank(el, el->el_line.cursor,
- el->el_line.lastchar - el->el_line.cursor);
+ (int)(el->el_line.lastchar - el->el_line.cursor));
return CC_REFRESH;
}
@@ -993,7 +994,8 @@ vi_histedit(EditLine *el, int c)
{
int fd;
pid_t pid;
- int st;
+ ssize_t st;
+ int status;
char tempfile[] = "/tmp/histedit.XXXXXXXXXX";
char *cp;
@@ -1006,7 +1008,7 @@ vi_histedit(EditLine *el, int c)
if (fd < 0)
return CC_ERROR;
cp = el->el_line.buffer;
- write(fd, cp, el->el_line.lastchar - cp +0u);
+ write(fd, cp, (size_t)(el->el_line.lastchar - cp));
write(fd, "\n", 1);
pid = fork();
switch (pid) {
@@ -1016,14 +1018,14 @@ vi_histedit(EditLine *el, int c)
return CC_ERROR;
case 0:
close(fd);
- execlp("vi", "vi", tempfile, NULL);
+ execlp("vi", "vi", tempfile, (char *)NULL);
exit(0);
/*NOTREACHED*/
default:
- while (waitpid(pid, &st, 0) != pid)
+ while (waitpid(pid, &status, 0) != pid)
continue;
- lseek(fd, 0ll, SEEK_SET);
- st = read(fd, cp, el->el_line.limit - cp +0u);
+ lseek(fd, (off_t)0, SEEK_SET);
+ st = read(fd, cp, (size_t)(el->el_line.limit - cp));
if (st > 0 && cp[st - 1] == '\n')
st--;
el->el_line.cursor = cp;
@@ -1072,7 +1074,7 @@ vi_history_word(EditLine *el, int c)
return CC_ERROR;
cv_undo(el);
- len = wep - wsp;
+ len = (int)(wep - wsp);
if (el->el_line.cursor < el->el_line.lastchar)
el->el_line.cursor++;
c_insert(el, len + 1);
diff --git a/lib/libelf/Makefile b/lib/libelf/Makefile
index fe921cb..ee96812 100644
--- a/lib/libelf/Makefile
+++ b/lib/libelf/Makefile
@@ -55,9 +55,24 @@ SRCS= elf_begin.c \
${GENSRCS}
INCS= libelf.h gelf.h
+#
+# We need to link against the correct version of these files. One
+# solution is to include ../../sys in the include path. This causes
+# problems when a header file in sys depends on a file in another
+# part of the tree, e.g. a machine dependent header.
+#
+SRCS+= sys/elf32.h sys/elf64.h sys/elf_common.h
+
GENSRCS= libelf_fsize.c libelf_msize.c libelf_convert.c
CLEANFILES= ${GENSRCS}
-CFLAGS+= -I${.CURDIR} -I${.CURDIR}/../../sys
+CLEANDIRS= sys
+CFLAGS+= -I${.CURDIR} -I.
+
+sys/elf32.h sys/elf64.h sys/elf_common.h: sys
+ ln -sf ${.CURDIR}/../../sys/${.TARGET} ${.TARGET}
+
+sys:
+ mkdir -p ${.OBJDIR}/sys
SHLIB_MAJOR= 1
diff --git a/lib/libelf/elf.3 b/lib/libelf/elf.3
index 609fab6..35bba9c 100644
--- a/lib/libelf/elf.3
+++ b/lib/libelf/elf.3
@@ -385,9 +385,9 @@ See
This section contains a brief overview of the available functionality
in the ELF library.
Each function listed here is described further in its own manual page.
-.Bl -tag -width indent
+.Bl -tag -width 2n
.It "Archive Access"
-.Bl -tag -compact
+.Bl -tag -width 17n -compact
.It Fn elf_getarsym
Retrieve the archive symbol table.
.It Fn elf_getarhdr
@@ -404,7 +404,7 @@ Random access inside an
archive.
.El
.It "Data Structures"
-.Bl -tag -compact
+.Bl -tag -width 17n -compact
.It Fn elf_getdata
Retrieve translated data for an ELF section.
.It Fn elf_getscn
@@ -437,7 +437,7 @@ Allocate an Executable Header in an ELF object.
Allocate or resize the Program Header Table in an ELF object.
.El
.It "Data Translation"
-.Bl -tag -compact
+.Bl -tag -width 17n -compact
.It Fn elf32_xlatetof , Fn elf64_xlatetof
Translate an ELF data structure from its native representation to its
file representation.
@@ -446,14 +446,14 @@ Translate an ELF data structure from its file representation to a
native representation.
.El
.It "Error Reporting"
-.Bl -tag -compact
+.Bl -tag -width 17n -compact
.It Fn elf_errno
Retrieve the current error.
.It Fn elf_errmsg
Retrieve a human readable description of the current error.
.El
.It "Initialization"
-.Bl -tag -compact
+.Bl -tag -width 17n -compact
.It Fn elf_begin
Opens an
.Xr ar 1
@@ -468,7 +468,7 @@ archive or ELF object present in a memory area.
Sets the operating version.
.El
.It "IO Control"
-.Bl -tag -width ".Fn elf_setshstrndx" -compact
+.Bl -tag -width 17n -compact
.It Fn elf_cntl
Manage the association between and ELF descriptor and its underlying file.
.It Fn elf_flagdata
@@ -492,7 +492,7 @@ Recompute ELF object layout and optionally write the modified object
back to the underlying file.
.El
.It "Queries"
-.Bl -tag -width ".Fn elf_getshstrndx" -compact
+.Bl -tag -width 17n -compact
.It Fn elf32_checksum , Fn elf64_checkum
Compute checksum of an ELF object.
.It Fn elf_getident
diff --git a/lib/libelf/elf_begin.3 b/lib/libelf/elf_begin.3
index ea68c26..6d9371a 100644
--- a/lib/libelf/elf_begin.3
+++ b/lib/libelf/elf_begin.3
@@ -252,7 +252,7 @@ was created.
.It Bq Er ELF_E_ARGUMENT
An
.Xr ar 1
-archive was opened with with
+archive was opened with
.Ar cmd
set to
.Dv ELF_C_RDWR .
diff --git a/lib/libelf/elf_getdata.3 b/lib/libelf/elf_getdata.3
index 9416a2c..97766d8 100644
--- a/lib/libelf/elf_getdata.3
+++ b/lib/libelf/elf_getdata.3
@@ -144,7 +144,7 @@ structures of type
.Dv ELF_T_BYTE .
.Ss Special handling of zero-sized and SHT_NOBITS sections
For sections of type
-.Dv SHT_NOBITS,
+.Dv SHT_NOBITS ,
and for zero-sized sections,
the functions
.Fn elf_getdata
diff --git a/lib/libelf/elf_strptr.3 b/lib/libelf/elf_strptr.3
index d672388..d2282df 100644
--- a/lib/libelf/elf_strptr.3
+++ b/lib/libelf/elf_strptr.3
@@ -64,7 +64,7 @@ encountered.
.It Bq Er ELF_E_ARGUMENT
Argument
.Ar elf
-was NULL
+was NULL.
.It Bq Er ELF_E_ARGUMENT
Argument
.Ar elf
diff --git a/lib/libelf/gelf.3 b/lib/libelf/gelf.3
index d541388..1c2f010 100644
--- a/lib/libelf/gelf.3
+++ b/lib/libelf/gelf.3
@@ -115,7 +115,7 @@ routines will signal an error if a GElf value is out of range
for the underlying ELF data type.
.Ss Namespace use
The GElf interface uses the following symbols:
-.Bl -tag
+.Bl -tag -width 8n
.It GElf_*
Class-independent data types.
.It gelf_*
@@ -125,16 +125,16 @@ For functions defined in the API set.
This section provides an overview of the GElf programming APIs.
Further information is provided in the manual page of each function
listed here.
-.Bl -tag
+.Bl -tag -width 2n
.It "Allocating ELF Data Structures"
-.Bl -tag -compact
+.Bl -tag -width 19n -compact
.It Fn gelf_newehdr
Allocate a new ELF Executable Header.
.It Fn gelf_newphdr
Allocate a new ELF Program Header Table.
.El
.It "Data Translation"
-.Bl -tag -compact
+.Bl -tag -width 19n -compact
.It Fn gelf_xlatetof
Translate the native representation of an ELF data structure to its
file representation.
@@ -143,7 +143,7 @@ Translate from the file representation of an ELF data structure to a
native representation.
.El
.It "Retrieving ELF Data"
-.Bl -tag -compact
+.Bl -tag -width 19n -compact
.It Fn gelf_getdyn
Retrieve an ELF
.Sy .dynamic
@@ -162,7 +162,7 @@ Retrieve an ELF Section Header Table entry from the underlying ELF descriptor.
Retrieve an ELF symbol table entry.
.El
.It Queries
-.Bl -tag -compact
+.Bl -tag -width 19n -compact
.It Fn gelf_checksum
Retrieves the ELF checksum for an ELF descriptor.
.It Fn gelf_fsize
@@ -171,7 +171,7 @@ Retrieves the size of the file representation of an ELF type.
Retrieves the ELF class of an ELF descriptor.
.El
.It "Updating ELF Data"
-.Bl -tag -compact -width ".Fn gelf_update_shdr"
+.Bl -tag -width 19n -compact
.It Fn gelf_update_dyn
Copy back an ELF
.Sy .dynamic
diff --git a/lib/libelf/gelf_getphdr.3 b/lib/libelf/gelf_getphdr.3
index 53fab17..13c588f 100644
--- a/lib/libelf/gelf_getphdr.3
+++ b/lib/libelf/gelf_getphdr.3
@@ -66,7 +66,7 @@ Function
will retrieve the program header table entry at index
.Ar index
from ELF descriptor
-.Ar elf.
+.Ar elf .
The translated program header table entry will be written to the
address pointed to be argument
.Ar dst .
diff --git a/lib/libelf/gelf_newehdr.3 b/lib/libelf/gelf_newehdr.3
index 6a2edf8..4dab647 100644
--- a/lib/libelf/gelf_newehdr.3
+++ b/lib/libelf/gelf_newehdr.3
@@ -58,7 +58,8 @@ structure.
Function
.Fn elf64_newehdr
returns a pointer to a 64 bit
-.Vt Elf64_Ehdr structure.
+.Vt Elf64_Ehdr
+structure.
.Pp
When argument
.Ar elfclass
diff --git a/lib/libfetch/common.c b/lib/libfetch/common.c
index e6f67c3..425b6de 100644
--- a/lib/libfetch/common.c
+++ b/lib/libfetch/common.c
@@ -209,11 +209,13 @@ conn_t *
fetch_reopen(int sd)
{
conn_t *conn;
+ int opt = 1;
/* allocate and fill connection structure */
if ((conn = calloc(1, sizeof(*conn))) == NULL)
return (NULL);
fcntl(sd, F_SETFD, FD_CLOEXEC);
+ setsockopt(sd, SOL_SOCKET, SO_NOSIGPIPE, &opt, sizeof opt);
conn->sd = sd;
++conn->ref;
return (conn);
@@ -455,11 +457,9 @@ fetch_read(conn_t *conn, char *buf, size_t len)
struct timeval now, timeout, delta;
fd_set readfds;
ssize_t rlen, total;
- int r;
char *start;
- if (fetchTimeout) {
- FD_ZERO(&readfds);
+ if (fetchTimeout > 0) {
gettimeofday(&timeout, NULL);
timeout.tv_sec += fetchTimeout;
}
@@ -523,23 +523,21 @@ fetch_read(conn_t *conn, char *buf, size_t len)
return (-1);
}
// assert(rlen == FETCH_READ_WAIT);
- while (fetchTimeout && !FD_ISSET(conn->sd, &readfds)) {
+ FD_ZERO(&readfds);
+ while (!FD_ISSET(conn->sd, &readfds)) {
FD_SET(conn->sd, &readfds);
- gettimeofday(&now, NULL);
- delta.tv_sec = timeout.tv_sec - now.tv_sec;
- delta.tv_usec = timeout.tv_usec - now.tv_usec;
- if (delta.tv_usec < 0) {
- delta.tv_usec += 1000000;
- delta.tv_sec--;
- }
- if (delta.tv_sec < 0) {
- errno = ETIMEDOUT;
- fetch_syserr();
- return (-1);
+ if (fetchTimeout > 0) {
+ gettimeofday(&now, NULL);
+ if (!timercmp(&timeout, &now, >)) {
+ errno = ETIMEDOUT;
+ fetch_syserr();
+ return (-1);
+ }
+ timersub(&timeout, &now, &delta);
}
errno = 0;
- r = select(conn->sd + 1, &readfds, NULL, NULL, &delta);
- if (r == -1) {
+ if (select(conn->sd + 1, &readfds, NULL, NULL,
+ fetchTimeout > 0 ? &delta : NULL) < 0) {
if (errno == EINTR) {
if (fetchRestartCalls)
continue;
diff --git a/lib/libfetch/http.c b/lib/libfetch/http.c
index 557ff26..f6e063a 100644
--- a/lib/libfetch/http.c
+++ b/lib/libfetch/http.c
@@ -1779,7 +1779,9 @@ http_request(struct url *URL, const char *op, struct url_stat *us,
DEBUG(fprintf(stderr, "failed to parse new URL\n"));
goto ouch;
}
- if (!*new->user && !*new->pwd) {
+
+ /* Only copy credentials if the host matches */
+ if (!strcmp(new->host, url->host) && !*new->user && !*new->pwd) {
strcpy(new->user, url->user);
strcpy(new->pwd, url->pwd);
}
diff --git a/lib/libgpib/gpib.3 b/lib/libgpib/gpib.3
index 9d80ae0..01f778b 100644
--- a/lib/libgpib/gpib.3
+++ b/lib/libgpib/gpib.3
@@ -207,7 +207,8 @@ The variable
.Dv iberr
provides an error code for the most recent library call.
The possible error codes are:
-.Bl -tag -offset indent -compact
+.Pp
+.Bl -tag -width 6n -offset indent -compact
.It EDVR
System error
.It ECIC
@@ -244,7 +245,8 @@ The variable
.Dv ibsta
contains the controller status.
This is an ORed status value, with the following individual bit names:
-.Bl -tag -offset indent -compact
+.Pp
+.Bl -tag -width 6n -offset indent -compact
.It ERR
Error
.It TIMO
@@ -329,7 +331,8 @@ The lower 8 bits of
are interpreted as an end-of-string character,
.Li EOS .
This character can be ORed with the following values:
-.Bl -tag -compact -offset indent
+.Pp
+.Bl -tag -width 6n -compact -offset indent
.It Dv REOS
When receiving a message byte on the bus that matches the
.Li EOS
@@ -348,6 +351,7 @@ If set, include all 8 bits of the
character in the comparison; if unset, compare only 7 bit ASCII
values.
.El
+.Pp
Passing 0 as
.Fa eos
will turn off any special character treatment, allowing for a fully
@@ -666,7 +670,7 @@ and sends its contents to the device.
.Pp
The function
.Fn ibwrtkey
-is obsolete, and not implemented
+is obsolete, and not implemented.
.Pp
The function
.Fn ibxtrc
diff --git a/lib/libgssapi/gss_accept_sec_context.3 b/lib/libgssapi/gss_accept_sec_context.3
index 825c28d..cc36887 100644
--- a/lib/libgssapi/gss_accept_sec_context.3
+++ b/lib/libgssapi/gss_accept_sec_context.3
@@ -212,7 +212,7 @@ exist in version 1 of the GSS-API specification, so applications that
wish to run over version 1 implementations must special-case these
codes.
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It input_chan_bindings"
.It context_handle
Context handle for new context.
Supply
@@ -400,7 +400,7 @@ Specify
Mechanism specific status code.
.El
.Sh RETURN VALUES
-.Bl -tag
+.Bl -tag -width ".It GSS_S_DEFECTIVE_CREDENTIAL"
.It GSS_S_CONTINUE_NEEDED
Indicates that a token from the peer application is required to
complete the context,
@@ -442,7 +442,7 @@ the implementation or the provided credential.
.Xr gss_release_name 3 ,
.Xr gss_wrap 3
.Sh STANDARDS
-.Bl -tag
+.Bl -tag -width ".It RFC 2743"
.It RFC 2743
Generic Security Service Application Program Interface Version 2, Update 1
.It RFC 2744
diff --git a/lib/libgssapi/gss_acquire_cred.3 b/lib/libgssapi/gss_acquire_cred.3
index 4b683e7..0a6caad 100644
--- a/lib/libgssapi/gss_acquire_cred.3
+++ b/lib/libgssapi/gss_acquire_cred.3
@@ -126,7 +126,7 @@ immediately following the call of
must return valid credential data,
and may therefore incur the overhead of a deferred credential acquisition.
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It output_cred_handle"
.It desired_name
Name of principal whose credential should be acquired.
.It time_req
@@ -174,7 +174,7 @@ Specify NULL if not required.
Mechanism specific status code.
.El
.Sh RETURN VALUES
-.Bl -tag
+.Bl -tag -width ".It GSS_S_CREDENTIALS_EXPIRED"
.It GSS_S_COMPLETE
Successful completion.
.It GSS_S_BAD_MECH
@@ -196,7 +196,7 @@ No credentials were found for the specified name.
.Xr gss_release_cred 3 ,
.Xr gss_release_oid_set 3
.Sh STANDARDS
-.Bl -tag
+.Bl -tag -width ".It RFC 2743"
.It RFC 2743
Generic Security Service Application Program Interface Version 2, Update 1
.It RFC 2744
diff --git a/lib/libgssapi/gss_add_cred.3 b/lib/libgssapi/gss_add_cred.3
index 67ff1c3..32d9885 100644
--- a/lib/libgssapi/gss_add_cred.3
+++ b/lib/libgssapi/gss_add_cred.3
@@ -170,7 +170,7 @@ a non-
.Fa output_cred_handle
must be supplied.
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It output_cred_handle"
.It minor_status
Mechanism specific status code.
.It input_cred_handle
@@ -270,7 +270,7 @@ Specify
if not required.
.El
.Sh RETURN VALUES
-.Bl -tag
+.Bl -tag -width ".It GSS_S_CREDENTIALS_EXPIRED"
.It GSS_S_COMPLETE
Successful completion.
.It GSS_S_BAD_MECH
@@ -296,7 +296,7 @@ No credentials were found for the specified name.
.Xr gss_release_cred 3 ,
.Xr gss_release_oid_set 3
.Sh STANDARDS
-.Bl -tag
+.Bl -tag -width ".It RFC 2743"
.It RFC 2743
Generic Security Service Application Program Interface Version 2, Update 1
.It RFC 2744
diff --git a/lib/libgssapi/gss_add_oid_set_member.3 b/lib/libgssapi/gss_add_oid_set_member.3
index 5839da6..e812681 100644
--- a/lib/libgssapi/gss_add_oid_set_member.3
+++ b/lib/libgssapi/gss_add_oid_set_member.3
@@ -71,7 +71,7 @@ the
.Fa oid_set
should remain unchanged.
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It minor_status"
.It minor_status
Mechanism specific status code.
.It member_oid
@@ -80,7 +80,7 @@ The object identifier to copied into the set.
The set in which the object identifier should be inserted.
.El
.Sh RETURN VALUES
-.Bl -tag
+.Bl -tag -width ".It GSS_S_COMPLETE"
.It GSS_S_COMPLETE
Successful completion
.El
@@ -88,7 +88,7 @@ Successful completion
.Xr gss_create_empty_oid_set 3 ,
.Xr gss_acquire_cred 3
.Sh STANDARDS
-.Bl -tag
+.Bl -tag -width ".It RFC 2743"
.It RFC 2743
Generic Security Service Application Program Interface Version 2, Update 1
.It RFC 2744
diff --git a/lib/libgssapi/gss_canonicalize_name.3 b/lib/libgssapi/gss_canonicalize_name.3
index 036c0ef..71daad5 100644
--- a/lib/libgssapi/gss_canonicalize_name.3
+++ b/lib/libgssapi/gss_canonicalize_name.3
@@ -62,7 +62,7 @@ specifying
.Fa mech_type
as the authentication mechanism.
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It minor_status"
.It minor_status
Mechanism specific status code.
.It input_name
@@ -79,7 +79,7 @@ after use with a call to
.Fn gss_release_name .
.El
.Sh RETURN VALUES
-.Bl -tag
+.Bl -tag -width ".It GSS_S_BAD_NAMETYPE"
.It GSS_S_COMPLETE
Successful completion.
.It GSS_S_BAD_MECH
@@ -95,7 +95,7 @@ The provided internal name was ill-formed.
.Xr gss_init_sec_context 3 ,
.Xr gss_release_name 3
.Sh STANDARDS
-.Bl -tag
+.Bl -tag -width ".It RFC 2743"
.It RFC 2743
Generic Security Service Application Program Interface Version 2, Update 1
.It RFC 2744
diff --git a/lib/libgssapi/gss_compare_name.3 b/lib/libgssapi/gss_compare_name.3
index 713af23..0890cf9 100644
--- a/lib/libgssapi/gss_compare_name.3
+++ b/lib/libgssapi/gss_compare_name.3
@@ -54,7 +54,7 @@ denotes an anonymous principal,
the routines should indicate that the two names do not refer to the
same identity.
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width "minor_status"
.It minor_status
Mechanism specific status code.
.It name1
@@ -62,7 +62,7 @@ Internal-form name.
.It name2
Internal-form name.
.It name_equal
-.Bl -tag
+.Bl -tag -width "non-zero"
.It non-zero
Names refer to same entity
.It zero
@@ -71,7 +71,7 @@ to refer to the same identity).
.El
.El
.Sh RETURN VALUES
-.Bl -tag
+.Bl -tag -width ".It GSS_S_BAD_NAMETYPE"
.It GSS_S_COMPLETE
Successful completion
.It GSS_S_BAD_NAMETYPE
@@ -80,7 +80,7 @@ The two names were of incomparable types.
One or both of name1 or name2 was ill-formed.
.El
.Sh STANDARDS
-.Bl -tag
+.Bl -tag -width ".It RFC 2743"
.It RFC 2743
Generic Security Service Application Program Interface Version 2, Update 1
.It RFC 2744
diff --git a/lib/libgssapi/gss_context_time.3 b/lib/libgssapi/gss_context_time.3
index b6b4157..4dae1d9 100644
--- a/lib/libgssapi/gss_context_time.3
+++ b/lib/libgssapi/gss_context_time.3
@@ -47,7 +47,7 @@
Determines the number of seconds for which the specified context will
remain valid.
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It context_handle"
.It minor_status
Mechanism specific status code.
.It context_handle
@@ -57,7 +57,7 @@ Number of seconds that the context will remain valid.
If the context has already expired, zero will be returned.
.El
.Sh RETURN VALUES
-.Bl -tag
+.Bl -tag -width ".It GSS_S_CONTEXT_EXPIRED"
.It GSS_S_COMPLETE
Successful completion
.It GSS_S_CONTEXT_EXPIRED
@@ -66,7 +66,7 @@ The context has already expired
The context_handle parameter did not identify a valid context
.El
.Sh STANDARDS
-.Bl -tag
+.Bl -tag -width ".It RFC 2743"
.It RFC 2743
Generic Security Service Application Program Interface Version 2, Update 1
.It RFC 2744
diff --git a/lib/libgssapi/gss_create_empty_oid_set.3 b/lib/libgssapi/gss_create_empty_oid_set.3
index 3a84f85..466ea01 100644
--- a/lib/libgssapi/gss_create_empty_oid_set.3
+++ b/lib/libgssapi/gss_create_empty_oid_set.3
@@ -51,7 +51,7 @@ These routines are intended to be used to construct sets of mechanism
object identifiers for input to
.Fn gss_acquire_cred .
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It minor_status"
.It minor_status
Mechanism specific status code.
.It oid_set
@@ -61,7 +61,7 @@ which the application must free after use with a call to
.Fn gss_release_oid_set .
.El
.Sh RETURN VALUES
-.Bl -tag
+.Bl -tag -width ".It GSS_S_COMPLETE"
.It GSS_S_COMPLETE
Successful completion
.El
@@ -69,7 +69,7 @@ Successful completion
.Xr gss_add_oid_set_member 3 ,
.Xr gss_acquire_cred 3
.Sh STANDARDS
-.Bl -tag
+.Bl -tag -width ".It RFC 2743"
.It RFC 2743
Generic Security Service Application Program Interface Version 2, Update 1
.It RFC 2744
diff --git a/lib/libgssapi/gss_delete_sec_context.3 b/lib/libgssapi/gss_delete_sec_context.3
index 1c4fa7b..be12165 100644
--- a/lib/libgssapi/gss_delete_sec_context.3
+++ b/lib/libgssapi/gss_delete_sec_context.3
@@ -88,7 +88,7 @@ mechanisms are encouraged to return a zero-length token,
indicating that no peer action is necessary,
and that no token should be transferred by the application.
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It context_handle"
.It minor_status
Mechanism specific status code.
.It context_handle
@@ -110,7 +110,7 @@ field of this token to zero to indicate to the application that no
token is to be sent to the peer.
.El
.Sh RETURN VALUES
-.Bl -tag
+.Bl -tag -width ".It context_handle"
.It GSS_S_COMPLETE
Successful completion
.It GSS_S_NO_CONTEXT
@@ -121,7 +121,7 @@ No valid context was supplied
.Xr gss_init_sec_context 3 ,
.Xr gss_accept_sec_context 3
.Sh STANDARDS
-.Bl -tag
+.Bl -tag -width ".It RFC 2743"
.It RFC 2743
Generic Security Service Application Program Interface Version 2, Update 1
.It RFC 2744
diff --git a/lib/libgssapi/gss_display_name.3 b/lib/libgssapi/gss_display_name.3
index 4944995..f22fcf5 100644
--- a/lib/libgssapi/gss_display_name.3
+++ b/lib/libgssapi/gss_display_name.3
@@ -76,7 +76,7 @@ via the
.Fa output_name_type
parameter.
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It output_name_buffer"
.It minor_status
Mechanism specific status code.
.It input_name
@@ -98,7 +98,7 @@ Specify
if not required.
.El
.Sh RETURN VALUES
-.Bl -tag
+.Bl -tag -width ".It GSS_S_COMPLETE"
.It GSS_S_COMPLETE
Successful completion
.It GSS_S_BAD_NAME
@@ -109,7 +109,7 @@ was ill-formed
.Xr gss_import_name 3 ,
.Xr gss_release_buffer 3
.Sh STANDARDS
-.Bl -tag
+.Bl -tag -width ".It RFC 2743"
.It RFC 2743
Generic Security Service Application Program Interface Version 2, Update 1
.It RFC 2744
diff --git a/lib/libgssapi/gss_display_status.3 b/lib/libgssapi/gss_display_status.3
index 4bf908b..7c05e62 100644
--- a/lib/libgssapi/gss_display_status.3
+++ b/lib/libgssapi/gss_display_status.3
@@ -111,13 +111,13 @@ do {
} while (message_context != 0);
.Ed
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It minor_status"
.It minor_status
Mechanism specific status code.
.It status_value
Status value to be converted
.It status_type
-.Bl -tag
+.Bl -tag -width ".It GSS_C_MECH_CODE"
.It GSS_C_GSS_CODE
.Fa status_value
is a GSS status code
@@ -153,7 +153,7 @@ application after use with a call to
.Fn gss_release_buffer .
.El
.Sh RETURN VALUES
-.Bl -tag
+.Bl -tag -width ".It GSS_S_BAD_STATUS"
.It GSS_S_COMPLETE
Successful completion
.It GSS_S_BAD_MECH
@@ -168,7 +168,7 @@ nor
.Sh SEE ALSO
.Xr gss_release_buffer 3
.Sh STANDARDS
-.Bl -tag
+.Bl -tag -width ".It RFC 2743"
.It RFC 2743
Generic Security Service Application Program Interface Version 2, Update 1
.It RFC 2744
diff --git a/lib/libgssapi/gss_duplicate_name.3 b/lib/libgssapi/gss_duplicate_name.3
index 5eb4a62..f9c9f83 100644
--- a/lib/libgssapi/gss_duplicate_name.3
+++ b/lib/libgssapi/gss_duplicate_name.3
@@ -57,7 +57,7 @@ and
must both be released,
and the release of one shall not affect the validity of the other).
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It minor_status"
.It minor_status
Mechanism specific status code.
.It src_name
@@ -70,7 +70,7 @@ after use with a call to
.Fn gss_release_name .
.El
.Sh RETURN VALUES
-.Bl -tag
+.Bl -tag -width ".It GSS_S_COMPLETE"
.It GSS_S_COMPLETE
Successful completion
.It GSS_S_BAD_NAME
@@ -81,7 +81,7 @@ parameter was ill-formed
.Sh SEE ALSO
.Xr gss_release_name 3
.Sh STANDARDS
-.Bl -tag
+.Bl -tag -width ".It RFC 2743"
.It RFC 2743
Generic Security Service Application Program Interface Version 2, Update 1
.It RFC 2744
diff --git a/lib/libgssapi/gss_export_name.3 b/lib/libgssapi/gss_export_name.3
index 5cbf803..f727c45 100644
--- a/lib/libgssapi/gss_export_name.3
+++ b/lib/libgssapi/gss_export_name.3
@@ -58,7 +58,7 @@ parameter must specify a valid MN
or by
.Fn gss_canonicalize_name ).
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It exported_name"
.It minor_status
Mechanism specific status code.
.It input_name
@@ -71,7 +71,7 @@ after use with
.Fn gss_release_buffer .
.El
.Sh RETURN VALUES
-.Bl -tag
+.Bl -tag -width ".It GSS_S_BAD_NAMETYPE"
.It GSS_S_COMPLETE
Successful completion
.It GSS_S_NAME_NOT_MN
@@ -86,7 +86,7 @@ The internal name was of a type not supported by the GSS-API implementation.
.Xr gss_canonicalize_name 3 ,
.Xr gss_release_buffer 3
.Sh STANDARDS
-.Bl -tag
+.Bl -tag -width ".It RFC 2743"
.It RFC 2743
Generic Security Service Application Program Interface Version 2, Update 1
.It RFC 2744
diff --git a/lib/libgssapi/gss_export_sec_context.3 b/lib/libgssapi/gss_export_sec_context.3
index 7ecbef3..ca1aedd 100644
--- a/lib/libgssapi/gss_export_sec_context.3
+++ b/lib/libgssapi/gss_export_sec_context.3
@@ -100,7 +100,7 @@ providing it also sets the
parameter to
.Dv GSS_C_NO_CONTEXT .
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It interprocess_token"
.It minor_status
Mechanism specific status code.
.It context_handle
@@ -112,7 +112,7 @@ after use with a call to
.Fn gss_release_buffer .
.El
.Sh RETURN VALUES
-.Bl -tag
+.Bl -tag -width ".It GSS_S_CONTEXT_EXPIRED"
.It GSS_S_COMPLETE
Successful completion
.It GSS_S_CONTEXT_EXPIRED
@@ -126,7 +126,7 @@ The operation is not supported
.Xr gss_import_sec_context 3 ,
.Xr gss_release_buffer 3
.Sh STANDARDS
-.Bl -tag
+.Bl -tag -width ".It RFC 2743"
.It RFC 2743
Generic Security Service Application Program Interface Version 2, Update 1
.It RFC 2744
diff --git a/lib/libgssapi/gss_get_mic.3 b/lib/libgssapi/gss_get_mic.3
index e5d81fa..431f9e3 100644
--- a/lib/libgssapi/gss_get_mic.3
+++ b/lib/libgssapi/gss_get_mic.3
@@ -81,7 +81,7 @@ both to allow GSS-API V1 applications to link
and to retain the slight parameter type differences between the
obsolete versions of this routine and its current form.
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It message_buffer"
.It minor_status
Mechanism specific status code.
.It context_handle
@@ -109,7 +109,7 @@ use with a call to
.Fn gss_release_buffer .
.El
.Sh RETURN VALUES
-.Bl -tag
+.Bl -tag -width ".It GSS_S_CONTEXT_EXPIRED"
.It GSS_S_COMPLETE
Successful completion
.It GSS_S_CONTEXT_EXPIRED
@@ -123,7 +123,7 @@ The specified QOP is not supported by the mechanism
.Xr gss_wrap 3 ,
.Xr gss_release_buffer 3
.Sh STANDARDS
-.Bl -tag
+.Bl -tag -width ".It RFC 2743"
.It RFC 2743
Generic Security Service Application Program Interface Version 2, Update 1
.It RFC 2744
diff --git a/lib/libgssapi/gss_import_name.3 b/lib/libgssapi/gss_import_name.3
index aef1ae8..df3ce9c 100644
--- a/lib/libgssapi/gss_import_name.3
+++ b/lib/libgssapi/gss_import_name.3
@@ -59,7 +59,7 @@ parameter is of type
in which case the returned internal name will be an MN for the
mechanism that exported the name.
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It input_name_buffer"
.It minor_status
Mechanism specific status code.
.It input_name_buffer
@@ -78,7 +78,7 @@ after use with a call to
.Fn gss_release_name .
.El
.Sh RETURN VALUES
-.Bl -tag
+.Bl -tag -width "It GSS_S_BAD_NAMETYPE"
.It GSS_S_COMPLETE
Successful completion
.It GSS_S_BAD_NAMETYPE
@@ -97,7 +97,7 @@ but the mechanism contained within the input-name is not supported
.Sh SEE ALSO
.Xr gss_release_name 3
.Sh STANDARDS
-.Bl -tag
+.Bl -tag -width ".It RFC 2743"
.It RFC 2743
Generic Security Service Application Program Interface Version 2, Update 1
.It RFC 2744
diff --git a/lib/libgssapi/gss_import_sec_context.3 b/lib/libgssapi/gss_import_sec_context.3
index 87aaa78..b2e1c78 100644
--- a/lib/libgssapi/gss_import_sec_context.3
+++ b/lib/libgssapi/gss_import_sec_context.3
@@ -50,7 +50,7 @@ A given interprocess token may be imported only once.
See
.Fn gss_export_sec_context .
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It interprocess_token"
.It minor_status
Mechanism specific status code.
.It interprocess_token
@@ -62,7 +62,7 @@ application after use with a call to
.Fn gss_delete_sec_context .
.El
.Sh RETURN VALUES
-.Bl -tag
+.Bl -tag -width ".It GSS_S_DEFECTIVE_TOKEN"
.It GSS_S_COMPLETE
Successful completion
.It GSS_S_NO_CONTEXT
@@ -78,7 +78,7 @@ Local policy prevents the import of this context by the current process
.Xr gss_export_sec_context 3 ,
.Xr gss_delete_sec_context 3
.Sh STANDARDS
-.Bl -tag
+.Bl -tag -width ".It RFC 2743"
.It RFC 2743
Generic Security Service Application Program Interface Version 2, Update 1
.It RFC 2744
diff --git a/lib/libgssapi/gss_indicate_mechs.3 b/lib/libgssapi/gss_indicate_mechs.3
index 3eec861..c49c83a 100644
--- a/lib/libgssapi/gss_indicate_mechs.3
+++ b/lib/libgssapi/gss_indicate_mechs.3
@@ -46,7 +46,7 @@
Allows an application to determine which underlying security
mechanisms are available.
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It minor_status"
.It minor_status
Mechanism specific status code.
.It mech_set
@@ -58,14 +58,14 @@ that should be released by the caller after use with a call to
.Fn gss_release_oid_set .
.El
.Sh RETURN VALUES
-.Bl -tag
+.Bl -tag -width ".It GSS_S_COMPLETE"
.It GSS_S_COMPLETE
Successful completion
.El
.Sh SEE ALSO
.Xr gss_release_oid_set 3
.Sh STANDARDS
-.Bl -tag
+.Bl -tag -width ".It RFC 2743"
.It RFC 2743
Generic Security Service Application Program Interface Version 2, Update 1
.It RFC 2744
diff --git a/lib/libgssapi/gss_init_sec_context.3 b/lib/libgssapi/gss_init_sec_context.3
index 9d14859..51556a6 100644
--- a/lib/libgssapi/gss_init_sec_context.3
+++ b/lib/libgssapi/gss_init_sec_context.3
@@ -233,7 +233,7 @@ exist in version 1 of the GSS-API specification, so applications that
wish to run over version 1 implementations must special-case these
codes.
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It initiator_cred_handle"
.It minor_status
Mechanism specific status code.
.It initiator_cred_handle
@@ -475,7 +475,7 @@ not support context expiration, the value
.Dv NULL if not required.
.El
.Sh RETURN VALUES
-.Bl -tag
+.Bl -tag -width ".It GSS_S_CREDENTIALS_EXPIRED"
.It GSS_S_COMPLETE
Successful completion
.It GSS_S_CONTINUE_NEEDED
@@ -529,7 +529,7 @@ implementation.
.Xr gss_release_buffer 3 ,
.Xr gss_wrap 3
.Sh STANDARDS
-.Bl -tag
+.Bl -tag -width ".It RFC 2743"
.It RFC 2743
Generic Security Service Application Program Interface Version 2, Update 1
.It RFC 2744
diff --git a/lib/libgssapi/gss_inquire_context.3 b/lib/libgssapi/gss_inquire_context.3
index ba5d649..d318234 100644
--- a/lib/libgssapi/gss_inquire_context.3
+++ b/lib/libgssapi/gss_inquire_context.3
@@ -55,7 +55,7 @@ The caller must already have obtained a handle that refers to the
context,
although the context need not be fully established.
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It locally_initiated"
.It minor_status
Mechanism specific status code.
.It context_handle
@@ -229,7 +229,7 @@ Specify
if not required.
.El
.Sh RETURN VALUES
-.Bl -tag
+.Bl -tag -width ".It GSS_S_NO_CONTEXT"
.It GSS_S_COMPLETE
Successful completion
.It GSS_S_NO_CONTEXT
@@ -242,7 +242,7 @@ The referenced context could not be accessed
.Xr gss_get_mic 3 ,
.Xr gss_export_sec_context 3
.Sh STANDARDS
-.Bl -tag
+.Bl -tag -width ".It RFC 2743"
.It RFC 2743
Generic Security Service Application Program Interface Version 2, Update 1
.It RFC 2744
diff --git a/lib/libgssapi/gss_inquire_cred.3 b/lib/libgssapi/gss_inquire_cred.3
index 923b373..8bbe0da 100644
--- a/lib/libgssapi/gss_inquire_cred.3
+++ b/lib/libgssapi/gss_inquire_cred.3
@@ -50,7 +50,7 @@
.Sh DESCRIPTION
Obtains information about a credential.
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It minor_status"
.It minor_status
Mechanism specific status code.
.It cred_handle
@@ -99,7 +99,7 @@ Specify
if not required.
.El
.Sh RETURN VALUES
-.Bl -tag
+.Bl -tag -width ".It GSS_S_DEFECTIVE_CREDENTIAL"
.It GSS_S_COMPLETE
Successful completion
.It GSS_S_NO_CRED
@@ -116,7 +116,7 @@ it will be set to 0
.Xr gss_release_name 3 ,
.Xr gss_release_oid_set 3
.Sh STANDARDS
-.Bl -tag
+.Bl -tag -width ".It RFC 2743"
.It RFC 2743
Generic Security Service Application Program Interface Version 2, Update 1
.It RFC 2744
diff --git a/lib/libgssapi/gss_inquire_cred_by_mech.3 b/lib/libgssapi/gss_inquire_cred_by_mech.3
index c316930..ebe6196 100644
--- a/lib/libgssapi/gss_inquire_cred_by_mech.3
+++ b/lib/libgssapi/gss_inquire_cred_by_mech.3
@@ -50,7 +50,7 @@
.Sh DESCRIPTION
Obtains per-mechanism information about a credential.
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It initiator_lifetime"
.It minor_status
Mechanism specific status code.
.It cred_handle
@@ -114,7 +114,7 @@ Specify
if not required.
.El
.Sh RETURN VALUES
-.Bl -tag
+.Bl -tag -width ".It GSS_S_DEFECTIVE_CREDENTIAL"
.It GSS_S_COMPLETE
Successful completion
.It GSS_S_NO_CRED
@@ -130,7 +130,7 @@ it will be set to 0.
.Sh SEE ALSO
.Xr gss_release_name 3
.Sh STANDARDS
-.Bl -tag
+.Bl -tag -width ".It RFC 2743"
.It RFC 2743
Generic Security Service Application Program Interface Version 2, Update 1
.It RFC 2744
diff --git a/lib/libgssapi/gss_inquire_mechs_for_name.3 b/lib/libgssapi/gss_inquire_mechs_for_name.3
index d8d94ed..661f9ac 100644
--- a/lib/libgssapi/gss_inquire_mechs_for_name.3
+++ b/lib/libgssapi/gss_inquire_mechs_for_name.3
@@ -68,7 +68,7 @@ type).
Thus this routine should be used only as a pre-filter for a call to a
subsequent mechanism-specific routine.
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It minor_status"
.It minor_status
Mechanism specific status code.
.It input_name
@@ -80,7 +80,7 @@ to
.Fn gss_release_oid_set .
.El
.Sh RETURN VALUES
-.Bl -tag
+.Bl -tag -width ".It GSS_S_COMPLETE"
.It GSS_S_COMPLETE
Successful completion
.It GSS_S_BAD_NAME
@@ -91,7 +91,7 @@ parameter was ill-formed
.Sh SEE ALSO
.Xr gss_release_oid_set 3
.Sh STANDARDS
-.Bl -tag
+.Bl -tag -width ".It RFC 2743"
.It RFC 2743
Generic Security Service Application Program Interface Version 2, Update 1
.It RFC 2744
diff --git a/lib/libgssapi/gss_inquire_names_for_mech.3 b/lib/libgssapi/gss_inquire_names_for_mech.3
index c1b7528..591ddb9 100644
--- a/lib/libgssapi/gss_inquire_names_for_mech.3
+++ b/lib/libgssapi/gss_inquire_names_for_mech.3
@@ -46,7 +46,7 @@
.Sh DESCRIPTION
Returns the set of name-types supported by the specified mechanism.
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It minor_status"
.It minor_status
Mechanism specific status code.
.It mechanism
@@ -58,14 +58,14 @@ call to
.Fn gss_release_oid_set .
.El
.Sh RETURN VALUES
-.Bl -tag
+.Bl -tag -width "GSS_S_COMPLETEXX"
.It GSS_S_COMPLETE
Successful completion
.El
.Sh SEE ALSO
.Xr gss_release_oid_set 3
.Sh STANDARDS
-.Bl -tag
+.Bl -tag -width ".It RFC 2743"
.It RFC 2743
Generic Security Service Application Program Interface Version 2, Update 1
.It RFC 2744
diff --git a/lib/libgssapi/gss_process_context_token.3 b/lib/libgssapi/gss_process_context_token.3
index 53f5ebf..a7e0ab4 100644
--- a/lib/libgssapi/gss_process_context_token.3
+++ b/lib/libgssapi/gss_process_context_token.3
@@ -71,7 +71,7 @@ believing that the context is fully established.
.Fn gss_process_context_token
provides a way to pass such a token to the mechanism at any time.
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It context_handle"
.It minor_status
Mechanism specific status code.
.It context_handle
@@ -80,7 +80,7 @@ Context handle of context on which token is to be processed.
Token to process.
.El
.Sh RETURN VALUES
-.Bl -tag
+.Bl -tag -width ".It GSS_S_DEFECTIVE_TOKEN"
.It GSS_S_COMPLETE
Successful completion
.It GSS_S_DEFECTIVE_TOKEN
@@ -94,7 +94,7 @@ did not refer to a valid context
.Xr gss_init_sec_context 3 ,
.Xr gss_accept_sec_context 3
.Sh STANDARDS
-.Bl -tag
+.Bl -tag -width ".It RFC 2743"
.It RFC 2743
Generic Security Service Application Program Interface Version 2, Update 1
.It RFC 2744
diff --git a/lib/libgssapi/gss_release_buffer.3 b/lib/libgssapi/gss_release_buffer.3
index c4acf81..d71a6f2 100644
--- a/lib/libgssapi/gss_release_buffer.3
+++ b/lib/libgssapi/gss_release_buffer.3
@@ -55,7 +55,7 @@ Any buffer object returned by a GSS-API routine may be passed to
.Fn gss_release_buffer
(even if there is no storage associated with the buffer).
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It minor_status"
.It minor_status
Mechanism specific status code.
.It buffer
@@ -64,12 +64,12 @@ The gss_buffer_desc object will not be freed,
but its length field will be zeroed.
.El
.Sh RETURN VALUES
-.Bl -tag
+.Bl -tag -width ".It GSS_S_COMPLETE"
.It GSS_S_COMPLETE
Successful completion
.El
.Sh STANDARDS
-.Bl -tag
+.Bl -tag -width ".It RFC 2743"
.It RFC 2743
Generic Security Service Application Program Interface Version 2, Update 1
.It RFC 2744
diff --git a/lib/libgssapi/gss_release_cred.3 b/lib/libgssapi/gss_release_cred.3
index 38fc784..99377e5 100644
--- a/lib/libgssapi/gss_release_cred.3
+++ b/lib/libgssapi/gss_release_cred.3
@@ -50,7 +50,7 @@ Implementations are encouraged to set the cred_handle to
.Dv GSS_C_NO_CREDENTIAL
on successful completion of this call.
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It minor_status"
.It minor_status
Mechanism specific status code.
.It cred_handle
@@ -59,14 +59,14 @@ If GSS_C_NO_CREDENTIAL is supplied,
the routine will complete successfully, but will do nothing.
.El
.Sh RETURN VALUES
-.Bl -tag
+.Bl -tag -width ".It GSS_S_COMPLETE"
.It GSS_S_COMPLETE
Successful completion
.It GSS_S_NO_CRED
Credentials could not be accessed
.El
.Sh STANDARDS
-.Bl -tag
+.Bl -tag -width ".It RFC 2743"
.It RFC 2743
Generic Security Service Application Program Interface Version 2, Update 1
.It RFC 2744
diff --git a/lib/libgssapi/gss_release_name.3 b/lib/libgssapi/gss_release_name.3
index ca737e0..b6f046e 100644
--- a/lib/libgssapi/gss_release_name.3
+++ b/lib/libgssapi/gss_release_name.3
@@ -48,21 +48,21 @@ Implementations are encouraged to set the name to
.Dv GSS_C_NO_NAME
on successful completion of this call.
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It minor status"
.It minor_status
Mechanism specific status code.
.It name
The name to be deleted.
.El
.Sh RETURN VALUES
-.Bl -tag
+.Bl -tag -width ".It GSS_S_COMPLETE"
.It GSS_S_COMPLETE
Successful completion
.It GSS_S_BAD_NAME
The name parameter did not contain a valid name
.El
.Sh STANDARDS
-.Bl -tag
+.Bl -tag -width ".It RFC 2743"
.It RFC 2743
Generic Security Service Application Program Interface Version 2, Update 1
.It RFC 2744
diff --git a/lib/libgssapi/gss_release_oid_set.3 b/lib/libgssapi/gss_release_oid_set.3
index 7de4e9a..6685816 100644
--- a/lib/libgssapi/gss_release_oid_set.3
+++ b/lib/libgssapi/gss_release_oid_set.3
@@ -55,19 +55,19 @@ Implementations are encouraged to set the gss_OID_set parameter to
.Dv GSS_C_NO_OID_SET
on successful completion of this routine.
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It minor_status"
.It minor_status
Mechanism specific status code.
.It set
The storage associated with the gss_OID_set will be deleted.
.El
.Sh RETURN VALUES
-.Bl -tag
+.Bl -tag -width ".It GSS_S_COMPLETE"
.It GSS_S_COMPLETE
Successful completion
.El
.Sh STANDARDS
-.Bl -tag
+.Bl -tag -width ".It RFC 2743"
.It RFC 2743
Generic Security Service Application Program Interface Version 2, Update 1
.It RFC 2744
diff --git a/lib/libgssapi/gss_test_oid_set_member.3 b/lib/libgssapi/gss_test_oid_set_member.3
index c6dad0f..5588e8a 100644
--- a/lib/libgssapi/gss_test_oid_set_member.3
+++ b/lib/libgssapi/gss_test_oid_set_member.3
@@ -54,7 +54,7 @@ and
.Fn gss_inquire_cred ,
but will also work with user-generated sets.
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It minor_status"
.It minor_status
Mechanism specific status code.
.It member
@@ -65,7 +65,7 @@ The Object Identifier set.
Non-zero if the specified OID is a member of the set, zero if not.
.El
.Sh RETURN VALUES
-.Bl -tag
+.Bl -tag -width ".It GSS_S_COMPLETE"
.It GSS_S_COMPLETE
Successful completion
.El
@@ -74,7 +74,7 @@ Successful completion
.Xr gss_acquire_cred 3 ,
.Xr gss_inquire_cred 3
.Sh STANDARDS
-.Bl -tag
+.Bl -tag -width ".It RFC 2743"
.It RFC 2743
Generic Security Service Application Program Interface Version 2, Update 1
.It RFC 2744
diff --git a/lib/libgssapi/gss_unwrap.3 b/lib/libgssapi/gss_unwrap.3
index 94537a4..368b361 100644
--- a/lib/libgssapi/gss_unwrap.3
+++ b/lib/libgssapi/gss_unwrap.3
@@ -90,7 +90,7 @@ both to allow GSS-API V1 applications to link
and to retain the slight parameter type differences between the
obsolete versions of this routine and its current form.
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It output_message_buffer"
.It minor_status
Mechanism specific status code.
.It context_handle
@@ -100,7 +100,7 @@ Protected message.
.It output_message_buffer
Buffer to receive unwrapped message.
Storage associated with this buffer must
-be freed by the application after use use
+be freed by the application after use
with a call to
.Xr gss_release_buffer 3 .
.It conf_state
@@ -116,7 +116,7 @@ Specify NULL if not required.
Quality of protection provided. Specify NULL if not required.
.El
.Sh RETURN VALUES
-.Bl -tag
+.Bl -tag -width ".It GSS_S_CONTEXT_EXPIRED"
.It GSS_S_COMPLETE
Successful completion.
.It GSS_S_DEFECTIVE_TOKEN
@@ -150,7 +150,7 @@ The context_handle parameter did not identify a valid context.
.Xr gss_wrap 3 ,
.Xr gss_release_buffer 3
.Sh STANDARDS
-.Bl -tag
+.Bl -tag -width ".It RFC 2743"
.It RFC 2743
Generic Security Service Application Program Interface Version 2, Update 1
.It RFC 2744
diff --git a/lib/libgssapi/gss_verify_mic.3 b/lib/libgssapi/gss_verify_mic.3
index e8a4611..ae7cee2 100644
--- a/lib/libgssapi/gss_verify_mic.3
+++ b/lib/libgssapi/gss_verify_mic.3
@@ -81,7 +81,7 @@ both to allow GSS-API V1 applications to link
and to retain the slight parameter type differences between the
obsolete versions of this routine and its current form.
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It context_handle"
.It minor_status
Mechanism specific status code.
.It context_handle
@@ -97,7 +97,7 @@ Specify
if not required.
.El
.Sh RETURN VALUES
-.Bl -tag
+.Bl -tag -width ".It GSS_S_CONTEXT_EXPIRED"
.It GSS_S_COMPLETE
Successful completion
.It GSS_S_DEFECTIVE_TOKEN
@@ -130,7 +130,7 @@ The context_handle parameter did not identify a valid context
.Sh SEE ALSO
.Xr gss_wrap 3
.Sh STANDARDS
-.Bl -tag
+.Bl -tag -width ".It RFC 2743"
.It RFC 2743
Generic Security Service Application Program Interface Version 2, Update 1
.It RFC 2744
diff --git a/lib/libgssapi/gss_wrap.3 b/lib/libgssapi/gss_wrap.3
index 5732dd2..edc1345 100644
--- a/lib/libgssapi/gss_wrap.3
+++ b/lib/libgssapi/gss_wrap.3
@@ -85,13 +85,13 @@ both to allow GSS-API V1 applications to link
and to retain the slight parameter type differences between the
obsolete versions of this routine and its current form.
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It output_message_buffer"
.It minor_status
Mechanism specific status code.
.It context_handle
Identifies the context on which the message will be sent.
.It conf_req_flag
-.Bl -tag -width "Non-zero"
+.Bl -tag -width "Non-zero" -compact
.It Non-zero
Both confidentiality and integrity services are requested.
.It Zero
@@ -108,7 +108,7 @@ will return a major_status of
.It input_message_buffer
Message to be protected.
.It conf_state
-.Bl -tag -width "Non-zero"
+.Bl -tag -width "Non-zero" -compact
.It Non-zero
Confidentiality, data origin authentication and integrity services
have been applied.
@@ -118,12 +118,12 @@ Integrity and data origin services only has been applied.
.It output_message_buffer
Buffer to receive protected message.
Storage associated with this buffer must
-be freed by the application after use use
+be freed by the application after use
with a call to
.Xr gss_release_buffer 3 .
.El
.Sh RETURN VALUES
-.Bl -tag
+.Bl -tag -width ".It GSS_S_CONTEXT_EXPIRED"
.It GSS_S_COMPLETE
Successful completion.
.It GSS_S_CONTEXT_EXPIRED
@@ -137,7 +137,7 @@ The specified QOP is not supported by the mechanism.
.Xr gss_unwrap 3 ,
.Xr gss_release_buffer 3
.Sh STANDARDS
-.Bl -tag
+.Bl -tag -width ".It RFC 2743"
.It RFC 2743
Generic Security Service Application Program Interface Version 2, Update 1
.It RFC 2744
diff --git a/lib/libgssapi/gss_wrap_size_limit.3 b/lib/libgssapi/gss_wrap_size_limit.3
index 7a1cb59..afbff86 100644
--- a/lib/libgssapi/gss_wrap_size_limit.3
+++ b/lib/libgssapi/gss_wrap_size_limit.3
@@ -83,7 +83,7 @@ the implementation should not return a value via
.Dv max_input_bytes
that is greater than this length.
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It req_output_size"
.It minor_status
Mechanism specific status code.
.It context_handle
@@ -109,7 +109,7 @@ be no larger than
bytes.
.El
.Sh RETURN VALUES
-.Bl -tag
+.Bl -tag -width ".It GSS_S_CONTEXT_EXPIRED"
.It GSS_S_COMPLETE
Successful completion.
.It GSS_S_NO_CONTEXT
@@ -122,7 +122,7 @@ The specified QOP is not supported by the mechanism.
.Sh SEE ALSO
.Xr gss_wrap 3
.Sh STANDARDS
-.Bl -tag
+.Bl -tag -width ".It RFC 2743"
.It RFC 2743
Generic Security Service Application Program Interface Version 2, Update 1
.It RFC 2744
diff --git a/lib/libgssapi/gssapi.3 b/lib/libgssapi/gssapi.3
index 121d9e4..d41595e 100644
--- a/lib/libgssapi/gssapi.3
+++ b/lib/libgssapi/gssapi.3
@@ -219,7 +219,7 @@ functionality is not available from the generic forms.
Applications are encouraged to use the generic routines wherever
possible on portability grounds.
.Sh STANDARDS
-.Bl -tag
+.Bl -tag -width ".It RFC 2743"
.It RFC 2743
Generic Security Service Application Program Interface Version 2, Update 1
.It RFC 2744
diff --git a/lib/libgssapi/mech.5 b/lib/libgssapi/mech.5
index b56565e..dd15ba9 100644
--- a/lib/libgssapi/mech.5
+++ b/lib/libgssapi/mech.5
@@ -39,17 +39,17 @@ The
file contains a list of installed GSS-API security mechanisms.
Each line of the file either contains a comment if the first character
is '#' or it contains five fields with the following meanings:
-.Bl -tag
+.Bl -tag -width ".It Object identifier"
.It Name
The name of this GSS-API mechanism.
.It Object identifier
The OID for this mechanism.
.It Library
A shared library containing the implementation of this mechanism.
-.It Kernel module (optional)
-A kernel module containing the implementation of this mechanism (not
+.It Kernel module
+Optional kernel module containing the implementation of this mechanism (not
yet supported in FreeBSD).
-.It Library options (optional)
+.It Library options
Optional parameters interpreted by the mechanism. Library options
must be enclosed in brackets ([ ]) to differentiate them from the
optional kernel module entry.
@@ -68,7 +68,7 @@ file contains a list of Quality of Protection values for use with
GSS-API.
Each line of the file either contains a comment if the first character
is '#' or it contains three fields with the following meanings:
-.Bl -tag
+.Bl -tag -width ".It Mechanism name"
.It QOP string
The name of this Quality of Protection algorithm.
.It QOP value
diff --git a/lib/libjail/jail.c b/lib/libjail/jail.c
index af0e40a..5cd2ad2 100644
--- a/lib/libjail/jail.c
+++ b/lib/libjail/jail.c
@@ -853,9 +853,9 @@ jailparam_free(struct jailparam *jp, unsigned njp)
static int
jailparam_type(struct jailparam *jp)
{
- char *p, *nname;
+ char *p, *name, *nname;
size_t miblen, desclen;
- int isarray;
+ int i, isarray;
struct {
int i;
char s[MAXPATHLEN];
@@ -863,7 +863,8 @@ jailparam_type(struct jailparam *jp)
int mib[CTL_MAXNAME];
/* The "lastjid" parameter isn't real. */
- if (!strcmp(jp->jp_name, "lastjid")) {
+ name = jp->jp_name;
+ if (!strcmp(name, "lastjid")) {
jp->jp_valuelen = sizeof(int);
jp->jp_ctltype = CTLTYPE_INT | CTLFLAG_WR;
return (0);
@@ -872,19 +873,19 @@ jailparam_type(struct jailparam *jp)
/* Find the sysctl that describes the parameter. */
mib[0] = 0;
mib[1] = 3;
- snprintf(desc.s, sizeof(desc.s), SJPARAM ".%s", jp->jp_name);
+ snprintf(desc.s, sizeof(desc.s), SJPARAM ".%s", name);
miblen = sizeof(mib) - 2 * sizeof(int);
if (sysctl(mib, 2, mib + 2, &miblen, desc.s, strlen(desc.s)) < 0) {
if (errno != ENOENT) {
snprintf(jail_errmsg, JAIL_ERRMSGLEN,
- "sysctl(0.3.%s): %s", jp->jp_name, strerror(errno));
+ "sysctl(0.3.%s): %s", name, strerror(errno));
return (-1);
}
/*
* The parameter probably doesn't exist. But it might be
* the "no" counterpart to a boolean.
*/
- nname = nononame(jp->jp_name);
+ nname = nononame(name);
if (nname == NULL) {
unknown_parameter:
snprintf(jail_errmsg, JAIL_ERRMSGLEN,
@@ -892,8 +893,10 @@ jailparam_type(struct jailparam *jp)
errno = ENOENT;
return (-1);
}
- snprintf(desc.s, sizeof(desc.s), SJPARAM ".%s", nname);
+ name = alloca(strlen(nname) + 1);
+ strcpy(name, nname);
free(nname);
+ snprintf(desc.s, sizeof(desc.s), SJPARAM ".%s", name);
miblen = sizeof(mib) - 2 * sizeof(int);
if (sysctl(mib, 2, mib + 2, &miblen, desc.s,
strlen(desc.s)) < 0)
@@ -906,7 +909,7 @@ jailparam_type(struct jailparam *jp)
if (sysctl(mib, (miblen / sizeof(int)) + 2, &desc, &desclen,
NULL, 0) < 0) {
snprintf(jail_errmsg, JAIL_ERRMSGLEN,
- "sysctl(0.4.%s): %s", jp->jp_name, strerror(errno));
+ "sysctl(0.4.%s): %s", name, strerror(errno));
return (-1);
}
jp->jp_ctltype = desc.i;
@@ -952,7 +955,7 @@ jailparam_type(struct jailparam *jp)
if (sysctl(mib + 2, miblen / sizeof(int), desc.s, &desclen,
NULL, 0) < 0) {
snprintf(jail_errmsg, JAIL_ERRMSGLEN,
- "sysctl(" SJPARAM ".%s): %s", jp->jp_name,
+ "sysctl(" SJPARAM ".%s): %s", name,
strerror(errno));
return (-1);
}
@@ -970,28 +973,39 @@ jailparam_type(struct jailparam *jp)
if (sysctl(mib + 2, miblen / sizeof(int),
NULL, &jp->jp_valuelen, NULL, 0) < 0) {
snprintf(jail_errmsg, JAIL_ERRMSGLEN,
- "sysctl(" SJPARAM ".%s): %s", jp->jp_name,
+ "sysctl(" SJPARAM ".%s): %s", name,
strerror(errno));
return (-1);
}
}
break;
case CTLTYPE_NODE:
- /* A node might be described by an empty-named child. */
+ /*
+ * A node might be described by an empty-named child,
+ * which would be immediately before or after the node itself.
+ */
mib[1] = 1;
- mib[(miblen / sizeof(int)) + 2] =
- mib[(miblen / sizeof(int)) + 1] - 1;
miblen += sizeof(int);
- desclen = sizeof(desc.s);
- if (sysctl(mib, (miblen / sizeof(int)) + 2, desc.s, &desclen,
- NULL, 0) < 0) {
- snprintf(jail_errmsg, JAIL_ERRMSGLEN,
- "sysctl(0.1): %s", strerror(errno));
- return (-1);
+ for (i = -1; i <= 1; i += 2) {
+ mib[(miblen / sizeof(int)) + 1] =
+ mib[(miblen / sizeof(int))] + i;
+ desclen = sizeof(desc.s);
+ if (sysctl(mib, (miblen / sizeof(int)) + 2, desc.s,
+ &desclen, NULL, 0) < 0) {
+ if (errno == ENOENT)
+ continue;
+ snprintf(jail_errmsg, JAIL_ERRMSGLEN,
+ "sysctl(0.1): %s", strerror(errno));
+ return (-1);
+ }
+ if (desclen == sizeof(SJPARAM) + strlen(name) + 2 &&
+ memcmp(SJPARAM ".", desc.s, sizeof(SJPARAM)) == 0 &&
+ memcmp(name, desc.s + sizeof(SJPARAM),
+ desclen - sizeof(SJPARAM) - 2) == 0 &&
+ desc.s[desclen - 2] == '.')
+ goto mib_desc;
}
- if (desc.s[desclen - 2] != '.')
- goto unknown_parameter;
- goto mib_desc;
+ goto unknown_parameter;
default:
snprintf(jail_errmsg, JAIL_ERRMSGLEN,
"unknown type for %s", jp->jp_name);
diff --git a/lib/libkiconv/Makefile b/lib/libkiconv/Makefile
index 4ba860e..bda505e 100644
--- a/lib/libkiconv/Makefile
+++ b/lib/libkiconv/Makefile
@@ -1,7 +1,10 @@
# $FreeBSD$
-LIB= kiconv
SHLIBDIR?= /lib
+
+.include <bsd.own.mk>
+
+LIB= kiconv
SRCS= kiconv_sysctl.c xlat16_iconv.c xlat16_sysctl.c
SRCS+= quirks.c
@@ -17,4 +20,8 @@ CFLAGS+= -I${.CURDIR}/../../sys
WARNS?= 1
+.if ${MK_ICONV} == "no"
+CFLAGS+= -DICONV_DLOPEN
+.endif
+
.include <bsd.lib.mk>
diff --git a/lib/libkiconv/xlat16_iconv.c b/lib/libkiconv/xlat16_iconv.c
index dc9dc86..f402b78 100644
--- a/lib/libkiconv/xlat16_iconv.c
+++ b/lib/libkiconv/xlat16_iconv.c
@@ -60,10 +60,18 @@ struct xlat16_table {
static struct xlat16_table kiconv_xlat16_open(const char *, const char *, int);
static int chklocale(int, const char *);
+#ifdef ICONV_DLOPEN
static int my_iconv_init(void);
static iconv_t (*my_iconv_open)(const char *, const char *);
static size_t (*my_iconv)(iconv_t, const char **, size_t *, char **, size_t *);
static int (*my_iconv_close)(iconv_t);
+#else
+#include <iconv.h>
+#define my_iconv_init() 0
+#define my_iconv_open iconv_open
+#define my_iconv iconv
+#define my_iconv_close iconv_close
+#endif
static size_t my_iconv_char(iconv_t, const u_char **, size_t *, u_char **, size_t *);
int
@@ -310,6 +318,7 @@ chklocale(int category, const char *code)
return (error);
}
+#ifdef ICONV_DLOPEN
static int
my_iconv_init(void)
{
@@ -327,6 +336,7 @@ my_iconv_init(void)
return (0);
}
+#endif
static size_t
my_iconv_char(iconv_t cd, const u_char **ibuf, size_t * ilen, u_char **obuf,
diff --git a/lib/libkvm/kvm_getpcpu.3 b/lib/libkvm/kvm_getpcpu.3
index 92036ca..1e0c1f4 100644
--- a/lib/libkvm/kvm_getpcpu.3
+++ b/lib/libkvm/kvm_getpcpu.3
@@ -114,7 +114,7 @@ it returns -1 instead.
On success, the
.Fn kvm_getpcpu
function returns a pointer to an allocated buffer or
-.Dv NULL.
+.Dv NULL .
If an error occurs,
it returns -1 instead.
.Pp
@@ -124,7 +124,7 @@ call returns 0; if an error occurs, it returns -1 instead.
.Pp
If any function encounters an error,
then an error message may be retrieved via
-.Xr kvm_geterr 3.
+.Xr kvm_geterr 3 .
.Sh SEE ALSO
.Xr free 3 ,
.Xr kvm 3
diff --git a/lib/libmagic/Makefile b/lib/libmagic/Makefile
index 5957306..fbf71ef 100644
--- a/lib/libmagic/Makefile
+++ b/lib/libmagic/Makefile
@@ -39,8 +39,9 @@ magic.mgc: mkmagic magic
CLEANFILES+= mkmagic
build-tools: mkmagic
-mkmagic: apprentice.c funcs.c magic.c print.c
- ${CC} ${CFLAGS} -DCOMPILE_ONLY ${LDFLAGS} -o ${.TARGET} ${.ALLSRC}
+mkmagic: apprentice.c funcs.c getline.c magic.c print.c
+ ${CC} ${CFLAGS} -DCOMPILE_ONLY -DHOSTPROG ${LDFLAGS} \
+ -o ${.TARGET} ${.ALLSRC}
FILEVER!= awk '$$1 == "\#define" && $$2 == "VERSION" { print $$3; exit }' \
${.CURDIR}/config.h
diff --git a/lib/libmagic/config.h b/lib/libmagic/config.h
index c7e38ec..c17883f 100644
--- a/lib/libmagic/config.h
+++ b/lib/libmagic/config.h
@@ -39,7 +39,9 @@
#define HAVE_FSEEKO 1
/* Define to 1 if you have the `getline' function. */
+#ifndef HOSTPROG
#define HAVE_GETLINE 1
+#endif
/* Define to 1 if you have the <getopt.h> header file. */
#define HAVE_GETOPT_H 1
diff --git a/lib/libmd/Makefile b/lib/libmd/Makefile
index 534e8b3..d0fe705 100644
--- a/lib/libmd/Makefile
+++ b/lib/libmd/Makefile
@@ -1,20 +1,18 @@
# $FreeBSD$
LIB= md
+SHLIB_MAJOR= 6
SHLIBDIR?= /lib
-SRCS= md2c.c md4c.c md5c.c md2hl.c md4hl.c md5hl.c \
+SRCS= md4c.c md5c.c md4hl.c md5hl.c \
rmd160c.c rmd160hl.c \
sha0c.c sha0hl.c sha1c.c sha1hl.c \
sha256c.c sha256hl.c \
sha512c.c sha512hl.c
-INCS= md2.h md4.h md5.h ripemd.h sha.h sha256.h sha512.h
+INCS= md4.h md5.h ripemd.h sha.h sha256.h sha512.h
WARNS?= 0
-MAN+= md2.3 md4.3 md5.3 ripemd.3 sha.3 sha256.3 sha512.3
-MLINKS+=md2.3 MD2Init.3 md2.3 MD2Update.3 md2.3 MD2Final.3
-MLINKS+=md2.3 MD2End.3 md2.3 MD2File.3 md2.3 MD2FileChunk.3
-MLINKS+=md2.3 MD2Data.3
+MAN+= md4.3 md5.3 ripemd.3 sha.3 sha256.3 sha512.3
MLINKS+=md4.3 MD4Init.3 md4.3 MD4Update.3 md4.3 MD4Final.3
MLINKS+=md4.3 MD4End.3 md4.3 MD4File.3 md4.3 MD4FileChunk.3
MLINKS+=md4.3 MD4Data.3
@@ -59,10 +57,6 @@ CFLAGS+= -DRMD160_ASM
ACFLAGS+= -DELF -Wa,--noexecstack
.endif
-md2hl.c: mdXhl.c
- (echo '#define LENGTH 16'; \
- sed -e 's/mdX/md2/g' -e 's/MDX/MD2/g' ${.ALLSRC}) > ${.TARGET}
-
md4hl.c: mdXhl.c
(echo '#define LENGTH 16'; \
sed -e 's/mdX/md4/g' -e 's/MDX/MD4/g' ${.ALLSRC}) > ${.TARGET}
@@ -105,16 +99,6 @@ md${i}.3: ${.CURDIR}/mdX.3
cat ${.CURDIR}/md${i}.copyright >> ${.TARGET}
.endfor
-md2.ref:
- echo 'MD2 test suite:' > ${.TARGET}
- @echo 'MD2 ("") = 8350e5a3e24c153df2275c9f80692773' >> ${.TARGET}
- @echo 'MD2 ("a") = 32ec01ec4a6dac72c0ab96fb34c0b5d1' >> ${.TARGET}
- @echo 'MD2 ("abc") = da853b0d3f88d99b30283a69e6ded6bb' >> ${.TARGET}
- @echo 'MD2 ("message digest") = ab4f496bfb2a530b219ff33031fe06b0' >> ${.TARGET}
- @echo 'MD2 ("abcdefghijklmnopqrstuvwxyz") = 4e8ddff3650292ab5a4108c3aa47940b' >> ${.TARGET}
- @echo 'MD2 ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") = da33def2a42df13975352846c30338cd' >> ${.TARGET}
- @echo 'MD2 ("12345678901234567890123456789012345678901234567890123456789012345678901234567890") = d5976f79d83d3a0dc9806c3c66f3efd8' >> ${.TARGET}
-
md4.ref:
echo 'MD4 test suite:' > ${.TARGET}
@echo 'MD4 ("") = 31d6cfe0d16ae931b73c59d7e0c089c0' >> ${.TARGET}
@@ -205,12 +189,9 @@ rmd160.ref:
@echo 'RIPEMD160 ("12345678901234567890123456789012345678901234567890123456789012345678901234567890") =' \
'9b752e45573d4b39f4dbd3323cab82bf63326bfb' >> ${.TARGET}
-test: md2.ref md4.ref md5.ref sha0.ref rmd160.ref sha1.ref sha256.ref sha512.ref
+test: md4.ref md5.ref sha0.ref rmd160.ref sha1.ref sha256.ref sha512.ref
@${ECHO} if any of these test fail, the code produces wrong results
@${ECHO} and should NOT be used.
- ${CC} ${CFLAGS} ${LDFLAGS} -DMD=2 -o mddriver ${.CURDIR}/mddriver.c ./libmd.a
- ./mddriver | cmp md2.ref -
- @${ECHO} MD2 passed test
${CC} ${CFLAGS} ${LDFLAGS} -DMD=4 -o mddriver ${.CURDIR}/mddriver.c libmd.a
./mddriver | cmp md4.ref -
@${ECHO} MD4 passed test
diff --git a/lib/libmd/md2.copyright b/lib/libmd/md2.copyright
deleted file mode 100644
index acef7ba..0000000
--- a/lib/libmd/md2.copyright
+++ /dev/null
@@ -1,17 +0,0 @@
-.\" $FreeBSD$
-Copyright (C) 1990-2, RSA Data Security, Inc. Created 1990. All
-rights reserved.
-.Pp
-License to copy and use this software is granted for
-non-commercial Internet Privacy-Enhanced Mail provided that it is
-identified as the "RSA Data Security, Inc. MD2 Message Digest
-Algorithm" in all material mentioning or referencing this software
-or this function.
-.Pp
-RSA Data Security, Inc. makes no representations concerning either
-the merchantability of this software or the suitability of this
-software for any particular purpose. It is provided "as is"
-without express or implied warranty of any kind.
-.Pp
-These notices must be retained in any copies of any part of this
-documentation and/or software.
diff --git a/lib/libmd/md2.h b/lib/libmd/md2.h
deleted file mode 100644
index f0229f5..0000000
--- a/lib/libmd/md2.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/* MD2.H - header file for MD2C.C
- * $FreeBSD$
- */
-
-/* Copyright (C) 1990-2, RSA Data Security, Inc. Created 1990. All
- rights reserved.
-
- License to copy and use this software is granted for
- non-commercial Internet Privacy-Enhanced Mail provided that it is
- identified as the "RSA Data Security, Inc. MD2 Message Digest
- Algorithm" in all material mentioning or referencing this software
- or this function.
-
- RSA Data Security, Inc. makes no representations concerning either
- the merchantability of this software or the suitability of this
- software for any particular purpose. It is provided "as is"
- without express or implied warranty of any kind.
-
- These notices must be retained in any copies of any part of this
- documentation and/or software.
- */
-
-#ifndef _MD2_H_
-#define _MD2_H_
-
-typedef struct MD2Context {
- unsigned char state[16]; /* state */
- unsigned char checksum[16]; /* checksum */
- unsigned int count; /* number of bytes, modulo 16 */
- unsigned char buffer[16]; /* input buffer */
-} MD2_CTX;
-
-#include <sys/cdefs.h>
-
-__BEGIN_DECLS
-void MD2Init(MD2_CTX *);
-void MD2Update(MD2_CTX *, const void *, unsigned int);
-void MD2Pad(MD2_CTX *);
-void MD2Final(unsigned char [16], MD2_CTX *);
-char * MD2End(MD2_CTX *, char *);
-char * MD2File(const char *, char *);
-char * MD2FileChunk(const char *, char *, off_t, off_t);
-char * MD2Data(const void *, unsigned int, char *);
-__END_DECLS
-
-#endif /* _MD2_H_ */
diff --git a/lib/libmd/md2c.c b/lib/libmd/md2c.c
deleted file mode 100644
index 4799457..0000000
--- a/lib/libmd/md2c.c
+++ /dev/null
@@ -1,211 +0,0 @@
-/* MD2C.C - RSA Data Security, Inc., MD2 message-digest algorithm
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-/* Copyright (C) 1990-2, RSA Data Security, Inc. Created 1990. All
- rights reserved.
-
- License to copy and use this software is granted for
- non-commercial Internet Privacy-Enhanced Mail provided that it is
- identified as the "RSA Data Security, Inc. MD2 Message Digest
- Algorithm" in all material mentioning or referencing this software
- or this function.
-
- RSA Data Security, Inc. makes no representations concerning either
- the merchantability of this software or the suitability of this
- software for any particular purpose. It is provided "as is"
- without express or implied warranty of any kind.
-
- These notices must be retained in any copies of any part of this
- documentation and/or software.
- */
-
-#include <sys/types.h>
-#include <string.h>
-#include "md2.h"
-
-
-typedef unsigned char *POINTER;
-typedef u_int16_t UINT2;
-typedef u_int32_t UINT4;
-
-#define PROTO_LIST(list) list
-
-static void MD2Transform PROTO_LIST
- ((unsigned char [16], unsigned char [16], const unsigned char [16]));
-
-/* Permutation of 0..255 constructed from the digits of pi. It gives a
- "random" nonlinear byte substitution operation.
- */
-static unsigned char PI_SUBST[256] = {
- 41, 46, 67, 201, 162, 216, 124, 1, 61, 54, 84, 161, 236, 240, 6,
- 19, 98, 167, 5, 243, 192, 199, 115, 140, 152, 147, 43, 217, 188,
- 76, 130, 202, 30, 155, 87, 60, 253, 212, 224, 22, 103, 66, 111, 24,
- 138, 23, 229, 18, 190, 78, 196, 214, 218, 158, 222, 73, 160, 251,
- 245, 142, 187, 47, 238, 122, 169, 104, 121, 145, 21, 178, 7, 63,
- 148, 194, 16, 137, 11, 34, 95, 33, 128, 127, 93, 154, 90, 144, 50,
- 39, 53, 62, 204, 231, 191, 247, 151, 3, 255, 25, 48, 179, 72, 165,
- 181, 209, 215, 94, 146, 42, 172, 86, 170, 198, 79, 184, 56, 210,
- 150, 164, 125, 182, 118, 252, 107, 226, 156, 116, 4, 241, 69, 157,
- 112, 89, 100, 113, 135, 32, 134, 91, 207, 101, 230, 45, 168, 2, 27,
- 96, 37, 173, 174, 176, 185, 246, 28, 70, 97, 105, 52, 64, 126, 15,
- 85, 71, 163, 35, 221, 81, 175, 58, 195, 92, 249, 206, 186, 197,
- 234, 38, 44, 83, 13, 110, 133, 40, 132, 9, 211, 223, 205, 244, 65,
- 129, 77, 82, 106, 220, 55, 200, 108, 193, 171, 250, 36, 225, 123,
- 8, 12, 189, 177, 74, 120, 136, 149, 139, 227, 99, 232, 109, 233,
- 203, 213, 254, 59, 0, 29, 57, 242, 239, 183, 14, 102, 88, 208, 228,
- 166, 119, 114, 248, 235, 117, 75, 10, 49, 68, 80, 180, 143, 237,
- 31, 26, 219, 153, 141, 51, 159, 17, 131, 20
-};
-
-static unsigned char *PADDING[] = {
- (unsigned char *)"",
- (unsigned char *)"\001",
- (unsigned char *)"\002\002",
- (unsigned char *)"\003\003\003",
- (unsigned char *)"\004\004\004\004",
- (unsigned char *)"\005\005\005\005\005",
- (unsigned char *)"\006\006\006\006\006\006",
- (unsigned char *)"\007\007\007\007\007\007\007",
- (unsigned char *)"\010\010\010\010\010\010\010\010",
- (unsigned char *)"\011\011\011\011\011\011\011\011\011",
- (unsigned char *)"\012\012\012\012\012\012\012\012\012\012",
- (unsigned char *)"\013\013\013\013\013\013\013\013\013\013\013",
- (unsigned char *)"\014\014\014\014\014\014\014\014\014\014\014\014",
- (unsigned char *)
- "\015\015\015\015\015\015\015\015\015\015\015\015\015",
- (unsigned char *)
- "\016\016\016\016\016\016\016\016\016\016\016\016\016\016",
- (unsigned char *)
- "\017\017\017\017\017\017\017\017\017\017\017\017\017\017\017",
- (unsigned char *)
- "\020\020\020\020\020\020\020\020\020\020\020\020\020\020\020\020"
-};
-
-/* MD2 initialization. Begins an MD2 operation, writing a new context.
- */
-void MD2Init (context)
-MD2_CTX *context; /* context */
-{
- context->count = 0;
- memset ((POINTER)context->state, 0, sizeof (context->state));
- memset
- ((POINTER)context->checksum, 0, sizeof (context->checksum));
-}
-
-/* MD2 block update operation. Continues an MD2 message-digest
- operation, processing another message block, and updating the
- context.
- */
-void MD2Update (context, in, inputLen)
-MD2_CTX *context; /* context */
-const void *in; /* input block */
-unsigned int inputLen; /* length of input block */
-{
- unsigned int i, idx, partLen;
- const unsigned char *input = in;
-
- /* Update number of bytes mod 16 */
- idx = context->count;
- context->count = (idx + inputLen) & 0xf;
-
- partLen = 16 - idx;
-
- /* Transform as many times as possible.
- */
- if (inputLen >= partLen) {
- memcpy
- ((POINTER)&context->buffer[idx], (POINTER)input, partLen);
- MD2Transform (context->state, context->checksum, context->buffer);
-
- for (i = partLen; i + 15 < inputLen; i += 16)
- MD2Transform (context->state, context->checksum, &input[i]);
-
- idx = 0;
- }
- else
- i = 0;
-
- /* Buffer remaining input */
- memcpy
- ((POINTER)&context->buffer[idx], (POINTER)&input[i],
- inputLen-i);
-}
-
-/* MD2 padding.
- */
-void MD2Pad (context)
-MD2_CTX *context; /* context */
-{
- unsigned int idx, padLen;
-
- /* Pad out to multiple of 16.
- */
- idx = context->count;
- padLen = 16 - idx;
- MD2Update (context, PADDING[padLen], padLen);
-
- /* Extend with checksum */
- MD2Update (context, context->checksum, 16);
-}
-
-/* MD2 finalization. Ends an MD2 message-digest operation, writing the
- message digest and zeroizing the context.
- */
-void MD2Final (digest, context)
-unsigned char digest[16]; /* message digest */
-MD2_CTX *context; /* context */
-{
- /* Do padding */
- MD2Pad (context);
-
- /* Store state in digest */
- memcpy ((POINTER)digest, (POINTER)context->state, 16);
-
- /* Zeroize sensitive information.
- */
- memset ((POINTER)context, 0, sizeof (*context));
-}
-
-/* MD2 basic transformation. Transforms state and updates checksum
- based on block.
- */
-static void MD2Transform (state, checksum, block)
-unsigned char state[16];
-unsigned char checksum[16];
-const unsigned char block[16];
-{
- unsigned int i, j, t;
- unsigned char x[48];
-
- /* Form encryption block from state, block, state ^ block.
- */
- memcpy ((POINTER)x, (POINTER)state, 16);
- memcpy ((POINTER)x+16, (POINTER)block, 16);
- for (i = 0; i < 16; i++)
- x[i+32] = state[i] ^ block[i];
-
- /* Encrypt block (18 rounds).
- */
- t = 0;
- for (i = 0; i < 18; i++) {
- for (j = 0; j < 48; j++)
- t = x[j] ^= PI_SUBST[t];
- t = (t + i) & 0xff;
- }
-
- /* Save new state */
- memcpy ((POINTER)state, (POINTER)x, 16);
-
- /* Update checksum.
- */
- t = checksum[15];
- for (i = 0; i < 16; i++)
- t = checksum[i] ^= PI_SUBST[block[i] ^ t];
-
- /* Zeroize sensitive information.
- */
- memset ((POINTER)x, 0, sizeof (x));
-}
diff --git a/lib/libmd/mdX.3 b/lib/libmd/mdX.3
index 03f50f1..223e2ef 100644
--- a/lib/libmd/mdX.3
+++ b/lib/libmd/mdX.3
@@ -52,8 +52,7 @@ This net result is a
.Dq fingerprint
of the input-data, which does not disclose the actual input.
.Pp
-MD2 is the slowest, MD4 is the fastest and MD5 is somewhere in the middle.
-MD2 can only be used for Privacy-Enhanced Mail.
+MD4 is the fastest and MD5 is somewhat slower.
MD4 has now been broken; it should only be used where necessary for
backward compatibility.
MD5 has not yet (1999-02-11) been broken, but sufficient attacks have been
@@ -144,16 +143,10 @@ If the
.Fa buf
argument is non-null it must point to at least 33 characters of buffer space.
.Sh SEE ALSO
-.Xr md2 3 ,
.Xr md4 3 ,
.Xr md5 3 ,
.Xr sha 3
.Rs
-.%A B. Kaliski
-.%T The MD2 Message-Digest Algorithm
-.%O RFC 1319
-.Re
-.Rs
.%A R. Rivest
.%T The MD4 Message-Digest Algorithm
.%O RFC 1186
@@ -192,6 +185,3 @@ Phk ristede runen.
No method is known to exist which finds two files having the same hash value,
nor to find a file with a specific hash value.
There is on the other hand no guarantee that such a method does not exist.
-.Pp
-MD2 has only been licensed for use in Privacy Enhanced Mail.
-Use MD4 or MD5 if that is not what you are doing.
diff --git a/lib/libnandfs/Makefile b/lib/libnandfs/Makefile
new file mode 100644
index 0000000..d87573e
--- /dev/null
+++ b/lib/libnandfs/Makefile
@@ -0,0 +1,9 @@
+# $FreeBSD$
+
+LIB= nandfs
+SRCS+= nandfs.c
+INCS= libnandfs.h
+
+CFLAGS += -I${.CURDIR}
+
+.include <bsd.lib.mk>
diff --git a/lib/libnandfs/libnandfs.h b/lib/libnandfs/libnandfs.h
new file mode 100644
index 0000000..8338c63
--- /dev/null
+++ b/lib/libnandfs/libnandfs.h
@@ -0,0 +1,65 @@
+/*-
+ * Copyright (c) 2010-2012 Semihalf.
+ * 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$
+ */
+
+#ifndef _LIBNANDFS_NANDFS_H
+#define _LIBNANDFS_NANDFS_H
+
+struct nandfs {
+ struct nandfs_fsdata n_fsdata;
+ struct nandfs_super_block n_sb;
+ char n_ioc[MNAMELEN];
+ char n_dev[MNAMELEN];
+ int n_iocfd;
+ int n_devfd;
+ int n_flags;
+ char n_errmsg[120];
+};
+
+int nandfs_iserror(struct nandfs *);
+const char *nandfs_errmsg(struct nandfs *);
+
+void nandfs_init(struct nandfs *, const char *);
+void nandfs_destroy(struct nandfs *);
+
+const char *nandfs_dev(struct nandfs *);
+
+int nandfs_open(struct nandfs *);
+void nandfs_close(struct nandfs *);
+
+int nandfs_get_cpstat(struct nandfs *, struct nandfs_cpstat *);
+
+ssize_t nandfs_get_cp(struct nandfs *, uint64_t,
+ struct nandfs_cpinfo *, size_t);
+
+ssize_t nandfs_get_snap(struct nandfs *, uint64_t,
+ struct nandfs_cpinfo *, size_t);
+
+int nandfs_make_snap(struct nandfs *, uint64_t *);
+int nandfs_delete_snap(struct nandfs *, uint64_t);
+
+#endif /* _LIBNANDFS_NANDFS_H */
diff --git a/lib/libnandfs/nandfs.c b/lib/libnandfs/nandfs.c
new file mode 100644
index 0000000..fd59a92
--- /dev/null
+++ b/lib/libnandfs/nandfs.c
@@ -0,0 +1,247 @@
+/*-
+ * Copyright (c) 2010-2012 Semihalf.
+ * 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 <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <assert.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <sys/param.h>
+#include <sys/stdint.h>
+#include <sys/ucred.h>
+#include <sys/disk.h>
+#include <sys/mount.h>
+
+#include <fs/nandfs/nandfs_fs.h>
+#include <libnandfs.h>
+
+#define NANDFS_IS_VALID 0x1
+#define NANDFS_IS_OPENED 0x2
+#define NANDFS_IS_OPENED_DEV 0x4
+#define NANDFS_IS_ERROR 0x8
+
+#define DEBUG
+#undef DEBUG
+#ifdef DEBUG
+#define NANDFS_DEBUG(fmt, args...) do { \
+ printf("libnandfs:" fmt "\n", ##args); } while (0)
+#else
+#define NANDFS_DEBUG(fmt, args...)
+#endif
+
+#define NANDFS_ASSERT_VALID(fs) assert((fs)->n_flags & NANDFS_IS_VALID)
+#define NANDFS_ASSERT_VALID_DEV(fs) \
+ assert(((fs)->n_flags & (NANDFS_IS_VALID | NANDFS_IS_OPENED_DEV)) == \
+ (NANDFS_IS_VALID | NANDFS_IS_OPENED_DEV))
+
+int
+nandfs_iserror(struct nandfs *fs)
+{
+
+ NANDFS_ASSERT_VALID(fs);
+
+ return (fs->n_flags & NANDFS_IS_ERROR);
+}
+
+const char *
+nandfs_errmsg(struct nandfs *fs)
+{
+
+ NANDFS_ASSERT_VALID(fs);
+
+ assert(nandfs_iserror(fs));
+ assert(fs->n_errmsg);
+ return (fs->n_errmsg);
+}
+
+static void
+nandfs_seterr(struct nandfs *fs, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ vsnprintf(fs->n_errmsg, sizeof(fs->n_errmsg), fmt, ap);
+ va_end(ap);
+ fs->n_flags |= NANDFS_IS_ERROR;
+}
+
+const char *
+nandfs_dev(struct nandfs *fs)
+{
+
+ NANDFS_ASSERT_VALID(fs);
+ return (fs->n_dev);
+}
+
+void
+nandfs_init(struct nandfs *fs, const char *dir)
+{
+
+ snprintf(fs->n_ioc, sizeof(fs->n_ioc), "%s/%s", dir, ".");
+ fs->n_iocfd = -1;
+ fs->n_flags = NANDFS_IS_VALID;
+}
+
+void
+nandfs_destroy(struct nandfs *fs)
+{
+
+ assert(fs->n_iocfd == -1);
+ fs->n_flags &=
+ ~(NANDFS_IS_ERROR | NANDFS_IS_VALID);
+ assert(fs->n_flags == 0);
+}
+
+int
+nandfs_open(struct nandfs *fs)
+{
+ struct nandfs_fsinfo fsinfo;
+
+ fs->n_flags |= NANDFS_IS_OPENED;
+
+ fs->n_iocfd = open(fs->n_ioc, O_RDONLY, S_IRUSR | S_IWUSR | S_IRGRP |
+ S_IWGRP | S_IROTH | S_IWOTH);
+ if (fs->n_iocfd == -1) {
+ nandfs_seterr(fs, "couldn't open %s: %s", fs->n_ioc,
+ strerror(errno));
+ return (-1);
+ }
+
+ if (ioctl(fs->n_iocfd, NANDFS_IOCTL_GET_FSINFO, &fsinfo) == -1) {
+ nandfs_seterr(fs, "couldn't fetch fsinfo: %s",
+ strerror(errno));
+ return (-1);
+ }
+
+ memcpy(&fs->n_fsdata, &fsinfo.fs_fsdata, sizeof(fs->n_fsdata));
+ memcpy(&fs->n_sb, &fsinfo.fs_super, sizeof(fs->n_sb));
+ snprintf(fs->n_dev, sizeof(fs->n_dev), "%s", fsinfo.fs_dev);
+
+ return (0);
+}
+
+void
+nandfs_close(struct nandfs *fs)
+{
+
+ NANDFS_ASSERT_VALID(fs);
+ assert(fs->n_flags & NANDFS_IS_OPENED);
+
+ close(fs->n_iocfd);
+ fs->n_iocfd = -1;
+ fs->n_flags &= ~NANDFS_IS_OPENED;
+}
+
+int
+nandfs_get_cpstat(struct nandfs *fs, struct nandfs_cpstat *cpstat)
+{
+
+ NANDFS_ASSERT_VALID(fs);
+
+ if (ioctl(fs->n_iocfd, NANDFS_IOCTL_GET_CPSTAT, cpstat) == -1) {
+ nandfs_seterr(fs, "ioctl NANDFS_IOCTL_GET_CPSTAT: %s",
+ strerror(errno));
+ return (-1);
+ }
+
+ return (0);
+}
+
+static ssize_t
+nandfs_get_cpinfo(struct nandfs *fs, uint64_t cno, int mode,
+ struct nandfs_cpinfo *cpinfo, size_t nci)
+{
+ struct nandfs_argv args;
+
+ NANDFS_ASSERT_VALID(fs);
+
+ args.nv_base = (u_long)cpinfo;
+ args.nv_nmembs = nci;
+ args.nv_index = cno;
+ args.nv_flags = mode;
+
+ if (ioctl(fs->n_iocfd, NANDFS_IOCTL_GET_CPINFO, &args) == -1) {
+ nandfs_seterr(fs, "ioctl NANDFS_IOCTL_GET_CPINFO: %s",
+ strerror(errno));
+ return (-1);
+ }
+
+ return (args.nv_nmembs);
+}
+
+ssize_t
+nandfs_get_cp(struct nandfs *fs, uint64_t cno, struct nandfs_cpinfo *cpinfo,
+ size_t nci)
+{
+
+ return (nandfs_get_cpinfo(fs, cno, NANDFS_CHECKPOINT, cpinfo, nci));
+}
+
+ssize_t
+nandfs_get_snap(struct nandfs *fs, uint64_t cno, struct nandfs_cpinfo *cpinfo,
+ size_t nci)
+{
+
+ return (nandfs_get_cpinfo(fs, cno, NANDFS_SNAPSHOT, cpinfo, nci));
+}
+
+int
+nandfs_make_snap(struct nandfs *fs, uint64_t *cno)
+{
+
+ NANDFS_ASSERT_VALID(fs);
+
+ if (ioctl(fs->n_iocfd, NANDFS_IOCTL_MAKE_SNAP, cno) == -1) {
+ nandfs_seterr(fs, "ioctl NANDFS_IOCTL_MAKE_SNAP: %s",
+ strerror(errno));
+ return (-1);
+ }
+
+ return (0);
+}
+
+int
+nandfs_delete_snap(struct nandfs *fs, uint64_t cno)
+{
+
+ NANDFS_ASSERT_VALID(fs);
+
+ if (ioctl(fs->n_iocfd, NANDFS_IOCTL_DELETE_SNAP, &cno) == -1) {
+ nandfs_seterr(fs, "ioctl NANDFS_IOCTL_DELETE_SNAP: %s",
+ strerror(errno));
+ return (-1);
+ }
+
+ return (0);
+}
diff --git a/lib/libncp/ncpl_nls.c b/lib/libncp/ncpl_nls.c
index 3ca83d6..14a26e5 100644
--- a/lib/libncp/ncpl_nls.c
+++ b/lib/libncp/ncpl_nls.c
@@ -200,6 +200,79 @@ static u_int8_t se_unix2nw[] = {
0x9c, 0x9b, 0x87, 0x98, 0x9d, 0x99, 0x97, 0x9a
};
+/*
+ * Characters mapping for codepages used in Germany.
+ */
+static u_int8_t de_nw2unix[] = {
+ 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, /* 0x00 */
+ 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f,
+ 0x5f, 0x5f, 0x5f, 0x5f, 0xb6, 0xa7, 0x5f, 0x5f, /* 0x10 */
+ 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f,
+ 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, /* 0x20 */
+ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
+ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, /* 0x30 */
+ 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
+ 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, /* 0x40 */
+ 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
+ 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, /* 0x50 */
+ 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
+ 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, /* 0x60 */
+ 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
+ 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, /* 0x70 */
+ 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
+ 0xc7, 0xfc, 0xe9, 0xe2, 0xe4, 0xe0, 0xe5, 0xe7, /* 0x80 */
+ 0xea, 0xeb, 0xe8, 0xef, 0xee, 0xec, 0xc4, 0xc5,
+ 0xc9, 0xe6, 0xc6, 0xf4, 0xf6, 0xf2, 0xfb, 0xf9, /* 0x90 */
+ 0xff, 0xd6, 0xdc, 0xa2, 0xa3, 0xa5, 0x5f, 0x5f,
+ 0xe1, 0xed, 0xf3, 0xfa, 0xf1, 0xd1, 0xaa, 0xba, /* 0xA0 */
+ 0xbf, 0x5f, 0xac, 0xbd, 0xbc, 0xa1, 0xab, 0xbb,
+ 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, /* 0xB0 */
+ 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f,
+ 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, /* 0xC0 */
+ 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f,
+ 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, /* 0xD0 */
+ 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f,
+ 0x5f, 0xdf, 0x5f, 0x5f, 0x5f, 0x5f, 0xb5, 0x5f, /* 0xE0 */
+ 0x5f, 0x5f, 0x5f, 0xf0, 0x5f, 0xf8, 0x5f, 0x5f,
+ 0x5f, 0xb1, 0x5f, 0x5f, 0x5f, 0x5f, 0xf7, 0x5f, /* 0xF0 */
+ 0xb0, 0x5f, 0xb7, 0x5f, 0x5f, 0xb2, 0x5f, 0xa0
+};
+
+static u_int8_t de_unix2nw[] = {
+ 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, /* 0x00 */
+ 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f,
+ 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, /* 0x10 */
+ 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f,
+ 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, /* 0x20 */
+ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
+ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, /* 0x30 */
+ 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
+ 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, /* 0x40 */
+ 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
+ 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, /* 0x50 */
+ 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
+ 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, /* 0x60 */
+ 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
+ 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, /* 0x70 */
+ 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
+ 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, /* 0x80 */
+ 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f,
+ 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, /* 0x90 */
+ 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f,
+ 0xff, 0xad, 0x9b, 0x9c, 0x5f, 0x9d, 0x5f, 0x15, /* 0xA0 */
+ 0x5f, 0x5f, 0xa6, 0xae, 0xaa, 0x5f, 0x5f, 0x5f,
+ 0xf8, 0xf1, 0xfd, 0x5f, 0x5f, 0xe6, 0x14, 0xfa, /* 0xB0 */
+ 0x5f, 0x5f, 0xa7, 0xaf, 0xac, 0xab, 0x5f, 0xa8,
+ 0x5f, 0x5f, 0x5f, 0x5f, 0x8e, 0x8f, 0x92, 0x80, /* 0xC0 */
+ 0x5f, 0x90, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f,
+ 0x5f, 0xa5, 0x5f, 0x5f, 0x5f, 0x5f, 0x99, 0x5f, /* 0xD0 */
+ 0x5f, 0x5f, 0x5f, 0x5f, 0x9a, 0x5f, 0x5f, 0xe1,
+ 0x85, 0xa0, 0x83, 0x5f, 0x84, 0x86, 0x91, 0x87, /* 0xE0 */
+ 0x8a, 0x82, 0x88, 0x89, 0x8d, 0xa1, 0x8c, 0x8b,
+ 0xeb, 0xa4, 0x95, 0xa2, 0x93, 0x5f, 0x94, 0xf6, /* 0xF0 */
+ 0xed, 0x97, 0xa3, 0x96, 0x81, 0x5f, 0x5f, 0x98
+};
+
static u_int8_t def2lower[256];
static u_int8_t def2upper[256];
@@ -225,6 +298,9 @@ static struct ncp_nlsdesc ncp_nlslist[] = {
{NCP_NLS_SE, NCP_NLS_SE_NAME,
{def2lower, def2upper, se_nw2unix, se_unix2nw, 0}
},
+ {NCP_NLS_DE, NCP_NLS_DE_NAME,
+ {def2lower, def2upper, de_nw2unix, de_unix2nw, 0}
+ },
{0}
};
diff --git a/lib/libpam/libpam/Makefile b/lib/libpam/libpam/Makefile
index 1071e05..b57a38e 100644
--- a/lib/libpam/libpam/Makefile
+++ b/lib/libpam/libpam/Makefile
@@ -47,16 +47,22 @@ SRCS= openpam_borrow_cred.c \
openpam_constants.c \
openpam_dispatch.c \
openpam_dynamic.c \
+ openpam_features.c \
openpam_findenv.c \
openpam_free_data.c \
openpam_free_envlist.c \
+ openpam_get_feature.c \
openpam_get_option.c \
openpam_load.c \
openpam_log.c \
openpam_nullconv.c \
openpam_readline.c \
+ openpam_readlinev.c \
+ openpam_readword.c \
openpam_restore_cred.c \
+ openpam_set_feature.c \
openpam_set_option.c \
+ openpam_straddch.c \
openpam_subst.c \
openpam_ttyconv.c \
pam_acct_mgmt.c \
@@ -91,12 +97,17 @@ MAN= openpam.3 \
openpam_borrow_cred.3 \
openpam_free_data.3 \
openpam_free_envlist.3 \
+ openpam_get_feature.3 \
openpam_get_option.3 \
openpam_log.3 \
openpam_nullconv.3 \
openpam_readline.3 \
+ openpam_readlinev.3 \
+ openpam_readword.3 \
openpam_restore_cred.3 \
+ openpam_set_feature.3 \
openpam_set_option.3 \
+ openpam_straddch.3 \
openpam_subst.3 \
openpam_ttyconv.3 \
pam.3 \
@@ -137,11 +148,13 @@ MAN= openpam.3 \
MLINKS= pam.conf.5 pam.d.5
CSTD?= c99
-WARNS?= 3
CFLAGS+= -I${.CURDIR} -I${OPENPAM}/include
CFLAGS+= -DLIB_MAJ=${SHLIB_MAJOR}
CFLAGS+= -DOPENPAM_MODULES_DIR='"${PAM_MOD_DIR:C/\/*$//}/"'
-CFLAGS+= -DHAVE_FPURGE=1 -DHAVE_STRLCPY=1
+CFLAGS+= -DHAVE_FDLOPEN=1
+CFLAGS+= -DHAVE_FPURGE=1
+CFLAGS+= -DHAVE_STRLCAT=1
+CFLAGS+= -DHAVE_STRLCPY=1
HEADERS= security/openpam.h \
security/openpam_attr.h \
diff --git a/lib/libpam/modules/pam_exec/pam_exec.8 b/lib/libpam/modules/pam_exec/pam_exec.8
index 3231228..e2be511 100644
--- a/lib/libpam/modules/pam_exec/pam_exec.8
+++ b/lib/libpam/modules/pam_exec/pam_exec.8
@@ -131,10 +131,10 @@ This is useful in shell scripts for instance.
.Xr pam 8 ,
.Xr pam_sm_acct_mgmt 8 ,
.Xr pam_sm_authenticate 8 ,
-.Xr pam_sm_chauthtok 8,
+.Xr pam_sm_chauthtok 8 ,
.Xr pam_sm_close_session 8 ,
.Xr pam_sm_open_session 8 ,
-.Xr pam_sm_setcred 8 .
+.Xr pam_sm_setcred 8
.Sh AUTHORS
The
.Nm
diff --git a/lib/libpam/modules/pam_ssh/pam_ssh.c b/lib/libpam/modules/pam_ssh/pam_ssh.c
index ab4990b..405dd6b 100644
--- a/lib/libpam/modules/pam_ssh/pam_ssh.c
+++ b/lib/libpam/modules/pam_ssh/pam_ssh.c
@@ -112,7 +112,7 @@ pam_ssh_load_key(const char *dir, const char *kfn, const char *passphrase,
* with an empty passphrase, and if the key is not encrypted,
* accept only an empty passphrase.
*/
- key = key_load_private(fn, NULL, &comment);
+ key = key_load_private(fn, "", &comment);
if (key != NULL && !(*passphrase == '\0' && nullok)) {
key_free(key);
return (NULL);
diff --git a/lib/libpcap/Makefile b/lib/libpcap/Makefile
index 5b613e7..1a3e634 100644
--- a/lib/libpcap/Makefile
+++ b/lib/libpcap/Makefile
@@ -37,8 +37,6 @@ MAN= pcap.3 \
pcap_file.3 \
pcap_fileno.3 \
pcap_findalldevs.3 \
- pcap_free_datalinks.3 \
- pcap_freealldevs.3 \
pcap_freecode.3 \
pcap_get_selectable_fd.3 \
pcap_geterr.3 \
@@ -46,6 +44,7 @@ MAN= pcap.3 \
pcap_is_swapped.3 \
pcap_lib_version.3 \
pcap_list_datalinks.3 \
+ pcap_list_tstamp_types.3 \
pcap_lookupdev.3 \
pcap_lookupnet.3 \
pcap_loop.3 \
@@ -61,6 +60,7 @@ MAN= pcap.3 \
pcap_set_rfmon.3 \
pcap_set_snaplen.3 \
pcap_set_timeout.3 \
+ pcap_set_tstamp_type.3 \
pcap_setdirection.3 \
pcap_setfilter.3 \
pcap_setnonblock.3 \
@@ -69,12 +69,17 @@ MAN= pcap.3 \
pcap_statustostr.3 \
pcap_strerror.3 \
pcap-savefile.5 \
+ pcap_tstamp_type_name_to_val.3 \
+ pcap_tstamp_type_val_to_name.3 \
pcap-filter.7 \
pcap-linktype.7
MLINKS= pcap_datalink_val_to_name.3 pcap_datalink_val_to_description.3 \
pcap_dump_open.3 pcap_dump_fopen.3 \
+ pcap_findalldevs.3 pcap_freealldevs.3 \
pcap_geterr.3 pcap_perror.3 \
pcap_inject.3 pcap_sendpacket.3 \
+ pcap_list_datalinks.3 pcap_free_datalinks.3 \
+ pcap_list_tstamp_types.3 pcap_free_tstamp_types.3 \
pcap_loop.3 pcap_dispatch.3 \
pcap_major_version.3 pcap_minor_version.3 \
pcap_next_ex.3 pcap_next.3 \
diff --git a/lib/libpcap/config.h b/lib/libpcap/config.h
index d3d4a9a..b364c13 100644
--- a/lib/libpcap/config.h
+++ b/lib/libpcap/config.h
@@ -22,6 +22,9 @@
/* define if you have streams capable DAG API */
/* #undef HAVE_DAG_STREAMS_API */
+/* define if you have vdag_set_device_info() */
+/* #undef HAVE_DAG_VDAG */
+
/* Define to 1 if you have the declaration of `ether_hostton', and to 0 if you
don't. */
#define HAVE_DECL_ETHER_HOSTTON 1
@@ -56,12 +59,30 @@
/* if libnl exists */
/* #undef HAVE_LIBNL */
+/* if libnl exists and is version 2.x */
+/* #undef HAVE_LIBNL_2_x */
+
/* Define to 1 if you have the <limits.h> header file. */
#define HAVE_LIMITS_H 1
+/* Define to 1 if you have the <linux/compiler.h> header file. */
+/* #undef HAVE_LINUX_COMPILER_H */
+
+/* Define to 1 if you have the <linux/ethtool.h> header file. */
+/* #undef HAVE_LINUX_ETHTOOL_H */
+
+/* Define to 1 if you have the <linux/if_packet.h> header file. */
+/* #undef HAVE_LINUX_IF_PACKET_H */
+
+/* Define to 1 if you have the <linux/net_tstamp.h> header file. */
+/* #undef HAVE_LINUX_NET_TSTAMP_H */
+
/* if tp_vlan_tci exists */
/* #undef HAVE_LINUX_TPACKET_AUXDATA_TP_VLAN_TCI */
+/* Define to 1 if you have the <linux/types.h> header file. */
+/* #undef HAVE_LINUX_TYPES_H */
+
/* Define to 1 if you have the <linux/usbdevice_fs.h> header file. */
/* #undef HAVE_LINUX_USBDEVICE_FS_H */
@@ -77,6 +98,12 @@
/* Define to 1 if you have the <netinet/if_ether.h> header file. */
#define HAVE_NETINET_IF_ETHER_H 1
+/* Define to 1 if you have the <netpacket/if_packet.h> header file. */
+/* #undef HAVE_NETPACKET_IF_PACKET_H */
+
+/* Define to 1 if you have the <netpacket/packet.h> header file. */
+/* #undef HAVE_NETPACKET_PACKET_H */
+
/* Define to 1 if you have the <net/if_media.h> header file. */
#define HAVE_NET_IF_MEDIA_H 1
@@ -175,7 +202,7 @@
#define HAVE_VSNPRINTF 1
/* define if the system supports zerocopy BPF */
-#define HAVE_ZEROCOPY_BPF 1
+#define HAVE_ZEROCOPY_BPF 1
/* define if your compiler has __attribute__ */
#define HAVE___ATTRIBUTE__ 1
@@ -223,6 +250,9 @@
/* target host supports CAN sniffing */
/* #undef PCAP_SUPPORT_CAN */
+/* target host supports netfilter sniffing */
+/* #undef PCAP_SUPPORT_NETFILTER */
+
/* target host supports USB sniffing */
/* #undef PCAP_SUPPORT_USB */
@@ -241,7 +271,7 @@
/* needed on HP-UX */
/* #undef _HPUX_SOURCE */
-/* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */
+/* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */
/* #undef _LARGEFILE_SOURCE */
/* Define for large files, on AIX-style hosts. */
diff --git a/lib/libpmc/pmc.3 b/lib/libpmc/pmc.3
index cf74f32..c970da8 100644
--- a/lib/libpmc/pmc.3
+++ b/lib/libpmc/pmc.3
@@ -111,7 +111,7 @@ processor.
Certain kinds of PMCs require that a log file be configured before
they may be started.
These include:
-.Bl -bullet -compact
+.Bl -bullet
.It
System scope sampling PMCs.
.It
@@ -120,6 +120,7 @@ Process scope sampling PMCs.
Process scope counting PMCs that have been configured to report PMC
readings on process context switches or process exits.
.El
+.Pp
Up to one log file may be configured per owner process.
Events logged to a log file may be subsequently analyzed using the
.Xr pmclog 3
@@ -129,6 +130,7 @@ The CPUs known to the PMC library are named by the
.Vt "enum pmc_cputype"
enumeration.
Supported CPUs include:
+.Pp
.Bl -tag -width "Li PMC_CPU_INTEL_CORE2" -compact
.It Li PMC_CPU_AMD_K7
.Tn "AMD Athlon"
@@ -185,6 +187,7 @@ PMC supported by this library are named by the
.Vt enum pmc_class
enumeration.
Supported PMC kinds include:
+.Pp
.Bl -tag -width "Li PMC_CLASS_IAF" -compact
.It Li PMC_CLASS_IAF
Fixed function hardware counters presents in CPUs conforming to the
@@ -232,6 +235,7 @@ the
.Vt "enum pmc_caps"
enumeration.
Supported capabilities include:
+.Pp
.Bl -tag -width "Li PMC_CAP_INTERRUPT" -compact
.It Li PMC_CAP_CASCADE
The ability to cascade counters.
@@ -273,9 +277,9 @@ Operations on non-existent CPUs will return an error.
This section contains a brief overview of the available functionality
in the PMC library.
Each function listed here is described further in its own manual page.
-.Bl -tag -width indent
+.Bl -tag -width 2n
.It Administration
-.Bl -tag -compact
+.Bl -tag -width 6n -compact
.It Fn pmc_disable , Fn pmc_enable
Administratively disable (enable) specific performance monitoring
counter hardware.
@@ -283,7 +287,7 @@ Counters that are disabled will not be available to applications to
use.
.El
.It "Convenience Functions"
-.Bl -tag -compact
+.Bl -tag -width 6n -compact
.It Fn pmc_event_names_of_class
Returns a list of event names supported by a given PMC type.
.It Fn pmc_name_of_capability
@@ -308,13 +312,13 @@ constant to a human-readable name.
Return a human-readable string describing a PMC's current state.
.El
.It "Library Initialization"
-.Bl -tag -compact
+.Bl -tag -width 6n -compact
.It Fn pmc_init
Initialize the library.
This function must be called before any other library function.
.El
.It "Log File Handling"
-.Bl -tag -compact
+.Bl -tag -width 6n -compact
.It Fn pmc_configure_logfile
Configure a log file for
.Xr hwpmc 4
@@ -331,7 +335,7 @@ side of the stream.
Append arbitrary user data to the current log file.
.El
.It "PMC Management"
-.Bl -tag -compact
+.Bl -tag -width 6n -compact
.It Fn pmc_allocate , Fn pmc_release
Allocate (free) a PMC.
.It Fn pmc_attach , Fn pmc_detach
@@ -344,7 +348,7 @@ Start (stop) a software PMC.
Set the reload value for a sampling PMC.
.El
.It "Queries"
-.Bl -tag -compact
+.Bl -tag -width 6n -compact
.It Fn pmc_capabilities
Retrieve the capabilities for a given PMC.
.It Fn pmc_cpuinfo
@@ -363,7 +367,7 @@ Return information about the state of a given CPU's PMCs.
Determine the width of a hardware counter in bits.
.El
.It "x86 Architecture Specific API"
-.Bl -tag -compact
+.Bl -tag -width 6n -compact
.It Fn pmc_get_msr
Returns the processor model specific register number
associated with
diff --git a/lib/libprocstat/cd9660.c b/lib/libprocstat/cd9660.c
index 95882be..ab95e2a 100644
--- a/lib/libprocstat/cd9660.c
+++ b/lib/libprocstat/cd9660.c
@@ -84,7 +84,7 @@ isofs_filestat(kvm_t *kd, struct vnode *vp, struct vnstat *vn)
}
vn->vn_fsid = dev2udev(kd, mnt.im_dev);
vn->vn_mode = (mode_t)isonode.inode.iso_mode;
- vn->vn_fileid = (long)isonode.i_number;
- vn->vn_size = (u_long)isonode.i_size;
+ vn->vn_fileid = isonode.i_number;
+ vn->vn_size = isonode.i_size;
return (0);
}
diff --git a/lib/libprocstat/common_kvm.c b/lib/libprocstat/common_kvm.c
index 63302bc..be05980 100644
--- a/lib/libprocstat/common_kvm.c
+++ b/lib/libprocstat/common_kvm.c
@@ -99,9 +99,9 @@ ufs_filestat(kvm_t *kd, struct vnode *vp, struct vnstat *vn)
* comparisons
*/
vn->vn_fsid = dev2udev(kd, inode.i_dev);
- vn->vn_fileid = (long)inode.i_number;
+ vn->vn_fileid = inode.i_number;
vn->vn_mode = (mode_t)inode.i_mode;
- vn->vn_size = (u_long)inode.i_size;
+ vn->vn_size = inode.i_size;
return (0);
}
diff --git a/lib/libprocstat/libprocstat.3 b/lib/libprocstat/libprocstat.3
index 07fffb2..dd163c2 100644
--- a/lib/libprocstat/libprocstat.3
+++ b/lib/libprocstat/libprocstat.3
@@ -203,7 +203,7 @@ The
.Fn procstat_get_socket_info
and
.Fn procstat_get_vnode_info
-functions are used to retrive information about pipes, pseudo-terminals,
+functions are used to retrieve information about pipes, pseudo-terminals,
shared memory objects,
sockets, and vnodes, respectively.
Each of them have a similar interface API.
diff --git a/lib/libprocstat/libprocstat.c b/lib/libprocstat/libprocstat.c
index 167d91a..56562e1 100644
--- a/lib/libprocstat/libprocstat.c
+++ b/lib/libprocstat/libprocstat.c
@@ -881,6 +881,8 @@ procstat_get_shm_info_kvm(kvm_t *kd, struct filestat *fst,
{
struct shmfd shmfd;
void *shmfdp;
+ char *path;
+ int i;
assert(kd);
assert(shm);
@@ -896,6 +898,21 @@ procstat_get_shm_info_kvm(kvm_t *kd, struct filestat *fst,
}
shm->mode = S_IFREG | shmfd.shm_mode;
shm->size = shmfd.shm_size;
+ if (fst->fs_path == NULL && shmfd.shm_path != NULL) {
+ path = malloc(MAXPATHLEN);
+ for (i = 0; i < MAXPATHLEN - 1; i++) {
+ if (!kvm_read_all(kd, (unsigned long)shmfd.shm_path + i,
+ path + i, 1))
+ break;
+ if (path[i] == '\0')
+ break;
+ }
+ path[i] = '\0';
+ if (i == 0)
+ free(path);
+ else
+ fst->fs_path = path;
+ }
return (0);
fail:
diff --git a/lib/libradius/libradius.3 b/lib/libradius/libradius.3
index da60d52..ae0ee24 100644
--- a/lib/libradius/libradius.3
+++ b/lib/libradius/libradius.3
@@ -108,8 +108,7 @@ allows clients to perform authentication and accounting by means of
network requests to remote servers.
.Ss Initialization
To use the library, an application must first call
-.Fn rad_auth_open
-,
+.Fn rad_auth_open ,
.Fn rad_acct_open
or
.Fn rad_server_open
@@ -119,8 +118,7 @@ which provides the context for subsequent operations.
The former function is used for RADIUS authentication and the
latter is used for RADIUS accounting.
Calls to
-.Fn rad_auth_open
-,
+.Fn rad_auth_open ,
.Fn rad_acct_open
and
.Fn rad_server_open
@@ -487,7 +485,7 @@ To respond to the request you should call
.Fn rad_create_response
and fill response content with same packet writing functions as for client.
When packet is ready, it should be sent with
-.Fn rad_send_response
+.Fn rad_send_response .
.Sh RETURN VALUES
The following functions return a non-negative value on success.
If
diff --git a/lib/librpcsec_gss/rpc_gss_get_error.3 b/lib/librpcsec_gss/rpc_gss_get_error.3
index 3b025d7..f1d8fc7 100644
--- a/lib/librpcsec_gss/rpc_gss_get_error.3
+++ b/lib/librpcsec_gss/rpc_gss_get_error.3
@@ -39,7 +39,7 @@
.Sh DESCRIPTION
Get details of the last RPCSEC_GSS error.
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It error"
.It error
A pointer to a structure where the error details will be returned
.El
diff --git a/lib/librpcsec_gss/rpc_gss_get_mech_info.3 b/lib/librpcsec_gss/rpc_gss_get_mech_info.3
index d6abf4d..9a26dc1 100644
--- a/lib/librpcsec_gss/rpc_gss_get_mech_info.3
+++ b/lib/librpcsec_gss/rpc_gss_get_mech_info.3
@@ -40,7 +40,7 @@
This function looks up a mechanism by name by reading the file
/etc/gss/mech and queries it for its capabilities.
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It service"
.It mech
The mechanism to search for
.It service
diff --git a/lib/librpcsec_gss/rpc_gss_get_principal_name.3 b/lib/librpcsec_gss/rpc_gss_get_principal_name.3
index 2eba5a9..50fc65b 100644
--- a/lib/librpcsec_gss/rpc_gss_get_principal_name.3
+++ b/lib/librpcsec_gss/rpc_gss_get_principal_name.3
@@ -46,7 +46,7 @@
This function can be used to generate a client principal name from
various strings.
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It principal"
.It principal
If the principal is created successfully,
.Fa *principal
diff --git a/lib/librpcsec_gss/rpc_gss_get_versions.3 b/lib/librpcsec_gss/rpc_gss_get_versions.3
index 9192054..d624f85 100644
--- a/lib/librpcsec_gss/rpc_gss_get_versions.3
+++ b/lib/librpcsec_gss/rpc_gss_get_versions.3
@@ -39,7 +39,7 @@
.Sh DESCRIPTION
Return the highest and lowest supported versions of the RPCSEC_GSS protocol.
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It vers_lo"
.It vers_hi
The value of
.Fa *vers_hi
diff --git a/lib/librpcsec_gss/rpc_gss_getcred.3 b/lib/librpcsec_gss/rpc_gss_getcred.3
index 72a6384..4ebd275 100644
--- a/lib/librpcsec_gss/rpc_gss_getcred.3
+++ b/lib/librpcsec_gss/rpc_gss_getcred.3
@@ -45,7 +45,7 @@
This function returns the RPCSEC_GSS authenticated credentials
associated with an RPC request.
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It cookie"
.It req
The RPC request to query
.It rcred
diff --git a/lib/librpcsec_gss/rpc_gss_is_installed.3 b/lib/librpcsec_gss/rpc_gss_is_installed.3
index f0e03d8..d427e87 100644
--- a/lib/librpcsec_gss/rpc_gss_is_installed.3
+++ b/lib/librpcsec_gss/rpc_gss_is_installed.3
@@ -40,7 +40,7 @@
This function looks up a mechanism by name by reading the file
/etc/gss/mech.
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It mech"
.It mech
The mechanism to search for
.El
diff --git a/lib/librpcsec_gss/rpc_gss_max_data_length.3 b/lib/librpcsec_gss/rpc_gss_max_data_length.3
index 67029a0..1d3a922 100644
--- a/lib/librpcsec_gss/rpc_gss_max_data_length.3
+++ b/lib/librpcsec_gss/rpc_gss_max_data_length.3
@@ -41,7 +41,7 @@ Calculate the maximum message size that will fit into a packet of size
.Fa max_tp_unit_len ,
given the current service and QoP setting.
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It max_tp_unit_len"
.It auth
A handle to a RPCSEC_GSS security context
.It max_tp_unit_len
diff --git a/lib/librpcsec_gss/rpc_gss_mech_to_oid.3 b/lib/librpcsec_gss/rpc_gss_mech_to_oid.3
index 3449d0e..14bd5ee 100644
--- a/lib/librpcsec_gss/rpc_gss_mech_to_oid.3
+++ b/lib/librpcsec_gss/rpc_gss_mech_to_oid.3
@@ -40,7 +40,7 @@
This function looks up a mechanism by name by reading the file
/etc/gss/mech.
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It oid_ret"
.It mech
The mechanism name to search for
.It oid_ret
diff --git a/lib/librpcsec_gss/rpc_gss_oid_to_mech.3 b/lib/librpcsec_gss/rpc_gss_oid_to_mech.3
index af2e7d0..661bdff 100644
--- a/lib/librpcsec_gss/rpc_gss_oid_to_mech.3
+++ b/lib/librpcsec_gss/rpc_gss_oid_to_mech.3
@@ -40,7 +40,7 @@
This function looks up a mechanism by oid by reading the file
/etc/gss/mech.
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It mech_ret"
.It oid
The mechanism oid to search for
.It mech_ret
diff --git a/lib/librpcsec_gss/rpc_gss_qop_to_num.3 b/lib/librpcsec_gss/rpc_gss_qop_to_num.3
index 6f52b7b..0f95d27 100644
--- a/lib/librpcsec_gss/rpc_gss_qop_to_num.3
+++ b/lib/librpcsec_gss/rpc_gss_qop_to_num.3
@@ -40,7 +40,7 @@
This function looks up a quality of protection by name by reading the file
/etc/gss/qop.
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It number_ret"
.It qop
The quality of protection to search for
.It mech
diff --git a/lib/librpcsec_gss/rpc_gss_seccreate.3 b/lib/librpcsec_gss/rpc_gss_seccreate.3
index 63978a5..836df23 100644
--- a/lib/librpcsec_gss/rpc_gss_seccreate.3
+++ b/lib/librpcsec_gss/rpc_gss_seccreate.3
@@ -48,7 +48,7 @@
This function is used to establish a security context between an
application and a remote peer using the RPSEC_GSS protocol.
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width "options_req"
.It clnt
An RPC handle which is connected to the remote peer
.It principal
@@ -62,7 +62,7 @@ The value of mechanism should be the name of one of the security
mechanisms listed in /etc/gss/mech.
.It service
Type of service requested.
-.Bl -tag
+.Bl -tag -width "rpc_gss_svc_integrity"
.It rpc_gss_svc_default
The default - typically the same as
.Dv rpc_gss_svc_none .
diff --git a/lib/librpcsec_gss/rpc_gss_set_callback.3 b/lib/librpcsec_gss/rpc_gss_set_callback.3
index eb90227..4226285 100644
--- a/lib/librpcsec_gss/rpc_gss_set_callback.3
+++ b/lib/librpcsec_gss/rpc_gss_set_callback.3
@@ -62,7 +62,7 @@ protection used by the context.
If a context is locked, any subsequent requests which use different
values for service and quality of protection will be rejected.
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It gss_context"
.It cb
A structure containing the RPC program and version for this callback
and a function which will be called when new contexts are created for
diff --git a/lib/librpcsec_gss/rpc_gss_set_defaults.3 b/lib/librpcsec_gss/rpc_gss_set_defaults.3
index e9b062d..72f2214 100644
--- a/lib/librpcsec_gss/rpc_gss_set_defaults.3
+++ b/lib/librpcsec_gss/rpc_gss_set_defaults.3
@@ -45,7 +45,7 @@ Set the service and quality of protection to be used for RPC requests.
The new values apply for the rest of the lifetime of the context
(unless changed again with this function).
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It service"
.It service
The service type to use for subsequent RPC requests
.It qop
diff --git a/lib/librpcsec_gss/rpc_gss_set_svc_name.3 b/lib/librpcsec_gss/rpc_gss_set_svc_name.3
index b63d38b..a06d7d3 100644
--- a/lib/librpcsec_gss/rpc_gss_set_svc_name.3
+++ b/lib/librpcsec_gss/rpc_gss_set_svc_name.3
@@ -47,7 +47,7 @@ This function registers a service principal which will be used to
authenticate RPCSEC_GSS security contexts for a given RPC program and
version.
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It mechanism"
.It principal
A string representing the service principal in the form
.Qq service@hostname
diff --git a/lib/librpcsec_gss/rpc_gss_svc_max_data_length.3 b/lib/librpcsec_gss/rpc_gss_svc_max_data_length.3
index fdf24a6..f466e10 100644
--- a/lib/librpcsec_gss/rpc_gss_svc_max_data_length.3
+++ b/lib/librpcsec_gss/rpc_gss_svc_max_data_length.3
@@ -41,7 +41,7 @@ Calculate the maximum message size that will fit into a packet of size
.Fa max_tp_unit_len ,
given the current service and QoP setting.
.Sh PARAMETERS
-.Bl -tag
+.Bl -tag -width ".It max_tp_unit_len"
.It req
An RPC request
.It max_tp_unit_len
diff --git a/lib/libstand/Makefile b/lib/libstand/Makefile
index 567c886..fd720a9 100644
--- a/lib/libstand/Makefile
+++ b/lib/libstand/Makefile
@@ -38,7 +38,7 @@ CFLAGS+= -msoft-float -D_STANDALONE
.endif
# standalone components and stuff we have modified locally
-SRCS+= zutil.h __main.c assert.c bcd.c bswap.c environment.c getopt.c gets.c \
+SRCS+= gzguts.h zutil.h __main.c assert.c bcd.c bswap.c environment.c getopt.c gets.c \
globals.c pager.c printf.c strdup.c strerror.c strtol.c random.c \
sbrk.c twiddle.c zalloc.c zalloc_malloc.c
@@ -118,23 +118,29 @@ libstand_bzlib_private.h: bzlib_private.h
# decompression functionality from libz
.PATH: ${.CURDIR}/../libz
CFLAGS+=-DHAVE_MEMCPY -I${.CURDIR}/../libz
-SRCS+= adler32.c crc32.c libstand_zutil.h
+SRCS+= adler32.c crc32.c libstand_zutil.h libstand_gzguts.h
.for file in infback.c inffast.c inflate.c inftrees.c zutil.c
SRCS+= _${file}
CLEANFILES+= _${file}
_${file}: ${file}
- sed "s|zutil\.h|libstand_zutil.h|" ${.ALLSRC} > ${.TARGET}
+ sed -e "s|zutil\.h|libstand_zutil.h|" \
+ -e "s|gzguts\.h|libstand_gzguts.h|" \
+ ${.ALLSRC} > ${.TARGET}
.endfor
# depend on stand.h being able to be included multiple times
-CLEANFILES+= libstand_zutil.h
-libstand_zutil.h: zutil.h
- sed -e 's|<stddef.h>|"stand.h"|' \
+.for file in zutil.h gzguts.h
+CLEANFILES+= libstand_${file}
+libstand_${file}: ${file}
+ sed -e 's|<fcntl.h>|"stand.h"|' \
+ -e 's|<stddef.h>|"stand.h"|' \
-e 's|<string.h>|"stand.h"|' \
+ -e 's|<stdio.h>|"stand.h"|' \
-e 's|<stdlib.h>|"stand.h"|' \
${.ALLSRC} > ${.TARGET}
+.endfor
# io routines
SRCS+= closeall.c dev.c ioctl.c nullfs.c stat.c \
@@ -150,6 +156,9 @@ SRCS+= bootp.c rarp.c bootparam.c
SRCS+= ufs.c nfs.c cd9660.c tftp.c gzipfs.c bzipfs.c
SRCS+= dosfs.c ext2fs.c
SRCS+= splitfs.c
+.if ${MK_NAND} != "no"
+SRCS+= nandfs.c
+.endif
.include <bsd.lib.mk>
diff --git a/lib/libstand/bswap.c b/lib/libstand/bswap.c
index b8e6ffb..308edda 100644
--- a/lib/libstand/bswap.c
+++ b/lib/libstand/bswap.c
@@ -31,7 +31,7 @@ bswap32(u_int32_t x)
u_int64_t
bswap64(u_int64_t x)
{
-#ifdef _LP64
+#ifdef __LP64__
/*
* Assume we have wide enough registers to do it without touching
* memory.
diff --git a/lib/libstand/nandfs.c b/lib/libstand/nandfs.c
new file mode 100644
index 0000000..67e2fea
--- /dev/null
+++ b/lib/libstand/nandfs.c
@@ -0,0 +1,1041 @@
+/*-
+ * Copyright (c) 2010-2012 Semihalf.
+ * 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 <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/queue.h>
+#include <sys/stdint.h>
+#include <ufs/ufs/dinode.h>
+#include <fs/nandfs/nandfs_fs.h>
+#include "stand.h"
+#include "string.h"
+#include "zlib.h"
+
+#define DEBUG
+#undef DEBUG
+#ifdef DEBUG
+#define NANDFS_DEBUG(fmt, args...) do { \
+ printf("NANDFS_DEBUG:" fmt "\n", ##args); } while (0)
+#else
+#define NANDFS_DEBUG(fmt, args...)
+#endif
+
+struct nandfs_mdt {
+ uint32_t entries_per_block;
+ uint32_t entries_per_group;
+ uint32_t blocks_per_group;
+ uint32_t groups_per_desc_block; /* desc is super group */
+ uint32_t blocks_per_desc_block; /* desc is super group */
+};
+
+struct bmap_buf {
+ LIST_ENTRY(bmap_buf) list;
+ nandfs_daddr_t blknr;
+ uint64_t *map;
+};
+
+struct nandfs_node {
+ struct nandfs_inode *inode;
+ LIST_HEAD(, bmap_buf) bmap_bufs;
+};
+struct nandfs {
+ int nf_blocksize;
+ int nf_sectorsize;
+ int nf_cpno;
+
+ struct open_file *nf_file;
+ struct nandfs_node *nf_opened_node;
+ u_int nf_offset;
+ uint8_t *nf_buf;
+ int64_t nf_buf_blknr;
+
+ struct nandfs_fsdata *nf_fsdata;
+ struct nandfs_super_block *nf_sb;
+ struct nandfs_segment_summary nf_segsum;
+ struct nandfs_checkpoint nf_checkpoint;
+ struct nandfs_super_root nf_sroot;
+ struct nandfs_node nf_ifile;
+ struct nandfs_node nf_datfile;
+ struct nandfs_node nf_cpfile;
+ struct nandfs_mdt nf_datfile_mdt;
+ struct nandfs_mdt nf_ifile_mdt;
+
+ int nf_nindir[NIADDR];
+};
+
+static int nandfs_open(const char *, struct open_file *);
+static int nandfs_close(struct open_file *);
+static int nandfs_read(struct open_file *, void *, size_t, size_t *);
+static off_t nandfs_seek(struct open_file *, off_t, int);
+static int nandfs_stat(struct open_file *, struct stat *);
+static int nandfs_readdir(struct open_file *, struct dirent *);
+
+static int nandfs_buf_read(struct nandfs *, char **, size_t *);
+static struct nandfs_node *nandfs_lookup_inode(struct nandfs *, nandfs_daddr_t);
+static struct nandfs_node *nandfs_lookup_path(struct nandfs *, const char *);
+static int nandfs_read_inode(struct nandfs *, struct nandfs_node *,
+ nandfs_lbn_t, u_int, void *, int);
+static int nandfs_read_blk(struct nandfs *, nandfs_daddr_t, void *, int);
+static int nandfs_bmap_lookup(struct nandfs *, struct nandfs_node *,
+ nandfs_lbn_t, nandfs_daddr_t *, int);
+static int nandfs_get_checkpoint(struct nandfs *, uint64_t,
+ struct nandfs_checkpoint *);
+static nandfs_daddr_t nandfs_vtop(struct nandfs *, nandfs_daddr_t);
+static void nandfs_calc_mdt_consts(int, struct nandfs_mdt *, int);
+static void nandfs_mdt_trans(struct nandfs_mdt *, uint64_t,
+ nandfs_daddr_t *, uint32_t *);
+static int ioread(struct open_file *, off_t, void *, u_int);
+static int nandfs_probe_sectorsize(struct open_file *);
+
+struct fs_ops nandfs_fsops = {
+ "nandfs",
+ nandfs_open,
+ nandfs_close,
+ nandfs_read,
+ null_write,
+ nandfs_seek,
+ nandfs_stat,
+ nandfs_readdir
+};
+
+#define NINDIR(fs) ((fs)->nf_blocksize / sizeof(nandfs_daddr_t))
+
+static int
+nandfs_check_fsdata_crc(struct nandfs_fsdata *fsdata)
+{
+ uint32_t fsdata_crc, comp_crc;
+
+ if (fsdata->f_magic != NANDFS_FSDATA_MAGIC)
+ return (0);
+
+ /* Preserve crc */
+ fsdata_crc = fsdata->f_sum;
+
+ /* Calculate */
+ fsdata->f_sum = (0);
+ comp_crc = crc32(0, (uint8_t *)fsdata, fsdata->f_bytes);
+
+ /* Restore */
+ fsdata->f_sum = fsdata_crc;
+
+ /* Check CRC */
+ return (fsdata_crc == comp_crc);
+}
+
+static int
+nandfs_check_superblock_crc(struct nandfs_fsdata *fsdata,
+ struct nandfs_super_block *super)
+{
+ uint32_t super_crc, comp_crc;
+
+ /* Check super block magic */
+ if (super->s_magic != NANDFS_SUPER_MAGIC)
+ return (0);
+
+ /* Preserve CRC */
+ super_crc = super->s_sum;
+
+ /* Calculate */
+ super->s_sum = (0);
+ comp_crc = crc32(0, (uint8_t *)super, fsdata->f_sbbytes);
+
+ /* Restore */
+ super->s_sum = super_crc;
+
+ /* Check CRC */
+ return (super_crc == comp_crc);
+}
+
+static int
+nandfs_find_super_block(struct nandfs *fs, struct open_file *f)
+{
+ struct nandfs_super_block *sb;
+ int i, j, n;
+ int sectors_to_read, error;
+
+ sb = malloc(fs->nf_sectorsize);
+ if (sb == NULL)
+ return (ENOMEM);
+
+ memset(fs->nf_sb, 0, sizeof(*fs->nf_sb));
+
+ sectors_to_read = (NANDFS_NFSAREAS * fs->nf_fsdata->f_erasesize) /
+ fs->nf_sectorsize;
+ for (i = 0; i < sectors_to_read; i++) {
+ NANDFS_DEBUG("reading i %d offset %d\n", i,
+ i * fs->nf_sectorsize);
+ error = ioread(f, i * fs->nf_sectorsize, (char *)sb,
+ fs->nf_sectorsize);
+ if (error) {
+ NANDFS_DEBUG("error %d\n", error);
+ continue;
+ }
+ n = fs->nf_sectorsize / sizeof(struct nandfs_super_block);
+ if ((i * fs->nf_sectorsize) % fs->nf_fsdata->f_erasesize == 0) {
+ if (fs->nf_sectorsize == sizeof(struct nandfs_fsdata))
+ continue;
+ else {
+ sb += (sizeof(struct nandfs_fsdata) /
+ sizeof(struct nandfs_super_block));
+ n -= (sizeof(struct nandfs_fsdata) /
+ sizeof(struct nandfs_super_block));
+ }
+ }
+
+ for (j = 0; j < n; j++) {
+ if (!nandfs_check_superblock_crc(fs->nf_fsdata, &sb[j]))
+ continue;
+ NANDFS_DEBUG("magic %x wtime %jd\n", sb->s_magic,
+ sb->s_wtime);
+ if (sb[j].s_wtime > fs->nf_sb->s_wtime)
+ memcpy(fs->nf_sb, &sb[j], sizeof(*fs->nf_sb));
+ }
+ }
+
+ free(sb);
+
+ return (fs->nf_sb->s_magic != 0 ? 0 : EINVAL);
+}
+
+static int
+nandfs_find_fsdata(struct nandfs *fs, struct open_file *f)
+{
+ int offset, error, i;
+
+ NANDFS_DEBUG("starting\n");
+
+ offset = 0;
+ for (i = 0; i < 64 * NANDFS_NFSAREAS; i++) {
+ error = ioread(f, offset, (char *)fs->nf_fsdata,
+ sizeof(struct nandfs_fsdata));
+ if (error)
+ return (error);
+ if (fs->nf_fsdata->f_magic == NANDFS_FSDATA_MAGIC) {
+ NANDFS_DEBUG("found at %x, volume %s\n", offset,
+ fs->nf_fsdata->f_volume_name);
+ if (nandfs_check_fsdata_crc(fs->nf_fsdata))
+ break;
+ }
+ offset += fs->nf_sectorsize;
+ }
+
+ return (error);
+}
+
+static int
+nandfs_read_structures(struct nandfs *fs, struct open_file *f)
+{
+ int error;
+
+ error = nandfs_find_fsdata(fs, f);
+ if (error)
+ return (error);
+
+ error = nandfs_find_super_block(fs, f);
+
+ if (error == 0)
+ NANDFS_DEBUG("selected sb with w_time %jd last_pseg %jx\n",
+ fs->nf_sb->s_wtime, fs->nf_sb->s_last_pseg);
+
+ return (error);
+}
+
+static int
+nandfs_mount(struct nandfs *fs, struct open_file *f)
+{
+ int err = 0, level;
+ uint64_t last_pseg;
+
+ fs->nf_fsdata = malloc(sizeof(struct nandfs_fsdata));
+ fs->nf_sb = malloc(sizeof(struct nandfs_super_block));
+
+ err = nandfs_read_structures(fs, f);
+ if (err) {
+ free(fs->nf_fsdata);
+ free(fs->nf_sb);
+ return (err);
+ }
+
+ fs->nf_blocksize = 1 << (fs->nf_fsdata->f_log_block_size + 10);
+
+ NANDFS_DEBUG("using superblock with wtime %jd\n", fs->nf_sb->s_wtime);
+
+ fs->nf_cpno = fs->nf_sb->s_last_cno;
+ last_pseg = fs->nf_sb->s_last_pseg;
+
+ /*
+ * Calculate indirect block levels.
+ */
+ nandfs_daddr_t mult;
+
+ mult = 1;
+ for (level = 0; level < NIADDR; level++) {
+ mult *= NINDIR(fs);
+ fs->nf_nindir[level] = mult;
+ }
+
+ nandfs_calc_mdt_consts(fs->nf_blocksize, &fs->nf_datfile_mdt,
+ fs->nf_fsdata->f_dat_entry_size);
+
+ nandfs_calc_mdt_consts(fs->nf_blocksize, &fs->nf_ifile_mdt,
+ fs->nf_fsdata->f_inode_size);
+
+ err = ioread(f, last_pseg * fs->nf_blocksize, &fs->nf_segsum,
+ sizeof(struct nandfs_segment_summary));
+ if (err) {
+ free(fs->nf_sb);
+ free(fs->nf_fsdata);
+ return (err);
+ }
+
+ err = ioread(f, (last_pseg + fs->nf_segsum.ss_nblocks - 1) *
+ fs->nf_blocksize, &fs->nf_sroot, sizeof(struct nandfs_super_root));
+ if (err) {
+ free(fs->nf_sb);
+ free(fs->nf_fsdata);
+ return (err);
+ }
+
+ fs->nf_datfile.inode = &fs->nf_sroot.sr_dat;
+ LIST_INIT(&fs->nf_datfile.bmap_bufs);
+ fs->nf_cpfile.inode = &fs->nf_sroot.sr_cpfile;
+ LIST_INIT(&fs->nf_cpfile.bmap_bufs);
+
+ err = nandfs_get_checkpoint(fs, fs->nf_cpno, &fs->nf_checkpoint);
+ if (err) {
+ free(fs->nf_sb);
+ free(fs->nf_fsdata);
+ return (err);
+ }
+
+ NANDFS_DEBUG("checkpoint cp_cno=%lld\n", fs->nf_checkpoint.cp_cno);
+ NANDFS_DEBUG("checkpoint cp_inodes_count=%lld\n",
+ fs->nf_checkpoint.cp_inodes_count);
+ NANDFS_DEBUG("checkpoint cp_ifile_inode.i_blocks=%lld\n",
+ fs->nf_checkpoint.cp_ifile_inode.i_blocks);
+
+ fs->nf_ifile.inode = &fs->nf_checkpoint.cp_ifile_inode;
+ LIST_INIT(&fs->nf_ifile.bmap_bufs);
+ return (0);
+}
+
+#define NINDIR(fs) ((fs)->nf_blocksize / sizeof(nandfs_daddr_t))
+
+static int
+nandfs_open(const char *path, struct open_file *f)
+{
+ struct nandfs *fs;
+ struct nandfs_node *node;
+ int err, bsize, level;
+
+ NANDFS_DEBUG("nandfs_open('%s', %p)\n", path, f);
+
+ fs = malloc(sizeof(struct nandfs));
+ f->f_fsdata = fs;
+ fs->nf_file = f;
+
+ bsize = nandfs_probe_sectorsize(f);
+ if (bsize < 0) {
+ printf("Cannot probe medium sector size\n");
+ return (EINVAL);
+ }
+
+ fs->nf_sectorsize = bsize;
+
+ /*
+ * Calculate indirect block levels.
+ */
+ nandfs_daddr_t mult;
+
+ mult = 1;
+ for (level = 0; level < NIADDR; level++) {
+ mult *= NINDIR(fs);
+ fs->nf_nindir[level] = mult;
+ }
+
+ NANDFS_DEBUG("fs %p nf_sectorsize=%x\n", fs, fs->nf_sectorsize);
+
+ err = nandfs_mount(fs, f);
+ if (err) {
+ NANDFS_DEBUG("Cannot mount nandfs: %s\n", strerror(err));
+ return (err);
+ }
+
+ node = nandfs_lookup_path(fs, path);
+ if (node == NULL)
+ return (EINVAL);
+
+ fs->nf_offset = 0;
+ fs->nf_buf = NULL;
+ fs->nf_buf_blknr = -1;
+ fs->nf_opened_node = node;
+ LIST_INIT(&fs->nf_opened_node->bmap_bufs);
+ return (0);
+}
+
+static int
+nandfs_free_node(struct nandfs_node *node)
+{
+ struct bmap_buf *bmap, *tmp;
+
+ free(node->inode);
+ LIST_FOREACH_SAFE(bmap, &node->bmap_bufs, list, tmp) {
+ LIST_REMOVE(bmap, list);
+ free(bmap->map);
+ free(bmap);
+ }
+ free(node);
+}
+
+static int
+nandfs_close(struct open_file *f)
+{
+ struct nandfs *fs = f->f_fsdata;
+
+ NANDFS_DEBUG("nandfs_close(%p)\n", f);
+
+ if (fs->nf_buf != NULL)
+ free(fs->nf_buf);
+
+ nandfs_free_node(fs->nf_opened_node);
+ free(fs->nf_sb);
+ free(fs);
+}
+
+static int
+nandfs_read(struct open_file *f, void *addr, size_t size, size_t *resid)
+{
+ struct nandfs *fs = (struct nandfs *)f->f_fsdata;
+ size_t csize, buf_size;
+ uint8_t *buf;
+ int error = 0;
+
+ NANDFS_DEBUG("nandfs_read(file=%p, addr=%p, size=%d)\n", f, addr, size);
+
+ while (size != 0) {
+ if (fs->nf_offset >= fs->nf_opened_node->inode->i_size)
+ break;
+
+ error = nandfs_buf_read(fs, (void *)&buf, &buf_size);
+ if (error)
+ break;
+
+ csize = size;
+ if (csize > buf_size)
+ csize = buf_size;
+
+ bcopy(buf, addr, csize);
+
+ fs->nf_offset += csize;
+ addr = (char *)addr + csize;
+ size -= csize;
+ }
+
+ if (resid)
+ *resid = size;
+ return (error);
+}
+
+static off_t
+nandfs_seek(struct open_file *f, off_t offset, int where)
+{
+ struct nandfs *fs = f->f_fsdata;
+ off_t off;
+ u_int size;
+
+ NANDFS_DEBUG("nandfs_seek(file=%p, offset=%lld, where=%d)\n", f,
+ offset, where);
+
+ size = fs->nf_opened_node->inode->i_size;
+
+ switch (where) {
+ case SEEK_SET:
+ off = 0;
+ break;
+ case SEEK_CUR:
+ off = fs->nf_offset;
+ break;
+ case SEEK_END:
+ off = size;
+ break;
+ default:
+ errno = EINVAL;
+ return (-1);
+ }
+
+ off += offset;
+ if (off < 0 || off > size) {
+ errno = EINVAL;
+ return(-1);
+ }
+
+ fs->nf_offset = (u_int)off;
+
+ return (off);
+}
+
+static int
+nandfs_stat(struct open_file *f, struct stat *sb)
+{
+ struct nandfs *fs = f->f_fsdata;
+
+ NANDFS_DEBUG("nandfs_stat(file=%p, stat=%p)\n", f, sb);
+
+ sb->st_size = fs->nf_opened_node->inode->i_size;
+ sb->st_mode = fs->nf_opened_node->inode->i_mode;
+ sb->st_uid = fs->nf_opened_node->inode->i_uid;
+ sb->st_gid = fs->nf_opened_node->inode->i_gid;
+ return (0);
+}
+
+static int
+nandfs_readdir(struct open_file *f, struct dirent *d)
+{
+ struct nandfs *fs = f->f_fsdata;
+ struct nandfs_dir_entry *dirent;
+ uint8_t *buf;
+ size_t buf_size;
+
+ NANDFS_DEBUG("nandfs_readdir(file=%p, dirent=%p)\n", f, d);
+
+ if (fs->nf_offset >= fs->nf_opened_node->inode->i_size) {
+ NANDFS_DEBUG("nandfs_readdir(file=%p, dirent=%p) ENOENT\n",
+ f, d);
+ return (ENOENT);
+ }
+
+ if (nandfs_buf_read(fs, (void *)&buf, &buf_size)) {
+ NANDFS_DEBUG("nandfs_readdir(file=%p, dirent=%p)"
+ "buf_read failed\n", f, d);
+ return (EIO);
+ }
+
+ NANDFS_DEBUG("nandfs_readdir(file=%p, dirent=%p) moving forward\n",
+ f, d);
+
+ dirent = (struct nandfs_dir_entry *)buf;
+ fs->nf_offset += dirent->rec_len;
+ strncpy(d->d_name, dirent->name, dirent->name_len);
+ d->d_name[dirent->name_len] = '\0';
+ d->d_type = dirent->file_type;
+ return (0);
+}
+
+static int
+nandfs_buf_read(struct nandfs *fs, char **buf_p, size_t *size_p)
+{
+ nandfs_daddr_t blknr, blkoff;
+
+ blknr = fs->nf_offset / fs->nf_blocksize;
+ blkoff = fs->nf_offset % fs->nf_blocksize;
+
+ if (blknr != fs->nf_buf_blknr) {
+ if (fs->nf_buf == NULL)
+ fs->nf_buf = malloc(fs->nf_blocksize);
+
+ if (nandfs_read_inode(fs, fs->nf_opened_node, blknr, 1,
+ fs->nf_buf, 0))
+ return (EIO);
+
+ fs->nf_buf_blknr = blknr;
+ }
+
+ *buf_p = fs->nf_buf + blkoff;
+ *size_p = fs->nf_blocksize - blkoff;
+
+ NANDFS_DEBUG("nandfs_buf_read buf_p=%p size_p=%d\n", *buf_p, *size_p);
+
+ if (*size_p > fs->nf_opened_node->inode->i_size - fs->nf_offset)
+ *size_p = fs->nf_opened_node->inode->i_size - fs->nf_offset;
+
+ return (0);
+}
+
+static struct nandfs_node *
+nandfs_lookup_node(struct nandfs *fs, uint64_t ino)
+{
+ uint64_t blocknr;
+ int entrynr;
+ struct nandfs_inode *buffer;
+ struct nandfs_node *node;
+ struct nandfs_inode *inode;
+
+ NANDFS_DEBUG("nandfs_lookup_node ino=%lld\n", ino);
+
+ if (ino == 0) {
+ printf("nandfs_lookup_node: invalid inode requested\n");
+ return (NULL);
+ }
+
+ buffer = malloc(fs->nf_blocksize);
+ inode = malloc(sizeof(struct nandfs_inode));
+ node = malloc(sizeof(struct nandfs_node));
+
+ nandfs_mdt_trans(&fs->nf_ifile_mdt, ino, &blocknr, &entrynr);
+
+ if (nandfs_read_inode(fs, &fs->nf_ifile, blocknr, 1, buffer, 0))
+ return (NULL);
+
+ memcpy(inode, &buffer[entrynr], sizeof(struct nandfs_inode));
+ node->inode = inode;
+ free(buffer);
+ return (node);
+}
+
+static struct nandfs_node *
+nandfs_lookup_path(struct nandfs *fs, const char *path)
+{
+ struct nandfs_node *node;
+ struct nandfs_dir_entry *dirent;
+ char *namebuf;
+ uint64_t i, j, done, counter, pinode, inode;
+ int nlinks = 0, len, link_len, nameidx;
+ uint8_t *buffer, *orig;
+ char *strp, *lpath;
+
+ buffer = malloc(fs->nf_blocksize);
+ orig = buffer;
+
+ namebuf = malloc(2 * MAXPATHLEN + 2);
+ strncpy(namebuf, path, MAXPATHLEN);
+ namebuf[MAXPATHLEN] = '\0';
+ done = nameidx = 0;
+ lpath = namebuf;
+
+ /* Get the root inode */
+ node = nandfs_lookup_node(fs, NANDFS_ROOT_INO);
+ inode = NANDFS_ROOT_INO;
+
+ while ((strp = strsep(&lpath, "/")) != NULL) {
+ if (*strp == '\0')
+ continue;
+ if ((node->inode->i_mode & IFMT) != IFDIR) {
+ nandfs_free_node(node);
+ node = NULL;
+ goto out;
+ }
+
+ len = strlen(strp);
+ NANDFS_DEBUG("%s: looking for %s\n", __func__, strp);
+ for (i = 0; i < node->inode->i_blocks; i++) {
+ if (nandfs_read_inode(fs, node, i, 1, orig, 0)) {
+ node = NULL;
+ goto out;
+ }
+
+ buffer = orig;
+ done = counter = 0;
+ while (1) {
+ dirent = (struct nandfs_dir_entry *)buffer;
+ NANDFS_DEBUG("%s: dirent.name = %s\n",
+ __func__, dirent->name);
+ NANDFS_DEBUG("%s: dirent.rec_len = %d\n",
+ __func__, dirent->rec_len);
+ NANDFS_DEBUG("%s: dirent.inode = %lld\n",
+ __func__, dirent->inode);
+ if (len == dirent->name_len &&
+ (strncmp(strp, dirent->name, len) == 0) &&
+ dirent->inode != 0) {
+ nandfs_free_node(node);
+ node = nandfs_lookup_node(fs,
+ dirent->inode);
+ pinode = inode;
+ inode = dirent->inode;
+ done = 1;
+ break;
+ }
+
+ counter += dirent->rec_len;
+ buffer += dirent->rec_len;
+
+ if (counter == fs->nf_blocksize)
+ break;
+ }
+
+ if (done)
+ break;
+ }
+
+ if (!done) {
+ node = NULL;
+ goto out;
+ }
+
+ NANDFS_DEBUG("%s: %.*s has mode %o\n", __func__,
+ dirent->name_len, dirent->name, node->inode->i_mode);
+
+ if ((node->inode->i_mode & IFMT) == IFLNK) {
+ NANDFS_DEBUG("%s: %.*s is symlink\n",
+ __func__, dirent->name_len, dirent->name);
+ link_len = node->inode->i_size;
+
+ if (++nlinks > MAXSYMLINKS) {
+ nandfs_free_node(node);
+ node = NULL;
+ goto out;
+ }
+
+ if (nandfs_read_inode(fs, node, 0, 1, orig, 0)) {
+ nandfs_free_node(node);
+ node = NULL;
+ goto out;
+ }
+
+ NANDFS_DEBUG("%s: symlink is %.*s\n",
+ __func__, link_len, (char *)orig);
+
+ nameidx = (nameidx == 0) ? MAXPATHLEN + 1 : 0;
+ bcopy((char *)orig, namebuf + nameidx,
+ (unsigned)link_len);
+ if (lpath != NULL) {
+ namebuf[nameidx + link_len++] = '/';
+ strncpy(namebuf + nameidx + link_len, lpath,
+ MAXPATHLEN - link_len);
+ namebuf[nameidx + MAXPATHLEN] = '\0';
+ } else
+ namebuf[nameidx + link_len] = '\0';
+
+ NANDFS_DEBUG("%s: strp=%s, lpath=%s, namebuf0=%s, "
+ "namebuf1=%s, idx=%d\n", __func__, strp, lpath,
+ namebuf + 0, namebuf + MAXPATHLEN + 1, nameidx);
+
+ lpath = namebuf + nameidx;
+
+ nandfs_free_node(node);
+
+ /*
+ * If absolute pathname, restart at root. Otherwise
+ * continue with out parent inode.
+ */
+ inode = (orig[0] == '/') ? NANDFS_ROOT_INO : pinode;
+ node = nandfs_lookup_node(fs, inode);
+ }
+ }
+
+out:
+ free(namebuf);
+ free(orig);
+ return (node);
+}
+
+static int
+nandfs_read_inode(struct nandfs *fs, struct nandfs_node *node,
+ nandfs_daddr_t blknr, u_int nblks, void *buf, int raw)
+{
+ int i;
+ uint64_t *pblks;
+ uint64_t *vblks;
+ int error;
+
+ pblks = malloc(nblks * sizeof(uint64_t));
+ vblks = malloc(nblks * sizeof(uint64_t));
+
+ NANDFS_DEBUG("nandfs_read_inode fs=%p node=%p blknr=%lld nblks=%d\n",
+ fs, node, blknr, nblks);
+ for (i = 0; i < nblks; i++) {
+ error = nandfs_bmap_lookup(fs, node, blknr + i, &vblks[i], raw);
+ if (error) {
+ free(pblks);
+ free(vblks);
+ return (error);
+ }
+ if (raw == 0)
+ pblks[i] = nandfs_vtop(fs, vblks[i]);
+ else
+ pblks[i] = vblks[i];
+ }
+
+ for (i = 0; i < nblks; i++) {
+ if (ioread(fs->nf_file, pblks[i] * fs->nf_blocksize, buf,
+ fs->nf_blocksize)) {
+ free(pblks);
+ free(vblks);
+ return (EIO);
+ }
+
+ buf += fs->nf_blocksize;
+ }
+
+ free(pblks);
+ free(vblks);
+ return (0);
+}
+
+static int
+nandfs_read_blk(struct nandfs *fs, nandfs_daddr_t blknr, void *buf, int phys)
+{
+ uint64_t pblknr;
+
+ pblknr = (phys ? blknr : nandfs_vtop(fs, blknr));
+
+ return (ioread(fs->nf_file, pblknr * fs->nf_blocksize, buf,
+ fs->nf_blocksize));
+}
+
+static int
+nandfs_get_checkpoint(struct nandfs *fs, uint64_t cpno,
+ struct nandfs_checkpoint *cp)
+{
+ uint64_t blocknr;
+ int blockoff, cp_per_block, dlen;
+ uint8_t *buf;
+
+ NANDFS_DEBUG("nandfs_get_checkpoint(fs=%p cpno=%lld)\n", fs, cpno);
+
+ buf = malloc(fs->nf_blocksize);
+
+ cpno += NANDFS_CPFILE_FIRST_CHECKPOINT_OFFSET - 1;
+ dlen = fs->nf_fsdata->f_checkpoint_size;
+ cp_per_block = fs->nf_blocksize / dlen;
+ blocknr = cpno / cp_per_block;
+ blockoff = (cpno % cp_per_block) * dlen;
+
+ if (nandfs_read_inode(fs, &fs->nf_cpfile, blocknr, 1, buf, 0)) {
+ free(buf);
+ return (EINVAL);
+ }
+
+ memcpy(cp, buf + blockoff, sizeof(struct nandfs_checkpoint));
+ free(buf);
+
+ return (0);
+}
+
+static uint64_t *
+nandfs_get_map(struct nandfs *fs, struct nandfs_node *node, nandfs_daddr_t blknr,
+ int phys)
+{
+ struct bmap_buf *bmap;
+ uint64_t *map;
+
+ LIST_FOREACH(bmap, &node->bmap_bufs, list) {
+ if (bmap->blknr == blknr)
+ return (bmap->map);
+ }
+
+ map = malloc(fs->nf_blocksize);
+ if (nandfs_read_blk(fs, blknr, map, phys)) {
+ free(map);
+ return (NULL);
+ }
+
+ bmap = malloc(sizeof(struct bmap_buf));
+ bmap->blknr = blknr;
+ bmap->map = map;
+
+ LIST_INSERT_HEAD(&node->bmap_bufs, bmap, list);
+
+ NANDFS_DEBUG("%s:(node=%p, map=%p)\n", __func__, node, map);
+ return (map);
+}
+
+static int
+nandfs_bmap_lookup(struct nandfs *fs, struct nandfs_node *node,
+ nandfs_lbn_t lblknr, nandfs_daddr_t *vblknr, int phys)
+{
+ struct nandfs_inode *ino;
+ nandfs_daddr_t ind_block_num;
+ uint64_t *map, *indir;
+ uint64_t idx0, idx1, vblk, tmp;
+ int idx;
+ int level;
+
+ ino = node->inode;
+
+ if (lblknr < NDADDR) {
+ *vblknr = ino->i_db[lblknr];
+ return (0);
+ }
+
+ lblknr -= NDADDR;
+
+ /*
+ * nindir[0] = NINDIR
+ * nindir[1] = NINDIR**2
+ * nindir[2] = NINDIR**3
+ * etc
+ */
+ for (level = 0; level < NIADDR; level++) {
+ NANDFS_DEBUG("lblknr=%jx fs->nf_nindir[%d]=%d\n", lblknr, level, fs->nf_nindir[level]);
+ if (lblknr < fs->nf_nindir[level])
+ break;
+ lblknr -= fs->nf_nindir[level];
+ }
+
+ if (level == NIADDR) {
+ /* Block number too high */
+ NANDFS_DEBUG("lblknr %jx too high\n", lblknr);
+ return (EFBIG);
+ }
+
+ ind_block_num = ino->i_ib[level];
+
+ for (; level >= 0; level--) {
+ if (ind_block_num == 0) {
+ *vblknr = 0; /* missing */
+ return (0);
+ }
+
+ twiddle();
+ NANDFS_DEBUG("calling get_map with %jx\n", ind_block_num);
+ map = nandfs_get_map(fs, node, ind_block_num, phys);
+ if (map == NULL)
+ return (EIO);
+
+ if (level > 0) {
+ idx = lblknr / fs->nf_nindir[level - 1];
+ lblknr %= fs->nf_nindir[level - 1];
+ } else
+ idx = lblknr;
+
+ ind_block_num = ((nandfs_daddr_t *)map)[idx];
+ }
+
+ *vblknr = ind_block_num;
+
+ return (0);
+}
+
+static nandfs_daddr_t
+nandfs_vtop(struct nandfs *fs, nandfs_daddr_t vblocknr)
+{
+ nandfs_lbn_t blocknr;
+ nandfs_daddr_t pblocknr;
+ int entrynr;
+ struct nandfs_dat_entry *dat;
+
+ dat = malloc(fs->nf_blocksize);
+ nandfs_mdt_trans(&fs->nf_datfile_mdt, vblocknr, &blocknr, &entrynr);
+
+ if (nandfs_read_inode(fs, &fs->nf_datfile, blocknr, 1, dat, 1)) {
+ free(dat);
+ return (0);
+ }
+
+ NANDFS_DEBUG("nandfs_vtop entrynr=%d vblocknr=%lld pblocknr=%lld\n",
+ entrynr, vblocknr, dat[entrynr].de_blocknr);
+
+ pblocknr = dat[entrynr].de_blocknr;
+ free(dat);
+ return (pblocknr);
+}
+
+static void
+nandfs_calc_mdt_consts(int blocksize, struct nandfs_mdt *mdt, int entry_size)
+{
+
+ mdt->entries_per_group = blocksize * 8; /* bits in sector */
+ mdt->entries_per_block = blocksize / entry_size;
+ mdt->blocks_per_group =
+ (mdt->entries_per_group -1) / mdt->entries_per_block + 1 + 1;
+ mdt->groups_per_desc_block =
+ blocksize / sizeof(struct nandfs_block_group_desc);
+ mdt->blocks_per_desc_block =
+ mdt->groups_per_desc_block * mdt->blocks_per_group + 1;
+}
+
+static void
+nandfs_mdt_trans(struct nandfs_mdt *mdt, uint64_t index,
+ nandfs_daddr_t *blocknr, uint32_t *entry_in_block)
+{
+ nandfs_daddr_t blknr;
+ uint64_t group, group_offset, blocknr_in_group;
+ uint64_t desc_block, desc_offset;
+
+ /* Calculate our offset in the file */
+ group = index / mdt->entries_per_group;
+ group_offset = index % mdt->entries_per_group;
+ desc_block = group / mdt->groups_per_desc_block;
+ desc_offset = group % mdt->groups_per_desc_block;
+ blocknr_in_group = group_offset / mdt->entries_per_block;
+
+ /* To descgroup offset */
+ blknr = 1 + desc_block * mdt->blocks_per_desc_block;
+
+ /* To group offset */
+ blknr += desc_offset * mdt->blocks_per_group;
+
+ /* To actual file block */
+ blknr += 1 + blocknr_in_group;
+
+ *blocknr = blknr;
+ *entry_in_block = group_offset % mdt->entries_per_block;
+}
+
+static int
+ioread(struct open_file *f, off_t pos, void *buf, u_int length)
+{
+ void *buffer;
+ int err;
+ int bsize = ((struct nandfs *)f->f_fsdata)->nf_sectorsize;
+ u_int off, nsec;
+
+ off = pos % bsize;
+ pos /= bsize;
+ nsec = (length + (bsize - 1)) / bsize;
+
+ NANDFS_DEBUG("pos=%lld length=%d off=%d nsec=%d\n", pos, length,
+ off, nsec);
+
+ buffer = malloc(nsec * bsize);
+
+ err = (f->f_dev->dv_strategy)(f->f_devdata, F_READ, pos,
+ nsec * bsize, buffer, NULL);
+
+ memcpy(buf, buffer + off, length);
+ free(buffer);
+
+ return (err);
+}
+
+static int
+nandfs_probe_sectorsize(struct open_file *f)
+{
+ void *buffer;
+ int i, err;
+
+ buffer = malloc(16 * 1024);
+
+ NANDFS_DEBUG("probing for sector size: ");
+
+ for (i = 512; i < (16 * 1024); i <<= 1) {
+ NANDFS_DEBUG("%d ", i);
+ err = (f->f_dev->dv_strategy)(f->f_devdata, F_READ, 0, i,
+ buffer, NULL);
+
+ if (err == 0) {
+ NANDFS_DEBUG("found");
+ free(buffer);
+ return (i);
+ }
+ }
+
+ free(buffer);
+ NANDFS_DEBUG("not found\n");
+ return (-1);
+}
diff --git a/lib/libstand/stand.h b/lib/libstand/stand.h
index db0490f..10bb829 100644
--- a/lib/libstand/stand.h
+++ b/lib/libstand/stand.h
@@ -118,6 +118,7 @@ extern struct fs_ops ufs_fsops;
extern struct fs_ops tftp_fsops;
extern struct fs_ops nfs_fsops;
extern struct fs_ops cd9660_fsops;
+extern struct fs_ops nandfs_fsops;
extern struct fs_ops gzipfs_fsops;
extern struct fs_ops bzipfs_fsops;
extern struct fs_ops dosfs_fsops;
diff --git a/lib/libstdbuf/Makefile b/lib/libstdbuf/Makefile
new file mode 100644
index 0000000..cf65e4f
--- /dev/null
+++ b/lib/libstdbuf/Makefile
@@ -0,0 +1,12 @@
+# $FreeBSD$
+
+.include <bsd.own.mk>
+
+LIB= stdbuf
+SRCS= stdbuf.c
+SHLIB_MAJOR= 1
+MAN= libstdbuf.3
+
+WARNS?= 6
+
+.include <bsd.lib.mk>
diff --git a/lib/libstdbuf/libstdbuf.3 b/lib/libstdbuf/libstdbuf.3
new file mode 100644
index 0000000..9b37cb0
--- /dev/null
+++ b/lib/libstdbuf/libstdbuf.3
@@ -0,0 +1,102 @@
+.\" Copyright (c) 2012 Jeremie Le Hen <jlh@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 and documentation 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 28, 2012
+.Dt LIBSTDBUF 3
+.Os
+.Sh NAME
+.Nm libstdbuf
+.Nd preloaded library to change standard streams initial buffering
+.Sh DESCRIPTION
+The
+.Nm
+library is meant to be preloaded with the
+.Ev LD_PRELOAD
+environment variable to as to change the initial buffering
+of standard input, standard output and standard error streams.
+.Pp
+Although you may load and configure this library manually,
+an utility,
+.Xr stdbuf 1 ,
+can be used to run a command with the appropriate environment variables.
+.Sh ENVIRONMENT
+Each stream can be configured independently through the following
+environment variables (values are defined below):
+.Bl -tag -width size -offset indent
+.It Ev _STDBUF_I
+Initial buffering definition for the standard input stream
+.It Ev _STDBUF_O
+Initial buffering definition for the standard output stream
+.It Ev _STDBUF_E
+Initial buffering definition for the standard error stream
+.El
+.Pp
+Each variable may take one of the following values:
+.Bl -tag -width size -offset indent
+.It Qq 0
+unbuffered
+.It Qq L
+line buffered
+.It Qq B
+fully buffered with the default buffer size
+.It Ar size
+fully buffered with a buffer of
+.Ar size
+bytes (suffixes 'k', 'M' and 'G' are accepted)
+.El
+.Sh EXAMPLE
+In the following example, the stdout stream of the
+.Xr awk 1
+command
+will be fully buffered by default because it does not refer
+to a terminal.
+.Nm
+is used to force it to be line-buffered so
+.Xr vmstat 8 Ns 's
+output will not stall until the full buffer fills.
+.Bd -literal -offset indent
+# vmstat 1 | LD_PRELOAD=/usr/lib/libstdbuf.so \\
+ STDBUF_1=L awk '$2 > 1 || $3 > 1' | cat -n
+.Ed
+.Pp
+See also the manpage of
+.Xr stdbuf 1
+for a simpler way to do this.
+.Sh HISTORY
+The
+.Nm
+library first appeared in
+.Fx 8.4 .
+.Sh AUTHORS
+.An -nosplit
+The original idea of the
+.Nm
+command comes from
+.An Padraig Brady
+who implemented it in the GNU coreutils.
+.An Jeremie Le Hen
+implemented it on
+.Fx .
diff --git a/lib/libstdbuf/stdbuf.c b/lib/libstdbuf/stdbuf.c
new file mode 100644
index 0000000..1b5d39a
--- /dev/null
+++ b/lib/libstdbuf/stdbuf.c
@@ -0,0 +1,115 @@
+/*-
+ * Copyright (c) 2012 Jeremie Le Hen <jlh@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 <err.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+static const char *
+stream_name(FILE *s)
+{
+
+ if (s == stdin)
+ return "stdin";
+ if (s == stdout)
+ return "stdout";
+ if (s == stderr)
+ return "stderr";
+ /* This should not happen. */
+ abort();
+}
+
+static void
+change_buf(FILE *s, const char *bufmode)
+{
+ char *unit;
+ size_t bufsize;
+ int mode;
+
+ bufsize = 0;
+ if (bufmode[0] == '0' && bufmode[1] == '\0')
+ mode = _IONBF;
+ else if (bufmode[0] == 'L' && bufmode[1] == '\0')
+ mode = _IOLBF;
+ else if (bufmode[0] == 'B' && bufmode[1] == '\0') {
+ mode = _IOFBF;
+ bufsize = 0;
+ } else {
+ /*
+ * This library being preloaded, depending on libutil
+ * would lead to excessive namespace pollution.
+ * Thus we do not use expand_number().
+ */
+ errno = 0;
+ bufsize = strtol(bufmode, &unit, 0);
+ if (errno == EINVAL || errno == ERANGE || unit == bufmode)
+ warn("Wrong buffer mode '%s' for %s", bufmode,
+ stream_name(s));
+ switch (*unit) {
+ case 'G':
+ bufsize *= 1024 * 1024 * 1024;
+ break;
+ case 'M':
+ bufsize *= 1024 * 1024;
+ break;
+ case 'k':
+ bufsize *= 1024;
+ break;
+ case '\0':
+ break;
+ default:
+ warnx("Unknown suffix '%c' for %s", *unit,
+ stream_name(s));
+ return;
+ }
+ mode = _IOFBF;
+ }
+ if (setvbuf(s, NULL, mode, bufsize) != 0)
+ warn("Cannot set buffer mode '%s' for %s", bufmode,
+ stream_name(s));
+}
+
+__attribute__ ((constructor)) static void
+stdbuf(void)
+{
+ char *i_mode, *o_mode, *e_mode;
+
+ i_mode = getenv("_STDBUF_I");
+ o_mode = getenv("_STDBUF_O");
+ e_mode = getenv("_STDBUF_E");
+
+ if (e_mode != NULL)
+ change_buf(stderr, e_mode);
+ if (i_mode != NULL)
+ change_buf(stdin, i_mode);
+ if (o_mode != NULL)
+ change_buf(stdout, o_mode);
+}
diff --git a/lib/libtacplus/libtacplus.3 b/lib/libtacplus/libtacplus.3
index f247a28..40ec6a2 100644
--- a/lib/libtacplus/libtacplus.3
+++ b/lib/libtacplus/libtacplus.3
@@ -380,7 +380,7 @@ the request, and waits for a reply.
On failure,
.Fn tac_send_acct
returns \-1.
-Otherwise, it returns the TACACS+ status code
+Otherwise, it returns the TACACS+ status code.
Possible status codes, defined in
.In taclib.h ,
include:
diff --git a/lib/libthr/thread/thr_init.c b/lib/libthr/thread/thr_init.c
index 86abad8..e1e304a 100644
--- a/lib/libthr/thread/thr_init.c
+++ b/lib/libthr/thread/thr_init.c
@@ -112,6 +112,7 @@ size_t _thr_stack_initial = THR_STACK_INITIAL;
int _thr_page_size;
int _thr_spinloops;
int _thr_yieldloops;
+int _thr_queuefifo = 4;
int _gc_count;
struct umutex _mutex_static_lock = DEFAULT_UMUTEX;
struct umutex _cond_static_lock = DEFAULT_UMUTEX;
@@ -470,6 +471,9 @@ init_private(void)
env = getenv("LIBPTHREAD_YIELDLOOPS");
if (env)
_thr_yieldloops = atoi(env);
+ env = getenv("LIBPTHREAD_QUEUE_FIFO");
+ if (env)
+ _thr_queuefifo = atoi(env);
TAILQ_INIT(&_thr_atfork_list);
}
init_once = 1;
diff --git a/lib/libthr/thread/thr_mutex.c b/lib/libthr/thread/thr_mutex.c
index 7573f28..91b47ec 100644
--- a/lib/libthr/thread/thr_mutex.c
+++ b/lib/libthr/thread/thr_mutex.c
@@ -538,6 +538,7 @@ mutex_self_trylock(struct pthread_mutex *m)
switch (PMUTEX_TYPE(m->m_flags)) {
case PTHREAD_MUTEX_ERRORCHECK:
case PTHREAD_MUTEX_NORMAL:
+ case PTHREAD_MUTEX_ADAPTIVE_NP:
ret = EBUSY;
break;
diff --git a/lib/libthr/thread/thr_private.h b/lib/libthr/thread/thr_private.h
index 4469f6b..5224c7c 100644
--- a/lib/libthr/thread/thr_private.h
+++ b/lib/libthr/thread/thr_private.h
@@ -710,6 +710,7 @@ extern size_t _thr_stack_initial __hidden;
extern int _thr_page_size __hidden;
extern int _thr_spinloops __hidden;
extern int _thr_yieldloops __hidden;
+extern int _thr_queuefifo __hidden;
/* Garbage thread count. */
extern int _gc_count __hidden;
diff --git a/lib/libthr/thread/thr_sleepq.c b/lib/libthr/thread/thr_sleepq.c
index 8549a87..c5dcac5 100644
--- a/lib/libthr/thread/thr_sleepq.c
+++ b/lib/libthr/thread/thr_sleepq.c
@@ -39,6 +39,7 @@
struct sleepqueue_chain {
struct umutex sc_lock;
+ int sc_enqcnt;
LIST_HEAD(, sleepqueue) sc_queues;
int sc_type;
};
@@ -93,30 +94,34 @@ _sleepq_unlock(void *wchan)
THR_LOCK_RELEASE(curthread, &sc->sc_lock);
}
-struct sleepqueue *
-_sleepq_lookup(void *wchan)
+static inline struct sleepqueue *
+lookup(struct sleepqueue_chain *sc, void *wchan)
{
- struct sleepqueue_chain *sc;
struct sleepqueue *sq;
- sc = SC_LOOKUP(wchan);
LIST_FOREACH(sq, &sc->sc_queues, sq_hash)
if (sq->sq_wchan == wchan)
return (sq);
return (NULL);
}
+struct sleepqueue *
+_sleepq_lookup(void *wchan)
+{
+ return (lookup(SC_LOOKUP(wchan), wchan));
+}
+
void
_sleepq_add(void *wchan, struct pthread *td)
{
struct sleepqueue_chain *sc;
struct sleepqueue *sq;
- sq = _sleepq_lookup(wchan);
+ sc = SC_LOOKUP(wchan);
+ sq = lookup(sc, wchan);
if (sq != NULL) {
SLIST_INSERT_HEAD(&sq->sq_freeq, td->sleepqueue, sq_flink);
} else {
- sc = SC_LOOKUP(wchan);
sq = td->sleepqueue;
LIST_INSERT_HEAD(&sc->sc_queues, sq, sq_hash);
sq->sq_wchan = wchan;
@@ -124,7 +129,10 @@ _sleepq_add(void *wchan, struct pthread *td)
}
td->sleepqueue = NULL;
td->wchan = wchan;
- TAILQ_INSERT_TAIL(&sq->sq_blocked, td, wle);
+ if (((++sc->sc_enqcnt << _thr_queuefifo) & 0xff) != 0)
+ TAILQ_INSERT_HEAD(&sq->sq_blocked, td, wle);
+ else
+ TAILQ_INSERT_TAIL(&sq->sq_blocked, td, wle);
}
int
diff --git a/lib/libusb/Makefile b/lib/libusb/Makefile
index 75efe2e..d45dd56 100644
--- a/lib/libusb/Makefile
+++ b/lib/libusb/Makefile
@@ -18,6 +18,9 @@ NOGCCERROR=
WARNS?= 2
+DPADD= ${LIBPTHREAD}
+LDADD= -lpthread
+
MLINKS+= libusb.3 usb.3
# libusb 0.1 compat
@@ -74,6 +77,7 @@ MLINKS += libusb.3 libusb_get_active_config_descriptor.3
MLINKS += libusb.3 libusb_get_config_descriptor.3
MLINKS += libusb.3 libusb_get_config_descriptor_by_value.3
MLINKS += libusb.3 libusb_free_config_descriptor.3
+MLINKS += libusb.3 libusb_get_string_descriptor.3
MLINKS += libusb.3 libusb_get_string_descriptor_ascii.3
MLINKS += libusb.3 libusb_parse_ss_endpoint_comp.3
MLINKS += libusb.3 libusb_free_ss_endpoint_comp.3
diff --git a/lib/libusb/libusb.3 b/lib/libusb/libusb.3
index 6b1defd..ffc761b 100644
--- a/lib/libusb/libusb.3
+++ b/lib/libusb/libusb.3
@@ -26,7 +26,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd April 12, 2012
+.Dd May 7, 2012
.Dt LIBUSB 3
.Os
.Sh NAME
@@ -100,12 +100,12 @@ counter decremented once.
.Ft uint8_t
.Fn libusb_get_bus_number "libusb_device *dev"
Returns the number of the bus contained by the device
-.Fa dev.
+.Fa dev .
.Pp
.Ft uint8_t
.Fn libusb_get_device_address "libusb_device *dev"
Returns the device_address contained by the device
-.Fa dev.
+.Fa dev .
.Pp
.Ft enum libusb_speed
.Fn libusb_get_device_speed "libusb_device *dev"
@@ -127,12 +127,12 @@ LIBUSB_ERROR_OTHERS on other failure.
.Ft libusb_device *
.Fn libusb_ref_device "libusb_device *dev"
Increment the reference counter of the device
-.Fa dev.
+.Fa dev .
.Pp
.Ft void
.Fn libusb_unref_device "libusb_device *dev"
Decrement the reference counter of the device
-.Fa dev.
+.Fa dev .
.Pp
.Ft int
.Fn libusb_open "libusb_device *dev" "libusb_device_handle **devh"
@@ -147,7 +147,7 @@ disconnected and a LIBUSB_ERROR code on other errors.
A convenience function to open a device by vendor and product IDs
.Fa vid
and
-.Fa pid.
+.Fa pid .
Returns NULL on error.
.Pp
.Ft void
@@ -161,7 +161,7 @@ Returns NULL on error.
.Pp
.Ft int
.Fn libusb_get_configuration "libusb_device_handle *devh" "int *config"
-Returns the bConfiguration value of the current configuration.
+Returns the value of the current configuration.
Returns 0
on success, LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
and a LIBUSB_ERROR code on error.
@@ -171,7 +171,7 @@ and a LIBUSB_ERROR code on error.
Set the active configuration to
.Fa config
for the device contained by
-.Fa devh.
+.Fa devh .
This function returns 0 on success, LIBUSB_ERROR_NOT_FOUND if the requested
configuration does not exist, LIBUSB_ERROR_BUSY if the interfaces are currently
claimed, LIBUSB_ERROR_NO_DEVICE if the device has been disconnected and a
@@ -180,7 +180,7 @@ LIBUSB_ERROR code on failure.
.Ft int
.Fn libusb_claim_interface "libusb_device_handle *devh" "int interface_number"
Claim an interface in a given libusb_handle
-.Fa devh.
+.Fa devh .
This is a non-blocking function.
It returns 0 on success, LIBUSB_ERROR_NOT_FOUND
if the requested interface does not exist, LIBUSB_ERROR_BUSY if a program or
@@ -279,7 +279,7 @@ LIBUSB_ERROR code on failure.
.Ft int
.Fn libusb_get_device_descriptor "libusb_device *dev" "libusb_device_descriptor *desc"
Get the USB device descriptor for the device
-.Fa dev.
+.Fa dev .
This is a non-blocking function.
Returns 0 on success and a LIBUSB_ERROR code on
failure.
@@ -314,6 +314,12 @@ LIBUSB_ERROR code on failure.
Free a configuration descriptor.
.Pp
.Ft int
+.Fn libusb_get_string_descriptor "libusb_device_handle *devh" "uint8_t desc_idx" "uint16_t langid" "unsigned char *data" "int length"
+Retrieve a string descriptor in raw format.
+Returns the number of bytes actually transferred on success
+or a negative LIBUSB_ERROR code on failure.
+.Pp
+.Ft int
.Fn libusb_get_string_descriptor_ascii "libusb_device_handle *devh" "uint8_t desc_idx" "unsigned char *data" "int length"
Retrieve a string descriptor in C style ASCII.
Returns the positive number of bytes in the resulting ASCII string
@@ -324,11 +330,11 @@ on success and a LIBUSB_ERROR code on failure.
This function parses the USB 3.0 endpoint companion descriptor in host endian format pointed to by
.Fa buf
and having a length of
-.Fa len.
+.Fa len .
Typically these arguments are the extra and extra_length fields of the
endpoint descriptor.
On success the pointer to resulting descriptor is stored at the location given by
-.Fa ep_comp.
+.Fa ep_comp .
Returns zero on success and a LIBUSB_ERROR code on failure.
On success the parsed USB 3.0 endpoint companion descriptor must be
freed using the libusb_free_ss_endpoint_comp function.
@@ -342,9 +348,9 @@ This function is NULL safe and frees a parsed USB 3.0 endpoint companion descrip
This function parses a Binary Object Store, BOS, descriptor into host endian format pointed to by
.Fa buf
and having a length of
-.Fa len.
+.Fa len .
On success the pointer to resulting descriptor is stored at the location given by
-.Fa bos.
+.Fa bos .
Returns zero on success and a LIBUSB_ERROR code on failure.
On success the parsed BOS descriptor must be freed using the
libusb_free_bos_descriptor function.
diff --git a/lib/libusb/libusb.h b/lib/libusb/libusb.h
index d8a22b5..1675f46 100644
--- a/lib/libusb/libusb.h
+++ b/lib/libusb/libusb.h
@@ -398,6 +398,7 @@ int libusb_get_active_config_descriptor(libusb_device * dev, struct libusb_confi
int libusb_get_config_descriptor(libusb_device * dev, uint8_t config_index, struct libusb_config_descriptor **config);
int libusb_get_config_descriptor_by_value(libusb_device * dev, uint8_t bConfigurationValue, struct libusb_config_descriptor **config);
void libusb_free_config_descriptor(struct libusb_config_descriptor *config);
+int libusb_get_string_descriptor(libusb_device_handle * devh, uint8_t desc_index, uint16_t langid, unsigned char *data, int length);
int libusb_get_string_descriptor_ascii(libusb_device_handle * devh, uint8_t desc_index, uint8_t *data, int length);
int libusb_get_descriptor(libusb_device_handle * devh, uint8_t desc_type, uint8_t desc_index, uint8_t *data, int length);
int libusb_parse_ss_endpoint_comp(const void *buf, int len, struct libusb_ss_endpoint_companion_descriptor **ep_comp);
diff --git a/lib/libusb/libusb10.c b/lib/libusb/libusb10.c
index 44331bc..256d67e 100644
--- a/lib/libusb/libusb10.c
+++ b/lib/libusb/libusb10.c
@@ -92,6 +92,7 @@ int
libusb_init(libusb_context **context)
{
struct libusb_context *ctx;
+ pthread_condattr_t attr;
char *debug;
int ret;
@@ -110,8 +111,28 @@ libusb_init(libusb_context **context)
TAILQ_INIT(&ctx->pollfds);
TAILQ_INIT(&ctx->tr_done);
- pthread_mutex_init(&ctx->ctx_lock, NULL);
- pthread_cond_init(&ctx->ctx_cond, NULL);
+ if (pthread_mutex_init(&ctx->ctx_lock, NULL) != 0) {
+ free(ctx);
+ return (LIBUSB_ERROR_NO_MEM);
+ }
+ if (pthread_condattr_init(&attr) != 0) {
+ pthread_mutex_destroy(&ctx->ctx_lock);
+ free(ctx);
+ return (LIBUSB_ERROR_NO_MEM);
+ }
+ if (pthread_condattr_setclock(&attr, CLOCK_MONOTONIC) != 0) {
+ pthread_mutex_destroy(&ctx->ctx_lock);
+ pthread_condattr_destroy(&attr);
+ free(ctx);
+ return (LIBUSB_ERROR_OTHER);
+ }
+ if (pthread_cond_init(&ctx->ctx_cond, &attr) != 0) {
+ pthread_mutex_destroy(&ctx->ctx_lock);
+ pthread_condattr_destroy(&attr);
+ free(ctx);
+ return (LIBUSB_ERROR_NO_MEM);
+ }
+ pthread_condattr_destroy(&attr);
ctx->ctx_handler = NO_THREAD;
diff --git a/lib/libusb/libusb10_desc.c b/lib/libusb/libusb10_desc.c
index 8e39bab..11e201f 100644
--- a/lib/libusb/libusb10_desc.c
+++ b/lib/libusb/libusb10_desc.c
@@ -294,6 +294,25 @@ libusb_free_config_descriptor(struct libusb_config_descriptor *config)
}
int
+libusb_get_string_descriptor(libusb_device_handle *pdev,
+ uint8_t desc_index, uint16_t langid, unsigned char *data,
+ int length)
+{
+ if (pdev == NULL || data == NULL || length < 1)
+ return (LIBUSB_ERROR_INVALID_PARAM);
+
+ if (length > 65535)
+ length = 65535;
+
+ /* put some default data into the destination buffer */
+ data[0] = 0;
+
+ return (libusb_control_transfer(pdev, LIBUSB_ENDPOINT_IN,
+ LIBUSB_REQUEST_GET_DESCRIPTOR, (LIBUSB_DT_STRING << 8) | desc_index,
+ langid, data, length, 1000));
+}
+
+int
libusb_get_string_descriptor_ascii(libusb_device_handle *pdev,
uint8_t desc_index, unsigned char *data, int length)
{
diff --git a/lib/libusb/libusb10_io.c b/lib/libusb/libusb10_io.c
index 63f833a..302fdb8 100644
--- a/lib/libusb/libusb10_io.c
+++ b/lib/libusb/libusb10_io.c
@@ -307,12 +307,16 @@ libusb_wait_for_event(libusb_context *ctx, struct timeval *tv)
&ctx->ctx_lock);
return (0);
}
- err = clock_gettime(CLOCK_REALTIME, &ts);
+ err = clock_gettime(CLOCK_MONOTONIC, &ts);
if (err < 0)
return (LIBUSB_ERROR_OTHER);
- ts.tv_sec = tv->tv_sec;
- ts.tv_nsec = tv->tv_usec * 1000;
+ /*
+ * The "tv" arguments points to a relative time structure and
+ * not an absolute time structure.
+ */
+ ts.tv_sec += tv->tv_sec;
+ ts.tv_nsec += tv->tv_usec * 1000;
if (ts.tv_nsec >= 1000000000) {
ts.tv_nsec -= 1000000000;
ts.tv_sec++;
diff --git a/lib/libusb/libusb20.3 b/lib/libusb/libusb20.3
index d1abc55..c9bf902 100644
--- a/lib/libusb/libusb20.3
+++ b/lib/libusb/libusb20.3
@@ -331,7 +331,7 @@ packets are avoided for proxy buffers.
.Pp
.
.Fn libusb20_tr_get_max_total_length
-function will return the maximum value for the data length sum of all USB
+will return the maximum value for the data length sum of all USB
frames associated with an USB transfer.
In case of control transfers the value returned does not include the
length of the SETUP packet, 8 bytes, which is part of frame zero.
@@ -401,7 +401,7 @@ The callback type is defined by libusb20_tr_callback_t.
.
.Fn libusb20_tr_set_flags
is used to set various USB flags for the given USB transfer.
-.Bl -tag
+.Bl -tag -width "LIBUSB20_TRANSFER_SINGLE_SHORT_NOT_OK"
.It LIBUSB20_TRANSFER_SINGLE_SHORT_NOT_OK
Report a short frame as error.
.It LIBUSB20_TRANSFER_MULTI_SHORT_NOT_OK
@@ -709,13 +709,14 @@ This function returns zero if the device is still connected else a LIBUSB20_ERRO
sets the power mode of the USB device.
.
Valid power modes:
-.Bl -tag
+.Bl -tag -width "LIBUSB20_POWER_OFF"
.It LIBUSB20_POWER_OFF
.It LIBUSB20_POWER_ON
.It LIBUSB20_POWER_SAVE
.It LIBUSB20_POWER_SUSPEND
.It LIBUSB20_POWER_RESUME
.El
+.Pp
.
This function returns zero on success else a LIBUSB20_ERROR value is
returned.
@@ -793,7 +794,7 @@ Valid bus numbers start at zero.
returns the current operation mode of the USB entity.
.
Valid return values are:
-.Bl -tag
+.Bl -tag -width "LIBUSB20_MODE_DEVICE"
.It LIBUSB20_MODE_HOST
.It LIBUSB20_MODE_DEVICE
.El
@@ -803,7 +804,7 @@ Valid return values are:
.Fn libusb20_dev_get_speed
returns the current speed of the given USB device.
.
-.Bl -tag
+.Bl -tag -width "LIBUSB20_SPEED_VARIABLE"
.It LIBUSB20_SPEED_UNKNOWN
.It LIBUSB20_SPEED_LOW
.It LIBUSB20_SPEED_FULL
@@ -815,7 +816,7 @@ returns the current speed of the given USB device.
.Pp
.
.Fn libusb20_dev_get_config_index
-This function returns the currently select config index for the given
+returns the currently selected config index for the given
USB device.
.
.Pp
@@ -832,7 +833,7 @@ will set the debug level for the given USB device.
.Pp
.
.Fn libusb20_dev_wait_process
-function will wait until a pending USB transfer has completed on
+will wait until a pending USB transfer has completed on
the given USB device.
.
A timeout value can be specified which is passed on to the
@@ -866,7 +867,7 @@ returned.
.Pp
.
.Fn libusb20_be_get_dev_quirk
-This function will return the device quirk according to
+will return the device quirk according to
.Fa index
into the libusb20_quirk structure pointed to by
.Fa pq .
@@ -948,7 +949,7 @@ Dequeued USB devices will not be freed when the backend is freed.
.Pp
.
.Fn libusb20_be_enqueue_device
-This function will enqueue the given USB device pointer in the backend USB device list.
+will enqueue the given USB device pointer in the backend USB device list.
.
Enqueued USB devices will get freed when the backend is freed.
.
diff --git a/lib/libusbhid/parse.c b/lib/libusbhid/parse.c
index f7c2cb1..041e289 100644
--- a/lib/libusbhid/parse.c
+++ b/lib/libusbhid/parse.c
@@ -392,7 +392,7 @@ hid_get_item(hid_data_t s, hid_item_t *h)
s->loc_size = dval & mask;
break;
case 8:
- hid_switch_rid(s, c, dval);
+ hid_switch_rid(s, c, dval & mask);
break;
case 9:
/* mask because value is unsigned */
diff --git a/lib/libutil/Makefile b/lib/libutil/Makefile
index 3136a05..413ba0b 100644
--- a/lib/libutil/Makefile
+++ b/lib/libutil/Makefile
@@ -25,14 +25,13 @@ CFLAGS+= -DINET6
CFLAGS+= -I${.CURDIR} -I${.CURDIR}/../libc/gen/
-MAN+= auth.3 expand_number.3 flopen.3 fparseln.3 hexdump.3 \
+MAN+= expand_number.3 flopen.3 fparseln.3 hexdump.3 \
humanize_number.3 kinfo_getallproc.3 kinfo_getfile.3 \
kinfo_getproc.3 kinfo_getvmmap.3 kld.3 login_auth.3 login_cap.3 \
login_class.3 login_ok.3 login_times.3 login_tty.3 pidfile.3 \
property.3 pty.3 quotafile.3 realhostname.3 realhostname_sa.3 \
_secure_path.3 trimdomain.3 uucplock.3
-MAN+= auth.conf.5 login.conf.5
-MLINKS+= auth.3 auth_getval.3
+MAN+= login.conf.5
MLINKS+= kld.3 kld_isloaded.3 kld.3 kld_load.3
MLINKS+=login_auth.3 auth_cat.3 login_auth.3 auth_checknologin.3
MLINKS+=login_cap.3 login_close.3 login_cap.3 login_getcapbool.3 \
diff --git a/lib/libutil/auth.3 b/lib/libutil/auth.3
deleted file mode 100644
index 247a098..0000000
--- a/lib/libutil/auth.3
+++ /dev/null
@@ -1,56 +0,0 @@
-.\"
-.\" Copyright (c) 1998 Jordan Hubbard
-.\"
-.\" 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 DEVELOPERS ``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 DEVELOPERS 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 October 7, 1998
-.Dt AUTH_GETVAL 3
-.Os
-.Sh NAME
-.Nm auth_getval
-.Nd functions for reading values from
-.Pa /etc/auth.conf
-.Sh LIBRARY
-.Lb libutil
-.Sh SYNOPSIS
-.In sys/types.h
-.In libutil.h
-.Ft char *
-.Fn auth_getval "const char *name"
-.Sh DESCRIPTION
-The function
-.Fn auth_getval
-returns the value associated with the field called
-.Fa name
-or NULL if no such field is found or the auth file cannot be opened.
-.Sh FILES
-.Pa /etc/auth.conf
-contains the name=value pairs looked up by
-.Fn auth_getval .
-.Sh SEE ALSO
-.Xr properties_free 3 ,
-.Xr properties_read 3 ,
-.Xr property_find 3 ,
-.Xr auth.conf 5
diff --git a/lib/libutil/auth.c b/lib/libutil/auth.c
index 748c3ad..b57a784 100644
--- a/lib/libutil/auth.c
+++ b/lib/libutil/auth.c
@@ -31,40 +31,14 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
-#include <sys/types.h>
-#include <fcntl.h>
-#include <libutil.h>
-#include <paths.h>
-#include <syslog.h>
-#include <unistd.h>
-
-static properties P;
-
-static int
-initauthconf(const char *path)
-{
- int fd;
+#include <stdlib.h>
- if (!P) {
- if ((fd = open(path, O_RDONLY)) < 0) {
- syslog(LOG_ERR, "initauthconf: unable to open file: %s", path);
- return 1;
- }
- P = properties_read(fd);
- close(fd);
- if (!P) {
- syslog(LOG_ERR, "initauthconf: unable to parse file: %s", path);
- return 1;
- }
- }
- return 0;
-}
+#include <libutil.h>
char *
auth_getval(const char *name)
{
- if (!P && initauthconf(_PATH_AUTHCONF))
- return NULL;
- else
- return property_find(P, name);
+
+ (void)name;
+ return (NULL);
}
diff --git a/lib/libutil/auth.conf.5 b/lib/libutil/auth.conf.5
deleted file mode 100644
index be10eb8..0000000
--- a/lib/libutil/auth.conf.5
+++ /dev/null
@@ -1,35 +0,0 @@
-.\" Copyright (c) 1998 Jordan Hubbard
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, is permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice immediately at the beginning of the file, without modification,
-.\" 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.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd October 7, 1998
-.Dt AUTH.CONF 5
-.Os
-.Sh NAME
-.Nm auth.conf
-.Nd authentication capability database
-.Sh SYNOPSIS
-.Pa /etc/auth.conf
-.Sh DESCRIPTION
-.Nm
-contains various attributes important to the authentication
-code, most notably
-.Xr crypt 3
-for the time being.
-This documentation will be updated as the
-.Pa /etc/auth.conf
-file, which is very new, evolves.
-.Sh SEE ALSO
-.Xr auth_getval 3 ,
-.Xr crypt 3
diff --git a/lib/libutil/login.conf.5 b/lib/libutil/login.conf.5
index a272073..a07e1f0 100644
--- a/lib/libutil/login.conf.5
+++ b/lib/libutil/login.conf.5
@@ -209,7 +209,8 @@ value.
The syntax is the same as for the
.Fl l
argument of
-.Xr cpuset 1 or the word
+.Xr cpuset 1
+or the word
.Ql default .
If set to
.Ql default
@@ -266,9 +267,11 @@ The backoff delay is the number of tries above
multiplied by 5 seconds.
.It "login-retries number 10 The number of login attempts"
allowed before the login fails.
-.It "passwd_format string md5 The encryption format that new or"
+.It "passwd_format string sha512 The encryption format that new or"
changed passwords will use.
-Valid values include "des", "md5" and "blf".
+Valid values include "des", "md5", "blf", "sha256" and "sha512"; see
+.Xr crypt 3
+for details.
NIS clients using a
.No non- Ns Fx
NIS server should probably use "des".
diff --git a/lib/libutil/property.3 b/lib/libutil/property.3
index efe0079..3d40114 100644
--- a/lib/libutil/property.3
+++ b/lib/libutil/property.3
@@ -90,8 +90,6 @@ are desired, the entire value should be enclosed in { } (curly-bracket)
characters.
Any line beginning with a # or ; character is assumed to
be a comment and will be ignored.
-.Sh SEE ALSO
-.Xr auth_getval 3
.Sh AUTHORS
.An Jordan Hubbard
.Sh BUGS
diff --git a/lib/libutil/pw_util.c b/lib/libutil/pw_util.c
index 63c63de..4bf3001 100644
--- a/lib/libutil/pw_util.c
+++ b/lib/libutil/pw_util.c
@@ -437,14 +437,21 @@ pw_copy(int ffd, int tfd, const struct passwd *pw, struct passwd *old_pw)
size_t len;
int eof, readlen;
- spw = pw;
+ if (old_pw == NULL && pw == NULL)
+ return (-1);
+
+ spw = old_pw;
+ /* deleting a user */
if (pw == NULL) {
line = NULL;
- if (old_pw == NULL)
+ } else {
+ if ((line = pw_make(pw)) == NULL)
return (-1);
- spw = old_pw;
- } else if ((line = pw_make(pw)) == NULL)
- return (-1);
+ }
+
+ /* adding a user */
+ if (spw == NULL)
+ spw = pw;
eof = 0;
len = 0;
@@ -511,7 +518,7 @@ pw_copy(int ffd, int tfd, const struct passwd *pw, struct passwd *old_pw)
*/
*q = t;
- if (fpw == NULL || fpw->pw_uid != spw->pw_uid) {
+ if (fpw == NULL || strcmp(fpw->pw_name, spw->pw_name) != 0) {
/* nope */
if (fpw != NULL)
free(fpw);
diff --git a/lib/libz/ChangeLog b/lib/libz/ChangeLog
index f310bb0..c2c643a 100644
--- a/lib/libz/ChangeLog
+++ b/lib/libz/ChangeLog
@@ -1,12 +1,213 @@
ChangeLog file for zlib
+Changes in 1.2.7 (2 May 2012)
+- Replace use of memmove() with a simple copy for portability
+- Test for existence of strerror
+- Restore gzgetc_ for backward compatibility with 1.2.6
+- Fix build with non-GNU make on Solaris
+- Require gcc 4.0 or later on Mac OS X to use the hidden attribute
+- Include unistd.h for Watcom C
+- Use __WATCOMC__ instead of __WATCOM__
+- Do not use the visibility attribute if NO_VIZ defined
+- Improve the detection of no hidden visibility attribute
+- Avoid using __int64 for gcc or solo compilation
+- Cast to char * in gzprintf to avoid warnings [Zinser]
+- Fix make_vms.com for VAX [Zinser]
+- Don't use library or built-in byte swaps
+- Simplify test and use of gcc hidden attribute
+- Fix bug in gzclose_w() when gzwrite() fails to allocate memory
+- Add "x" (O_EXCL) and "e" (O_CLOEXEC) modes support to gzopen()
+- Fix bug in test/minigzip.c for configure --solo
+- Fix contrib/vstudio project link errors [Mohanathas]
+- Add ability to choose the builder in make_vms.com [Schweda]
+- Add DESTDIR support to mingw32 win32/Makefile.gcc
+- Fix comments in win32/Makefile.gcc for proper usage
+- Allow overriding the default install locations for cmake
+- Generate and install the pkg-config file with cmake
+- Build both a static and a shared version of zlib with cmake
+- Include version symbols for cmake builds
+- If using cmake with MSVC, add the source directory to the includes
+- Remove unneeded EXTRA_CFLAGS from win32/Makefile.gcc [Truta]
+- Move obsolete emx makefile to old [Truta]
+- Allow the use of -Wundef when compiling or using zlib
+- Avoid the use of the -u option with mktemp
+- Improve inflate() documentation on the use of Z_FINISH
+- Recognize clang as gcc
+- Add gzopen_w() in Windows for wide character path names
+- Rename zconf.h in CMakeLists.txt to move it out of the way
+- Add source directory in CMakeLists.txt for building examples
+- Look in build directory for zlib.pc in CMakeLists.txt
+- Remove gzflags from zlibvc.def in vc9 and vc10
+- Fix contrib/minizip compilation in the MinGW environment
+- Update ./configure for Solaris, support --64 [Mooney]
+- Remove -R. from Solaris shared build (possible security issue)
+- Avoid race condition for parallel make (-j) running example
+- Fix type mismatch between get_crc_table() and crc_table
+- Fix parsing of version with "-" in CMakeLists.txt [Snider, Ziegler]
+- Fix the path to zlib.map in CMakeLists.txt
+- Force the native libtool in Mac OS X to avoid GNU libtool [Beebe]
+- Add instructions to win32/Makefile.gcc for shared install [Torri]
+
+Changes in 1.2.6.1 (12 Feb 2012)
+- Avoid the use of the Objective-C reserved name "id"
+- Include io.h in gzguts.h for Microsoft compilers
+- Fix problem with ./configure --prefix and gzgetc macro
+- Include gz_header definition when compiling zlib solo
+- Put gzflags() functionality back in zutil.c
+- Avoid library header include in crc32.c for Z_SOLO
+- Use name in GCC_CLASSIC as C compiler for coverage testing, if set
+- Minor cleanup in contrib/minizip/zip.c [Vollant]
+- Update make_vms.com [Zinser]
+- Remove unnecessary gzgetc_ function
+- Use optimized byte swap operations for Microsoft and GNU [Snyder]
+- Fix minor typo in zlib.h comments [Rzesniowiecki]
+
+Changes in 1.2.6 (29 Jan 2012)
+- Update the Pascal interface in contrib/pascal
+- Fix function numbers for gzgetc_ in zlibvc.def files
+- Fix configure.ac for contrib/minizip [Schiffer]
+- Fix large-entry detection in minizip on 64-bit systems [Schiffer]
+- Have ./configure use the compiler return code for error indication
+- Fix CMakeLists.txt for cross compilation [McClure]
+- Fix contrib/minizip/zip.c for 64-bit architectures [Dalsnes]
+- Fix compilation of contrib/minizip on FreeBSD [Marquez]
+- Correct suggested usages in win32/Makefile.msc [Shachar, Horvath]
+- Include io.h for Turbo C / Borland C on all platforms [Truta]
+- Make version explicit in contrib/minizip/configure.ac [Bosmans]
+- Avoid warning for no encryption in contrib/minizip/zip.c [Vollant]
+- Minor cleanup up contrib/minizip/unzip.c [Vollant]
+- Fix bug when compiling minizip with C++ [Vollant]
+- Protect for long name and extra fields in contrib/minizip [Vollant]
+- Avoid some warnings in contrib/minizip [Vollant]
+- Add -I../.. -L../.. to CFLAGS for minizip and miniunzip
+- Add missing libs to minizip linker command
+- Add support for VPATH builds in contrib/minizip
+- Add an --enable-demos option to contrib/minizip/configure
+- Add the generation of configure.log by ./configure
+- Exit when required parameters not provided to win32/Makefile.gcc
+- Have gzputc return the character written instead of the argument
+- Use the -m option on ldconfig for BSD systems [Tobias]
+- Correct in zlib.map when deflateResetKeep was added
+
+Changes in 1.2.5.3 (15 Jan 2012)
+- Restore gzgetc function for binary compatibility
+- Do not use _lseeki64 under Borland C++ [Truta]
+- Update win32/Makefile.msc to build test/*.c [Truta]
+- Remove old/visualc6 given CMakefile and other alternatives
+- Update AS400 build files and documentation [Monnerat]
+- Update win32/Makefile.gcc to build test/*.c [Truta]
+- Permit stronger flushes after Z_BLOCK flushes
+- Avoid extraneous empty blocks when doing empty flushes
+- Permit Z_NULL arguments to deflatePending
+- Allow deflatePrime() to insert bits in the middle of a stream
+- Remove second empty static block for Z_PARTIAL_FLUSH
+- Write out all of the available bits when using Z_BLOCK
+- Insert the first two strings in the hash table after a flush
+
+Changes in 1.2.5.2 (17 Dec 2011)
+- fix ld error: unable to find version dependency 'ZLIB_1.2.5'
+- use relative symlinks for shared libs
+- Avoid searching past window for Z_RLE strategy
+- Assure that high-water mark initialization is always applied in deflate
+- Add assertions to fill_window() in deflate.c to match comments
+- Update python link in README
+- Correct spelling error in gzread.c
+- Fix bug in gzgets() for a concatenated empty gzip stream
+- Correct error in comment for gz_make()
+- Change gzread() and related to ignore junk after gzip streams
+- Allow gzread() and related to continue after gzclearerr()
+- Allow gzrewind() and gzseek() after a premature end-of-file
+- Simplify gzseek() now that raw after gzip is ignored
+- Change gzgetc() to a macro for speed (~40% speedup in testing)
+- Fix gzclose() to return the actual error last encountered
+- Always add large file support for windows
+- Include zconf.h for windows large file support
+- Include zconf.h.cmakein for windows large file support
+- Update zconf.h.cmakein on make distclean
+- Merge vestigial vsnprintf determination from zutil.h to gzguts.h
+- Clarify how gzopen() appends in zlib.h comments
+- Correct documentation of gzdirect() since junk at end now ignored
+- Add a transparent write mode to gzopen() when 'T' is in the mode
+- Update python link in zlib man page
+- Get inffixed.h and MAKEFIXED result to match
+- Add a ./config --solo option to make zlib subset with no libary use
+- Add undocumented inflateResetKeep() function for CAB file decoding
+- Add --cover option to ./configure for gcc coverage testing
+- Add #define ZLIB_CONST option to use const in the z_stream interface
+- Add comment to gzdopen() in zlib.h to use dup() when using fileno()
+- Note behavior of uncompress() to provide as much data as it can
+- Add files in contrib/minizip to aid in building libminizip
+- Split off AR options in Makefile.in and configure
+- Change ON macro to Z_ARG to avoid application conflicts
+- Facilitate compilation with Borland C++ for pragmas and vsnprintf
+- Include io.h for Turbo C / Borland C++
+- Move example.c and minigzip.c to test/
+- Simplify incomplete code table filling in inflate_table()
+- Remove code from inflate.c and infback.c that is impossible to execute
+- Test the inflate code with full coverage
+- Allow deflateSetDictionary, inflateSetDictionary at any time (in raw)
+- Add deflateResetKeep and fix inflateResetKeep to retain dictionary
+- Fix gzwrite.c to accommodate reduced memory zlib compilation
+- Have inflate() with Z_FINISH avoid the allocation of a window
+- Do not set strm->adler when doing raw inflate
+- Fix gzeof() to behave just like feof() when read is not past end of file
+- Fix bug in gzread.c when end-of-file is reached
+- Avoid use of Z_BUF_ERROR in gz* functions except for premature EOF
+- Document gzread() capability to read concurrently written files
+- Remove hard-coding of resource compiler in CMakeLists.txt [Blammo]
+
+Changes in 1.2.5.1 (10 Sep 2011)
+- Update FAQ entry on shared builds (#13)
+- Avoid symbolic argument to chmod in Makefile.in
+- Fix bug and add consts in contrib/puff [Oberhumer]
+- Update contrib/puff/zeros.raw test file to have all block types
+- Add full coverage test for puff in contrib/puff/Makefile
+- Fix static-only-build install in Makefile.in
+- Fix bug in unzGetCurrentFileInfo() in contrib/minizip [Kuno]
+- Add libz.a dependency to shared in Makefile.in for parallel builds
+- Spell out "number" (instead of "nb") in zlib.h for total_in, total_out
+- Replace $(...) with `...` in configure for non-bash sh [Bowler]
+- Add darwin* to Darwin* and solaris* to SunOS\ 5* in configure [Groffen]
+- Add solaris* to Linux* in configure to allow gcc use [Groffen]
+- Add *bsd* to Linux* case in configure [Bar-Lev]
+- Add inffast.obj to dependencies in win32/Makefile.msc
+- Correct spelling error in deflate.h [Kohler]
+- Change libzdll.a again to libz.dll.a (!) in win32/Makefile.gcc
+- Add test to configure for GNU C looking for gcc in output of $cc -v
+- Add zlib.pc generation to win32/Makefile.gcc [Weigelt]
+- Fix bug in zlib.h for _FILE_OFFSET_BITS set and _LARGEFILE64_SOURCE not
+- Add comment in zlib.h that adler32_combine with len2 < 0 makes no sense
+- Make NO_DIVIDE option in adler32.c much faster (thanks to John Reiser)
+- Make stronger test in zconf.h to include unistd.h for LFS
+- Apply Darwin patches for 64-bit file offsets to contrib/minizip [Slack]
+- Fix zlib.h LFS support when Z_PREFIX used
+- Add updated as400 support (removed from old) [Monnerat]
+- Avoid deflate sensitivity to volatile input data
+- Avoid division in adler32_combine for NO_DIVIDE
+- Clarify the use of Z_FINISH with deflateBound() amount of space
+- Set binary for output file in puff.c
+- Use u4 type for crc_table to avoid conversion warnings
+- Apply casts in zlib.h to avoid conversion warnings
+- Add OF to prototypes for adler32_combine_ and crc32_combine_ [Miller]
+- Improve inflateSync() documentation to note indeterminancy
+- Add deflatePending() function to return the amount of pending output
+- Correct the spelling of "specification" in FAQ [Randers-Pehrson]
+- Add a check in configure for stdarg.h, use for gzprintf()
+- Check that pointers fit in ints when gzprint() compiled old style
+- Add dummy name before $(SHAREDLIBV) in Makefile [Bar-Lev, Bowler]
+- Delete line in configure that adds -L. libz.a to LDFLAGS [Weigelt]
+- Add debug records in assmebler code [Londer]
+- Update RFC references to use http://tools.ietf.org/html/... [Li]
+- Add --archs option, use of libtool to configure for Mac OS X [Borstel]
+
Changes in 1.2.5 (19 Apr 2010)
- Disable visibility attribute in win32/Makefile.gcc [Bar-Lev]
- Default to libdir as sharedlibdir in configure [Nieder]
- Update copyright dates on modified source files
- Update trees.c to be able to generate modified trees.h
- Exit configure for MinGW, suggesting win32/Makefile.gcc
+- Check for NULL path in gz_open [Homurlu]
Changes in 1.2.4.5 (18 Apr 2010)
- Set sharedlibdir in configure [Torok]
@@ -261,7 +462,7 @@ Changes in 1.2.3.4 (21 Dec 2009)
- Clear bytes after deflate lookahead to avoid use of uninitialized data
- Change a limit in inftrees.c to be more transparent to Coverity Prevent
- Update win32/zlib.def with exported symbols from zlib.h
-- Correct spelling error in zlib.h [Willem]
+- Correct spelling errors in zlib.h [Willem, Sobrado]
- Allow Z_BLOCK for deflate() to force a new block
- Allow negative bits in inflatePrime() to delete existing bit buffer
- Add Z_TREES flush option to inflate() to return at end of trees
diff --git a/lib/libz/FAQ b/lib/libz/FAQ
index 1a22750..99b7cf9 100644
--- a/lib/libz/FAQ
+++ b/lib/libz/FAQ
@@ -44,8 +44,8 @@ The lastest zlib FAQ is at http://zlib.net/zlib_faq.html
6. Where's the zlib documentation (man pages, etc.)?
- It's in zlib.h . Examples of zlib usage are in the files example.c and
- minigzip.c, with more in examples/ .
+ It's in zlib.h . Examples of zlib usage are in the files test/example.c
+ and test/minigzip.c, with more in examples/ .
7. Why don't you use GNU autoconf or libtool or ...?
@@ -84,8 +84,10 @@ The lastest zlib FAQ is at http://zlib.net/zlib_faq.html
13. How can I make a Unix shared library?
- make clean
- ./configure -s
+ By default a shared (and a static) library is built for Unix. So:
+
+ make distclean
+ ./configure
make
14. How do I install a shared zlib library on Unix?
@@ -325,7 +327,7 @@ The lastest zlib FAQ is at http://zlib.net/zlib_faq.html
correctly points to the zlib specification in RFC 1950 for the "deflate"
transfer encoding, there have been reports of servers and browsers that
incorrectly produce or expect raw deflate data per the deflate
- specficiation in RFC 1951, most notably Microsoft. So even though the
+ specification in RFC 1951, most notably Microsoft. So even though the
"deflate" transfer encoding using the zlib format would be the more
efficient approach (and in fact exactly what the zlib format was designed
for), using the "gzip" transfer encoding is probably more reliable due to
diff --git a/lib/libz/FREEBSD-upgrade b/lib/libz/FREEBSD-upgrade
index 4ee4eeb..d2d251b 100644
--- a/lib/libz/FREEBSD-upgrade
+++ b/lib/libz/FREEBSD-upgrade
@@ -1,4 +1,4 @@
-$FreeBSD$
+$FreeBSD: head/lib/libz/FREEBSD-upgrade 146082 2005-05-11 03:50:50Z kientzle $
ZLib 1.2.2
diff --git a/lib/libz/Makefile b/lib/libz/Makefile
index e373e83..4ecb022 100644
--- a/lib/libz/Makefile
+++ b/lib/libz/Makefile
@@ -1,5 +1,5 @@
#
-# $FreeBSD$
+# $FreeBSD: head/lib/libz/Makefile 232263 2012-02-28 18:30:18Z dim $
#
LIB= z
@@ -35,12 +35,12 @@ SRCS+= uncompr.c
SRCS+= zopen.c
SRCS+= zutil.c
-.if ${MACHINE_ARCH} == "i386" && ${MACHINE_CPU:M*i686*}
-.PATH: ${.CURDIR}/contrib/asm686
-SRCS+= match.S
-CFLAGS+= -DASMV -DNO_UNDERLINE
-ACFLAGS+= -Wa,--noexecstack
-.endif
+#.if ${MACHINE_ARCH} == "i386" && ${MACHINE_CPU:M*i686*}
+#.PATH: ${.CURDIR}/contrib/asm686
+#SRCS+= match.S
+#CFLAGS+= -DASMV -DNO_UNDERLINE
+#ACFLAGS+= -Wa,--noexecstack
+#.endif
#.if ${MACHINE_ARCH} == "amd64"
#.PATH: ${.CURDIR}/contrib/gcc_gvmat64
diff --git a/lib/libz/README b/lib/libz/README
index d4219bf..6f1255f 100644
--- a/lib/libz/README
+++ b/lib/libz/README
@@ -1,22 +1,22 @@
ZLIB DATA COMPRESSION LIBRARY
-zlib 1.2.5 is a general purpose data compression library. All the code is
+zlib 1.2.7 is a general purpose data compression library. All the code is
thread safe. The data format used by the zlib library is described by RFCs
(Request for Comments) 1950 to 1952 in the files
-http://www.ietf.org/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate format)
-and rfc1952.txt (gzip format).
+http://tools.ietf.org/html/rfc1950 (zlib format), rfc1951 (deflate format) and
+rfc1952 (gzip format).
All functions of the compression library are documented in the file zlib.h
(volunteer to write man pages welcome, contact zlib@gzip.org). A usage example
-of the library is given in the file example.c which also tests that the library
-is working correctly. Another example is given in the file minigzip.c. The
-compression library itself is composed of all source files except example.c and
-minigzip.c.
+of the library is given in the file test/example.c which also tests that
+the library is working correctly. Another example is given in the file
+test/minigzip.c. The compression library itself is composed of all source
+files in the root directory.
To compile all files and run the test program, follow the instructions given at
the top of Makefile.in. In short "./configure; make test", and if that goes
-well, "make install" should work for most flavors of Unix. For Windows, use one
-of the special makefiles in win32/ or contrib/vstudio/ . For VMS, use
+well, "make install" should work for most flavors of Unix. For Windows, use
+one of the special makefiles in win32/ or contrib/vstudio/ . For VMS, use
make_vms.com.
Questions about zlib should be sent to <zlib@gzip.org>, or to Gilles Vollant
@@ -31,7 +31,7 @@ Mark Nelson <markn@ieee.org> wrote an article about zlib for the Jan. 1997
issue of Dr. Dobb's Journal; a copy of the article is available at
http://marknelson.us/1997/01/01/zlib-engine/ .
-The changes made in version 1.2.5 are documented in the file ChangeLog.
+The changes made in version 1.2.7 are documented in the file ChangeLog.
Unsupported third party contributions are provided in directory contrib/ .
@@ -44,7 +44,7 @@ http://search.cpan.org/~pmqs/IO-Compress-Zlib/ .
A Python interface to zlib written by A.M. Kuchling <amk@amk.ca> is
available in Python 1.5 and later versions, see
-http://www.python.org/doc/lib/module-zlib.html .
+http://docs.python.org/library/zlib.html .
zlib is built into tcl: http://wiki.tcl.tk/4610 .
@@ -84,7 +84,7 @@ Acknowledgments:
Copyright notice:
- (C) 1995-2010 Jean-loup Gailly and Mark Adler
+ (C) 1995-2012 Jean-loup Gailly and Mark Adler
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
diff --git a/lib/libz/Symbol.map b/lib/libz/Symbol.map
index 2651efc..c9eef6f 100644
--- a/lib/libz/Symbol.map
+++ b/lib/libz/Symbol.map
@@ -1,7 +1,14 @@
/*
- * $FreeBSD$
+ * $FreeBSD: head/lib/libz/Symbol.map 206709 2010-04-16 20:07:24Z delphij $
*/
+ZLIB_1.2.7.0 {
+ deflatePending;
+ deflateResetKeep;
+ gzgetc_;
+ inflateResetKeep;
+};
+
ZLIB_1.2.4.0 {
adler32;
adler32_combine;
diff --git a/lib/libz/Versions.def b/lib/libz/Versions.def
index fe413a4..a5aeb28 100644
--- a/lib/libz/Versions.def
+++ b/lib/libz/Versions.def
@@ -1,8 +1,11 @@
-# $FreeBSD$
+# $FreeBSD: head/lib/libz/Versions.def 205486 2010-03-22 22:12:27Z delphij $
ZLIB_1.2.4.0 {
};
+ZLIB_1.2.7.0 {
+} ZLIB_1.2.4.0;
+
FBSD_1.2 {
} ZLIB_1.2.4.0;
diff --git a/lib/libz/adler32.c b/lib/libz/adler32.c
index 65ad6a5..a868f07 100644
--- a/lib/libz/adler32.c
+++ b/lib/libz/adler32.c
@@ -1,5 +1,5 @@
/* adler32.c -- compute the Adler-32 checksum of a data stream
- * Copyright (C) 1995-2007 Mark Adler
+ * Copyright (C) 1995-2011 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@@ -9,9 +9,9 @@
#define local static
-local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2);
+local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2));
-#define BASE 65521UL /* largest prime smaller than 65536 */
+#define BASE 65521 /* largest prime smaller than 65536 */
#define NMAX 5552
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
@@ -21,39 +21,44 @@ local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2);
#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
#define DO16(buf) DO8(buf,0); DO8(buf,8);
-/* use NO_DIVIDE if your processor does not do division in hardware */
+/* use NO_DIVIDE if your processor does not do division in hardware --
+ try it both ways to see which is faster */
#ifdef NO_DIVIDE
-# define MOD(a) \
+/* note that this assumes BASE is 65521, where 65536 % 65521 == 15
+ (thank you to John Reiser for pointing this out) */
+# define CHOP(a) \
+ do { \
+ unsigned long tmp = a >> 16; \
+ a &= 0xffffUL; \
+ a += (tmp << 4) - tmp; \
+ } while (0)
+# define MOD28(a) \
do { \
- if (a >= (BASE << 16)) a -= (BASE << 16); \
- if (a >= (BASE << 15)) a -= (BASE << 15); \
- if (a >= (BASE << 14)) a -= (BASE << 14); \
- if (a >= (BASE << 13)) a -= (BASE << 13); \
- if (a >= (BASE << 12)) a -= (BASE << 12); \
- if (a >= (BASE << 11)) a -= (BASE << 11); \
- if (a >= (BASE << 10)) a -= (BASE << 10); \
- if (a >= (BASE << 9)) a -= (BASE << 9); \
- if (a >= (BASE << 8)) a -= (BASE << 8); \
- if (a >= (BASE << 7)) a -= (BASE << 7); \
- if (a >= (BASE << 6)) a -= (BASE << 6); \
- if (a >= (BASE << 5)) a -= (BASE << 5); \
- if (a >= (BASE << 4)) a -= (BASE << 4); \
- if (a >= (BASE << 3)) a -= (BASE << 3); \
- if (a >= (BASE << 2)) a -= (BASE << 2); \
- if (a >= (BASE << 1)) a -= (BASE << 1); \
+ CHOP(a); \
if (a >= BASE) a -= BASE; \
} while (0)
-# define MOD4(a) \
+# define MOD(a) \
do { \
- if (a >= (BASE << 4)) a -= (BASE << 4); \
- if (a >= (BASE << 3)) a -= (BASE << 3); \
- if (a >= (BASE << 2)) a -= (BASE << 2); \
- if (a >= (BASE << 1)) a -= (BASE << 1); \
+ CHOP(a); \
+ MOD28(a); \
+ } while (0)
+# define MOD63(a) \
+ do { /* this assumes a is not negative */ \
+ z_off64_t tmp = a >> 32; \
+ a &= 0xffffffffL; \
+ a += (tmp << 8) - (tmp << 5) + tmp; \
+ tmp = a >> 16; \
+ a &= 0xffffL; \
+ a += (tmp << 4) - tmp; \
+ tmp = a >> 16; \
+ a &= 0xffffL; \
+ a += (tmp << 4) - tmp; \
if (a >= BASE) a -= BASE; \
} while (0)
#else
# define MOD(a) a %= BASE
-# define MOD4(a) a %= BASE
+# define MOD28(a) a %= BASE
+# define MOD63(a) a %= BASE
#endif
/* ========================================================================= */
@@ -92,7 +97,7 @@ uLong ZEXPORT adler32(adler, buf, len)
}
if (adler >= BASE)
adler -= BASE;
- MOD4(sum2); /* only added so many BASE's */
+ MOD28(sum2); /* only added so many BASE's */
return adler | (sum2 << 16);
}
@@ -137,8 +142,13 @@ local uLong adler32_combine_(adler1, adler2, len2)
unsigned long sum2;
unsigned rem;
+ /* for negative len, return invalid adler32 as a clue for debugging */
+ if (len2 < 0)
+ return 0xffffffffUL;
+
/* the derivation of this formula is left as an exercise for the reader */
- rem = (unsigned)(len2 % BASE);
+ MOD63(len2); /* assumes len2 >= 0 */
+ rem = (unsigned)len2;
sum1 = adler1 & 0xffff;
sum2 = rem * sum1;
MOD(sum2);
diff --git a/lib/libz/contrib/asm686/match.S b/lib/libz/contrib/asm686/match.S
index 06817e1..fa42109 100644
--- a/lib/libz/contrib/asm686/match.S
+++ b/lib/libz/contrib/asm686/match.S
@@ -83,17 +83,25 @@
.text
/* uInt longest_match(deflate_state *deflatestate, IPos curmatch) */
+.cfi_sections .debug_frame
longest_match:
+.cfi_startproc
/* Save registers that the compiler may be using, and adjust %esp to */
/* make room for our stack frame. */
pushl %ebp
+ .cfi_def_cfa_offset 8
+ .cfi_offset ebp, -8
pushl %edi
+ .cfi_def_cfa_offset 12
pushl %esi
+ .cfi_def_cfa_offset 16
pushl %ebx
+ .cfi_def_cfa_offset 20
subl $LocalVarsSize, %esp
+ .cfi_def_cfa_offset LocalVarsSize+20
/* Retrieve the function arguments. %ecx will hold cur_match */
/* throughout the entire function. %edx will hold the pointer to the */
@@ -108,7 +116,7 @@ longest_match:
/* if (s->prev_length >= s->good_match) { */
/* chain_length >>= 2; */
/* } */
-
+
movl dsPrevLen(%edx), %eax
movl dsGoodMatch(%edx), %ebx
cmpl %ebx, %eax
@@ -336,8 +344,14 @@ LookaheadRet:
/* Restore the stack and return from whence we came. */
addl $LocalVarsSize, %esp
+ .cfi_def_cfa_offset 20
popl %ebx
+ .cfi_def_cfa_offset 16
popl %esi
+ .cfi_def_cfa_offset 12
popl %edi
+ .cfi_def_cfa_offset 8
popl %ebp
+ .cfi_def_cfa_offset 4
+.cfi_endproc
match_init: ret
diff --git a/lib/libz/crc32.c b/lib/libz/crc32.c
index 91be372..979a719 100644
--- a/lib/libz/crc32.c
+++ b/lib/libz/crc32.c
@@ -1,5 +1,5 @@
/* crc32.c -- compute the CRC-32 of a data stream
- * Copyright (C) 1995-2006, 2010 Mark Adler
+ * Copyright (C) 1995-2006, 2010, 2011, 2012 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*
* Thanks to Rodney Brown <rbrown64@csc.com.au> for his contribution of faster
@@ -17,6 +17,8 @@
of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should
first call get_crc_table() to initialize the tables before allowing more than
one thread to use crc32().
+
+ DYNAMIC_CRC_TABLE and MAKECRCH can be #defined to write out crc32.h.
*/
#ifdef MAKECRCH
@@ -30,31 +32,11 @@
#define local static
-/* Find a four-byte integer type for crc32_little() and crc32_big(). */
-#ifndef NOBYFOUR
-# ifdef STDC /* need ANSI C limits.h to determine sizes */
-# include <limits.h>
-# define BYFOUR
-# if (UINT_MAX == 0xffffffffUL)
- typedef unsigned int u4;
-# else
-# if (ULONG_MAX == 0xffffffffUL)
- typedef unsigned long u4;
-# else
-# if (USHRT_MAX == 0xffffffffUL)
- typedef unsigned short u4;
-# else
-# undef BYFOUR /* can't find a four-byte integer type! */
-# endif
-# endif
-# endif
-# endif /* STDC */
-#endif /* !NOBYFOUR */
-
/* Definitions for doing the crc four data bytes at a time. */
+#if !defined(NOBYFOUR) && defined(Z_U4)
+# define BYFOUR
+#endif
#ifdef BYFOUR
-# define REV(w) ((((w)>>24)&0xff)+(((w)>>8)&0xff00)+ \
- (((w)&0xff00)<<8)+(((w)&0xff)<<24))
local unsigned long crc32_little OF((unsigned long,
const unsigned char FAR *, unsigned));
local unsigned long crc32_big OF((unsigned long,
@@ -68,16 +50,16 @@
local unsigned long gf2_matrix_times OF((unsigned long *mat,
unsigned long vec));
local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
-local uLong crc32_combine_(uLong crc1, uLong crc2, z_off64_t len2);
+local uLong crc32_combine_ OF((uLong crc1, uLong crc2, z_off64_t len2));
#ifdef DYNAMIC_CRC_TABLE
local volatile int crc_table_empty = 1;
-local unsigned long FAR crc_table[TBLS][256];
+local z_crc_t FAR crc_table[TBLS][256];
local void make_crc_table OF((void));
#ifdef MAKECRCH
- local void write_table OF((FILE *, const unsigned long FAR *));
+ local void write_table OF((FILE *, const z_crc_t FAR *));
#endif /* MAKECRCH */
/*
Generate tables for a byte-wise 32-bit CRC calculation on the polynomial:
@@ -107,9 +89,9 @@ local void make_crc_table OF((void));
*/
local void make_crc_table()
{
- unsigned long c;
+ z_crc_t c;
int n, k;
- unsigned long poly; /* polynomial exclusive-or pattern */
+ z_crc_t poly; /* polynomial exclusive-or pattern */
/* terms of polynomial defining this crc (except x^32): */
static volatile int first = 1; /* flag to limit concurrent making */
static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
@@ -121,13 +103,13 @@ local void make_crc_table()
first = 0;
/* make exclusive-or pattern from polynomial (0xedb88320UL) */
- poly = 0UL;
- for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
- poly |= 1UL << (31 - p[n]);
+ poly = 0;
+ for (n = 0; n < (int)(sizeof(p)/sizeof(unsigned char)); n++)
+ poly |= (z_crc_t)1 << (31 - p[n]);
/* generate a crc for every 8-bit value */
for (n = 0; n < 256; n++) {
- c = (unsigned long)n;
+ c = (z_crc_t)n;
for (k = 0; k < 8; k++)
c = c & 1 ? poly ^ (c >> 1) : c >> 1;
crc_table[0][n] = c;
@@ -138,11 +120,11 @@ local void make_crc_table()
and then the byte reversal of those as well as the first table */
for (n = 0; n < 256; n++) {
c = crc_table[0][n];
- crc_table[4][n] = REV(c);
+ crc_table[4][n] = ZSWAP32(c);
for (k = 1; k < 4; k++) {
c = crc_table[0][c & 0xff] ^ (c >> 8);
crc_table[k][n] = c;
- crc_table[k + 4][n] = REV(c);
+ crc_table[k + 4][n] = ZSWAP32(c);
}
}
#endif /* BYFOUR */
@@ -164,7 +146,7 @@ local void make_crc_table()
if (out == NULL) return;
fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
- fprintf(out, "local const unsigned long FAR ");
+ fprintf(out, "local const z_crc_t FAR ");
fprintf(out, "crc_table[TBLS][256] =\n{\n {\n");
write_table(out, crc_table[0]);
# ifdef BYFOUR
@@ -184,12 +166,13 @@ local void make_crc_table()
#ifdef MAKECRCH
local void write_table(out, table)
FILE *out;
- const unsigned long FAR *table;
+ const z_crc_t FAR *table;
{
int n;
for (n = 0; n < 256; n++)
- fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", table[n],
+ fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ",
+ (unsigned long)(table[n]),
n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
}
#endif /* MAKECRCH */
@@ -204,13 +187,13 @@ local void write_table(out, table)
/* =========================================================================
* This function can be used by asm versions of crc32()
*/
-const unsigned long FAR * ZEXPORT get_crc_table()
+const z_crc_t FAR * ZEXPORT get_crc_table()
{
#ifdef DYNAMIC_CRC_TABLE
if (crc_table_empty)
make_crc_table();
#endif /* DYNAMIC_CRC_TABLE */
- return (const unsigned long FAR *)crc_table;
+ return (const z_crc_t FAR *)crc_table;
}
/* ========================================================================= */
@@ -232,7 +215,7 @@ unsigned long ZEXPORT crc32(crc, buf, len)
#ifdef BYFOUR
if (sizeof(void *) == sizeof(ptrdiff_t)) {
- u4 endian;
+ z_crc_t endian;
endian = 1;
if (*((unsigned char *)(&endian)))
@@ -266,17 +249,17 @@ local unsigned long crc32_little(crc, buf, len)
const unsigned char FAR *buf;
unsigned len;
{
- register u4 c;
- register const u4 FAR *buf4;
+ register z_crc_t c;
+ register const z_crc_t FAR *buf4;
- c = (u4)crc;
+ c = (z_crc_t)crc;
c = ~c;
while (len && ((ptrdiff_t)buf & 3)) {
c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
len--;
}
- buf4 = (const u4 FAR *)(const void FAR *)buf;
+ buf4 = (const z_crc_t FAR *)(const void FAR *)buf;
while (len >= 32) {
DOLIT32;
len -= 32;
@@ -306,17 +289,17 @@ local unsigned long crc32_big(crc, buf, len)
const unsigned char FAR *buf;
unsigned len;
{
- register u4 c;
- register const u4 FAR *buf4;
+ register z_crc_t c;
+ register const z_crc_t FAR *buf4;
- c = REV((u4)crc);
+ c = ZSWAP32((z_crc_t)crc);
c = ~c;
while (len && ((ptrdiff_t)buf & 3)) {
c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
len--;
}
- buf4 = (const u4 FAR *)(const void FAR *)buf;
+ buf4 = (const z_crc_t FAR *)(const void FAR *)buf;
buf4--;
while (len >= 32) {
DOBIG32;
@@ -333,7 +316,7 @@ local unsigned long crc32_big(crc, buf, len)
c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
} while (--len);
c = ~c;
- return (unsigned long)(REV(c));
+ return (unsigned long)(ZSWAP32(c));
}
#endif /* BYFOUR */
diff --git a/lib/libz/crc32.h b/lib/libz/crc32.h
index 8053b61..9e0c778 100644
--- a/lib/libz/crc32.h
+++ b/lib/libz/crc32.h
@@ -2,7 +2,7 @@
* Generated automatically by crc32.c
*/
-local const unsigned long FAR crc_table[TBLS][256] =
+local const z_crc_t FAR crc_table[TBLS][256] =
{
{
0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL,
diff --git a/lib/libz/deflate.c b/lib/libz/deflate.c
index 5c4022f..9e4c2cb 100644
--- a/lib/libz/deflate.c
+++ b/lib/libz/deflate.c
@@ -1,5 +1,5 @@
/* deflate.c -- compress data using the deflation algorithm
- * Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler
+ * Copyright (C) 1995-2012 Jean-loup Gailly and Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@@ -37,7 +37,7 @@
* REFERENCES
*
* Deutsch, L.P.,"DEFLATE Compressed Data Format Specification".
- * Available in http://www.ietf.org/rfc/rfc1951.txt
+ * Available in http://tools.ietf.org/html/rfc1951
*
* A description of the Rabin and Karp algorithm is given in the book
* "Algorithms" by R. Sedgewick, Addison-Wesley, p252.
@@ -52,7 +52,7 @@
#include "deflate.h"
const char deflate_copyright[] =
- " deflate 1.2.5 Copyright 1995-2010 Jean-loup Gailly and Mark Adler ";
+ " deflate 1.2.7 Copyright 1995-2012 Jean-loup Gailly and Mark Adler ";
/*
If you use the zlib library in a product, an acknowledgment is welcome
in the documentation of your product. If for some reason you cannot
@@ -155,6 +155,9 @@ local const config configuration_table[10] = {
struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
#endif
+/* rank Z_BLOCK between Z_NO_FLUSH and Z_PARTIAL_FLUSH */
+#define RANK(f) (((f) << 1) - ((f) > 4 ? 9 : 0))
+
/* ===========================================================================
* Update a hash value with the given input byte
* IN assertion: all calls to to UPDATE_HASH are made with consecutive
@@ -235,10 +238,19 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
strm->msg = Z_NULL;
if (strm->zalloc == (alloc_func)0) {
+#ifdef Z_SOLO
+ return Z_STREAM_ERROR;
+#else
strm->zalloc = zcalloc;
strm->opaque = (voidpf)0;
+#endif
}
- if (strm->zfree == (free_func)0) strm->zfree = zcfree;
+ if (strm->zfree == (free_func)0)
+#ifdef Z_SOLO
+ return Z_STREAM_ERROR;
+#else
+ strm->zfree = zcfree;
+#endif
#ifdef FASTEST
if (level != 0) level = 1;
@@ -314,43 +326,70 @@ int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength)
uInt dictLength;
{
deflate_state *s;
- uInt length = dictLength;
- uInt n;
- IPos hash_head = 0;
+ uInt str, n;
+ int wrap;
+ unsigned avail;
+ unsigned char *next;
- if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL ||
- strm->state->wrap == 2 ||
- (strm->state->wrap == 1 && strm->state->status != INIT_STATE))
+ if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL)
return Z_STREAM_ERROR;
-
s = strm->state;
- if (s->wrap)
- strm->adler = adler32(strm->adler, dictionary, dictLength);
+ wrap = s->wrap;
+ if (wrap == 2 || (wrap == 1 && s->status != INIT_STATE) || s->lookahead)
+ return Z_STREAM_ERROR;
- if (length < MIN_MATCH) return Z_OK;
- if (length > s->w_size) {
- length = s->w_size;
- dictionary += dictLength - length; /* use the tail of the dictionary */
+ /* when using zlib wrappers, compute Adler-32 for provided dictionary */
+ if (wrap == 1)
+ strm->adler = adler32(strm->adler, dictionary, dictLength);
+ s->wrap = 0; /* avoid computing Adler-32 in read_buf */
+
+ /* if dictionary would fill window, just replace the history */
+ if (dictLength >= s->w_size) {
+ if (wrap == 0) { /* already empty otherwise */
+ CLEAR_HASH(s);
+ s->strstart = 0;
+ s->block_start = 0L;
+ s->insert = 0;
+ }
+ dictionary += dictLength - s->w_size; /* use the tail */
+ dictLength = s->w_size;
}
- zmemcpy(s->window, dictionary, length);
- s->strstart = length;
- s->block_start = (long)length;
- /* Insert all strings in the hash table (except for the last two bytes).
- * s->lookahead stays null, so s->ins_h will be recomputed at the next
- * call of fill_window.
- */
- s->ins_h = s->window[0];
- UPDATE_HASH(s, s->ins_h, s->window[1]);
- for (n = 0; n <= length - MIN_MATCH; n++) {
- INSERT_STRING(s, n, hash_head);
+ /* insert dictionary into window and hash */
+ avail = strm->avail_in;
+ next = strm->next_in;
+ strm->avail_in = dictLength;
+ strm->next_in = (Bytef *)dictionary;
+ fill_window(s);
+ while (s->lookahead >= MIN_MATCH) {
+ str = s->strstart;
+ n = s->lookahead - (MIN_MATCH-1);
+ do {
+ UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]);
+#ifndef FASTEST
+ s->prev[str & s->w_mask] = s->head[s->ins_h];
+#endif
+ s->head[s->ins_h] = (Pos)str;
+ str++;
+ } while (--n);
+ s->strstart = str;
+ s->lookahead = MIN_MATCH-1;
+ fill_window(s);
}
- if (hash_head) hash_head = 0; /* to make compiler happy */
+ s->strstart += s->lookahead;
+ s->block_start = (long)s->strstart;
+ s->insert = s->lookahead;
+ s->lookahead = 0;
+ s->match_length = s->prev_length = MIN_MATCH-1;
+ s->match_available = 0;
+ strm->next_in = next;
+ strm->avail_in = avail;
+ s->wrap = wrap;
return Z_OK;
}
/* ========================================================================= */
-int ZEXPORT deflateReset (strm)
+int ZEXPORT deflateResetKeep (strm)
z_streamp strm;
{
deflate_state *s;
@@ -380,12 +419,23 @@ int ZEXPORT deflateReset (strm)
s->last_flush = Z_NO_FLUSH;
_tr_init(s);
- lm_init(s);
return Z_OK;
}
/* ========================================================================= */
+int ZEXPORT deflateReset (strm)
+ z_streamp strm;
+{
+ int ret;
+
+ ret = deflateResetKeep(strm);
+ if (ret == Z_OK)
+ lm_init(strm->state);
+ return ret;
+}
+
+/* ========================================================================= */
int ZEXPORT deflateSetHeader (strm, head)
z_streamp strm;
gz_headerp head;
@@ -397,14 +447,42 @@ int ZEXPORT deflateSetHeader (strm, head)
}
/* ========================================================================= */
+int ZEXPORT deflatePending (strm, pending, bits)
+ unsigned *pending;
+ int *bits;
+ z_streamp strm;
+{
+ if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ if (pending != Z_NULL)
+ *pending = strm->state->pending;
+ if (bits != Z_NULL)
+ *bits = strm->state->bi_valid;
+ return Z_OK;
+}
+
+/* ========================================================================= */
int ZEXPORT deflatePrime (strm, bits, value)
z_streamp strm;
int bits;
int value;
{
+ deflate_state *s;
+ int put;
+
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
- strm->state->bi_valid = bits;
- strm->state->bi_buf = (ush)(value & ((1 << bits) - 1));
+ s = strm->state;
+ if ((Bytef *)(s->d_buf) < s->pending_out + ((Buf_size + 7) >> 3))
+ return Z_BUF_ERROR;
+ do {
+ put = Buf_size - s->bi_valid;
+ if (put > bits)
+ put = bits;
+ s->bi_buf |= (ush)((value & ((1 << put) - 1)) << s->bi_valid);
+ s->bi_valid += put;
+ _tr_flush_bits(s);
+ value >>= put;
+ bits -= put;
+ } while (bits);
return Z_OK;
}
@@ -562,19 +640,22 @@ local void putShortMSB (s, b)
local void flush_pending(strm)
z_streamp strm;
{
- unsigned len = strm->state->pending;
+ unsigned len;
+ deflate_state *s = strm->state;
+ _tr_flush_bits(s);
+ len = s->pending;
if (len > strm->avail_out) len = strm->avail_out;
if (len == 0) return;
- zmemcpy(strm->next_out, strm->state->pending_out, len);
+ zmemcpy(strm->next_out, s->pending_out, len);
strm->next_out += len;
- strm->state->pending_out += len;
+ s->pending_out += len;
strm->total_out += len;
strm->avail_out -= len;
- strm->state->pending -= len;
- if (strm->state->pending == 0) {
- strm->state->pending_out = strm->state->pending_buf;
+ s->pending -= len;
+ if (s->pending == 0) {
+ s->pending_out = s->pending_buf;
}
}
@@ -801,7 +882,7 @@ int ZEXPORT deflate (strm, flush)
* flushes. For repeated and useless calls with Z_FINISH, we keep
* returning Z_STREAM_END instead of Z_BUF_ERROR.
*/
- } else if (strm->avail_in == 0 && flush <= old_flush &&
+ } else if (strm->avail_in == 0 && RANK(flush) <= RANK(old_flush) &&
flush != Z_FINISH) {
ERR_RETURN(strm, Z_BUF_ERROR);
}
@@ -850,6 +931,7 @@ int ZEXPORT deflate (strm, flush)
if (s->lookahead == 0) {
s->strstart = 0;
s->block_start = 0L;
+ s->insert = 0;
}
}
}
@@ -945,12 +1027,12 @@ int ZEXPORT deflateCopy (dest, source)
ss = source->state;
- zmemcpy(dest, source, sizeof(z_stream));
+ zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream));
ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
if (ds == Z_NULL) return Z_MEM_ERROR;
dest->state = (struct internal_state FAR *) ds;
- zmemcpy(ds, ss, sizeof(deflate_state));
+ zmemcpy((voidpf)ds, (voidpf)ss, sizeof(deflate_state));
ds->strm = dest;
ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
@@ -966,8 +1048,8 @@ int ZEXPORT deflateCopy (dest, source)
}
/* following zmemcpy do not work for 16-bit MSDOS */
zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
- zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos));
- zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos));
+ zmemcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size * sizeof(Pos));
+ zmemcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size * sizeof(Pos));
zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
@@ -1001,15 +1083,15 @@ local int read_buf(strm, buf, size)
strm->avail_in -= len;
+ zmemcpy(buf, strm->next_in, len);
if (strm->state->wrap == 1) {
- strm->adler = adler32(strm->adler, strm->next_in, len);
+ strm->adler = adler32(strm->adler, buf, len);
}
#ifdef GZIP
else if (strm->state->wrap == 2) {
- strm->adler = crc32(strm->adler, strm->next_in, len);
+ strm->adler = crc32(strm->adler, buf, len);
}
#endif
- zmemcpy(buf, strm->next_in, len);
strm->next_in += len;
strm->total_in += len;
@@ -1036,6 +1118,7 @@ local void lm_init (s)
s->strstart = 0;
s->block_start = 0L;
s->lookahead = 0;
+ s->insert = 0;
s->match_length = s->prev_length = MIN_MATCH-1;
s->match_available = 0;
s->ins_h = 0;
@@ -1310,6 +1393,8 @@ local void fill_window(s)
unsigned more; /* Amount of free space at the end of the window. */
uInt wsize = s->w_size;
+ Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead");
+
do {
more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
@@ -1362,7 +1447,7 @@ local void fill_window(s)
#endif
more += wsize;
}
- if (s->strm->avail_in == 0) return;
+ if (s->strm->avail_in == 0) break;
/* If there was no sliding:
* strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
@@ -1381,12 +1466,24 @@ local void fill_window(s)
s->lookahead += n;
/* Initialize the hash value now that we have some input: */
- if (s->lookahead >= MIN_MATCH) {
- s->ins_h = s->window[s->strstart];
- UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
+ if (s->lookahead + s->insert >= MIN_MATCH) {
+ uInt str = s->strstart - s->insert;
+ s->ins_h = s->window[str];
+ UPDATE_HASH(s, s->ins_h, s->window[str + 1]);
#if MIN_MATCH != 3
Call UPDATE_HASH() MIN_MATCH-3 more times
#endif
+ while (s->insert) {
+ UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]);
+#ifndef FASTEST
+ s->prev[str & s->w_mask] = s->head[s->ins_h];
+#endif
+ s->head[s->ins_h] = (Pos)str;
+ str++;
+ s->insert--;
+ if (s->lookahead + s->insert < MIN_MATCH)
+ break;
+ }
}
/* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
* but this is not important since only literal bytes will be emitted.
@@ -1427,6 +1524,9 @@ local void fill_window(s)
s->high_water += init;
}
}
+
+ Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD,
+ "not enough room for search");
}
/* ===========================================================================
@@ -1506,8 +1606,14 @@ local block_state deflate_stored(s, flush)
FLUSH_BLOCK(s, 0);
}
}
- FLUSH_BLOCK(s, flush == Z_FINISH);
- return flush == Z_FINISH ? finish_done : block_done;
+ s->insert = 0;
+ if (flush == Z_FINISH) {
+ FLUSH_BLOCK(s, 1);
+ return finish_done;
+ }
+ if ((long)s->strstart > s->block_start)
+ FLUSH_BLOCK(s, 0);
+ return block_done;
}
/* ===========================================================================
@@ -1603,8 +1709,14 @@ local block_state deflate_fast(s, flush)
}
if (bflush) FLUSH_BLOCK(s, 0);
}
- FLUSH_BLOCK(s, flush == Z_FINISH);
- return flush == Z_FINISH ? finish_done : block_done;
+ s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1;
+ if (flush == Z_FINISH) {
+ FLUSH_BLOCK(s, 1);
+ return finish_done;
+ }
+ if (s->last_lit)
+ FLUSH_BLOCK(s, 0);
+ return block_done;
}
#ifndef FASTEST
@@ -1728,8 +1840,14 @@ local block_state deflate_slow(s, flush)
_tr_tally_lit(s, s->window[s->strstart-1], bflush);
s->match_available = 0;
}
- FLUSH_BLOCK(s, flush == Z_FINISH);
- return flush == Z_FINISH ? finish_done : block_done;
+ s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1;
+ if (flush == Z_FINISH) {
+ FLUSH_BLOCK(s, 1);
+ return finish_done;
+ }
+ if (s->last_lit)
+ FLUSH_BLOCK(s, 0);
+ return block_done;
}
#endif /* FASTEST */
@@ -1749,11 +1867,11 @@ local block_state deflate_rle(s, flush)
for (;;) {
/* Make sure that we always have enough lookahead, except
* at the end of the input file. We need MAX_MATCH bytes
- * for the longest encodable run.
+ * for the longest run, plus one for the unrolled loop.
*/
- if (s->lookahead < MAX_MATCH) {
+ if (s->lookahead <= MAX_MATCH) {
fill_window(s);
- if (s->lookahead < MAX_MATCH && flush == Z_NO_FLUSH) {
+ if (s->lookahead <= MAX_MATCH && flush == Z_NO_FLUSH) {
return need_more;
}
if (s->lookahead == 0) break; /* flush the current block */
@@ -1776,6 +1894,7 @@ local block_state deflate_rle(s, flush)
if (s->match_length > s->lookahead)
s->match_length = s->lookahead;
}
+ Assert(scan <= s->window+(uInt)(s->window_size-1), "wild scan");
}
/* Emit match if have run of MIN_MATCH or longer, else emit literal */
@@ -1796,8 +1915,14 @@ local block_state deflate_rle(s, flush)
}
if (bflush) FLUSH_BLOCK(s, 0);
}
- FLUSH_BLOCK(s, flush == Z_FINISH);
- return flush == Z_FINISH ? finish_done : block_done;
+ s->insert = 0;
+ if (flush == Z_FINISH) {
+ FLUSH_BLOCK(s, 1);
+ return finish_done;
+ }
+ if (s->last_lit)
+ FLUSH_BLOCK(s, 0);
+ return block_done;
}
/* ===========================================================================
@@ -1829,6 +1954,12 @@ local block_state deflate_huff(s, flush)
s->strstart++;
if (bflush) FLUSH_BLOCK(s, 0);
}
- FLUSH_BLOCK(s, flush == Z_FINISH);
- return flush == Z_FINISH ? finish_done : block_done;
+ s->insert = 0;
+ if (flush == Z_FINISH) {
+ FLUSH_BLOCK(s, 1);
+ return finish_done;
+ }
+ if (s->last_lit)
+ FLUSH_BLOCK(s, 0);
+ return block_done;
}
diff --git a/lib/libz/deflate.h b/lib/libz/deflate.h
index cbf0d1e..fbac44d 100644
--- a/lib/libz/deflate.h
+++ b/lib/libz/deflate.h
@@ -1,5 +1,5 @@
/* deflate.h -- internal compression state
- * Copyright (C) 1995-2010 Jean-loup Gailly
+ * Copyright (C) 1995-2012 Jean-loup Gailly
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@@ -48,6 +48,9 @@
#define MAX_BITS 15
/* All codes must not exceed MAX_BITS bits */
+#define Buf_size 16
+/* size of bit buffer in bi_buf */
+
#define INIT_STATE 42
#define EXTRA_STATE 69
#define NAME_STATE 73
@@ -188,7 +191,7 @@ typedef struct internal_state {
int nice_match; /* Stop searching when current match exceeds this */
/* used by trees.c: */
- /* Didn't use ct_data typedef below to supress compiler warning */
+ /* Didn't use ct_data typedef below to suppress compiler warning */
struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
@@ -244,7 +247,7 @@ typedef struct internal_state {
ulg opt_len; /* bit length of current block with optimal trees */
ulg static_len; /* bit length of current block with static trees */
uInt matches; /* number of string matches in current block */
- int last_eob_len; /* bit length of EOB code for last block */
+ uInt insert; /* bytes at end of window left to insert */
#ifdef DEBUG
ulg compressed_len; /* total bit length of compressed file mod 2^32 */
@@ -294,6 +297,7 @@ void ZLIB_INTERNAL _tr_init OF((deflate_state *s));
int ZLIB_INTERNAL _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
void ZLIB_INTERNAL _tr_flush_block OF((deflate_state *s, charf *buf,
ulg stored_len, int last));
+void ZLIB_INTERNAL _tr_flush_bits OF((deflate_state *s));
void ZLIB_INTERNAL _tr_align OF((deflate_state *s));
void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf,
ulg stored_len, int last));
diff --git a/lib/libz/doc/algorithm.txt b/lib/libz/doc/algorithm.txt
index 34960bd..c97f495 100644
--- a/lib/libz/doc/algorithm.txt
+++ b/lib/libz/doc/algorithm.txt
@@ -206,4 +206,4 @@ Compression,'' IEEE Transactions on Information Theory, Vol. 23, No. 3,
pp. 337-343.
``DEFLATE Compressed Data Format Specification'' available in
-http://www.ietf.org/rfc/rfc1951.txt
+http://tools.ietf.org/html/rfc1951
diff --git a/lib/libz/gzguts.h b/lib/libz/gzguts.h
index 0f8fb79..ee3f281 100644
--- a/lib/libz/gzguts.h
+++ b/lib/libz/gzguts.h
@@ -1,5 +1,5 @@
/* gzguts.h -- zlib internal header definitions for gz* operations
- * Copyright (C) 2004, 2005, 2010 Mark Adler
+ * Copyright (C) 2004, 2005, 2010, 2011, 2012 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@@ -12,7 +12,7 @@
# endif
#endif
-#if ((__GNUC__-0) * 10 + __GNUC_MINOR__-0 >= 33) && !defined(NO_VIZ)
+#ifdef HAVE_HIDDEN
# define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
#else
# define ZLIB_INTERNAL
@@ -27,13 +27,65 @@
#endif
#include <fcntl.h>
+#ifdef _WIN32
+# include <stddef.h>
+#endif
+
+#if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32)
+# include <io.h>
+#endif
+
#ifdef NO_DEFLATE /* for compatibility with old definition */
# define NO_GZCOMPRESS
#endif
-#ifdef _MSC_VER
-# include <io.h>
-# define vsnprintf _vsnprintf
+#if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
+# ifndef HAVE_VSNPRINTF
+# define HAVE_VSNPRINTF
+# endif
+#endif
+
+#if defined(__CYGWIN__)
+# ifndef HAVE_VSNPRINTF
+# define HAVE_VSNPRINTF
+# endif
+#endif
+
+#if defined(MSDOS) && defined(__BORLANDC__) && (BORLANDC > 0x410)
+# ifndef HAVE_VSNPRINTF
+# define HAVE_VSNPRINTF
+# endif
+#endif
+
+#ifndef HAVE_VSNPRINTF
+# ifdef MSDOS
+/* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
+ but for now we just assume it doesn't. */
+# define NO_vsnprintf
+# endif
+# ifdef __TURBOC__
+# define NO_vsnprintf
+# endif
+# ifdef WIN32
+/* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
+# if !defined(vsnprintf) && !defined(NO_vsnprintf)
+# if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 )
+# define vsnprintf _vsnprintf
+# endif
+# endif
+# endif
+# ifdef __SASC
+# define NO_vsnprintf
+# endif
+# ifdef VMS
+# define NO_vsnprintf
+# endif
+# ifdef __OS400__
+# define NO_vsnprintf
+# endif
+# ifdef __MVS__
+# define NO_vsnprintf
+# endif
#endif
#ifndef local
@@ -52,7 +104,7 @@
# include <windows.h>
# define zstrerror() gz_strwinerror((DWORD)GetLastError())
#else
-# ifdef STDC
+# ifndef NO_STRERROR
# include <errno.h>
# define zstrerror() strerror(errno)
# else
@@ -68,6 +120,13 @@
ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile));
#endif
+/* default memLevel */
+#if MAX_MEM_LEVEL >= 8
+# define DEF_MEM_LEVEL 8
+#else
+# define DEF_MEM_LEVEL MAX_MEM_LEVEL
+#endif
+
/* default i/o buffer size -- double this for output when reading */
#define GZBUFSIZE 8192
@@ -84,23 +143,25 @@
/* internal gzip file state data structure */
typedef struct {
+ /* exposed contents for gzgetc() macro */
+ struct gzFile_s x; /* "x" for exposed */
+ /* x.have: number of bytes available at x.next */
+ /* x.next: next output data to deliver or write */
+ /* x.pos: current position in uncompressed data */
/* used for both reading and writing */
int mode; /* see gzip modes above */
int fd; /* file descriptor */
char *path; /* path or fd for error messages */
- z_off64_t pos; /* current position in uncompressed data */
unsigned size; /* buffer size, zero if not allocated yet */
unsigned want; /* requested buffer size, default is GZBUFSIZE */
unsigned char *in; /* input buffer */
unsigned char *out; /* output buffer (double-sized when reading) */
- unsigned char *next; /* next output data to deliver or write */
+ int direct; /* 0 if processing gzip, 1 if transparent */
/* just for reading */
- unsigned have; /* amount of output data unused at next */
- int eof; /* true if end of input file reached */
- z_off64_t start; /* where the gzip data started, for rewinding */
- z_off64_t raw; /* where the raw data started, for seeking */
int how; /* 0: get header, 1: copy, 2: decompress */
- int direct; /* true if last read direct, false if gzip */
+ z_off64_t start; /* where the gzip data started, for rewinding */
+ int eof; /* true if end of input file reached */
+ int past; /* true if read requested past end */
/* just for writing */
int level; /* compression level */
int strategy; /* compression strategy */
diff --git a/lib/libz/gzlib.c b/lib/libz/gzlib.c
index 999455d..33a8a5c 100644
--- a/lib/libz/gzlib.c
+++ b/lib/libz/gzlib.c
@@ -1,5 +1,5 @@
/* gzlib.c -- zlib functions common to reading and writing gzip files
- * Copyright (C) 2004, 2010 Mark Adler
+ * Copyright (C) 2004, 2010, 2011, 2012 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@@ -8,15 +8,19 @@
#include "gzguts.h"
#include "zutil.h"
+#if defined(_WIN32) && !defined(__BORLANDC__)
+# define LSEEK _lseeki64
+#else
#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
# define LSEEK lseek64
#else
# define LSEEK lseek
#endif
+#endif
/* Local functions */
local void gz_reset OF((gz_statep));
-local gzFile gz_open OF((const char *, int, const char *));
+local gzFile gz_open OF((const void *, int, const char *));
#if defined UNDER_CE
@@ -74,25 +78,37 @@ char ZLIB_INTERNAL *gz_strwinerror (error)
local void gz_reset(state)
gz_statep state;
{
+ state->x.have = 0; /* no output data available */
if (state->mode == GZ_READ) { /* for reading ... */
- state->have = 0; /* no output data available */
state->eof = 0; /* not at end of file */
+ state->past = 0; /* have not read past end yet */
state->how = LOOK; /* look for gzip header */
- state->direct = 1; /* default for empty file */
}
state->seek = 0; /* no seek request pending */
gz_error(state, Z_OK, NULL); /* clear error */
- state->pos = 0; /* no uncompressed data yet */
+ state->x.pos = 0; /* no uncompressed data yet */
state->strm.avail_in = 0; /* no input data yet */
}
/* Open a gzip file either by name or file descriptor. */
local gzFile gz_open(path, fd, mode)
- const char *path;
+ const void *path;
int fd;
const char *mode;
{
gz_statep state;
+ size_t len;
+ int oflag;
+#ifdef O_CLOEXEC
+ int cloexec = 0;
+#endif
+#ifdef O_EXCL
+ int exclusive = 0;
+#endif
+
+ /* check input */
+ if (path == NULL)
+ return NULL;
/* allocate gzFile structure to return */
state = malloc(sizeof(gz_state));
@@ -106,6 +122,7 @@ local gzFile gz_open(path, fd, mode)
state->mode = GZ_NONE;
state->level = Z_DEFAULT_COMPRESSION;
state->strategy = Z_DEFAULT_STRATEGY;
+ state->direct = 0;
while (*mode) {
if (*mode >= '0' && *mode <= '9')
state->level = *mode - '0';
@@ -127,6 +144,16 @@ local gzFile gz_open(path, fd, mode)
return NULL;
case 'b': /* ignore -- will request binary anyway */
break;
+#ifdef O_CLOEXEC
+ case 'e':
+ cloexec = 1;
+ break;
+#endif
+#ifdef O_EXCL
+ case 'x':
+ exclusive = 1;
+ break;
+#endif
case 'f':
state->strategy = Z_FILTERED;
break;
@@ -138,6 +165,8 @@ local gzFile gz_open(path, fd, mode)
break;
case 'F':
state->strategy = Z_FIXED;
+ case 'T':
+ state->direct = 1;
default: /* could consider as an error, but just ignore */
;
}
@@ -150,30 +179,67 @@ local gzFile gz_open(path, fd, mode)
return NULL;
}
+ /* can't force transparent read */
+ if (state->mode == GZ_READ) {
+ if (state->direct) {
+ free(state);
+ return NULL;
+ }
+ state->direct = 1; /* for empty file */
+ }
+
/* save the path name for error messages */
- state->path = malloc(strlen(path) + 1);
+#ifdef _WIN32
+ if (fd == -2) {
+ len = wcstombs(NULL, path, 0);
+ if (len == (size_t)-1)
+ len = 0;
+ }
+ else
+#endif
+ len = strlen(path);
+ state->path = malloc(len + 1);
if (state->path == NULL) {
free(state);
return NULL;
}
- strcpy(state->path, path);
+#ifdef _WIN32
+ if (fd == -2)
+ if (len)
+ wcstombs(state->path, path, len + 1);
+ else
+ *(state->path) = 0;
+ else
+#endif
+ strcpy(state->path, path);
- /* open the file with the appropriate mode (or just use fd) */
- state->fd = fd != -1 ? fd :
- open(path,
+ /* compute the flags for open() */
+ oflag =
#ifdef O_LARGEFILE
- O_LARGEFILE |
+ O_LARGEFILE |
#endif
#ifdef O_BINARY
- O_BINARY |
+ O_BINARY |
+#endif
+#ifdef O_CLOEXEC
+ (cloexec ? O_CLOEXEC : 0) |
#endif
- (state->mode == GZ_READ ?
- O_RDONLY :
- (O_WRONLY | O_CREAT | (
- state->mode == GZ_WRITE ?
- O_TRUNC :
- O_APPEND))),
- 0666);
+ (state->mode == GZ_READ ?
+ O_RDONLY :
+ (O_WRONLY | O_CREAT |
+#ifdef O_EXCL
+ (exclusive ? O_EXCL : 0) |
+#endif
+ (state->mode == GZ_WRITE ?
+ O_TRUNC :
+ O_APPEND)));
+
+ /* open the file with the appropriate flags (or just use fd) */
+ state->fd = fd > -1 ? fd : (
+#ifdef _WIN32
+ fd == -2 ? _wopen(path, oflag, 0666) :
+#endif
+ open(path, oflag, 0666));
if (state->fd == -1) {
free(state->path);
free(state);
@@ -228,6 +294,16 @@ gzFile ZEXPORT gzdopen(fd, mode)
}
/* -- see zlib.h -- */
+#ifdef _WIN32
+gzFile ZEXPORT gzopen_w(path, mode)
+ const wchar_t *path;
+ const char *mode;
+{
+ return gz_open(path, -2, mode);
+}
+#endif
+
+/* -- see zlib.h -- */
int ZEXPORT gzbuffer(file, size)
gzFile file;
unsigned size;
@@ -246,8 +322,8 @@ int ZEXPORT gzbuffer(file, size)
return -1;
/* check and set requested size */
- if (size == 0)
- return -1;
+ if (size < 2)
+ size = 2; /* need two bytes to check magic header */
state->want = size;
return 0;
}
@@ -264,7 +340,8 @@ int ZEXPORT gzrewind(file)
state = (gz_statep)file;
/* check that we're reading and that there's no error */
- if (state->mode != GZ_READ || state->err != Z_OK)
+ if (state->mode != GZ_READ ||
+ (state->err != Z_OK && state->err != Z_BUF_ERROR))
return -1;
/* back up and start over */
@@ -292,7 +369,7 @@ z_off64_t ZEXPORT gzseek64(file, offset, whence)
return -1;
/* check that there's no error */
- if (state->err != Z_OK)
+ if (state->err != Z_OK && state->err != Z_BUF_ERROR)
return -1;
/* can only seek from start or relative to current position */
@@ -301,31 +378,32 @@ z_off64_t ZEXPORT gzseek64(file, offset, whence)
/* normalize offset to a SEEK_CUR specification */
if (whence == SEEK_SET)
- offset -= state->pos;
+ offset -= state->x.pos;
else if (state->seek)
offset += state->skip;
state->seek = 0;
/* if within raw area while reading, just go there */
if (state->mode == GZ_READ && state->how == COPY &&
- state->pos + offset >= state->raw) {
- ret = LSEEK(state->fd, offset - state->have, SEEK_CUR);
+ state->x.pos + offset >= 0) {
+ ret = LSEEK(state->fd, offset - state->x.have, SEEK_CUR);
if (ret == -1)
return -1;
- state->have = 0;
+ state->x.have = 0;
state->eof = 0;
+ state->past = 0;
state->seek = 0;
gz_error(state, Z_OK, NULL);
state->strm.avail_in = 0;
- state->pos += offset;
- return state->pos;
+ state->x.pos += offset;
+ return state->x.pos;
}
/* calculate skip amount, rewinding if needed for back seek when reading */
if (offset < 0) {
if (state->mode != GZ_READ) /* writing -- can't go backwards */
return -1;
- offset += state->pos;
+ offset += state->x.pos;
if (offset < 0) /* before start of file! */
return -1;
if (gzrewind(file) == -1) /* rewind, then skip to offset */
@@ -334,11 +412,11 @@ z_off64_t ZEXPORT gzseek64(file, offset, whence)
/* if reading, skip what's in output buffer (one less gzgetc() check) */
if (state->mode == GZ_READ) {
- n = GT_OFF(state->have) || (z_off64_t)state->have > offset ?
- (unsigned)offset : state->have;
- state->have -= n;
- state->next += n;
- state->pos += n;
+ n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > offset ?
+ (unsigned)offset : state->x.have;
+ state->x.have -= n;
+ state->x.next += n;
+ state->x.pos += n;
offset -= n;
}
@@ -347,7 +425,7 @@ z_off64_t ZEXPORT gzseek64(file, offset, whence)
state->seek = 1;
state->skip = offset;
}
- return state->pos + offset;
+ return state->x.pos + offset;
}
/* -- see zlib.h -- */
@@ -376,7 +454,7 @@ z_off64_t ZEXPORT gztell64(file)
return -1;
/* return position */
- return state->pos + (state->seek ? state->skip : 0);
+ return state->x.pos + (state->seek ? state->skip : 0);
}
/* -- see zlib.h -- */
@@ -436,8 +514,7 @@ int ZEXPORT gzeof(file)
return 0;
/* return end-of-file state */
- return state->mode == GZ_READ ?
- (state->eof && state->strm.avail_in == 0 && state->have == 0) : 0;
+ return state->mode == GZ_READ ? state->past : 0;
}
/* -- see zlib.h -- */
@@ -474,8 +551,10 @@ void ZEXPORT gzclearerr(file)
return;
/* clear error and end-of-file */
- if (state->mode == GZ_READ)
+ if (state->mode == GZ_READ) {
state->eof = 0;
+ state->past = 0;
+ }
gz_error(state, Z_OK, NULL);
}
@@ -497,6 +576,10 @@ void ZLIB_INTERNAL gz_error(state, err, msg)
state->msg = NULL;
}
+ /* if fatal, set state->x.have to 0 so that the gzgetc() macro fails */
+ if (err != Z_OK && err != Z_BUF_ERROR)
+ state->x.have = 0;
+
/* set error code, and if no message, then done */
state->err = err;
if (msg == NULL)
diff --git a/lib/libz/gzread.c b/lib/libz/gzread.c
index 5c37bab..bd21205 100644
--- a/lib/libz/gzread.c
+++ b/lib/libz/gzread.c
@@ -1,5 +1,5 @@
/* gzread.c -- zlib functions for reading gzip files
- * Copyright (C) 2004, 2005, 2010 Mark Adler
+ * Copyright (C) 2004, 2005, 2010, 2011, 2012 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@@ -11,10 +11,9 @@
/* Local functions */
local int gz_load OF((gz_statep, unsigned char *, unsigned, unsigned *));
local int gz_avail OF((gz_statep));
-local int gz_next4 OF((gz_statep, unsigned long *));
-local int gz_head OF((gz_statep));
+local int gz_look OF((gz_statep));
local int gz_decomp OF((gz_statep));
-local int gz_make OF((gz_statep));
+local int gz_fetch OF((gz_statep));
local int gz_skip OF((gz_statep, z_off64_t));
/* Use read() to load a buffer -- return -1 on error, otherwise 0. Read from
@@ -49,67 +48,47 @@ local int gz_load(state, buf, len, have)
error, 0 otherwise. Note that the eof flag is set when the end of the input
file is reached, even though there may be unused data in the buffer. Once
that data has been used, no more attempts will be made to read the file.
- gz_avail() assumes that strm->avail_in == 0. */
+ If strm->avail_in != 0, then the current data is moved to the beginning of
+ the input buffer, and then the remainder of the buffer is loaded with the
+ available data from the input file. */
local int gz_avail(state)
gz_statep state;
{
+ unsigned got;
z_streamp strm = &(state->strm);
- if (state->err != Z_OK)
+ if (state->err != Z_OK && state->err != Z_BUF_ERROR)
return -1;
if (state->eof == 0) {
- if (gz_load(state, state->in, state->size,
- (unsigned *)&(strm->avail_in)) == -1)
+ if (strm->avail_in) { /* copy what's there to the start */
+ unsigned char *p = state->in, *q = strm->next_in;
+ unsigned n = strm->avail_in;
+ do {
+ *p++ = *q++;
+ } while (--n);
+ }
+ if (gz_load(state, state->in + strm->avail_in,
+ state->size - strm->avail_in, &got) == -1)
return -1;
+ strm->avail_in += got;
strm->next_in = state->in;
}
return 0;
}
-/* Get next byte from input, or -1 if end or error. */
-#define NEXT() ((strm->avail_in == 0 && gz_avail(state) == -1) ? -1 : \
- (strm->avail_in == 0 ? -1 : \
- (strm->avail_in--, *(strm->next_in)++)))
-
-/* Get a four-byte little-endian integer and return 0 on success and the value
- in *ret. Otherwise -1 is returned and *ret is not modified. */
-local int gz_next4(state, ret)
- gz_statep state;
- unsigned long *ret;
-{
- int ch;
- unsigned long val;
- z_streamp strm = &(state->strm);
-
- val = NEXT();
- val += (unsigned)NEXT() << 8;
- val += (unsigned long)NEXT() << 16;
- ch = NEXT();
- if (ch == -1)
- return -1;
- val += (unsigned long)ch << 24;
- *ret = val;
- return 0;
-}
-
-/* Look for gzip header, set up for inflate or copy. state->have must be zero.
+/* Look for gzip header, set up for inflate or copy. state->x.have must be 0.
If this is the first time in, allocate required memory. state->how will be
left unchanged if there is no more input data available, will be set to COPY
if there is no gzip header and direct copying will be performed, or it will
- be set to GZIP for decompression, and the gzip header will be skipped so
- that the next available input data is the raw deflate stream. If direct
- copying, then leftover input data from the input buffer will be copied to
- the output buffer. In that case, all further file reads will be directly to
- either the output buffer or a user buffer. If decompressing, the inflate
- state and the check value will be initialized. gz_head() will return 0 on
- success or -1 on failure. Failures may include read errors or gzip header
- errors. */
-local int gz_head(state)
+ be set to GZIP for decompression. If direct copying, then leftover input
+ data from the input buffer will be copied to the output buffer. In that
+ case, all further file reads will be directly to either the output buffer or
+ a user buffer. If decompressing, the inflate state will be initialized.
+ gz_look() will return 0 on success or -1 on failure. */
+local int gz_look(state)
gz_statep state;
{
z_streamp strm = &(state->strm);
- int flags;
- unsigned len;
/* allocate read buffers and inflate memory */
if (state->size == 0) {
@@ -132,7 +111,7 @@ local int gz_head(state)
state->strm.opaque = Z_NULL;
state->strm.avail_in = 0;
state->strm.next_in = Z_NULL;
- if (inflateInit2(&(state->strm), -15) != Z_OK) { /* raw inflate */
+ if (inflateInit2(&(state->strm), 15 + 16) != Z_OK) { /* gunzip */
free(state->out);
free(state->in);
state->size = 0;
@@ -141,83 +120,45 @@ local int gz_head(state)
}
}
- /* get some data in the input buffer */
- if (strm->avail_in == 0) {
+ /* get at least the magic bytes in the input buffer */
+ if (strm->avail_in < 2) {
if (gz_avail(state) == -1)
return -1;
if (strm->avail_in == 0)
return 0;
}
- /* look for the gzip magic header bytes 31 and 139 */
- if (strm->next_in[0] == 31) {
- strm->avail_in--;
- strm->next_in++;
- if (strm->avail_in == 0 && gz_avail(state) == -1)
- return -1;
- if (strm->avail_in && strm->next_in[0] == 139) {
- /* we have a gzip header, woo hoo! */
- strm->avail_in--;
- strm->next_in++;
-
- /* skip rest of header */
- if (NEXT() != 8) { /* compression method */
- gz_error(state, Z_DATA_ERROR, "unknown compression method");
- return -1;
- }
- flags = NEXT();
- if (flags & 0xe0) { /* reserved flag bits */
- gz_error(state, Z_DATA_ERROR, "unknown header flags set");
- return -1;
- }
- NEXT(); /* modification time */
- NEXT();
- NEXT();
- NEXT();
- NEXT(); /* extra flags */
- NEXT(); /* operating system */
- if (flags & 4) { /* extra field */
- len = (unsigned)NEXT();
- len += (unsigned)NEXT() << 8;
- while (len--)
- if (NEXT() < 0)
- break;
- }
- if (flags & 8) /* file name */
- while (NEXT() > 0)
- ;
- if (flags & 16) /* comment */
- while (NEXT() > 0)
- ;
- if (flags & 2) { /* header crc */
- NEXT();
- NEXT();
- }
- /* an unexpected end of file is not checked for here -- it will be
- noticed on the first request for uncompressed data */
-
- /* set up for decompression */
- inflateReset(strm);
- strm->adler = crc32(0L, Z_NULL, 0);
- state->how = GZIP;
- state->direct = 0;
- return 0;
- }
- else {
- /* not a gzip file -- save first byte (31) and fall to raw i/o */
- state->out[0] = 31;
- state->have = 1;
- }
+ /* look for gzip magic bytes -- if there, do gzip decoding (note: there is
+ a logical dilemma here when considering the case of a partially written
+ gzip file, to wit, if a single 31 byte is written, then we cannot tell
+ whether this is a single-byte file, or just a partially written gzip
+ file -- for here we assume that if a gzip file is being written, then
+ the header will be written in a single operation, so that reading a
+ single byte is sufficient indication that it is not a gzip file) */
+ if (strm->avail_in > 1 &&
+ strm->next_in[0] == 31 && strm->next_in[1] == 139) {
+ inflateReset(strm);
+ state->how = GZIP;
+ state->direct = 0;
+ return 0;
+ }
+
+ /* no gzip header -- if we were decoding gzip before, then this is trailing
+ garbage. Ignore the trailing garbage and finish. */
+ if (state->direct == 0) {
+ strm->avail_in = 0;
+ state->eof = 1;
+ state->x.have = 0;
+ return 0;
}
- /* doing raw i/o, save start of raw data for seeking, copy any leftover
- input to output -- this assumes that the output buffer is larger than
- the input buffer, which also assures space for gzungetc() */
- state->raw = state->pos;
- state->next = state->out;
+ /* doing raw i/o, copy any leftover input to output -- this assumes that
+ the output buffer is larger than the input buffer, which also assures
+ space for gzungetc() */
+ state->x.next = state->out;
if (strm->avail_in) {
- memcpy(state->next + state->have, strm->next_in, strm->avail_in);
- state->have += strm->avail_in;
+ memcpy(state->x.next, strm->next_in, strm->avail_in);
+ state->x.have = strm->avail_in;
strm->avail_in = 0;
}
state->how = COPY;
@@ -226,19 +167,15 @@ local int gz_head(state)
}
/* Decompress from input to the provided next_out and avail_out in the state.
- If the end of the compressed data is reached, then verify the gzip trailer
- check value and length (modulo 2^32). state->have and state->next are set
- to point to the just decompressed data, and the crc is updated. If the
- trailer is verified, state->how is reset to LOOK to look for the next gzip
- stream or raw data, once state->have is depleted. Returns 0 on success, -1
- on failure. Failures may include invalid compressed data or a failed gzip
- trailer verification. */
+ On return, state->x.have and state->x.next point to the just decompressed
+ data. If the gzip stream completes, state->how is reset to LOOK to look for
+ the next gzip stream or raw data, once state->x.have is depleted. Returns 0
+ on success, -1 on failure. */
local int gz_decomp(state)
gz_statep state;
{
- int ret;
+ int ret = Z_OK;
unsigned had;
- unsigned long crc, len;
z_streamp strm = &(state->strm);
/* fill output buffer up to end of deflate stream */
@@ -248,15 +185,15 @@ local int gz_decomp(state)
if (strm->avail_in == 0 && gz_avail(state) == -1)
return -1;
if (strm->avail_in == 0) {
- gz_error(state, Z_DATA_ERROR, "unexpected end of file");
- return -1;
+ gz_error(state, Z_BUF_ERROR, "unexpected end of file");
+ break;
}
/* decompress and handle errors */
ret = inflate(strm, Z_NO_FLUSH);
if (ret == Z_STREAM_ERROR || ret == Z_NEED_DICT) {
gz_error(state, Z_STREAM_ERROR,
- "internal error: inflate stream corrupt");
+ "internal error: inflate stream corrupt");
return -1;
}
if (ret == Z_MEM_ERROR) {
@@ -265,67 +202,55 @@ local int gz_decomp(state)
}
if (ret == Z_DATA_ERROR) { /* deflate stream invalid */
gz_error(state, Z_DATA_ERROR,
- strm->msg == NULL ? "compressed data error" : strm->msg);
+ strm->msg == NULL ? "compressed data error" : strm->msg);
return -1;
}
} while (strm->avail_out && ret != Z_STREAM_END);
- /* update available output and crc check value */
- state->have = had - strm->avail_out;
- state->next = strm->next_out - state->have;
- strm->adler = crc32(strm->adler, state->next, state->have);
+ /* update available output */
+ state->x.have = had - strm->avail_out;
+ state->x.next = strm->next_out - state->x.have;
- /* check gzip trailer if at end of deflate stream */
- if (ret == Z_STREAM_END) {
- if (gz_next4(state, &crc) == -1 || gz_next4(state, &len) == -1) {
- gz_error(state, Z_DATA_ERROR, "unexpected end of file");
- return -1;
- }
- if (crc != strm->adler) {
- gz_error(state, Z_DATA_ERROR, "incorrect data check");
- return -1;
- }
- if (len != (strm->total_out & 0xffffffffL)) {
- gz_error(state, Z_DATA_ERROR, "incorrect length check");
- return -1;
- }
- state->how = LOOK; /* ready for next stream, once have is 0 (leave
- state->direct unchanged to remember how) */
- }
+ /* if the gzip stream completed successfully, look for another */
+ if (ret == Z_STREAM_END)
+ state->how = LOOK;
/* good decompression */
return 0;
}
-/* Make data and put in the output buffer. Assumes that state->have == 0.
+/* Fetch data and put it in the output buffer. Assumes state->x.have is 0.
Data is either copied from the input file or decompressed from the input
file depending on state->how. If state->how is LOOK, then a gzip header is
- looked for (and skipped if found) to determine wither to copy or decompress.
- Returns -1 on error, otherwise 0. gz_make() will leave state->have as COPY
- or GZIP unless the end of the input file has been reached and all data has
- been processed. */
-local int gz_make(state)
+ looked for to determine whether to copy or decompress. Returns -1 on error,
+ otherwise 0. gz_fetch() will leave state->how as COPY or GZIP unless the
+ end of the input file has been reached and all data has been processed. */
+local int gz_fetch(state)
gz_statep state;
{
z_streamp strm = &(state->strm);
- if (state->how == LOOK) { /* look for gzip header */
- if (gz_head(state) == -1)
- return -1;
- if (state->have) /* got some data from gz_head() */
+ do {
+ switch(state->how) {
+ case LOOK: /* -> LOOK, COPY (only if never GZIP), or GZIP */
+ if (gz_look(state) == -1)
+ return -1;
+ if (state->how == LOOK)
+ return 0;
+ break;
+ case COPY: /* -> COPY */
+ if (gz_load(state, state->out, state->size << 1, &(state->x.have))
+ == -1)
+ return -1;
+ state->x.next = state->out;
return 0;
- }
- if (state->how == COPY) { /* straight copy */
- if (gz_load(state, state->out, state->size << 1, &(state->have)) == -1)
- return -1;
- state->next = state->out;
- }
- else if (state->how == GZIP) { /* decompress */
- strm->avail_out = state->size << 1;
- strm->next_out = state->out;
- if (gz_decomp(state) == -1)
- return -1;
- }
+ case GZIP: /* -> GZIP or LOOK (if end of gzip stream) */
+ strm->avail_out = state->size << 1;
+ strm->next_out = state->out;
+ if (gz_decomp(state) == -1)
+ return -1;
+ }
+ } while (state->x.have == 0 && (!state->eof || strm->avail_in));
return 0;
}
@@ -339,12 +264,12 @@ local int gz_skip(state, len)
/* skip over len bytes or reach end-of-file, whichever comes first */
while (len)
/* skip over whatever is in output buffer */
- if (state->have) {
- n = GT_OFF(state->have) || (z_off64_t)state->have > len ?
- (unsigned)len : state->have;
- state->have -= n;
- state->next += n;
- state->pos += n;
+ if (state->x.have) {
+ n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > len ?
+ (unsigned)len : state->x.have;
+ state->x.have -= n;
+ state->x.next += n;
+ state->x.pos += n;
len -= n;
}
@@ -355,7 +280,7 @@ local int gz_skip(state, len)
/* need more data to skip -- load up output buffer */
else {
/* get more output, looking for header if required */
- if (gz_make(state) == -1)
+ if (gz_fetch(state) == -1)
return -1;
}
return 0;
@@ -377,14 +302,15 @@ int ZEXPORT gzread(file, buf, len)
state = (gz_statep)file;
strm = &(state->strm);
- /* check that we're reading and that there's no error */
- if (state->mode != GZ_READ || state->err != Z_OK)
+ /* check that we're reading and that there's no (serious) error */
+ if (state->mode != GZ_READ ||
+ (state->err != Z_OK && state->err != Z_BUF_ERROR))
return -1;
/* since an int is returned, make sure len fits in one, otherwise return
with an error (this avoids the flaw in the interface) */
if ((int)len < 0) {
- gz_error(state, Z_BUF_ERROR, "requested length does not fit in int");
+ gz_error(state, Z_DATA_ERROR, "requested length does not fit in int");
return -1;
}
@@ -403,24 +329,26 @@ int ZEXPORT gzread(file, buf, len)
got = 0;
do {
/* first just try copying data from the output buffer */
- if (state->have) {
- n = state->have > len ? len : state->have;
- memcpy(buf, state->next, n);
- state->next += n;
- state->have -= n;
+ if (state->x.have) {
+ n = state->x.have > len ? len : state->x.have;
+ memcpy(buf, state->x.next, n);
+ state->x.next += n;
+ state->x.have -= n;
}
/* output buffer empty -- return if we're at the end of the input */
- else if (state->eof && strm->avail_in == 0)
+ else if (state->eof && strm->avail_in == 0) {
+ state->past = 1; /* tried to read past end */
break;
+ }
/* need output data -- for small len or new stream load up our output
buffer */
else if (state->how == LOOK || len < (state->size << 1)) {
/* get more output, looking for header if required */
- if (gz_make(state) == -1)
+ if (gz_fetch(state) == -1)
return -1;
- continue; /* no progress yet -- go back to memcpy() above */
+ continue; /* no progress yet -- go back to copy above */
/* the copy above assures that we will leave with space in the
output buffer, allowing at least one gzungetc() to succeed */
}
@@ -437,15 +365,15 @@ int ZEXPORT gzread(file, buf, len)
strm->next_out = buf;
if (gz_decomp(state) == -1)
return -1;
- n = state->have;
- state->have = 0;
+ n = state->x.have;
+ state->x.have = 0;
}
/* update progress */
len -= n;
buf = (char *)buf + n;
got += n;
- state->pos += n;
+ state->x.pos += n;
} while (len);
/* return number of bytes read into user buffer (will fit in int) */
@@ -453,6 +381,7 @@ int ZEXPORT gzread(file, buf, len)
}
/* -- see zlib.h -- */
+#undef gzgetc
int ZEXPORT gzgetc(file)
gzFile file;
{
@@ -465,15 +394,16 @@ int ZEXPORT gzgetc(file)
return -1;
state = (gz_statep)file;
- /* check that we're reading and that there's no error */
- if (state->mode != GZ_READ || state->err != Z_OK)
+ /* check that we're reading and that there's no (serious) error */
+ if (state->mode != GZ_READ ||
+ (state->err != Z_OK && state->err != Z_BUF_ERROR))
return -1;
/* try output buffer (no need to check for skip request) */
- if (state->have) {
- state->have--;
- state->pos++;
- return *(state->next)++;
+ if (state->x.have) {
+ state->x.have--;
+ state->x.pos++;
+ return *(state->x.next)++;
}
/* nothing there -- try gzread() */
@@ -481,6 +411,12 @@ int ZEXPORT gzgetc(file)
return ret < 1 ? -1 : buf[0];
}
+int ZEXPORT gzgetc_(file)
+gzFile file;
+{
+ return gzgetc(file);
+}
+
/* -- see zlib.h -- */
int ZEXPORT gzungetc(c, file)
int c;
@@ -493,8 +429,9 @@ int ZEXPORT gzungetc(c, file)
return -1;
state = (gz_statep)file;
- /* check that we're reading and that there's no error */
- if (state->mode != GZ_READ || state->err != Z_OK)
+ /* check that we're reading and that there's no (serious) error */
+ if (state->mode != GZ_READ ||
+ (state->err != Z_OK && state->err != Z_BUF_ERROR))
return -1;
/* process a skip request */
@@ -509,32 +446,34 @@ int ZEXPORT gzungetc(c, file)
return -1;
/* if output buffer empty, put byte at end (allows more pushing) */
- if (state->have == 0) {
- state->have = 1;
- state->next = state->out + (state->size << 1) - 1;
- state->next[0] = c;
- state->pos--;
+ if (state->x.have == 0) {
+ state->x.have = 1;
+ state->x.next = state->out + (state->size << 1) - 1;
+ state->x.next[0] = c;
+ state->x.pos--;
+ state->past = 0;
return c;
}
/* if no room, give up (must have already done a gzungetc()) */
- if (state->have == (state->size << 1)) {
- gz_error(state, Z_BUF_ERROR, "out of room to push characters");
+ if (state->x.have == (state->size << 1)) {
+ gz_error(state, Z_DATA_ERROR, "out of room to push characters");
return -1;
}
/* slide output data if needed and insert byte before existing data */
- if (state->next == state->out) {
- unsigned char *src = state->out + state->have;
+ if (state->x.next == state->out) {
+ unsigned char *src = state->out + state->x.have;
unsigned char *dest = state->out + (state->size << 1);
while (src > state->out)
*--dest = *--src;
- state->next = dest;
+ state->x.next = dest;
}
- state->have++;
- state->next--;
- state->next[0] = c;
- state->pos--;
+ state->x.have++;
+ state->x.next--;
+ state->x.next[0] = c;
+ state->x.pos--;
+ state->past = 0;
return c;
}
@@ -554,8 +493,9 @@ char * ZEXPORT gzgets(file, buf, len)
return NULL;
state = (gz_statep)file;
- /* check that we're reading and that there's no error */
- if (state->mode != GZ_READ || state->err != Z_OK)
+ /* check that we're reading and that there's no (serious) error */
+ if (state->mode != GZ_READ ||
+ (state->err != Z_OK && state->err != Z_BUF_ERROR))
return NULL;
/* process a skip request */
@@ -572,32 +512,31 @@ char * ZEXPORT gzgets(file, buf, len)
left = (unsigned)len - 1;
if (left) do {
/* assure that something is in the output buffer */
- if (state->have == 0) {
- if (gz_make(state) == -1)
- return NULL; /* error */
- if (state->have == 0) { /* end of file */
- if (buf == str) /* got bupkus */
- return NULL;
- break; /* got something -- return it */
- }
+ if (state->x.have == 0 && gz_fetch(state) == -1)
+ return NULL; /* error */
+ if (state->x.have == 0) { /* end of file */
+ state->past = 1; /* read past end */
+ break; /* return what we have */
}
/* look for end-of-line in current output buffer */
- n = state->have > left ? left : state->have;
- eol = memchr(state->next, '\n', n);
+ n = state->x.have > left ? left : state->x.have;
+ eol = memchr(state->x.next, '\n', n);
if (eol != NULL)
- n = (unsigned)(eol - state->next) + 1;
+ n = (unsigned)(eol - state->x.next) + 1;
/* copy through end-of-line, or remainder if not found */
- memcpy(buf, state->next, n);
- state->have -= n;
- state->next += n;
- state->pos += n;
+ memcpy(buf, state->x.next, n);
+ state->x.have -= n;
+ state->x.next += n;
+ state->x.pos += n;
left -= n;
buf += n;
} while (left && eol == NULL);
- /* found end-of-line or out of space -- terminate string and return it */
+ /* return terminated string, or if nothing, end of file */
+ if (buf == str)
+ return NULL;
buf[0] = 0;
return str;
}
@@ -613,16 +552,12 @@ int ZEXPORT gzdirect(file)
return 0;
state = (gz_statep)file;
- /* check that we're reading */
- if (state->mode != GZ_READ)
- return 0;
-
/* if the state is not known, but we can find out, then do so (this is
mainly for right after a gzopen() or gzdopen()) */
- if (state->how == LOOK && state->have == 0)
- (void)gz_head(state);
+ if (state->mode == GZ_READ && state->how == LOOK && state->x.have == 0)
+ (void)gz_look(state);
- /* return 1 if reading direct, 0 if decompressing a gzip stream */
+ /* return 1 if transparent, 0 if processing a gzip stream */
return state->direct;
}
@@ -630,7 +565,7 @@ int ZEXPORT gzdirect(file)
int ZEXPORT gzclose_r(file)
gzFile file;
{
- int ret;
+ int ret, err;
gz_statep state;
/* get internal structure */
@@ -648,9 +583,10 @@ int ZEXPORT gzclose_r(file)
free(state->out);
free(state->in);
}
+ err = state->err == Z_BUF_ERROR ? Z_BUF_ERROR : Z_OK;
gz_error(state, Z_OK, NULL);
free(state->path);
ret = close(state->fd);
free(state);
- return ret ? Z_ERRNO : Z_OK;
+ return ret ? Z_ERRNO : err;
}
diff --git a/lib/libz/gzwrite.c b/lib/libz/gzwrite.c
index 0f14731..20344a2 100644
--- a/lib/libz/gzwrite.c
+++ b/lib/libz/gzwrite.c
@@ -1,8 +1,10 @@
/* gzwrite.c -- zlib functions for writing gzip files
- * Copyright (C) 2004, 2005, 2010 Mark Adler
+ * Copyright (C) 2004, 2005, 2010, 2011, 2012 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
+/* $FreeBSD$ */
+
#include "gzguts.h"
#include <unistd.h>
@@ -19,44 +21,55 @@ local int gz_init(state)
int ret;
z_streamp strm = &(state->strm);
- /* allocate input and output buffers */
+ /* allocate input buffer */
state->in = malloc(state->want);
- state->out = malloc(state->want);
- if (state->in == NULL || state->out == NULL) {
- if (state->out != NULL)
- free(state->out);
- if (state->in != NULL)
- free(state->in);
+ if (state->in == NULL) {
gz_error(state, Z_MEM_ERROR, "out of memory");
return -1;
}
- /* allocate deflate memory, set up for gzip compression */
- strm->zalloc = Z_NULL;
- strm->zfree = Z_NULL;
- strm->opaque = Z_NULL;
- ret = deflateInit2(strm, state->level, Z_DEFLATED,
- 15 + 16, 8, state->strategy);
- if (ret != Z_OK) {
- free(state->in);
- gz_error(state, Z_MEM_ERROR, "out of memory");
- return -1;
+ /* only need output buffer and deflate state if compressing */
+ if (!state->direct) {
+ /* allocate output buffer */
+ state->out = malloc(state->want);
+ if (state->out == NULL) {
+ free(state->in);
+ gz_error(state, Z_MEM_ERROR, "out of memory");
+ return -1;
+ }
+
+ /* allocate deflate memory, set up for gzip compression */
+ strm->zalloc = Z_NULL;
+ strm->zfree = Z_NULL;
+ strm->opaque = Z_NULL;
+ ret = deflateInit2(strm, state->level, Z_DEFLATED,
+ MAX_WBITS + 16, DEF_MEM_LEVEL, state->strategy);
+ if (ret != Z_OK) {
+ free(state->out);
+ free(state->in);
+ gz_error(state, Z_MEM_ERROR, "out of memory");
+ return -1;
+ }
}
/* mark state as initialized */
state->size = state->want;
- /* initialize write buffer */
- strm->avail_out = state->size;
- strm->next_out = state->out;
- state->next = strm->next_out;
+ /* initialize write buffer if compressing */
+ if (!state->direct) {
+ strm->avail_out = state->size;
+ strm->next_out = state->out;
+ state->x.next = strm->next_out;
+ }
return 0;
}
/* Compress whatever is at avail_in and next_in and write to the output file.
Return -1 if there is an error writing to the output file, otherwise 0.
flush is assumed to be a valid deflate() flush value. If flush is Z_FINISH,
- then the deflate() state is reset to start a new gzip stream. */
+ then the deflate() state is reset to start a new gzip stream. If gz->direct
+ is true, then simply write to the output file without compressing, and
+ ignore flush. */
local int gz_comp(state, flush)
gz_statep state;
int flush;
@@ -69,6 +82,17 @@ local int gz_comp(state, flush)
if (state->size == 0 && gz_init(state) == -1)
return -1;
+ /* write directly if requested */
+ if (state->direct) {
+ got = write(state->fd, strm->next_in, strm->avail_in);
+ if (got < 0 || (unsigned)got != strm->avail_in) {
+ gz_error(state, Z_ERRNO, zstrerror());
+ return -1;
+ }
+ strm->avail_in = 0;
+ return 0;
+ }
+
/* run deflate() on provided input until it produces no more output */
ret = Z_OK;
do {
@@ -76,8 +100,8 @@ local int gz_comp(state, flush)
doing Z_FINISH then don't write until we get to Z_STREAM_END */
if (strm->avail_out == 0 || (flush != Z_NO_FLUSH &&
(flush != Z_FINISH || ret == Z_STREAM_END))) {
- have = (unsigned)(strm->next_out - state->next);
- if (have && ((got = write(state->fd, state->next, have)) < 0 ||
+ have = (unsigned)(strm->next_out - state->x.next);
+ if (have && ((got = write(state->fd, state->x.next, have)) < 0 ||
(unsigned)got != have)) {
gz_error(state, Z_ERRNO, zstrerror());
return -1;
@@ -86,7 +110,7 @@ local int gz_comp(state, flush)
strm->avail_out = state->size;
strm->next_out = state->out;
}
- state->next = strm->next_out;
+ state->x.next = strm->next_out;
}
/* compress */
@@ -132,7 +156,7 @@ local int gz_zero(state, len)
}
strm->avail_in = n;
strm->next_in = state->in;
- state->pos += n;
+ state->x.pos += n;
if (gz_comp(state, Z_NO_FLUSH) == -1)
return -1;
len -= n;
@@ -164,7 +188,7 @@ int ZEXPORT gzwrite(file, buf, len)
/* since an int is returned, make sure len fits in one, otherwise return
with an error (this avoids the flaw in the interface) */
if ((int)len < 0) {
- gz_error(state, Z_BUF_ERROR, "requested length does not fit in int");
+ gz_error(state, Z_DATA_ERROR, "requested length does not fit in int");
return 0;
}
@@ -194,7 +218,7 @@ int ZEXPORT gzwrite(file, buf, len)
n = len;
memcpy(strm->next_in + strm->avail_in, buf, n);
strm->avail_in += n;
- state->pos += n;
+ state->x.pos += n;
buf = (char *)buf + n;
len -= n;
if (len && gz_comp(state, Z_NO_FLUSH) == -1)
@@ -209,7 +233,7 @@ int ZEXPORT gzwrite(file, buf, len)
/* directly compress user buffer to file */
strm->avail_in = len;
strm->next_in = (voidp)buf;
- state->pos += len;
+ state->x.pos += len;
if (gz_comp(state, Z_NO_FLUSH) == -1)
return 0;
}
@@ -250,15 +274,15 @@ int ZEXPORT gzputc(file, c)
if (strm->avail_in == 0)
strm->next_in = state->in;
strm->next_in[strm->avail_in++] = c;
- state->pos++;
- return c;
+ state->x.pos++;
+ return c & 0xff;
}
/* no room in buffer or not initialized, use gz_write() */
buf[0] = c;
if (gzwrite(file, buf, 1) != 1)
return -1;
- return c;
+ return c & 0xff;
}
/* -- see zlib.h -- */
@@ -275,7 +299,7 @@ int ZEXPORT gzputs(file, str)
return ret == 0 && len != 0 ? -1 : ret;
}
-#ifdef STDC
+#if defined(STDC) || defined(Z_HAVE_STDARG_H)
#include <stdarg.h>
/* -- see zlib.h -- */
@@ -317,19 +341,19 @@ int ZEXPORTVA gzprintf (gzFile file, const char *format, ...)
va_start(va, format);
#ifdef NO_vsnprintf
# ifdef HAS_vsprintf_void
- (void)vsprintf(state->in, format, va);
+ (void)vsprintf((char *)(state->in), format, va);
va_end(va);
for (len = 0; len < size; len++)
if (state->in[len] == 0) break;
# else
- len = vsprintf(state->in, format, va);
+ len = vsprintf((char *)(state->in), format, va);
va_end(va);
# endif
#else
# ifdef HAS_vsnprintf_void
- (void)vsnprintf(state->in, size, format, va);
+ (void)vsnprintf((char *)(state->in), size, format, va);
va_end(va);
- len = strlen(state->in);
+ len = strlen((char *)(state->in));
# else
len = vsnprintf((char *)(state->in), size, format, va);
va_end(va);
@@ -343,11 +367,11 @@ int ZEXPORTVA gzprintf (gzFile file, const char *format, ...)
/* update buffer and position, defer compression until needed */
strm->avail_in = (unsigned)len;
strm->next_in = state->in;
- state->pos += len;
+ state->x.pos += len;
return len;
}
-#else /* !STDC */
+#else /* !STDC && !Z_HAVE_STDARG_H */
/* -- see zlib.h -- */
int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
@@ -367,6 +391,10 @@ int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
state = (gz_statep)file;
strm = &(state->strm);
+ /* check that can really pass pointer in ints */
+ if (sizeof(int) != sizeof(void *))
+ return 0;
+
/* check that we're writing and that there's no error */
if (state->mode != GZ_WRITE || state->err != Z_OK)
return 0;
@@ -391,22 +419,23 @@ int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
state->in[size - 1] = 0;
#ifdef NO_snprintf
# ifdef HAS_sprintf_void
- sprintf(state->in, format, a1, a2, a3, a4, a5, a6, a7, a8,
+ sprintf((char *)(state->in), format, a1, a2, a3, a4, a5, a6, a7, a8,
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
for (len = 0; len < size; len++)
if (state->in[len] == 0) break;
# else
- len = sprintf(state->in, format, a1, a2, a3, a4, a5, a6, a7, a8,
- a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
+ len = sprintf((char *)(state->in), format, a1, a2, a3, a4, a5, a6, a7, a8,
+ a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
# endif
#else
# ifdef HAS_snprintf_void
- snprintf(state->in, size, format, a1, a2, a3, a4, a5, a6, a7, a8,
+ snprintf((char *)(state->in), size, format, a1, a2, a3, a4, a5, a6, a7, a8,
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
- len = strlen(state->in);
+ len = strlen((char *)(state->in));
# else
- len = snprintf(state->in, size, format, a1, a2, a3, a4, a5, a6, a7, a8,
- a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
+ len = snprintf((char *)(state->in), size, format, a1, a2, a3, a4, a5, a6,
+ a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18,
+ a19, a20);
# endif
#endif
@@ -417,7 +446,7 @@ int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
/* update buffer and position, defer compression until needed */
strm->avail_in = (unsigned)len;
strm->next_in = state->in;
- state->pos += len;
+ state->x.pos += len;
return len;
}
@@ -501,7 +530,7 @@ int ZEXPORT gzsetparams(file, level, strategy)
int ZEXPORT gzclose_w(file)
gzFile file;
{
- int ret = 0;
+ int ret = Z_OK;
gz_statep state;
/* get internal structure */
@@ -516,17 +545,24 @@ int ZEXPORT gzclose_w(file)
/* check for seek request */
if (state->seek) {
state->seek = 0;
- ret += gz_zero(state, state->skip);
+ if (gz_zero(state, state->skip) == -1)
+ ret = state->err;
}
/* flush, free memory, and close file */
- ret += gz_comp(state, Z_FINISH);
- (void)deflateEnd(&(state->strm));
- free(state->out);
- free(state->in);
+ if (state->size) {
+ if (gz_comp(state, Z_FINISH) == -1)
+ ret = state->err;
+ if (!state->direct) {
+ (void)deflateEnd(&(state->strm));
+ free(state->out);
+ }
+ free(state->in);
+ }
gz_error(state, Z_OK, NULL);
free(state->path);
- ret += close(state->fd);
+ if (close(state->fd) == -1)
+ ret = Z_ERRNO;
free(state);
- return ret ? Z_ERRNO : Z_OK;
+ return ret;
}
diff --git a/lib/libz/infback.c b/lib/libz/infback.c
index af3a8c9..981aff1 100644
--- a/lib/libz/infback.c
+++ b/lib/libz/infback.c
@@ -1,5 +1,5 @@
/* infback.c -- inflate using a call-back interface
- * Copyright (C) 1995-2009 Mark Adler
+ * Copyright (C) 1995-2011 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@@ -42,10 +42,19 @@ int stream_size;
return Z_STREAM_ERROR;
strm->msg = Z_NULL; /* in case we return an error */
if (strm->zalloc == (alloc_func)0) {
+#ifdef Z_SOLO
+ return Z_STREAM_ERROR;
+#else
strm->zalloc = zcalloc;
strm->opaque = (voidpf)0;
+#endif
}
- if (strm->zfree == (free_func)0) strm->zfree = zcfree;
+ if (strm->zfree == (free_func)0)
+#ifdef Z_SOLO
+ return Z_STREAM_ERROR;
+#else
+ strm->zfree = zcfree;
+#endif
state = (struct inflate_state FAR *)ZALLOC(strm, 1,
sizeof(struct inflate_state));
if (state == Z_NULL) return Z_MEM_ERROR;
@@ -394,7 +403,6 @@ void FAR *out_desc;
PULLBYTE();
}
if (here.val < 16) {
- NEEDBITS(here.bits);
DROPBITS(here.bits);
state->lens[state->have++] = here.val;
}
diff --git a/lib/libz/inffixed.h b/lib/libz/inffixed.h
index 75ed4b5..d628327 100644
--- a/lib/libz/inffixed.h
+++ b/lib/libz/inffixed.h
@@ -2,9 +2,9 @@
* Generated automatically by makefixed().
*/
- /* WARNING: this file should *not* be used by applications. It
- is part of the implementation of the compression library and
- is subject to change. Applications should only use zlib.h.
+ /* WARNING: this file should *not* be used by applications.
+ It is part of the implementation of this library and is
+ subject to change. Applications should only use zlib.h.
*/
static const code lenfix[512] = {
diff --git a/lib/libz/inflate.c b/lib/libz/inflate.c
index a8431ab..47418a1 100644
--- a/lib/libz/inflate.c
+++ b/lib/libz/inflate.c
@@ -1,5 +1,5 @@
/* inflate.c -- zlib decompression
- * Copyright (C) 1995-2010 Mark Adler
+ * Copyright (C) 1995-2012 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@@ -100,7 +100,7 @@ local int updatewindow OF((z_streamp strm, unsigned out));
local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf,
unsigned len));
-int ZEXPORT inflateReset(strm)
+int ZEXPORT inflateResetKeep(strm)
z_streamp strm;
{
struct inflate_state FAR *state;
@@ -109,15 +109,13 @@ z_streamp strm;
state = (struct inflate_state FAR *)strm->state;
strm->total_in = strm->total_out = state->total = 0;
strm->msg = Z_NULL;
- strm->adler = 1; /* to support ill-conceived Java test suite */
+ if (state->wrap) /* to support ill-conceived Java test suite */
+ strm->adler = state->wrap & 1;
state->mode = HEAD;
state->last = 0;
state->havedict = 0;
state->dmax = 32768U;
state->head = Z_NULL;
- state->wsize = 0;
- state->whave = 0;
- state->wnext = 0;
state->hold = 0;
state->bits = 0;
state->lencode = state->distcode = state->next = state->codes;
@@ -127,6 +125,19 @@ z_streamp strm;
return Z_OK;
}
+int ZEXPORT inflateReset(strm)
+z_streamp strm;
+{
+ struct inflate_state FAR *state;
+
+ if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ state = (struct inflate_state FAR *)strm->state;
+ state->wsize = 0;
+ state->whave = 0;
+ state->wnext = 0;
+ return inflateResetKeep(strm);
+}
+
int ZEXPORT inflateReset2(strm, windowBits)
z_streamp strm;
int windowBits;
@@ -180,10 +191,19 @@ int stream_size;
if (strm == Z_NULL) return Z_STREAM_ERROR;
strm->msg = Z_NULL; /* in case we return an error */
if (strm->zalloc == (alloc_func)0) {
+#ifdef Z_SOLO
+ return Z_STREAM_ERROR;
+#else
strm->zalloc = zcalloc;
strm->opaque = (voidpf)0;
+#endif
}
- if (strm->zfree == (free_func)0) strm->zfree = zcfree;
+ if (strm->zfree == (free_func)0)
+#ifdef Z_SOLO
+ return Z_STREAM_ERROR;
+#else
+ strm->zfree = zcfree;
+#endif
state = (struct inflate_state FAR *)
ZALLOC(strm, 1, sizeof(struct inflate_state));
if (state == Z_NULL) return Z_MEM_ERROR;
@@ -321,8 +341,8 @@ void makefixed()
low = 0;
for (;;) {
if ((low % 7) == 0) printf("\n ");
- printf("{%u,%u,%d}", state.lencode[low].op, state.lencode[low].bits,
- state.lencode[low].val);
+ printf("{%u,%u,%d}", (low & 127) == 99 ? 64 : state.lencode[low].op,
+ state.lencode[low].bits, state.lencode[low].val);
if (++low == size) break;
putchar(',');
}
@@ -499,11 +519,6 @@ unsigned out;
bits -= bits & 7; \
} while (0)
-/* Reverse the bytes in a 32-bit value */
-#define REVERSE(q) \
- ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
- (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
-
/*
inflate() uses a state machine to process as much input data and generate as
much output data as possible before returning. The state machine is
@@ -797,7 +812,7 @@ int flush;
#endif
case DICTID:
NEEDBITS(32);
- strm->adler = state->check = REVERSE(hold);
+ strm->adler = state->check = ZSWAP32(hold);
INITBITS();
state->mode = DICT;
case DICT:
@@ -925,7 +940,6 @@ int flush;
PULLBYTE();
}
if (here.val < 16) {
- NEEDBITS(here.bits);
DROPBITS(here.bits);
state->lens[state->have++] = here.val;
}
@@ -1170,7 +1184,7 @@ int flush;
#ifdef GUNZIP
state->flags ? hold :
#endif
- REVERSE(hold)) != state->check) {
+ ZSWAP32(hold)) != state->check) {
strm->msg = (char *)"incorrect data check";
state->mode = BAD;
break;
@@ -1214,7 +1228,8 @@ int flush;
*/
inf_leave:
RESTORE();
- if (state->wsize || (state->mode < CHECK && out != strm->avail_out))
+ if (state->wsize || (out != strm->avail_out && state->mode < BAD &&
+ (state->mode < CHECK || flush != Z_FINISH)))
if (updatewindow(strm, out)) {
state->mode = MEM;
return Z_MEM_ERROR;
@@ -1255,7 +1270,10 @@ const Bytef *dictionary;
uInt dictLength;
{
struct inflate_state FAR *state;
- unsigned long id;
+ unsigned long dictid;
+ unsigned char *next;
+ unsigned avail;
+ int ret;
/* check state */
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
@@ -1263,29 +1281,27 @@ uInt dictLength;
if (state->wrap != 0 && state->mode != DICT)
return Z_STREAM_ERROR;
- /* check for correct dictionary id */
+ /* check for correct dictionary identifier */
if (state->mode == DICT) {
- id = adler32(0L, Z_NULL, 0);
- id = adler32(id, dictionary, dictLength);
- if (id != state->check)
+ dictid = adler32(0L, Z_NULL, 0);
+ dictid = adler32(dictid, dictionary, dictLength);
+ if (dictid != state->check)
return Z_DATA_ERROR;
}
- /* copy dictionary to window */
- if (updatewindow(strm, strm->avail_out)) {
+ /* copy dictionary to window using updatewindow(), which will amend the
+ existing dictionary if appropriate */
+ next = strm->next_out;
+ avail = strm->avail_out;
+ strm->next_out = (Bytef *)dictionary + dictLength;
+ strm->avail_out = 0;
+ ret = updatewindow(strm, dictLength);
+ strm->avail_out = avail;
+ strm->next_out = next;
+ if (ret) {
state->mode = MEM;
return Z_MEM_ERROR;
}
- if (dictLength > state->wsize) {
- zmemcpy(state->window, dictionary + dictLength - state->wsize,
- state->wsize);
- state->whave = state->wsize;
- }
- else {
- zmemcpy(state->window + state->wsize - dictLength, dictionary,
- dictLength);
- state->whave = dictLength;
- }
state->havedict = 1;
Tracev((stderr, "inflate: dictionary set\n"));
return Z_OK;
@@ -1433,8 +1449,8 @@ z_streamp source;
}
/* copy state */
- zmemcpy(dest, source, sizeof(z_stream));
- zmemcpy(copy, state, sizeof(struct inflate_state));
+ zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream));
+ zmemcpy((voidpf)copy, (voidpf)state, sizeof(struct inflate_state));
if (state->lencode >= state->codes &&
state->lencode <= state->codes + ENOUGH - 1) {
copy->lencode = copy->codes + (state->lencode - state->codes);
diff --git a/lib/libz/inftrees.c b/lib/libz/inftrees.c
index 11e9c52..abcd7c4 100644
--- a/lib/libz/inftrees.c
+++ b/lib/libz/inftrees.c
@@ -1,5 +1,5 @@
/* inftrees.c -- generate Huffman trees for efficient decoding
- * Copyright (C) 1995-2010 Mark Adler
+ * Copyright (C) 1995-2012 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@@ -9,7 +9,7 @@
#define MAXBITS 15
const char inflate_copyright[] =
- " inflate 1.2.5 Copyright 1995-2010 Mark Adler ";
+ " inflate 1.2.7 Copyright 1995-2012 Mark Adler ";
/*
If you use the zlib library in a product, an acknowledgment is welcome
in the documentation of your product. If for some reason you cannot
@@ -62,7 +62,7 @@ unsigned short FAR *work;
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
static const unsigned short lext[31] = { /* Length codes 257..285 extra */
16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
- 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 73, 195};
+ 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 78, 68};
static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
@@ -289,38 +289,14 @@ unsigned short FAR *work;
}
}
- /*
- Fill in rest of table for incomplete codes. This loop is similar to the
- loop above in incrementing huff for table indices. It is assumed that
- len is equal to curr + drop, so there is no loop needed to increment
- through high index bits. When the current sub-table is filled, the loop
- drops back to the root table to fill in any remaining entries there.
- */
- here.op = (unsigned char)64; /* invalid code marker */
- here.bits = (unsigned char)(len - drop);
- here.val = (unsigned short)0;
- while (huff != 0) {
- /* when done with sub-table, drop back to root table */
- if (drop != 0 && (huff & mask) != low) {
- drop = 0;
- len = root;
- next = *table;
- here.bits = (unsigned char)len;
- }
-
- /* put invalid code marker in table */
- next[huff >> drop] = here;
-
- /* backwards increment the len-bit code huff */
- incr = 1U << (len - 1);
- while (huff & incr)
- incr >>= 1;
- if (incr != 0) {
- huff &= incr - 1;
- huff += incr;
- }
- else
- huff = 0;
+ /* fill in remaining table entry if code is incomplete (guaranteed to have
+ at most one remaining entry, since if the code is incomplete, the
+ maximum code length that was allowed to get this far is one bit) */
+ if (huff != 0) {
+ here.op = (unsigned char)64; /* invalid code marker */
+ here.bits = (unsigned char)(len - drop);
+ here.val = (unsigned short)0;
+ next[huff] = here;
}
/* set return parameters */
diff --git a/lib/libz/example.c b/lib/libz/test/example.c
index 604736f..f515a48 100644
--- a/lib/libz/example.c
+++ b/lib/libz/test/example.c
@@ -1,5 +1,5 @@
/* example.c -- usage example of the zlib compression library
- * Copyright (C) 1995-2006 Jean-loup Gailly.
+ * Copyright (C) 1995-2006, 2011 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@@ -34,10 +34,6 @@ const char hello[] = "hello, hello!";
const char dictionary[] = "hello";
uLong dictId; /* Adler32 value of the dictionary */
-void test_compress OF((Byte *compr, uLong comprLen,
- Byte *uncompr, uLong uncomprLen));
-void test_gzio OF((const char *fname,
- Byte *uncompr, uLong uncomprLen));
void test_deflate OF((Byte *compr, uLong comprLen));
void test_inflate OF((Byte *compr, uLong comprLen,
Byte *uncompr, uLong uncomprLen));
@@ -53,6 +49,39 @@ void test_dict_inflate OF((Byte *compr, uLong comprLen,
Byte *uncompr, uLong uncomprLen));
int main OF((int argc, char *argv[]));
+
+#ifdef Z_SOLO
+
+void *myalloc OF((void *, unsigned, unsigned));
+void myfree OF((void *, void *));
+
+void *myalloc(q, n, m)
+ void *q;
+ unsigned n, m;
+{
+ q = Z_NULL;
+ return calloc(n, m);
+}
+
+void myfree(void *q, void *p)
+{
+ q = Z_NULL;
+ free(p);
+}
+
+static alloc_func zalloc = myalloc;
+static free_func zfree = myfree;
+
+#else /* !Z_SOLO */
+
+static alloc_func zalloc = (alloc_func)0;
+static free_func zfree = (free_func)0;
+
+void test_compress OF((Byte *compr, uLong comprLen,
+ Byte *uncompr, uLong uncomprLen));
+void test_gzio OF((const char *fname,
+ Byte *uncompr, uLong uncomprLen));
+
/* ===========================================================================
* Test compress() and uncompress()
*/
@@ -163,6 +192,8 @@ void test_gzio(fname, uncompr, uncomprLen)
#endif
}
+#endif /* Z_SOLO */
+
/* ===========================================================================
* Test deflate() with small buffers
*/
@@ -174,8 +205,8 @@ void test_deflate(compr, comprLen)
int err;
uLong len = (uLong)strlen(hello)+1;
- c_stream.zalloc = (alloc_func)0;
- c_stream.zfree = (free_func)0;
+ c_stream.zalloc = zalloc;
+ c_stream.zfree = zfree;
c_stream.opaque = (voidpf)0;
err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
@@ -213,8 +244,8 @@ void test_inflate(compr, comprLen, uncompr, uncomprLen)
strcpy((char*)uncompr, "garbage");
- d_stream.zalloc = (alloc_func)0;
- d_stream.zfree = (free_func)0;
+ d_stream.zalloc = zalloc;
+ d_stream.zfree = zfree;
d_stream.opaque = (voidpf)0;
d_stream.next_in = compr;
@@ -252,8 +283,8 @@ void test_large_deflate(compr, comprLen, uncompr, uncomprLen)
z_stream c_stream; /* compression stream */
int err;
- c_stream.zalloc = (alloc_func)0;
- c_stream.zfree = (free_func)0;
+ c_stream.zalloc = zalloc;
+ c_stream.zfree = zfree;
c_stream.opaque = (voidpf)0;
err = deflateInit(&c_stream, Z_BEST_SPEED);
@@ -309,8 +340,8 @@ void test_large_inflate(compr, comprLen, uncompr, uncomprLen)
strcpy((char*)uncompr, "garbage");
- d_stream.zalloc = (alloc_func)0;
- d_stream.zfree = (free_func)0;
+ d_stream.zalloc = zalloc;
+ d_stream.zfree = zfree;
d_stream.opaque = (voidpf)0;
d_stream.next_in = compr;
@@ -349,8 +380,8 @@ void test_flush(compr, comprLen)
int err;
uInt len = (uInt)strlen(hello)+1;
- c_stream.zalloc = (alloc_func)0;
- c_stream.zfree = (free_func)0;
+ c_stream.zalloc = zalloc;
+ c_stream.zfree = zfree;
c_stream.opaque = (voidpf)0;
err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
@@ -388,8 +419,8 @@ void test_sync(compr, comprLen, uncompr, uncomprLen)
strcpy((char*)uncompr, "garbage");
- d_stream.zalloc = (alloc_func)0;
- d_stream.zfree = (free_func)0;
+ d_stream.zalloc = zalloc;
+ d_stream.zfree = zfree;
d_stream.opaque = (voidpf)0;
d_stream.next_in = compr;
@@ -430,15 +461,15 @@ void test_dict_deflate(compr, comprLen)
z_stream c_stream; /* compression stream */
int err;
- c_stream.zalloc = (alloc_func)0;
- c_stream.zfree = (free_func)0;
+ c_stream.zalloc = zalloc;
+ c_stream.zfree = zfree;
c_stream.opaque = (voidpf)0;
err = deflateInit(&c_stream, Z_BEST_COMPRESSION);
CHECK_ERR(err, "deflateInit");
err = deflateSetDictionary(&c_stream,
- (const Bytef*)dictionary, sizeof(dictionary));
+ (const Bytef*)dictionary, (int)sizeof(dictionary));
CHECK_ERR(err, "deflateSetDictionary");
dictId = c_stream.adler;
@@ -469,8 +500,8 @@ void test_dict_inflate(compr, comprLen, uncompr, uncomprLen)
strcpy((char*)uncompr, "garbage");
- d_stream.zalloc = (alloc_func)0;
- d_stream.zfree = (free_func)0;
+ d_stream.zalloc = zalloc;
+ d_stream.zfree = zfree;
d_stream.opaque = (voidpf)0;
d_stream.next_in = compr;
@@ -491,7 +522,7 @@ void test_dict_inflate(compr, comprLen, uncompr, uncomprLen)
exit(1);
}
err = inflateSetDictionary(&d_stream, (const Bytef*)dictionary,
- sizeof(dictionary));
+ (int)sizeof(dictionary));
}
CHECK_ERR(err, "inflate with dict");
}
@@ -540,10 +571,15 @@ int main(argc, argv)
printf("out of memory\n");
exit(1);
}
+
+#ifdef Z_SOLO
+ argc = strlen(argv[0]);
+#else
test_compress(compr, comprLen, uncompr, uncomprLen);
test_gzio((argc > 1 ? argv[1] : TESTFILE),
uncompr, uncomprLen);
+#endif
test_deflate(compr, comprLen);
test_inflate(compr, comprLen, uncompr, uncomprLen);
diff --git a/lib/libz/test/infcover.c b/lib/libz/test/infcover.c
new file mode 100644
index 0000000..fe3d920
--- /dev/null
+++ b/lib/libz/test/infcover.c
@@ -0,0 +1,671 @@
+/* infcover.c -- test zlib's inflate routines with full code coverage
+ * Copyright (C) 2011 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* to use, do: ./configure --cover && make cover */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include "zlib.h"
+
+/* get definition of internal structure so we can mess with it (see pull()),
+ and so we can call inflate_trees() (see cover5()) */
+#define ZLIB_INTERNAL
+#include "inftrees.h"
+#include "inflate.h"
+
+#define local static
+
+/* -- memory tracking routines -- */
+
+/*
+ These memory tracking routines are provided to zlib and track all of zlib's
+ allocations and deallocations, check for LIFO operations, keep a current
+ and high water mark of total bytes requested, optionally set a limit on the
+ total memory that can be allocated, and when done check for memory leaks.
+
+ They are used as follows:
+
+ z_stream strm;
+ mem_setup(&strm) initializes the memory tracking and sets the
+ zalloc, zfree, and opaque members of strm to use
+ memory tracking for all zlib operations on strm
+ mem_limit(&strm, limit) sets a limit on the total bytes requested -- a
+ request that exceeds this limit will result in an
+ allocation failure (returns NULL) -- setting the
+ limit to zero means no limit, which is the default
+ after mem_setup()
+ mem_used(&strm, "msg") prints to stderr "msg" and the total bytes used
+ mem_high(&strm, "msg") prints to stderr "msg" and the high water mark
+ mem_done(&strm, "msg") ends memory tracking, releases all allocations
+ for the tracking as well as leaked zlib blocks, if
+ any. If there was anything unusual, such as leaked
+ blocks, non-FIFO frees, or frees of addresses not
+ allocated, then "msg" and information about the
+ problem is printed to stderr. If everything is
+ normal, nothing is printed. mem_done resets the
+ strm members to Z_NULL to use the default memory
+ allocation routines on the next zlib initialization
+ using strm.
+ */
+
+/* these items are strung together in a linked list, one for each allocation */
+struct mem_item {
+ void *ptr; /* pointer to allocated memory */
+ size_t size; /* requested size of allocation */
+ struct mem_item *next; /* pointer to next item in list, or NULL */
+};
+
+/* this structure is at the root of the linked list, and tracks statistics */
+struct mem_zone {
+ struct mem_item *first; /* pointer to first item in list, or NULL */
+ size_t total, highwater; /* total allocations, and largest total */
+ size_t limit; /* memory allocation limit, or 0 if no limit */
+ int notlifo, rogue; /* counts of non-LIFO frees and rogue frees */
+};
+
+/* memory allocation routine to pass to zlib */
+local void *mem_alloc(void *mem, unsigned count, unsigned size)
+{
+ void *ptr;
+ struct mem_item *item;
+ struct mem_zone *zone = mem;
+ size_t len = count * (size_t)size;
+
+ /* induced allocation failure */
+ if (zone == NULL || (zone->limit && zone->total + len > zone->limit))
+ return NULL;
+
+ /* perform allocation using the standard library, fill memory with a
+ non-zero value to make sure that the code isn't depending on zeros */
+ ptr = malloc(len);
+ if (ptr == NULL)
+ return NULL;
+ memset(ptr, 0xa5, len);
+
+ /* create a new item for the list */
+ item = malloc(sizeof(struct mem_item));
+ if (item == NULL) {
+ free(ptr);
+ return NULL;
+ }
+ item->ptr = ptr;
+ item->size = len;
+
+ /* insert item at the beginning of the list */
+ item->next = zone->first;
+ zone->first = item;
+
+ /* update the statistics */
+ zone->total += item->size;
+ if (zone->total > zone->highwater)
+ zone->highwater = zone->total;
+
+ /* return the allocated memory */
+ return ptr;
+}
+
+/* memory free routine to pass to zlib */
+local void mem_free(void *mem, void *ptr)
+{
+ struct mem_item *item, *next;
+ struct mem_zone *zone = mem;
+
+ /* if no zone, just do a free */
+ if (zone == NULL) {
+ free(ptr);
+ return;
+ }
+
+ /* point next to the item that matches ptr, or NULL if not found -- remove
+ the item from the linked list if found */
+ next = zone->first;
+ if (next) {
+ if (next->ptr == ptr)
+ zone->first = next->next; /* first one is it, remove from list */
+ else {
+ do { /* search the linked list */
+ item = next;
+ next = item->next;
+ } while (next != NULL && next->ptr != ptr);
+ if (next) { /* if found, remove from linked list */
+ item->next = next->next;
+ zone->notlifo++; /* not a LIFO free */
+ }
+
+ }
+ }
+
+ /* if found, update the statistics and free the item */
+ if (next) {
+ zone->total -= next->size;
+ free(next);
+ }
+
+ /* if not found, update the rogue count */
+ else
+ zone->rogue++;
+
+ /* in any case, do the requested free with the standard library function */
+ free(ptr);
+}
+
+/* set up a controlled memory allocation space for monitoring, set the stream
+ parameters to the controlled routines, with opaque pointing to the space */
+local void mem_setup(z_stream *strm)
+{
+ struct mem_zone *zone;
+
+ zone = malloc(sizeof(struct mem_zone));
+ assert(zone != NULL);
+ zone->first = NULL;
+ zone->total = 0;
+ zone->highwater = 0;
+ zone->limit = 0;
+ zone->notlifo = 0;
+ zone->rogue = 0;
+ strm->opaque = zone;
+ strm->zalloc = mem_alloc;
+ strm->zfree = mem_free;
+}
+
+/* set a limit on the total memory allocation, or 0 to remove the limit */
+local void mem_limit(z_stream *strm, size_t limit)
+{
+ struct mem_zone *zone = strm->opaque;
+
+ zone->limit = limit;
+}
+
+/* show the current total requested allocations in bytes */
+local void mem_used(z_stream *strm, char *prefix)
+{
+ struct mem_zone *zone = strm->opaque;
+
+ fprintf(stderr, "%s: %lu allocated\n", prefix, zone->total);
+}
+
+/* show the high water allocation in bytes */
+local void mem_high(z_stream *strm, char *prefix)
+{
+ struct mem_zone *zone = strm->opaque;
+
+ fprintf(stderr, "%s: %lu high water mark\n", prefix, zone->highwater);
+}
+
+/* release the memory allocation zone -- if there are any surprises, notify */
+local void mem_done(z_stream *strm, char *prefix)
+{
+ int count = 0;
+ struct mem_item *item, *next;
+ struct mem_zone *zone = strm->opaque;
+
+ /* show high water mark */
+ mem_high(strm, prefix);
+
+ /* free leftover allocations and item structures, if any */
+ item = zone->first;
+ while (item != NULL) {
+ free(item->ptr);
+ next = item->next;
+ free(item);
+ item = next;
+ count++;
+ }
+
+ /* issue alerts about anything unexpected */
+ if (count || zone->total)
+ fprintf(stderr, "** %s: %lu bytes in %d blocks not freed\n",
+ prefix, zone->total, count);
+ if (zone->notlifo)
+ fprintf(stderr, "** %s: %d frees not LIFO\n", prefix, zone->notlifo);
+ if (zone->rogue)
+ fprintf(stderr, "** %s: %d frees not recognized\n",
+ prefix, zone->rogue);
+
+ /* free the zone and delete from the stream */
+ free(zone);
+ strm->opaque = Z_NULL;
+ strm->zalloc = Z_NULL;
+ strm->zfree = Z_NULL;
+}
+
+/* -- inflate test routines -- */
+
+/* Decode a hexadecimal string, set *len to length, in[] to the bytes. This
+ decodes liberally, in that hex digits can be adjacent, in which case two in
+ a row writes a byte. Or they can delimited by any non-hex character, where
+ the delimiters are ignored except when a single hex digit is followed by a
+ delimiter in which case that single digit writes a byte. The returned
+ data is allocated and must eventually be freed. NULL is returned if out of
+ memory. If the length is not needed, then len can be NULL. */
+local unsigned char *h2b(const char *hex, unsigned *len)
+{
+ unsigned char *in;
+ unsigned next, val;
+
+ in = malloc((strlen(hex) + 1) >> 1);
+ if (in == NULL)
+ return NULL;
+ next = 0;
+ val = 1;
+ do {
+ if (*hex >= '0' && *hex <= '9')
+ val = (val << 4) + *hex - '0';
+ else if (*hex >= 'A' && *hex <= 'F')
+ val = (val << 4) + *hex - 'A' + 10;
+ else if (*hex >= 'a' && *hex <= 'f')
+ val = (val << 4) + *hex - 'a' + 10;
+ else if (val != 1 && val < 32) /* one digit followed by delimiter */
+ val += 240; /* make it look like two digits */
+ if (val > 255) { /* have two digits */
+ in[next++] = val & 0xff; /* save the decoded byte */
+ val = 1; /* start over */
+ }
+ } while (*hex++); /* go through the loop with the terminating null */
+ if (len != NULL)
+ *len = next;
+ in = reallocf(in, next);
+ return in;
+}
+
+/* generic inflate() run, where hex is the hexadecimal input data, what is the
+ text to include in an error message, step is how much input data to feed
+ inflate() on each call, or zero to feed it all, win is the window bits
+ parameter to inflateInit2(), len is the size of the output buffer, and err
+ is the error code expected from the first inflate() call (the second
+ inflate() call is expected to return Z_STREAM_END). If win is 47, then
+ header information is collected with inflateGetHeader(). If a zlib stream
+ is looking for a dictionary, then an empty dictionary is provided.
+ inflate() is run until all of the input data is consumed. */
+local void inf(char *hex, char *what, unsigned step, int win, unsigned len,
+ int err)
+{
+ int ret;
+ unsigned have;
+ unsigned char *in, *out;
+ z_stream strm, copy;
+ gz_header head;
+
+ mem_setup(&strm);
+ strm.avail_in = 0;
+ strm.next_in = Z_NULL;
+ ret = inflateInit2(&strm, win);
+ if (ret != Z_OK) {
+ mem_done(&strm, what);
+ return;
+ }
+ out = malloc(len); assert(out != NULL);
+ if (win == 47) {
+ head.extra = out;
+ head.extra_max = len;
+ head.name = out;
+ head.name_max = len;
+ head.comment = out;
+ head.comm_max = len;
+ ret = inflateGetHeader(&strm, &head); assert(ret == Z_OK);
+ }
+ in = h2b(hex, &have); assert(in != NULL);
+ if (step == 0 || step > have)
+ step = have;
+ strm.avail_in = step;
+ have -= step;
+ strm.next_in = in;
+ do {
+ strm.avail_out = len;
+ strm.next_out = out;
+ ret = inflate(&strm, Z_NO_FLUSH); assert(err == 9 || ret == err);
+ if (ret != Z_OK && ret != Z_BUF_ERROR && ret != Z_NEED_DICT)
+ break;
+ if (ret == Z_NEED_DICT) {
+ ret = inflateSetDictionary(&strm, in, 1);
+ assert(ret == Z_DATA_ERROR);
+ mem_limit(&strm, 1);
+ ret = inflateSetDictionary(&strm, out, 0);
+ assert(ret == Z_MEM_ERROR);
+ mem_limit(&strm, 0);
+ ((struct inflate_state *)strm.state)->mode = DICT;
+ ret = inflateSetDictionary(&strm, out, 0);
+ assert(ret == Z_OK);
+ ret = inflate(&strm, Z_NO_FLUSH); assert(ret == Z_BUF_ERROR);
+ }
+ ret = inflateCopy(&copy, &strm); assert(ret == Z_OK);
+ ret = inflateEnd(&copy); assert(ret == Z_OK);
+ err = 9; /* don't care next time around */
+ have += strm.avail_in;
+ strm.avail_in = step > have ? have : step;
+ have -= strm.avail_in;
+ } while (strm.avail_in);
+ free(in);
+ free(out);
+ ret = inflateReset2(&strm, -8); assert(ret == Z_OK);
+ ret = inflateEnd(&strm); assert(ret == Z_OK);
+ mem_done(&strm, what);
+}
+
+/* cover all of the lines in inflate.c up to inflate() */
+local void cover_support(void)
+{
+ int ret;
+ z_stream strm;
+
+ mem_setup(&strm);
+ strm.avail_in = 0;
+ strm.next_in = Z_NULL;
+ ret = inflateInit(&strm); assert(ret == Z_OK);
+ mem_used(&strm, "inflate init");
+ ret = inflatePrime(&strm, 5, 31); assert(ret == Z_OK);
+ ret = inflatePrime(&strm, -1, 0); assert(ret == Z_OK);
+ ret = inflateSetDictionary(&strm, Z_NULL, 0);
+ assert(ret == Z_STREAM_ERROR);
+ ret = inflateEnd(&strm); assert(ret == Z_OK);
+ mem_done(&strm, "prime");
+
+ inf("63 0", "force window allocation", 0, -15, 1, Z_OK);
+ inf("63 18 5", "force window replacement", 0, -8, 259, Z_OK);
+ inf("63 18 68 30 d0 0 0", "force split window update", 4, -8, 259, Z_OK);
+ inf("3 0", "use fixed blocks", 0, -15, 1, Z_STREAM_END);
+ inf("", "bad window size", 0, 1, 0, Z_STREAM_ERROR);
+
+ mem_setup(&strm);
+ strm.avail_in = 0;
+ strm.next_in = Z_NULL;
+ ret = inflateInit_(&strm, ZLIB_VERSION - 1, (int)sizeof(z_stream));
+ assert(ret == Z_VERSION_ERROR);
+ mem_done(&strm, "wrong version");
+
+ strm.avail_in = 0;
+ strm.next_in = Z_NULL;
+ ret = inflateInit(&strm); assert(ret == Z_OK);
+ ret = inflateEnd(&strm); assert(ret == Z_OK);
+ fputs("inflate built-in memory routines\n", stderr);
+}
+
+/* cover all inflate() header and trailer cases and code after inflate() */
+local void cover_wrap(void)
+{
+ int ret;
+ z_stream strm, copy;
+ unsigned char dict[257];
+
+ ret = inflate(Z_NULL, 0); assert(ret == Z_STREAM_ERROR);
+ ret = inflateEnd(Z_NULL); assert(ret == Z_STREAM_ERROR);
+ ret = inflateCopy(Z_NULL, Z_NULL); assert(ret == Z_STREAM_ERROR);
+ fputs("inflate bad parameters\n", stderr);
+
+ inf("1f 8b 0 0", "bad gzip method", 0, 31, 0, Z_DATA_ERROR);
+ inf("1f 8b 8 80", "bad gzip flags", 0, 31, 0, Z_DATA_ERROR);
+ inf("77 85", "bad zlib method", 0, 15, 0, Z_DATA_ERROR);
+ inf("8 99", "set window size from header", 0, 0, 0, Z_OK);
+ inf("78 9c", "bad zlib window size", 0, 8, 0, Z_DATA_ERROR);
+ inf("78 9c 63 0 0 0 1 0 1", "check adler32", 0, 15, 1, Z_STREAM_END);
+ inf("1f 8b 8 1e 0 0 0 0 0 0 1 0 0 0 0 0 0", "bad header crc", 0, 47, 1,
+ Z_DATA_ERROR);
+ inf("1f 8b 8 2 0 0 0 0 0 0 1d 26 3 0 0 0 0 0 0 0 0 0", "check gzip length",
+ 0, 47, 0, Z_STREAM_END);
+ inf("78 90", "bad zlib header check", 0, 47, 0, Z_DATA_ERROR);
+ inf("8 b8 0 0 0 1", "need dictionary", 0, 8, 0, Z_NEED_DICT);
+ inf("78 9c 63 0", "compute adler32", 0, 15, 1, Z_OK);
+
+ mem_setup(&strm);
+ strm.avail_in = 0;
+ strm.next_in = Z_NULL;
+ ret = inflateInit2(&strm, -8);
+ strm.avail_in = 2;
+ strm.next_in = (void *)"\x63";
+ strm.avail_out = 1;
+ strm.next_out = (void *)&ret;
+ mem_limit(&strm, 1);
+ ret = inflate(&strm, Z_NO_FLUSH); assert(ret == Z_MEM_ERROR);
+ ret = inflate(&strm, Z_NO_FLUSH); assert(ret == Z_MEM_ERROR);
+ mem_limit(&strm, 0);
+ memset(dict, 0, 257);
+ ret = inflateSetDictionary(&strm, dict, 257);
+ assert(ret == Z_OK);
+ mem_limit(&strm, (sizeof(struct inflate_state) << 1) + 256);
+ ret = inflatePrime(&strm, 16, 0); assert(ret == Z_OK);
+ strm.avail_in = 2;
+ strm.next_in = (void *)"\x80";
+ ret = inflateSync(&strm); assert(ret == Z_DATA_ERROR);
+ ret = inflate(&strm, Z_NO_FLUSH); assert(ret == Z_STREAM_ERROR);
+ strm.avail_in = 4;
+ strm.next_in = (void *)"\0\0\xff\xff";
+ ret = inflateSync(&strm); assert(ret == Z_OK);
+ (void)inflateSyncPoint(&strm);
+ ret = inflateCopy(&copy, &strm); assert(ret == Z_MEM_ERROR);
+ mem_limit(&strm, 0);
+ ret = inflateUndermine(&strm, 1); assert(ret == Z_DATA_ERROR);
+ (void)inflateMark(&strm);
+ ret = inflateEnd(&strm); assert(ret == Z_OK);
+ mem_done(&strm, "miscellaneous, force memory errors");
+}
+
+/* input and output functions for inflateBack() */
+local unsigned pull(void *desc, unsigned char **buf)
+{
+ static unsigned int next = 0;
+ static unsigned char dat[] = {0x63, 0, 2, 0};
+ struct inflate_state *state;
+
+ if (desc == Z_NULL) {
+ next = 0;
+ return 0; /* no input (already provided at next_in) */
+ }
+ state = (void *)((z_stream *)desc)->state;
+ if (state != Z_NULL)
+ state->mode = SYNC; /* force an otherwise impossible situation */
+ return next < sizeof(dat) ? (*buf = dat + next++, 1) : 0;
+}
+
+local int push(void *desc, unsigned char *buf, unsigned len)
+{
+ buf += len;
+ return desc != Z_NULL; /* force error if desc not null */
+}
+
+/* cover inflateBack() up to common deflate data cases and after those */
+local void cover_back(void)
+{
+ int ret;
+ z_stream strm;
+ unsigned char win[32768];
+
+ ret = inflateBackInit_(Z_NULL, 0, win, 0, 0);
+ assert(ret == Z_VERSION_ERROR);
+ ret = inflateBackInit(Z_NULL, 0, win); assert(ret == Z_STREAM_ERROR);
+ ret = inflateBack(Z_NULL, Z_NULL, Z_NULL, Z_NULL, Z_NULL);
+ assert(ret == Z_STREAM_ERROR);
+ ret = inflateBackEnd(Z_NULL); assert(ret == Z_STREAM_ERROR);
+ fputs("inflateBack bad parameters\n", stderr);
+
+ mem_setup(&strm);
+ ret = inflateBackInit(&strm, 15, win); assert(ret == Z_OK);
+ strm.avail_in = 2;
+ strm.next_in = (void *)"\x03";
+ ret = inflateBack(&strm, pull, Z_NULL, push, Z_NULL);
+ assert(ret == Z_STREAM_END);
+ /* force output error */
+ strm.avail_in = 3;
+ strm.next_in = (void *)"\x63\x00";
+ ret = inflateBack(&strm, pull, Z_NULL, push, &strm);
+ assert(ret == Z_BUF_ERROR);
+ /* force mode error by mucking with state */
+ ret = inflateBack(&strm, pull, &strm, push, Z_NULL);
+ assert(ret == Z_STREAM_ERROR);
+ ret = inflateBackEnd(&strm); assert(ret == Z_OK);
+ mem_done(&strm, "inflateBack bad state");
+
+ ret = inflateBackInit(&strm, 15, win); assert(ret == Z_OK);
+ ret = inflateBackEnd(&strm); assert(ret == Z_OK);
+ fputs("inflateBack built-in memory routines\n", stderr);
+}
+
+/* do a raw inflate of data in hexadecimal with both inflate and inflateBack */
+local int try(char *hex, char *id, int err)
+{
+ int ret;
+ unsigned len, size;
+ unsigned char *in, *out, *win;
+ char *prefix;
+ z_stream strm;
+
+ /* convert to hex */
+ in = h2b(hex, &len);
+ assert(in != NULL);
+
+ /* allocate work areas */
+ size = len << 3;
+ out = malloc(size);
+ assert(out != NULL);
+ win = malloc(32768);
+ assert(win != NULL);
+ prefix = malloc(strlen(id) + 6);
+ assert(prefix != NULL);
+
+ /* first with inflate */
+ strcpy(prefix, id);
+ strcat(prefix, "-late");
+ mem_setup(&strm);
+ strm.avail_in = 0;
+ strm.next_in = Z_NULL;
+ ret = inflateInit2(&strm, err < 0 ? 47 : -15);
+ assert(ret == Z_OK);
+ strm.avail_in = len;
+ strm.next_in = in;
+ do {
+ strm.avail_out = size;
+ strm.next_out = out;
+ ret = inflate(&strm, Z_TREES);
+ assert(ret != Z_STREAM_ERROR && ret != Z_MEM_ERROR);
+ if (ret == Z_DATA_ERROR || ret == Z_NEED_DICT)
+ break;
+ } while (strm.avail_in || strm.avail_out == 0);
+ if (err) {
+ assert(ret == Z_DATA_ERROR);
+ assert(strcmp(id, strm.msg) == 0);
+ }
+ inflateEnd(&strm);
+ mem_done(&strm, prefix);
+
+ /* then with inflateBack */
+ if (err >= 0) {
+ strcpy(prefix, id);
+ strcat(prefix, "-back");
+ mem_setup(&strm);
+ ret = inflateBackInit(&strm, 15, win);
+ assert(ret == Z_OK);
+ strm.avail_in = len;
+ strm.next_in = in;
+ ret = inflateBack(&strm, pull, Z_NULL, push, Z_NULL);
+ assert(ret != Z_STREAM_ERROR);
+ if (err) {
+ assert(ret == Z_DATA_ERROR);
+ assert(strcmp(id, strm.msg) == 0);
+ }
+ inflateBackEnd(&strm);
+ mem_done(&strm, prefix);
+ }
+
+ /* clean up */
+ free(prefix);
+ free(win);
+ free(out);
+ free(in);
+ return ret;
+}
+
+/* cover deflate data cases in both inflate() and inflateBack() */
+local void cover_inflate(void)
+{
+ try("0 0 0 0 0", "invalid stored block lengths", 1);
+ try("3 0", "fixed", 0);
+ try("6", "invalid block type", 1);
+ try("1 1 0 fe ff 0", "stored", 0);
+ try("fc 0 0", "too many length or distance symbols", 1);
+ try("4 0 fe ff", "invalid code lengths set", 1);
+ try("4 0 24 49 0", "invalid bit length repeat", 1);
+ try("4 0 24 e9 ff ff", "invalid bit length repeat", 1);
+ try("4 0 24 e9 ff 6d", "invalid code -- missing end-of-block", 1);
+ try("4 80 49 92 24 49 92 24 71 ff ff 93 11 0",
+ "invalid literal/lengths set", 1);
+ try("4 80 49 92 24 49 92 24 f b4 ff ff c3 84", "invalid distances set", 1);
+ try("4 c0 81 8 0 0 0 0 20 7f eb b 0 0", "invalid literal/length code", 1);
+ try("2 7e ff ff", "invalid distance code", 1);
+ try("c c0 81 0 0 0 0 0 90 ff 6b 4 0", "invalid distance too far back", 1);
+
+ /* also trailer mismatch just in inflate() */
+ try("1f 8b 8 0 0 0 0 0 0 0 3 0 0 0 0 1", "incorrect data check", -1);
+ try("1f 8b 8 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 1",
+ "incorrect length check", -1);
+ try("5 c0 21 d 0 0 0 80 b0 fe 6d 2f 91 6c", "pull 17", 0);
+ try("5 e0 81 91 24 cb b2 2c 49 e2 f 2e 8b 9a 47 56 9f fb fe ec d2 ff 1f",
+ "long code", 0);
+ try("ed c0 1 1 0 0 0 40 20 ff 57 1b 42 2c 4f", "length extra", 0);
+ try("ed cf c1 b1 2c 47 10 c4 30 fa 6f 35 1d 1 82 59 3d fb be 2e 2a fc f c",
+ "long distance and extra", 0);
+ try("ed c0 81 0 0 0 0 80 a0 fd a9 17 a9 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 "
+ "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6", "window end", 0);
+ inf("2 8 20 80 0 3 0", "inflate_fast TYPE return", 0, -15, 258,
+ Z_STREAM_END);
+ inf("63 18 5 40 c 0", "window wrap", 3, -8, 300, Z_OK);
+}
+
+/* cover remaining lines in inftrees.c */
+local void cover_trees(void)
+{
+ int ret;
+ unsigned bits;
+ unsigned short lens[16], work[16];
+ code *next, table[ENOUGH_DISTS];
+
+ /* we need to call inflate_table() directly in order to manifest not-
+ enough errors, since zlib insures that enough is always enough */
+ for (bits = 0; bits < 15; bits++)
+ lens[bits] = (unsigned short)(bits + 1);
+ lens[15] = 15;
+ next = table;
+ bits = 15;
+ ret = inflate_table(DISTS, lens, 16, &next, &bits, work);
+ assert(ret == 1);
+ next = table;
+ bits = 1;
+ ret = inflate_table(DISTS, lens, 16, &next, &bits, work);
+ assert(ret == 1);
+ fputs("inflate_table not enough errors\n", stderr);
+}
+
+/* cover remaining inffast.c decoding and window copying */
+local void cover_fast(void)
+{
+ inf("e5 e0 81 ad 6d cb b2 2c c9 01 1e 59 63 ae 7d ee fb 4d fd b5 35 41 68"
+ " ff 7f 0f 0 0 0", "fast length extra bits", 0, -8, 258, Z_DATA_ERROR);
+ inf("25 fd 81 b5 6d 59 b6 6a 49 ea af 35 6 34 eb 8c b9 f6 b9 1e ef 67 49"
+ " 50 fe ff ff 3f 0 0", "fast distance extra bits", 0, -8, 258,
+ Z_DATA_ERROR);
+ inf("3 7e 0 0 0 0 0", "fast invalid distance code", 0, -8, 258,
+ Z_DATA_ERROR);
+ inf("1b 7 0 0 0 0 0", "fast invalid literal/length code", 0, -8, 258,
+ Z_DATA_ERROR);
+ inf("d c7 1 ae eb 38 c 4 41 a0 87 72 de df fb 1f b8 36 b1 38 5d ff ff 0",
+ "fast 2nd level codes and too far back", 0, -8, 258, Z_DATA_ERROR);
+ inf("63 18 5 8c 10 8 0 0 0 0", "very common case", 0, -8, 259, Z_OK);
+ inf("63 60 60 18 c9 0 8 18 18 18 26 c0 28 0 29 0 0 0",
+ "contiguous and wrap around window", 6, -8, 259, Z_OK);
+ inf("63 0 3 0 0 0 0 0", "copy direct from output", 0, -8, 259,
+ Z_STREAM_END);
+}
+
+int main(void)
+{
+ fprintf(stderr, "%s\n", zlibVersion());
+ cover_support();
+ cover_wrap();
+ cover_back();
+ cover_inflate();
+ cover_trees();
+ cover_fast();
+ return 0;
+}
diff --git a/lib/libz/minigzip.c b/lib/libz/test/minigzip.c
index 9825ccc..aa7ac7a 100644
--- a/lib/libz/minigzip.c
+++ b/lib/libz/test/minigzip.c
@@ -1,5 +1,5 @@
/* minigzip.c -- simulate gzip using the zlib compression library
- * Copyright (C) 1995-2006, 2010 Jean-loup Gailly.
+ * Copyright (C) 1995-2006, 2010, 2011 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@@ -138,6 +138,197 @@ static void pwinerror (s)
# define local
#endif
+#ifdef Z_SOLO
+/* for Z_SOLO, create simplified gz* functions using deflate and inflate */
+
+#if defined(Z_HAVE_UNISTD_H) || defined(Z_LARGE)
+# include <unistd.h> /* for unlink() */
+#endif
+
+void *myalloc OF((void *, unsigned, unsigned));
+void myfree OF((void *, void *));
+
+void *myalloc(q, n, m)
+ void *q;
+ unsigned n, m;
+{
+ q = Z_NULL;
+ return calloc(n, m);
+}
+
+void myfree(q, p)
+ void *q, *p;
+{
+ q = Z_NULL;
+ free(p);
+}
+
+typedef struct gzFile_s {
+ FILE *file;
+ int write;
+ int err;
+ char *msg;
+ z_stream strm;
+} *gzFile;
+
+gzFile gzopen OF((const char *, const char *));
+gzFile gzdopen OF((int, const char *));
+gzFile gz_open OF((const char *, int, const char *));
+
+gzFile gzopen(path, mode)
+const char *path;
+const char *mode;
+{
+ return gz_open(path, -1, mode);
+}
+
+gzFile gzdopen(fd, mode)
+int fd;
+const char *mode;
+{
+ return gz_open(NULL, fd, mode);
+}
+
+gzFile gz_open(path, fd, mode)
+ const char *path;
+ int fd;
+ const char *mode;
+{
+ gzFile gz;
+ int ret;
+
+ gz = malloc(sizeof(struct gzFile_s));
+ if (gz == NULL)
+ return NULL;
+ gz->write = strchr(mode, 'w') != NULL;
+ gz->strm.zalloc = myalloc;
+ gz->strm.zfree = myfree;
+ gz->strm.opaque = Z_NULL;
+ if (gz->write)
+ ret = deflateInit2(&(gz->strm), -1, 8, 15 + 16, 8, 0);
+ else {
+ gz->strm.next_in = 0;
+ gz->strm.avail_in = Z_NULL;
+ ret = inflateInit2(&(gz->strm), 15 + 16);
+ }
+ if (ret != Z_OK) {
+ free(gz);
+ return NULL;
+ }
+ gz->file = path == NULL ? fdopen(fd, gz->write ? "wb" : "rb") :
+ fopen(path, gz->write ? "wb" : "rb");
+ if (gz->file == NULL) {
+ gz->write ? deflateEnd(&(gz->strm)) : inflateEnd(&(gz->strm));
+ free(gz);
+ return NULL;
+ }
+ gz->err = 0;
+ gz->msg = "";
+ return gz;
+}
+
+int gzwrite OF((gzFile, const void *, unsigned));
+
+int gzwrite(gz, buf, len)
+ gzFile gz;
+ const void *buf;
+ unsigned len;
+{
+ z_stream *strm;
+ unsigned char out[BUFLEN];
+
+ if (gz == NULL || !gz->write)
+ return 0;
+ strm = &(gz->strm);
+ strm->next_in = (void *)buf;
+ strm->avail_in = len;
+ do {
+ strm->next_out = out;
+ strm->avail_out = BUFLEN;
+ (void)deflate(strm, Z_NO_FLUSH);
+ fwrite(out, 1, BUFLEN - strm->avail_out, gz->file);
+ } while (strm->avail_out == 0);
+ return len;
+}
+
+int gzread OF((gzFile, void *, unsigned));
+
+int gzread(gz, buf, len)
+ gzFile gz;
+ void *buf;
+ unsigned len;
+{
+ int ret;
+ unsigned got;
+ unsigned char in[1];
+ z_stream *strm;
+
+ if (gz == NULL || gz->write)
+ return 0;
+ if (gz->err)
+ return 0;
+ strm = &(gz->strm);
+ strm->next_out = (void *)buf;
+ strm->avail_out = len;
+ do {
+ got = fread(in, 1, 1, gz->file);
+ if (got == 0)
+ break;
+ strm->next_in = in;
+ strm->avail_in = 1;
+ ret = inflate(strm, Z_NO_FLUSH);
+ if (ret == Z_DATA_ERROR) {
+ gz->err = Z_DATA_ERROR;
+ gz->msg = strm->msg;
+ return 0;
+ }
+ if (ret == Z_STREAM_END)
+ inflateReset(strm);
+ } while (strm->avail_out);
+ return len - strm->avail_out;
+}
+
+int gzclose OF((gzFile));
+
+int gzclose(gz)
+ gzFile gz;
+{
+ z_stream *strm;
+ unsigned char out[BUFLEN];
+
+ if (gz == NULL)
+ return Z_STREAM_ERROR;
+ strm = &(gz->strm);
+ if (gz->write) {
+ strm->next_in = Z_NULL;
+ strm->avail_in = 0;
+ do {
+ strm->next_out = out;
+ strm->avail_out = BUFLEN;
+ (void)deflate(strm, Z_FINISH);
+ fwrite(out, 1, BUFLEN - strm->avail_out, gz->file);
+ } while (strm->avail_out == 0);
+ deflateEnd(strm);
+ }
+ else
+ inflateEnd(strm);
+ fclose(gz->file);
+ free(gz);
+ return Z_OK;
+}
+
+const char *gzerror OF((gzFile, int *));
+
+const char *gzerror(gz, err)
+ gzFile gz;
+ int *err;
+{
+ *err = gz->err;
+ return gz->msg;
+}
+
+#endif
+
char *prog;
void error OF((const char *msg));
diff --git a/lib/libz/trees.c b/lib/libz/trees.c
index 56e9bb1..8c32b21 100644
--- a/lib/libz/trees.c
+++ b/lib/libz/trees.c
@@ -1,5 +1,5 @@
/* trees.c -- output deflated data using Huffman coding
- * Copyright (C) 1995-2010 Jean-loup Gailly
+ * Copyright (C) 1995-2012 Jean-loup Gailly
* detect_data_type() function provided freely by Cosmin Truta, 2006
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@@ -74,11 +74,6 @@ local const uch bl_order[BL_CODES]
* probability, to avoid transmitting the lengths for unused bit length codes.
*/
-#define Buf_size (8 * 2*sizeof(char))
-/* Number of bits used within bi_buf. (bi_buf might be implemented on
- * more than 16 bits on some systems.)
- */
-
/* ===========================================================================
* Local data. These are initialized only once.
*/
@@ -399,7 +394,6 @@ void ZLIB_INTERNAL _tr_init(s)
s->bi_buf = 0;
s->bi_valid = 0;
- s->last_eob_len = 8; /* enough lookahead for inflate */
#ifdef DEBUG
s->compressed_len = 0L;
s->bits_sent = 0L;
@@ -883,15 +877,17 @@ void ZLIB_INTERNAL _tr_stored_block(s, buf, stored_len, last)
}
/* ===========================================================================
+ * Flush the bits in the bit buffer to pending output (leaves at most 7 bits)
+ */
+void ZLIB_INTERNAL _tr_flush_bits(s)
+ deflate_state *s;
+{
+ bi_flush(s);
+}
+
+/* ===========================================================================
* Send one empty static block to give enough lookahead for inflate.
* This takes 10 bits, of which 7 may remain in the bit buffer.
- * The current inflate code requires 9 bits of lookahead. If the
- * last two codes for the previous block (real code plus EOB) were coded
- * on 5 bits or less, inflate may have only 5+3 bits of lookahead to decode
- * the last real code. In this case we send two empty static blocks instead
- * of one. (There are no problems if the previous block is stored or fixed.)
- * To simplify the code, we assume the worst case of last real code encoded
- * on one bit only.
*/
void ZLIB_INTERNAL _tr_align(s)
deflate_state *s;
@@ -902,20 +898,6 @@ void ZLIB_INTERNAL _tr_align(s)
s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
#endif
bi_flush(s);
- /* Of the 10 bits for the empty block, we have already sent
- * (10 - bi_valid) bits. The lookahead for the last real code (before
- * the EOB of the previous block) was thus at least one plus the length
- * of the EOB plus what we have just sent of the empty static block.
- */
- if (1 + s->last_eob_len + 10 - s->bi_valid < 9) {
- send_bits(s, STATIC_TREES<<1, 3);
- send_code(s, END_BLOCK, static_ltree);
-#ifdef DEBUG
- s->compressed_len += 10L;
-#endif
- bi_flush(s);
- }
- s->last_eob_len = 7;
}
/* ===========================================================================
@@ -1118,7 +1100,6 @@ local void compress_block(s, ltree, dtree)
} while (lx < s->last_lit);
send_code(s, END_BLOCK, ltree);
- s->last_eob_len = ltree[END_BLOCK].Len;
}
/* ===========================================================================
@@ -1226,7 +1207,6 @@ local void copy_block(s, buf, len, header)
int header; /* true if block header must be written */
{
bi_windup(s); /* align on byte boundary */
- s->last_eob_len = 8; /* enough lookahead for inflate */
if (header) {
put_short(s, (ush)len);
diff --git a/lib/libz/zconf.h b/lib/libz/zconf.h
index 4efd6b2..a6f6b7e 100644
--- a/lib/libz/zconf.h
+++ b/lib/libz/zconf.h
@@ -1,5 +1,5 @@
/* zconf.h -- configuration of the zlib compression library
- * Copyright (C) 1995-2010 Jean-loup Gailly.
+ * Copyright (C) 1995-2012 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@@ -15,6 +15,7 @@
* this permanently in zconf.h using "./configure --zprefix".
*/
#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */
+# define Z_PREFIX_SET
/* all linked symbols */
# define _dist_code z__dist_code
@@ -27,9 +28,11 @@
# define adler32 z_adler32
# define adler32_combine z_adler32_combine
# define adler32_combine64 z_adler32_combine64
-# define compress z_compress
-# define compress2 z_compress2
-# define compressBound z_compressBound
+# ifndef Z_SOLO
+# define compress z_compress
+# define compress2 z_compress2
+# define compressBound z_compressBound
+# endif
# define crc32 z_crc32
# define crc32_combine z_crc32_combine
# define crc32_combine64 z_crc32_combine64
@@ -40,44 +43,52 @@
# define deflateInit2_ z_deflateInit2_
# define deflateInit_ z_deflateInit_
# define deflateParams z_deflateParams
+# define deflatePending z_deflatePending
# define deflatePrime z_deflatePrime
# define deflateReset z_deflateReset
+# define deflateResetKeep z_deflateResetKeep
# define deflateSetDictionary z_deflateSetDictionary
# define deflateSetHeader z_deflateSetHeader
# define deflateTune z_deflateTune
# define deflate_copyright z_deflate_copyright
# define get_crc_table z_get_crc_table
-# define gz_error z_gz_error
-# define gz_intmax z_gz_intmax
-# define gz_strwinerror z_gz_strwinerror
-# define gzbuffer z_gzbuffer
-# define gzclearerr z_gzclearerr
-# define gzclose z_gzclose
-# define gzclose_r z_gzclose_r
-# define gzclose_w z_gzclose_w
-# define gzdirect z_gzdirect
-# define gzdopen z_gzdopen
-# define gzeof z_gzeof
-# define gzerror z_gzerror
-# define gzflush z_gzflush
-# define gzgetc z_gzgetc
-# define gzgets z_gzgets
-# define gzoffset z_gzoffset
-# define gzoffset64 z_gzoffset64
-# define gzopen z_gzopen
-# define gzopen64 z_gzopen64
-# define gzprintf z_gzprintf
-# define gzputc z_gzputc
-# define gzputs z_gzputs
-# define gzread z_gzread
-# define gzrewind z_gzrewind
-# define gzseek z_gzseek
-# define gzseek64 z_gzseek64
-# define gzsetparams z_gzsetparams
-# define gztell z_gztell
-# define gztell64 z_gztell64
-# define gzungetc z_gzungetc
-# define gzwrite z_gzwrite
+# ifndef Z_SOLO
+# define gz_error z_gz_error
+# define gz_intmax z_gz_intmax
+# define gz_strwinerror z_gz_strwinerror
+# define gzbuffer z_gzbuffer
+# define gzclearerr z_gzclearerr
+# define gzclose z_gzclose
+# define gzclose_r z_gzclose_r
+# define gzclose_w z_gzclose_w
+# define gzdirect z_gzdirect
+# define gzdopen z_gzdopen
+# define gzeof z_gzeof
+# define gzerror z_gzerror
+# define gzflush z_gzflush
+# define gzgetc z_gzgetc
+# define gzgetc_ z_gzgetc_
+# define gzgets z_gzgets
+# define gzoffset z_gzoffset
+# define gzoffset64 z_gzoffset64
+# define gzopen z_gzopen
+# define gzopen64 z_gzopen64
+# ifdef _WIN32
+# define gzopen_w z_gzopen_w
+# endif
+# define gzprintf z_gzprintf
+# define gzputc z_gzputc
+# define gzputs z_gzputs
+# define gzread z_gzread
+# define gzrewind z_gzrewind
+# define gzseek z_gzseek
+# define gzseek64 z_gzseek64
+# define gzsetparams z_gzsetparams
+# define gztell z_gztell
+# define gztell64 z_gztell64
+# define gzungetc z_gzungetc
+# define gzwrite z_gzwrite
+# endif
# define inflate z_inflate
# define inflateBack z_inflateBack
# define inflateBackEnd z_inflateBackEnd
@@ -95,13 +106,18 @@
# define inflateSync z_inflateSync
# define inflateSyncPoint z_inflateSyncPoint
# define inflateUndermine z_inflateUndermine
+# define inflateResetKeep z_inflateResetKeep
# define inflate_copyright z_inflate_copyright
# define inflate_fast z_inflate_fast
# define inflate_table z_inflate_table
-# define uncompress z_uncompress
+# ifndef Z_SOLO
+# define uncompress z_uncompress
+# endif
# define zError z_zError
-# define zcalloc z_zcalloc
-# define zcfree z_zcfree
+# ifndef Z_SOLO
+# define zcalloc z_zcalloc
+# define zcfree z_zcfree
+# endif
# define zlibCompileFlags z_zlibCompileFlags
# define zlibVersion z_zlibVersion
@@ -111,7 +127,9 @@
# define alloc_func z_alloc_func
# define charf z_charf
# define free_func z_free_func
-# define gzFile z_gzFile
+# ifndef Z_SOLO
+# define gzFile z_gzFile
+# endif
# define gz_header z_gz_header
# define gz_headerp z_gz_headerp
# define in_func z_in_func
@@ -197,6 +215,12 @@
# endif
#endif
+#if defined(ZLIB_CONST) && !defined(z_const)
+# define z_const const
+#else
+# define z_const
+#endif
+
/* Some Mac compilers merge all .h files incorrectly: */
#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
# define NO_DUMMY_DECL
@@ -243,6 +267,14 @@
# endif
#endif
+#ifndef Z_ARG /* function prototypes for stdarg */
+# if defined(STDC) || defined(Z_HAVE_STDARG_H)
+# define Z_ARG(args) args
+# else
+# define Z_ARG(args) ()
+# endif
+#endif
+
/* The following definitions for FAR are needed only for MSDOS mixed
* model programming (small or medium model with some far allocations).
* This was tested only with MSC; for other MSDOS compilers you may have
@@ -356,12 +388,45 @@ typedef uLong FAR uLongf;
typedef Byte *voidp;
#endif
+/* ./configure may #define Z_U4 here */
+
+#if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC)
+# include <limits.h>
+# if (UINT_MAX == 0xffffffffUL)
+# define Z_U4 unsigned
+# else
+# if (ULONG_MAX == 0xffffffffUL)
+# define Z_U4 unsigned long
+# else
+# if (USHRT_MAX == 0xffffffffUL)
+# define Z_U4 unsigned short
+# endif
+# endif
+# endif
+#endif
+
+#ifdef Z_U4
+ typedef Z_U4 z_crc_t;
+#else
+ typedef unsigned long z_crc_t;
+#endif
+
#if 0 /* was set to #if 0 by ./configure */
# define Z_HAVE_UNISTD_H
#endif
+#ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */
+# define Z_HAVE_STDARG_H
+#endif
+
#ifdef STDC
-# include <sys/types.h> /* for off_t */
+# ifndef Z_SOLO
+# include <sys/types.h> /* for off_t */
+# endif
+#endif
+
+#ifdef _WIN32
+# include <stddef.h> /* for wchar_t */
#endif
/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and
@@ -370,21 +435,38 @@ typedef uLong FAR uLongf;
* both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as
* equivalently requesting no 64-bit operations
*/
-#if -_LARGEFILE64_SOURCE - -1 == 1
+#if defined(LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1
# undef _LARGEFILE64_SOURCE
#endif
-#if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE)
-# include <unistd.h> /* for SEEK_* and off_t */
-# ifdef VMS
-# include <unixio.h> /* for off_t */
-# endif
-# ifndef z_off_t
-# define z_off_t off_t
+#if defined(__WATCOMC__) && !defined(Z_HAVE_UNISTD_H)
+# define Z_HAVE_UNISTD_H
+#endif
+#ifndef Z_SOLO
+# if defined(Z_HAVE_UNISTD_H) || defined(LARGEFILE64_SOURCE)
+# include <unistd.h> /* for SEEK_*, off_t, and _LFS64_LARGEFILE */
+# ifdef VMS
+# include <unixio.h> /* for off_t */
+# endif
+# ifndef z_off_t
+# define z_off_t off_t
+# endif
# endif
#endif
-#ifndef SEEK_SET
+#if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0
+# define Z_LFS64
+#endif
+
+#if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64)
+# define Z_LARGE64
+#endif
+
+#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64)
+# define Z_WANT64
+#endif
+
+#if !defined(SEEK_SET) && !defined(Z_SOLO)
# define SEEK_SET 0 /* Seek from beginning of file. */
# define SEEK_CUR 1 /* Seek from current position. */
# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
@@ -402,18 +484,14 @@ typedef uLong FAR uLongf;
# define z_off_t long
#endif
-#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
+#if !defined(_WIN32) && defined(Z_LARGE64)
# define z_off64_t off64_t
#else
-# define z_off64_t z_off_t
-#endif
-
-#if defined(__OS400__)
-# define NO_vsnprintf
-#endif
-
-#if defined(__MVS__)
-# define NO_vsnprintf
+# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO)
+# define z_off64_t __int64
+# else
+# define z_off64_t z_off_t
+# endif
#endif
/* MVS linker does not support external names larger than 8 bytes */
diff --git a/lib/libz/zlib.3 b/lib/libz/zlib.3
index 27adc4c..79d3402 100644
--- a/lib/libz/zlib.3
+++ b/lib/libz/zlib.3
@@ -1,4 +1,4 @@
-.TH ZLIB 3 "19 Apr 2010"
+.TH ZLIB 3 "2 May 2012"
.SH NAME
zlib \- compression/decompression library
.SH SYNOPSIS
@@ -36,9 +36,9 @@ All functions of the compression library are documented in the file
.IR zlib.h .
The distribution source includes examples of use of the library
in the files
-.I example.c
+.I test/example.c
and
-.IR minigzip.c,
+.IR test/minigzip.c,
as well as other examples in the
.IR examples/
directory.
@@ -65,7 +65,7 @@ A Python interface to
written by A.M. Kuchling (amk@magnet.com),
is available in Python 1.5 and later versions:
.IP
-http://www.python.org/doc/lib/module-zlib.html
+http://docs.python.org/library/zlib.html
.LP
.I zlib
is built into
@@ -95,11 +95,11 @@ http://zlib.net/
The data format used by the zlib library is described by RFC
(Request for Comments) 1950 to 1952 in the files:
.IP
-http://www.ietf.org/rfc/rfc1950.txt (for the zlib header and trailer format)
+http://tools.ietf.org/html/rfc1950 (for the zlib header and trailer format)
.br
-http://www.ietf.org/rfc/rfc1951.txt (for the deflate compressed data format)
+http://tools.ietf.org/html/rfc1951 (for the deflate compressed data format)
.br
-http://www.ietf.org/rfc/rfc1952.txt (for the gzip header and trailer format)
+http://tools.ietf.org/html/rfc1952 (for the gzip header and trailer format)
.LP
Mark Nelson wrote an article about
.I zlib
@@ -125,8 +125,8 @@ before asking for help.
Send questions and/or comments to zlib@gzip.org,
or (for the Windows DLL version) to Gilles Vollant (info@winimage.com).
.SH AUTHORS
-Version 1.2.5
-Copyright (C) 1995-2010 Jean-loup Gailly (jloup@gzip.org)
+Version 1.2.7
+Copyright (C) 1995-2012 Jean-loup Gailly (jloup@gzip.org)
and Mark Adler (madler@alumni.caltech.edu).
.LP
This software is provided "as-is,"
diff --git a/lib/libz/zlib.h b/lib/libz/zlib.h
index bfbba83..3edf3ac 100644
--- a/lib/libz/zlib.h
+++ b/lib/libz/zlib.h
@@ -1,7 +1,7 @@
/* zlib.h -- interface of the 'zlib' general purpose compression library
- version 1.2.5, April 19th, 2010
+ version 1.2.7, May 2nd, 2012
- Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler
+ Copyright (C) 1995-2012 Jean-loup Gailly and Mark Adler
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -24,8 +24,8 @@
The data format used by the zlib library is described by RFCs (Request for
- Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt
- (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
+ Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950
+ (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format).
*/
#ifndef ZLIB_H
@@ -37,11 +37,11 @@
extern "C" {
#endif
-#define ZLIB_VERSION "1.2.5"
-#define ZLIB_VERNUM 0x1250
+#define ZLIB_VERSION "1.2.7"
+#define ZLIB_VERNUM 0x1270
#define ZLIB_VER_MAJOR 1
#define ZLIB_VER_MINOR 2
-#define ZLIB_VER_REVISION 5
+#define ZLIB_VER_REVISION 7
#define ZLIB_VER_SUBREVISION 0
/*
@@ -83,15 +83,15 @@ typedef void (*free_func) OF((voidpf opaque, voidpf address));
struct internal_state;
typedef struct z_stream_s {
- Bytef *next_in; /* next input byte */
+ z_const Bytef *next_in; /* next input byte */
uInt avail_in; /* number of bytes available at next_in */
- uLong total_in; /* total nb of input bytes read so far */
+ uLong total_in; /* total number of input bytes read so far */
Bytef *next_out; /* next output byte should be put there */
uInt avail_out; /* remaining free space at next_out */
- uLong total_out; /* total nb of bytes output so far */
+ uLong total_out; /* total number of bytes output so far */
- char *msg; /* last error message, NULL if no error */
+ z_const char *msg; /* last error message, NULL if no error */
struct internal_state FAR *state; /* not visible by applications */
alloc_func zalloc; /* used to allocate the internal state */
@@ -327,8 +327,9 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
Z_FINISH can be used immediately after deflateInit if all the compression
is to be done in a single step. In this case, avail_out must be at least the
- value returned by deflateBound (see below). If deflate does not return
- Z_STREAM_END, then it must be called again as described above.
+ value returned by deflateBound (see below). Then deflate is guaranteed to
+ return Z_STREAM_END. If not enough output space is provided, deflate will
+ not return Z_STREAM_END, and it must be called again as described above.
deflate() sets strm->adler to the adler32 checksum of all input read
so far (that is, total_in bytes).
@@ -451,23 +452,29 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
error. However if all decompression is to be performed in a single step (a
single call of inflate), the parameter flush should be set to Z_FINISH. In
this case all pending input is processed and all pending output is flushed;
- avail_out must be large enough to hold all the uncompressed data. (The size
- of the uncompressed data may have been saved by the compressor for this
- purpose.) The next operation on this stream must be inflateEnd to deallocate
- the decompression state. The use of Z_FINISH is never required, but can be
- used to inform inflate that a faster approach may be used for the single
- inflate() call.
+ avail_out must be large enough to hold all of the uncompressed data for the
+ operation to complete. (The size of the uncompressed data may have been
+ saved by the compressor for this purpose.) The use of Z_FINISH is not
+ required to perform an inflation in one step. However it may be used to
+ inform inflate that a faster approach can be used for the single inflate()
+ call. Z_FINISH also informs inflate to not maintain a sliding window if the
+ stream completes, which reduces inflate's memory footprint. If the stream
+ does not complete, either because not all of the stream is provided or not
+ enough output space is provided, then a sliding window will be allocated and
+ inflate() can be called again to continue the operation as if Z_NO_FLUSH had
+ been used.
In this implementation, inflate() always flushes as much output as
possible to the output buffer, and always uses the faster approach on the
- first call. So the only effect of the flush parameter in this implementation
- is on the return value of inflate(), as noted below, or when it returns early
- because Z_BLOCK or Z_TREES is used.
+ first call. So the effects of the flush parameter in this implementation are
+ on the return value of inflate() as noted below, when inflate() returns early
+ when Z_BLOCK or Z_TREES is used, and when inflate() avoids the allocation of
+ memory for a sliding window when Z_FINISH is used.
If a preset dictionary is needed after this call (see inflateSetDictionary
- below), inflate sets strm->adler to the adler32 checksum of the dictionary
+ below), inflate sets strm->adler to the Adler-32 checksum of the dictionary
chosen by the compressor and returns Z_NEED_DICT; otherwise it sets
- strm->adler to the adler32 checksum of all output produced so far (that is,
+ strm->adler to the Adler-32 checksum of all output produced so far (that is,
total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described
below. At the end of the stream, inflate() checks that its computed adler32
checksum is equal to that saved by the compressor and returns Z_STREAM_END
@@ -478,7 +485,9 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
initializing with inflateInit2(). Any information contained in the gzip
header is not retained, so applications that need that information should
instead use raw inflate, see inflateInit2() below, or inflateBack() and
- perform their own processing of the gzip header and trailer.
+ perform their own processing of the gzip header and trailer. When processing
+ gzip-wrapped deflate data, strm->adler32 is set to the CRC-32 of the output
+ producted so far. The CRC-32 is checked against the gzip trailer.
inflate() returns Z_OK if some progress has been made (more input processed
or more output produced), Z_STREAM_END if the end of the compressed data has
@@ -580,10 +589,15 @@ ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
uInt dictLength));
/*
Initializes the compression dictionary from the given byte sequence
- without producing any compressed output. This function must be called
- immediately after deflateInit, deflateInit2 or deflateReset, before any call
- of deflate. The compressor and decompressor must use exactly the same
- dictionary (see inflateSetDictionary).
+ without producing any compressed output. When using the zlib format, this
+ function must be called immediately after deflateInit, deflateInit2 or
+ deflateReset, and before any call of deflate. When doing raw deflate, this
+ function must be called either before any call of deflate, or immediately
+ after the completion of a deflate block, i.e. after all input has been
+ consumed and all output has been delivered when using any of the flush
+ options Z_BLOCK, Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, or Z_FULL_FLUSH. The
+ compressor and decompressor must use exactly the same dictionary (see
+ inflateSetDictionary).
The dictionary should consist of strings (byte sequences) that are likely
to be encountered later in the data to be compressed, with the most commonly
@@ -610,8 +624,8 @@ ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is
inconsistent (for example if deflate has already been called for this stream
- or if the compression method is bsort). deflateSetDictionary does not
- perform any compression: this will be done by deflate().
+ or if not at a block boundary for raw deflate). deflateSetDictionary does
+ not perform any compression: this will be done by deflate().
*/
ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
@@ -688,8 +702,28 @@ ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
deflation of sourceLen bytes. It must be called after deflateInit() or
deflateInit2(), and after deflateSetHeader(), if used. This would be used
to allocate an output buffer for deflation in a single pass, and so would be
- called before deflate().
-*/
+ called before deflate(). If that first deflate() call is provided the
+ sourceLen input bytes, an output buffer allocated to the size returned by
+ deflateBound(), and the flush value Z_FINISH, then deflate() is guaranteed
+ to return Z_STREAM_END. Note that it is possible for the compressed size to
+ be larger than the value returned by deflateBound() if flush options other
+ than Z_FINISH or Z_NO_FLUSH are used.
+*/
+
+ZEXTERN int ZEXPORT deflatePending OF((z_streamp strm,
+ unsigned *pending,
+ int *bits));
+/*
+ deflatePending() returns the number of bytes and bits of output that have
+ been generated, but not yet provided in the available output. The bytes not
+ provided would be due to the available output space having being consumed.
+ The number of bits of output not provided are between 0 and 7, where they
+ await more bits to join them in order to fill out a full byte. If pending
+ or bits are Z_NULL, then those values are not set.
+
+ deflatePending returns Z_OK if success, or Z_STREAM_ERROR if the source
+ stream state was inconsistent.
+ */
ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
int bits,
@@ -703,8 +737,9 @@ ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
than or equal to 16, and that many of the least significant bits of value
will be inserted in the output.
- deflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
- stream state was inconsistent.
+ deflatePrime returns Z_OK if success, Z_BUF_ERROR if there was not enough
+ room in the internal buffer to insert the bits, or Z_STREAM_ERROR if the
+ source stream state was inconsistent.
*/
ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
@@ -790,10 +825,11 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
if that call returned Z_NEED_DICT. The dictionary chosen by the compressor
can be determined from the adler32 value returned by that call of inflate.
The compressor and decompressor must use exactly the same dictionary (see
- deflateSetDictionary). For raw inflate, this function can be called
- immediately after inflateInit2() or inflateReset() and before any call of
- inflate() to set the dictionary. The application must insure that the
- dictionary that was used for compression is provided.
+ deflateSetDictionary). For raw inflate, this function can be called at any
+ time to set the dictionary. If the provided dictionary is smaller than the
+ window and there is already data in the window, then the provided dictionary
+ will amend what's there. The application must insure that the dictionary
+ that was used for compression is provided.
inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is
@@ -805,17 +841,21 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
/*
- Skips invalid compressed data until a full flush point (see above the
- description of deflate with Z_FULL_FLUSH) can be found, or until all
+ Skips invalid compressed data until a possible full flush point (see above
+ for the description of deflate with Z_FULL_FLUSH) can be found, or until all
available input is skipped. No output is provided.
- inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR
- if no more input was provided, Z_DATA_ERROR if no flush point has been
- found, or Z_STREAM_ERROR if the stream structure was inconsistent. In the
- success case, the application may save the current current value of total_in
- which indicates where valid compressed data was found. In the error case,
- the application may repeatedly call inflateSync, providing more input each
- time, until success or end of the input data.
+ inflateSync searches for a 00 00 FF FF pattern in the compressed data.
+ All full flush points have this pattern, but not all occurences of this
+ pattern are full flush points.
+
+ inflateSync returns Z_OK if a possible full flush point has been found,
+ Z_BUF_ERROR if no more input was provided, Z_DATA_ERROR if no flush point
+ has been found, or Z_STREAM_ERROR if the stream structure was inconsistent.
+ In the success case, the application may save the current current value of
+ total_in which indicates where valid compressed data was found. In the
+ error case, the application may repeatedly call inflateSync, providing more
+ input each time, until success or end of the input data.
*/
ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
@@ -962,7 +1002,7 @@ ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits,
See inflateBack() for the usage of these routines.
inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of
- the paramaters are invalid, Z_MEM_ERROR if the internal state could not be
+ the parameters are invalid, Z_MEM_ERROR if the internal state could not be
allocated, or Z_VERSION_ERROR if the version of the library does not match
the version of the header file.
*/
@@ -1088,6 +1128,7 @@ ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
27-31: 0 (reserved)
*/
+#ifndef Z_SOLO
/* utility functions */
@@ -1149,10 +1190,11 @@ ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
enough memory, Z_BUF_ERROR if there was not enough room in the output
- buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete.
+ buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. In
+ the case where there is not enough room, uncompress() will fill the output
+ buffer with the uncompressed data up to that point.
*/
-
/* gzip file access functions */
/*
@@ -1162,7 +1204,7 @@ ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
wrapper, documented in RFC 1952, wrapped around a deflate stream.
*/
-typedef voidp gzFile; /* opaque gzip file descriptor */
+typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */
/*
ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
@@ -1172,13 +1214,28 @@ ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
a strategy: 'f' for filtered data as in "wb6f", 'h' for Huffman-only
compression as in "wb1h", 'R' for run-length encoding as in "wb1R", or 'F'
for fixed code compression as in "wb9F". (See the description of
- deflateInit2 for more information about the strategy parameter.) Also "a"
- can be used instead of "w" to request that the gzip stream that will be
- written be appended to the file. "+" will result in an error, since reading
- and writing to the same gzip file is not supported.
+ deflateInit2 for more information about the strategy parameter.) 'T' will
+ request transparent writing or appending with no compression and not using
+ the gzip format.
+
+ "a" can be used instead of "w" to request that the gzip stream that will
+ be written be appended to the file. "+" will result in an error, since
+ reading and writing to the same gzip file is not supported. The addition of
+ "x" when writing will create the file exclusively, which fails if the file
+ already exists. On systems that support it, the addition of "e" when
+ reading or writing will set the flag to close the file on an execve() call.
+
+ These functions, as well as gzip, will read and decode a sequence of gzip
+ streams in a file. The append function of gzopen() can be used to create
+ such a file. (Also see gzflush() for another way to do this.) When
+ appending, gzopen does not test whether the file begins with a gzip stream,
+ nor does it look for the end of the gzip streams to begin appending. gzopen
+ will simply append a gzip stream to the existing file.
gzopen can be used to read a file which is not in gzip format; in this
- case gzread will directly read from the file without decompression.
+ case gzread will directly read from the file without decompression. When
+ reading, this will be detected automatically by looking for the magic two-
+ byte gzip header.
gzopen returns NULL if the file could not be opened, if there was
insufficient memory to allocate the gzFile state, or if an invalid mode was
@@ -1197,7 +1254,11 @@ ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor
fd. If you want to keep fd open, use fd = dup(fd_keep); gz = gzdopen(fd,
mode);. The duplicated descriptor should be saved to avoid a leak, since
- gzdopen does not close fd if it fails.
+ gzdopen does not close fd if it fails. If you are using fileno() to get the
+ file descriptor from a FILE *, then you will have to use dup() to avoid
+ double-close()ing the file descriptor. Both gzclose() and fclose() will
+ close the associated file descriptor, so they need to have different file
+ descriptors.
gzdopen returns NULL if there was insufficient memory to allocate the
gzFile state, if an invalid mode was specified (an 'r', 'w', or 'a' was not
@@ -1235,14 +1296,26 @@ ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
/*
Reads the given number of uncompressed bytes from the compressed file. If
- the input file was not in gzip format, gzread copies the given number of
- bytes into the buffer.
+ the input file is not in gzip format, gzread copies the given number of
+ bytes into the buffer directly from the file.
After reaching the end of a gzip stream in the input, gzread will continue
- to read, looking for another gzip stream, or failing that, reading the rest
- of the input file directly without decompression. The entire input file
- will be read if gzread is called until it returns less than the requested
- len.
+ to read, looking for another gzip stream. Any number of gzip streams may be
+ concatenated in the input file, and will all be decompressed by gzread().
+ If something other than a gzip stream is encountered after a gzip stream,
+ that remaining trailing garbage is ignored (and no error is returned).
+
+ gzread can be used to read a gzip file that is being concurrently written.
+ Upon reaching the end of the input, gzread will return with the available
+ data. If the error code returned by gzerror is Z_OK or Z_BUF_ERROR, then
+ gzclearerr can be used to clear the end of file indicator in order to permit
+ gzread to be tried again. Z_OK indicates that a gzip stream was completed
+ on the last gzread. Z_BUF_ERROR indicates that the input file ended in the
+ middle of a gzip stream. Note that gzread does not return -1 in the event
+ of an incomplete gzip stream. This error is deferred until gzclose(), which
+ will return Z_BUF_ERROR if the last gzread ended in the middle of a gzip
+ stream. Alternatively, gzerror can be used before gzclose to detect this
+ case.
gzread returns the number of uncompressed bytes actually read, less than
len for end of file, or -1 for error.
@@ -1256,7 +1329,7 @@ ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
error.
*/
-ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
+ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...));
/*
Converts, formats, and writes the arguments to the compressed file under
control of the format string, as in fprintf. gzprintf returns the number of
@@ -1301,7 +1374,10 @@ ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
/*
Reads one byte from the compressed file. gzgetc returns this byte or -1
- in case of end of file or error.
+ in case of end of file or error. This is implemented as a macro for speed.
+ As such, it does not do all of the checking the other functions do. I.e.
+ it does not check to see if file is NULL, nor whether the structure file
+ points to has been clobbered or not.
*/
ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
@@ -1397,9 +1473,7 @@ ZEXTERN int ZEXPORT gzeof OF((gzFile file));
ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
/*
Returns true (1) if file is being copied directly while reading, or false
- (0) if file is a gzip stream being decompressed. This state can change from
- false to true while reading the input file if the end of a gzip stream is
- reached, but is followed by data that is not another gzip stream.
+ (0) if file is a gzip stream being decompressed.
If the input file is empty, gzdirect() will return true, since the input
does not contain a gzip stream.
@@ -1408,6 +1482,13 @@ ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
cause buffers to be allocated to allow reading the file to determine if it
is a gzip file. Therefore if gzbuffer() is used, it should be called before
gzdirect().
+
+ When writing, gzdirect() returns true (1) if transparent writing was
+ requested ("wT" for the gzopen() mode), or false (0) otherwise. (Note:
+ gzdirect() is not needed when writing. Transparent writing must be
+ explicitly requested, so the application already knows the answer. When
+ linking statically, using gzdirect() will include all of the zlib code for
+ gzip file reading and decompression, which may not be desired.)
*/
ZEXTERN int ZEXPORT gzclose OF((gzFile file));
@@ -1419,7 +1500,8 @@ ZEXTERN int ZEXPORT gzclose OF((gzFile file));
must not be called more than once on the same allocation.
gzclose will return Z_STREAM_ERROR if file is not valid, Z_ERRNO on a
- file operation error, or Z_OK on success.
+ file operation error, Z_MEM_ERROR if out of memory, Z_BUF_ERROR if the
+ last read ended in the middle of a gzip stream, or Z_OK on success.
*/
ZEXTERN int ZEXPORT gzclose_r OF((gzFile file));
@@ -1457,6 +1539,7 @@ ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
file that is being written concurrently.
*/
+#endif /* !Z_SOLO */
/* checksum functions */
@@ -1492,16 +1575,17 @@ ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
Combine two Adler-32 checksums into one. For two sequences of bytes, seq1
and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for
each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of
- seq1 and seq2 concatenated, requiring only adler1, adler2, and len2.
+ seq1 and seq2 concatenated, requiring only adler1, adler2, and len2. Note
+ that the z_off_t type (like off_t) is a signed integer. If len2 is
+ negative, the result has no meaning or utility.
*/
ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
/*
Update a running CRC-32 with the bytes buf[0..len-1] and return the
updated CRC-32. If buf is Z_NULL, this function returns the required
- initial value for the for the crc. Pre- and post-conditioning (one's
- complement) is performed within this function so it shouldn't be done by the
- application.
+ initial value for the crc. Pre- and post-conditioning (one's complement) is
+ performed within this function so it shouldn't be done by the application.
Usage example:
@@ -1544,17 +1628,42 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
const char *version,
int stream_size));
#define deflateInit(strm, level) \
- deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
+ deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream))
#define inflateInit(strm) \
- inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
+ inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream))
#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
- (strategy), ZLIB_VERSION, sizeof(z_stream))
+ (strategy), ZLIB_VERSION, (int)sizeof(z_stream))
#define inflateInit2(strm, windowBits) \
- inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
+ inflateInit2_((strm), (windowBits), ZLIB_VERSION, \
+ (int)sizeof(z_stream))
#define inflateBackInit(strm, windowBits, window) \
inflateBackInit_((strm), (windowBits), (window), \
- ZLIB_VERSION, sizeof(z_stream))
+ ZLIB_VERSION, (int)sizeof(z_stream))
+
+#ifndef Z_SOLO
+
+/* gzgetc() macro and its supporting function and exposed data structure. Note
+ * that the real internal state is much larger than the exposed structure.
+ * This abbreviated structure exposes just enough for the gzgetc() macro. The
+ * user should not mess with these exposed elements, since their names or
+ * behavior could change in the future, perhaps even capriciously. They can
+ * only be used by the gzgetc() macro. You have been warned.
+ */
+struct gzFile_s {
+ unsigned have;
+ unsigned char *next;
+ z_off64_t pos;
+};
+ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */
+#ifdef Z_PREFIX_SET
+# undef z_gzgetc
+# define z_gzgetc(g) \
+ ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g))
+#else
+# define gzgetc(g) \
+ ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g))
+#endif
/* provide 64-bit offset functions if _LARGEFILE64_SOURCE defined, and/or
* change the regular functions to 64 bits if _FILE_OFFSET_BITS is 64 (if
@@ -1562,7 +1671,7 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
* functions are changed to 64 bits) -- in case these are set on systems
* without large file support, _LFS64_LARGEFILE must also be true
*/
-#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
+#ifdef Z_LARGE64
ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int));
ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile));
@@ -1571,14 +1680,23 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off64_t));
#endif
-#if !defined(ZLIB_INTERNAL) && _FILE_OFFSET_BITS-0 == 64 && _LFS64_LARGEFILE-0
-# define gzopen gzopen64
-# define gzseek gzseek64
-# define gztell gztell64
-# define gzoffset gzoffset64
-# define adler32_combine adler32_combine64
-# define crc32_combine crc32_combine64
-# ifdef _LARGEFILE64_SOURCE
+#if !defined(ZLIB_INTERNAL) && defined(Z_WANT64)
+# ifdef Z_PREFIX_SET
+# define z_gzopen z_gzopen64
+# define z_gzseek z_gzseek64
+# define z_gztell z_gztell64
+# define z_gzoffset z_gzoffset64
+# define z_adler32_combine z_adler32_combine64
+# define z_crc32_combine z_crc32_combine64
+# else
+# define gzopen gzopen64
+# define gzseek gzseek64
+# define gztell gztell64
+# define gzoffset gzoffset64
+# define adler32_combine adler32_combine64
+# define crc32_combine crc32_combine64
+# endif
+# ifndef Z_LARGE64
ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
ZEXTERN z_off_t ZEXPORT gzseek64 OF((gzFile, z_off_t, int));
ZEXTERN z_off_t ZEXPORT gztell64 OF((gzFile));
@@ -1595,6 +1713,13 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t));
#endif
+#else /* Z_SOLO */
+
+ ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t));
+ ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t));
+
+#endif /* !Z_SOLO */
+
/* hack for buggy compilers */
#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
struct internal_state {int dummy;};
@@ -1603,8 +1728,14 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
/* undocumented functions */
ZEXTERN const char * ZEXPORT zError OF((int));
ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp));
-ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
+ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table OF((void));
ZEXTERN int ZEXPORT inflateUndermine OF((z_streamp, int));
+ZEXTERN int ZEXPORT inflateResetKeep OF((z_streamp));
+ZEXTERN int ZEXPORT deflateResetKeep OF((z_streamp));
+#if defined(_WIN32) && !defined(Z_SOLO)
+ZEXTERN gzFile ZEXPORT gzopen_w OF((const wchar_t *path,
+ const char *mode));
+#endif
#ifdef __cplusplus
}
diff --git a/lib/libz/zopen.c b/lib/libz/zopen.c
index 025899f..822a5e1 100644
--- a/lib/libz/zopen.c
+++ b/lib/libz/zopen.c
@@ -3,7 +3,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libz/zopen.c 84228 2001-09-30 22:39:00Z dillon $");
#include <stdio.h>
#include <zlib.h>
@@ -23,6 +23,12 @@ xgzwrite(void *cookie, const char *data, int size)
return gzwrite(cookie, (void*)data, size);
}
+static int
+xgzclose(void *cookie)
+{
+ return gzclose(cookie);
+}
+
FILE *
zopen(const char *fname, const char *mode)
{
@@ -31,7 +37,7 @@ zopen(const char *fname, const char *mode)
return NULL;
if(*mode == 'r')
- return (funopen(gz, xgzread, NULL, NULL, gzclose));
+ return (funopen(gz, xgzread, NULL, NULL, xgzclose));
else
- return (funopen(gz, NULL, xgzwrite, NULL, gzclose));
+ return (funopen(gz, NULL, xgzwrite, NULL, xgzclose));
}
diff --git a/lib/libz/zutil.c b/lib/libz/zutil.c
index 898ed34..65e0d3b 100644
--- a/lib/libz/zutil.c
+++ b/lib/libz/zutil.c
@@ -1,11 +1,14 @@
/* zutil.c -- target dependent utility functions for the compression library
- * Copyright (C) 1995-2005, 2010 Jean-loup Gailly.
+ * Copyright (C) 1995-2005, 2010, 2011, 2012 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* @(#) $Id$ */
#include "zutil.h"
+#ifndef Z_SOLO
+# include "gzguts.h"
+#endif
#ifndef NO_DUMMY_DECL
struct internal_state {int dummy;}; /* for buggy compilers */
@@ -85,27 +88,27 @@ uLong ZEXPORT zlibCompileFlags()
#ifdef FASTEST
flags += 1L << 21;
#endif
-#ifdef STDC
+#if defined(STDC) || defined(Z_HAVE_STDARG_H)
# ifdef NO_vsnprintf
- flags += 1L << 25;
+ flags += 1L << 25;
# ifdef HAS_vsprintf_void
- flags += 1L << 26;
+ flags += 1L << 26;
# endif
# else
# ifdef HAS_vsnprintf_void
- flags += 1L << 26;
+ flags += 1L << 26;
# endif
# endif
#else
- flags += 1L << 24;
+ flags += 1L << 24;
# ifdef NO_snprintf
- flags += 1L << 25;
+ flags += 1L << 25;
# ifdef HAS_sprintf_void
- flags += 1L << 26;
+ flags += 1L << 26;
# endif
# else
# ifdef HAS_snprintf_void
- flags += 1L << 26;
+ flags += 1L << 26;
# endif
# endif
#endif
@@ -181,6 +184,7 @@ void ZLIB_INTERNAL zmemzero(dest, len)
}
#endif
+#ifndef Z_SOLO
#ifdef SYS16BIT
@@ -316,3 +320,5 @@ void ZLIB_INTERNAL zcfree (opaque, ptr)
}
#endif /* MY_ZCALLOC */
+
+#endif /* !Z_SOLO */
diff --git a/lib/libz/zutil.h b/lib/libz/zutil.h
index 258fa88..4e3dcc6 100644
--- a/lib/libz/zutil.h
+++ b/lib/libz/zutil.h
@@ -1,5 +1,5 @@
/* zutil.h -- internal interface and configuration of the compression library
- * Copyright (C) 1995-2010 Jean-loup Gailly.
+ * Copyright (C) 1995-2012 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@@ -13,7 +13,7 @@
#ifndef ZUTIL_H
#define ZUTIL_H
-#if ((__GNUC__-0) * 10 + __GNUC_MINOR__-0 >= 33) && !defined(NO_VIZ)
+#ifdef HAVE_HIDDEN
# define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
#else
# define ZLIB_INTERNAL
@@ -21,7 +21,7 @@
#include "zlib.h"
-#ifdef STDC
+#if defined(STDC) && !defined(Z_SOLO)
# if !(defined(_WIN32_WCE) && defined(_MSC_VER))
# include <stddef.h>
# endif
@@ -29,6 +29,10 @@
# include <stdlib.h>
#endif
+#ifdef Z_SOLO
+ typedef long ptrdiff_t; /* guess -- will be caught if guess is wrong */
+#endif
+
#ifndef local
# define local static
#endif
@@ -78,16 +82,18 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
#if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
# define OS_CODE 0x00
-# if defined(__TURBOC__) || defined(__BORLANDC__)
-# if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
- /* Allow compilation with ANSI keywords only enabled */
- void _Cdecl farfree( void *block );
- void *_Cdecl farmalloc( unsigned long nbytes );
-# else
-# include <alloc.h>
+# ifndef Z_SOLO
+# if defined(__TURBOC__) || defined(__BORLANDC__)
+# if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
+ /* Allow compilation with ANSI keywords only enabled */
+ void _Cdecl farfree( void *block );
+ void *_Cdecl farmalloc( unsigned long nbytes );
+# else
+# include <alloc.h>
+# endif
+# else /* MSC or DJGPP */
+# include <malloc.h>
# endif
-# else /* MSC or DJGPP */
-# include <malloc.h>
# endif
#endif
@@ -107,18 +113,20 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
#ifdef OS2
# define OS_CODE 0x06
-# ifdef M_I86
+# if defined(M_I86) && !defined(Z_SOLO)
# include <malloc.h>
# endif
#endif
#if defined(MACOS) || defined(TARGET_OS_MAC)
# define OS_CODE 0x07
-# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
-# include <unix.h> /* for fdopen */
-# else
-# ifndef fdopen
-# define fdopen(fd,mode) NULL /* No fdopen() */
+# ifndef Z_SOLO
+# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
+# include <unix.h> /* for fdopen */
+# else
+# ifndef fdopen
+# define fdopen(fd,mode) NULL /* No fdopen() */
+# endif
# endif
# endif
#endif
@@ -153,14 +161,14 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
# endif
#endif
-#if defined(__BORLANDC__)
+#if defined(__BORLANDC__) && !defined(MSDOS)
#pragma warn -8004
#pragma warn -8008
#pragma warn -8066
#endif
/* provide prototypes for these when building zlib without LFS */
-#if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0
+#if !defined(_WIN32) && (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0)
ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t));
ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t));
#endif
@@ -177,42 +185,7 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
/* functions */
-#if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
-# ifndef HAVE_VSNPRINTF
-# define HAVE_VSNPRINTF
-# endif
-#endif
-#if defined(__CYGWIN__)
-# ifndef HAVE_VSNPRINTF
-# define HAVE_VSNPRINTF
-# endif
-#endif
-#ifndef HAVE_VSNPRINTF
-# ifdef MSDOS
- /* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
- but for now we just assume it doesn't. */
-# define NO_vsnprintf
-# endif
-# ifdef __TURBOC__
-# define NO_vsnprintf
-# endif
-# ifdef WIN32
- /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
-# if !defined(vsnprintf) && !defined(NO_vsnprintf)
-# if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 )
-# define vsnprintf _vsnprintf
-# endif
-# endif
-# endif
-# ifdef __SASC
-# define NO_vsnprintf
-# endif
-#endif
-#ifdef VMS
-# define NO_vsnprintf
-#endif
-
-#if defined(pyr)
+#if defined(pyr) || defined(Z_SOLO)
# define NO_MEMCPY
#endif
#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
@@ -261,14 +234,19 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
# define Tracecv(c,x)
#endif
-
-voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items,
- unsigned size));
-void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr));
+#ifndef Z_SOLO
+ voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items,
+ unsigned size));
+ void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr));
+#endif
#define ZALLOC(strm, items, size) \
(*((strm)->zalloc))((strm)->opaque, (items), (size))
#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
#define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
+/* Reverse the bytes in a 32-bit value */
+#define ZSWAP32(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
+ (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
+
#endif /* ZUTIL_H */
diff --git a/lib/msun/man/cexp.3 b/lib/msun/man/cexp.3
index 407284c..59bb1cd 100644
--- a/lib/msun/man/cexp.3
+++ b/lib/msun/man/cexp.3
@@ -48,7 +48,7 @@ functions compute the complex exponential of
.Fa z ,
also known as
.Em cis Ns ( Ns
-.Fa z Ns )
+.Fa z Ns ) .
.Sh RETURN VALUES
For real numbers
.Fa x
diff --git a/lib/msun/man/complex.3 b/lib/msun/man/complex.3
index a8d9f95..4c4dd68 100644
--- a/lib/msun/man/complex.3
+++ b/lib/msun/man/complex.3
@@ -111,7 +111,7 @@ The
functions described here conform to
.St -isoC-99 .
.Sh BUGS
-The inverse trigonmetric and hyperbolic functions
+The inverse trigonometric and hyperbolic functions
.Fn cacos ,
.Fn cacosh ,
.Fn casin ,
diff --git a/lib/msun/src/math.h b/lib/msun/src/math.h
index 9389dda..cf34583 100644
--- a/lib/msun/src/math.h
+++ b/lib/msun/src/math.h
@@ -395,35 +395,15 @@ float significandf(float);
* long double versions of ISO/POSIX math functions
*/
#if __ISO_C_VISIBLE >= 1999
-#if _DECLARE_C99_LDBL_MATH
-long double acoshl(long double);
-#endif
long double acosl(long double);
-#if _DECLARE_C99_LDBL_MATH
-long double asinhl(long double);
-#endif
long double asinl(long double);
long double atan2l(long double, long double);
-#if _DECLARE_C99_LDBL_MATH
-long double atanhl(long double);
-#endif
long double atanl(long double);
long double cbrtl(long double);
long double ceill(long double);
long double copysignl(long double, long double) __pure2;
-#if _DECLARE_C99_LDBL_MATH
-long double coshl(long double);
-#endif
long double cosl(long double);
-#if _DECLARE_C99_LDBL_MATH
-long double erfcl(long double);
-long double erfl(long double);
-#endif
long double exp2l(long double);
-#if _DECLARE_C99_LDBL_MATH
-long double expl(long double);
-long double expm1l(long double);
-#endif
long double fabsl(long double) __pure2;
long double fdiml(long double, long double);
long double floorl(long double);
@@ -435,20 +415,9 @@ long double frexpl(long double value, int *); /* fundamentally !__pure2 */
long double hypotl(long double, long double);
int ilogbl(long double) __pure2;
long double ldexpl(long double, int);
-#if _DECLARE_C99_LDBL_MATH
-long double lgammal(long double);
-#endif
long long llrintl(long double);
long long llroundl(long double);
-#if _DECLARE_C99_LDBL_MATH
-long double log10l(long double);
-long double log1pl(long double);
-long double log2l(long double);
-#endif
long double logbl(long double);
-#if _DECLARE_C99_LDBL_MATH
-long double logl(long double);
-#endif
long lrintl(long double);
long lroundl(long double);
long double modfl(long double, long double *); /* fundamentally !__pure2 */
@@ -458,30 +427,54 @@ long double nextafterl(long double, long double);
double nexttoward(double, long double);
float nexttowardf(float, long double);
long double nexttowardl(long double, long double);
-#if _DECLARE_C99_LDBL_MATH
-long double powl(long double, long double);
-#endif
long double remainderl(long double, long double);
long double remquol(long double, long double, int *);
long double rintl(long double);
long double roundl(long double);
long double scalblnl(long double, long);
long double scalbnl(long double, int);
-#if _DECLARE_C99_LDBL_MATH
-long double sinhl(long double);
-#endif
long double sinl(long double);
long double sqrtl(long double);
-#if _DECLARE_C99_LDBL_MATH
-long double tanhl(long double);
-#endif
long double tanl(long double);
-#if _DECLARE_C99_LDBL_MATH
-long double tgammal(long double);
-#endif
long double truncl(long double);
#endif /* __ISO_C_VISIBLE >= 1999 */
__END_DECLS
#endif /* !_MATH_H_ */
+
+/* separate header for cmath */
+#ifndef _MATH_EXTRA_H_
+#if __ISO_C_VISIBLE >= 1999
+#if _DECLARE_C99_LDBL_MATH
+
+#define _MATH_EXTRA_H_
+
+/*
+ * extra long double versions of math functions for C99 and cmath
+ */
+__BEGIN_DECLS
+
+long double acoshl(long double);
+long double asinhl(long double);
+long double atanhl(long double);
+long double coshl(long double);
+long double erfcl(long double);
+long double erfl(long double);
+long double expl(long double);
+long double expm1l(long double);
+long double lgammal(long double);
+long double log10l(long double);
+long double log1pl(long double);
+long double log2l(long double);
+long double logl(long double);
+long double powl(long double, long double);
+long double sinhl(long double);
+long double tanhl(long double);
+long double tgammal(long double);
+
+__END_DECLS
+
+#endif /* !_DECLARE_C99_LDBL_MATH */
+#endif /* __ISO_C_VISIBLE >= 1999 */
+#endif /* !_MATH_EXTRA_H_ */
OpenPOWER on IntegriCloud