[Zrouter-src-freebsd] ZRouter.org: push to FreeBSD HEAD tree

zrouter-src-freebsd at zrouter.org zrouter-src-freebsd at zrouter.org
Wed Jul 25 14:36:04 UTC 2012


details:   http://zrouter.org/hg/FreeBSD/head//rev/7449ca4973e7
changeset: 488:7449ca4973e7
user:      Aleksandr Rybalko <ray at ddteam.net>
date:      Wed Jul 25 16:23:00 2012 +0300
description:
Lazy update

diffstat:

 head/lib/Makefile                                    |     8 +-
 head/lib/bind/dns/code.h                             |    21 +-
 head/lib/bind/dns/dns/enumtype.h                     |     4 +-
 head/lib/bind/dns/dns/rdatastruct.h                  |    37 +-
 head/lib/clang/Makefile                              |     3 +-
 head/lib/clang/clang.build.mk                        |    12 +-
 head/lib/clang/include/Makefile                      |    10 +-
 head/lib/clang/include/clang/Basic/Version.inc       |     6 +-
 head/lib/clang/include/clang/Config/config.h         |    14 +-
 head/lib/clang/include/llvm/Config/config.h          |     9 +-
 head/lib/clang/libclangindex/Makefile                |    23 -
 head/lib/clang/libclangsema/Makefile                 |     3 +-
 head/lib/clang/libllvmruntimedyld/Makefile           |     5 +-
 head/lib/clang/libllvmsupport/Makefile               |     3 +-
 head/lib/csu/powerpc/Makefile                        |     5 +-
 head/lib/libbluetooth/bluetooth.3                    |     5 +-
 head/lib/libc++/Makefile                             |   285 ++--
 head/lib/libc/Makefile                               |    10 +-
 head/lib/libc/amd64/sys/Makefile.inc                 |     5 +-
 head/lib/libc/amd64/sys/__vdso_gettc.c               |    49 +
 head/lib/libc/arm/Symbol.map                         |     6 +-
 head/lib/libc/compat-43/sigpause.2                   |     7 +-
 head/lib/libc/gen/Makefile.inc                       |     4 +-
 head/lib/libc/gen/Symbol.map                         |     3 +-
 head/lib/libc/gen/arc4random.c                       |    42 +-
 head/lib/libc/gen/aux.c                              |    17 +-
 head/lib/libc/gen/closedir.c                         |     3 +-
 head/lib/libc/gen/directory.3                        |    19 +-
 head/lib/libc/gen/dirfd.c                            |    45 +
 head/lib/libc/gen/err.3                              |    16 +-
 head/lib/libc/gen/fstab.c                            |    14 +-
 head/lib/libc/gen/fts-compat.c                       |     6 +-
 head/lib/libc/gen/fts.c                              |     6 +-
 head/lib/libc/gen/gen-private.h                      |    59 +
 head/lib/libc/gen/getcwd.c                           |    12 +-
 head/lib/libc/gen/getnetgrent.c                      |   186 +-
 head/lib/libc/gen/opendir.c                          |     3 +-
 head/lib/libc/gen/posix_spawnattr_getflags.3         |     4 +-
 head/lib/libc/gen/readdir.c                          |     3 +-
 head/lib/libc/gen/rewinddir.c                        |     3 +-
 head/lib/libc/gen/seekdir.c                          |     3 +-
 head/lib/libc/gen/signal.3                           |    21 +-
 head/lib/libc/gen/sysconf.c                          |     6 +-
 head/lib/libc/gen/syslog.c                           |     8 +-
 head/lib/libc/gen/telldir.c                          |     3 +-
 head/lib/libc/gen/tls.c                              |    26 +-
 head/lib/libc/gmon/gmon.c                            |     9 +-
 head/lib/libc/gmon/moncontrol.3                      |     9 +-
 head/lib/libc/i386/gen/getcontextx.c                 |     4 +-
 head/lib/libc/i386/sys/Makefile.inc                  |     5 +-
 head/lib/libc/i386/sys/__vdso_gettc.c                |    50 +
 head/lib/libc/include/libc_private.h                 |    22 +-
 head/lib/libc/include/port_before.h                  |     4 +-
 head/lib/libc/locale/Symbol.map                      |    10 +-
 head/lib/libc/locale/collate.c                       |    12 +-
 head/lib/libc/locale/ctype_l.3                       |    17 +-
 head/lib/libc/locale/duplocale.3                     |     6 +-
 head/lib/libc/locale/freelocale.3                    |     4 +-
 head/lib/libc/locale/newlocale.3                     |     6 +-
 head/lib/libc/locale/querylocale.3                   |     6 +-
 head/lib/libc/locale/setrunelocale.c                 |    23 +-
 head/lib/libc/locale/toupper.c                       |     4 +-
 head/lib/libc/locale/uselocale.3                     |     4 +-
 head/lib/libc/locale/xlocale.3                       |     4 +-
 head/lib/libc/net/Makefile.inc                       |     4 +-
 head/lib/libc/net/Symbol.map                         |     7 +-
 head/lib/libc/net/getaddrinfo.c                      |    31 +-
 head/lib/libc/net/if_indextoname.c                   |     4 +-
 head/lib/libc/net/if_nameindex.c                     |     4 +-
 head/lib/libc/net/if_nametoindex.c                   |     4 +-
 head/lib/libc/net/nsdispatch.3                       |    12 +-
 head/lib/libc/net/nsparser.y                         |     3 +-
 head/lib/libc/net/sctp_connectx.3                    |     4 +-
 head/lib/libc/net/sctp_recvmsg.3                     |     4 +-
 head/lib/libc/net/sctp_sys_calls.c                   |     8 +-
 head/lib/libc/net/sourcefilter.3                     |     6 +-
 head/lib/libc/net/sourcefilter.c                     |     4 +-
 head/lib/libc/posix1e/acl_delete_entry.3             |     4 +-
 head/lib/libc/posix1e/mac_prepare.3                  |     4 +-
 head/lib/libc/powerpc/Symbol.map                     |     6 +-
 head/lib/libc/powerpc/gen/Makefile.inc               |     4 +-
 head/lib/libc/powerpc/gen/eabi.S                     |    33 +
 head/lib/libc/rpc/auth_unix.c                        |     9 +-
 head/lib/libc/rpc/getnetpath.c                       |     5 +-
 head/lib/libc/rpc/publickey.3                        |     6 +-
 head/lib/libc/rpc/svc.c                              |    12 +-
 head/lib/libc/rpc/svc_raw.c                          |    16 +-
 head/lib/libc/stdio/Makefile.inc                     |    10 +-
 head/lib/libc/stdio/fclose.c                         |    16 +-
 head/lib/libc/stdio/fgets.3                          |     6 +-
 head/lib/libc/stdio/fgetwc.c                         |    26 +-
 head/lib/libc/stdio/findfp.c                         |    18 +-
 head/lib/libc/stdio/fpurge.c                         |     4 +-
 head/lib/libc/stdio/local.h                          |    11 +-
 head/lib/libc/stdio/printf_l.3                       |    80 +
 head/lib/libc/stdio/scanf.3                          |     6 +-
 head/lib/libc/stdio/scanf_l.3                        |    70 +
 head/lib/libc/stdio/setbuf.3                         |     6 +-
 head/lib/libc/stdio/vfscanf.c                        |   737 ++++++------
 head/lib/libc/stdio/vfwscanf.c                       |   664 ++++++-----
 head/lib/libc/stdio/wscanf.3                         |     6 +-
 head/lib/libc/stdio/xprintf.c                        |     4 +-
 head/lib/libc/stdlib/Makefile.inc                    |     3 +-
 head/lib/libc/stdlib/getenv.3                        |     5 +-
 head/lib/libc/stdlib/getopt_long.c                   |    11 +-
 head/lib/libc/stdlib/realpath.3                      |    10 +-
 head/lib/libc/stdlib/realpath.c                      |    38 +-
 head/lib/libc/stdlib/strfmon.3                       |    25 +-
 head/lib/libc/stdtime/Makefile.inc                   |     4 +-
 head/lib/libc/stdtime/strftime.3                     |    15 +-
 head/lib/libc/stdtime/strftime.c                     |     4 +-
 head/lib/libc/stdtime/strptime.3                     |    16 +-
 head/lib/libc/string/Makefile.inc                    |    11 +-
 head/lib/libc/string/strcasecmp.3                    |    25 +-
 head/lib/libc/string/strcoll.3                       |    16 +-
 head/lib/libc/string/strlcpy.3                       |     4 +-
 head/lib/libc/string/strstr.3                        |    12 +-
 head/lib/libc/string/strxfrm.3                       |    16 +-
 head/lib/libc/sys/Makefile.inc                       |     6 +-
 head/lib/libc/sys/Symbol.map                         |     8 +-
 head/lib/libc/sys/__vdso_gettimeofday.c              |   142 ++
 head/lib/libc/sys/clock_gettime.c                    |    52 +
 head/lib/libc/sys/fcntl.2                            |    21 +-
 head/lib/libc/sys/fcntl.c                            |     4 +-
 head/lib/libc/sys/ffclock.2                          |     6 +-
 head/lib/libc/sys/gettimeofday.c                     |    51 +
 head/lib/libc/sys/jail.2                             |    42 +-
 head/lib/libc/sys/ktrace.2                           |     4 +-
 head/lib/libc/sys/lseek.2                            |    10 +-
 head/lib/libc/sys/msgsnd.2                           |     4 +-
 head/lib/libc/sys/pathconf.2                         |     4 +-
 head/lib/libc/sys/pdfork.2                           |     8 +-
 head/lib/libc/sys/posix_fadvise.2                    |    11 +-
 head/lib/libc/sys/read.2                             |     4 +-
 head/lib/libc/sys/rtprio.2                           |     9 +-
 head/lib/libc/sys/setfib.2                           |    10 +-
 head/lib/libc/sys/shm_open.2                         |     4 +-
 head/lib/libc/sys/sigqueue.2                         |     4 +-
 head/lib/libc/sys/stat.2                             |     6 +-
 head/lib/libc/sys/timer_create.2                     |     4 +-
 head/lib/libc/sys/timer_delete.2                     |     4 +-
 head/lib/libc/sys/timer_settime.2                    |     4 +-
 head/lib/libc/sys/unlink.2                           |     4 +-
 head/lib/libcompiler_rt/Makefile                     |     4 +-
 head/lib/libcrypt/Makefile                           |     8 +-
 head/lib/libcrypt/crypt.3                            |    12 +-
 head/lib/libcrypt/crypt.c                            |    16 +-
 head/lib/libcxxrt/Makefile                           |    34 +-
 head/lib/libcxxrt/Version.map                        |    20 +-
 head/lib/libedit/chared.c                            |    35 +-
 head/lib/libedit/chared.h                            |     6 +-
 head/lib/libedit/common.c                            |     4 +-
 head/lib/libedit/edit/readline/Makefile              |     5 +-
 head/lib/libedit/edit/readline/tilde.h               |    32 +
 head/lib/libedit/editline.3                          |   114 +-
 head/lib/libedit/editrc.5                            |    34 +-
 head/lib/libedit/el.c                                |    48 +-
 head/lib/libedit/el.h                                |     3 +-
 head/lib/libedit/histedit.h                          |     8 +-
 head/lib/libedit/history.c                           |   111 +-
 head/lib/libedit/key.c                               |    37 +-
 head/lib/libedit/key.h                               |     6 +-
 head/lib/libedit/makelist                            |     6 +-
 head/lib/libedit/prompt.c                            |    90 +-
 head/lib/libedit/prompt.h                            |     8 +-
 head/lib/libedit/read.c                              |    88 +-
 head/lib/libedit/refresh.c                           |   215 +-
 head/lib/libedit/search.c                            |     6 +-
 head/lib/libedit/sig.c                               |    80 +-
 head/lib/libedit/sig.h                               |    13 +-
 head/lib/libedit/term.c                              |   186 +-
 head/lib/libedit/term.h                              |     8 +-
 head/lib/libedit/tokenizer.c                         |     8 +-
 head/lib/libedit/tty.c                               |     4 +-
 head/lib/libedit/vi.c                                |    42 +-
 head/lib/libelf/Makefile                             |    17 +-
 head/lib/libelf/elf.3                                |    18 +-
 head/lib/libelf/elf_begin.3                          |     4 +-
 head/lib/libelf/elf_getdata.3                        |     4 +-
 head/lib/libelf/elf_strptr.3                         |     4 +-
 head/lib/libelf/gelf.3                               |    16 +-
 head/lib/libelf/gelf_getphdr.3                       |     4 +-
 head/lib/libelf/gelf_newehdr.3                       |     5 +-
 head/lib/libfetch/common.c                           |    34 +-
 head/lib/libfetch/common.h                           |     4 +-
 head/lib/libfetch/http.c                             |     6 +-
 head/lib/libgpib/gpib.3                              |    14 +-
 head/lib/libgssapi/gss_accept_sec_context.3          |     8 +-
 head/lib/libgssapi/gss_acquire_cred.3                |     8 +-
 head/lib/libgssapi/gss_add_cred.3                    |     8 +-
 head/lib/libgssapi/gss_add_oid_set_member.3          |     8 +-
 head/lib/libgssapi/gss_canonicalize_name.3           |     8 +-
 head/lib/libgssapi/gss_compare_name.3                |    10 +-
 head/lib/libgssapi/gss_context_time.3                |     8 +-
 head/lib/libgssapi/gss_create_empty_oid_set.3        |     8 +-
 head/lib/libgssapi/gss_delete_sec_context.3          |     8 +-
 head/lib/libgssapi/gss_display_name.3                |     8 +-
 head/lib/libgssapi/gss_display_status.3              |    10 +-
 head/lib/libgssapi/gss_duplicate_name.3              |     8 +-
 head/lib/libgssapi/gss_export_name.3                 |     8 +-
 head/lib/libgssapi/gss_export_sec_context.3          |     8 +-
 head/lib/libgssapi/gss_get_mic.3                     |     8 +-
 head/lib/libgssapi/gss_import_name.3                 |     8 +-
 head/lib/libgssapi/gss_import_sec_context.3          |     8 +-
 head/lib/libgssapi/gss_indicate_mechs.3              |     8 +-
 head/lib/libgssapi/gss_init_sec_context.3            |     8 +-
 head/lib/libgssapi/gss_inquire_context.3             |     8 +-
 head/lib/libgssapi/gss_inquire_cred.3                |     8 +-
 head/lib/libgssapi/gss_inquire_cred_by_mech.3        |     8 +-
 head/lib/libgssapi/gss_inquire_mechs_for_name.3      |     8 +-
 head/lib/libgssapi/gss_inquire_names_for_mech.3      |     8 +-
 head/lib/libgssapi/gss_process_context_token.3       |     8 +-
 head/lib/libgssapi/gss_release_buffer.3              |     8 +-
 head/lib/libgssapi/gss_release_cred.3                |     8 +-
 head/lib/libgssapi/gss_release_name.3                |     8 +-
 head/lib/libgssapi/gss_release_oid_set.3             |     8 +-
 head/lib/libgssapi/gss_test_oid_set_member.3         |     8 +-
 head/lib/libgssapi/gss_unwrap.3                      |    10 +-
 head/lib/libgssapi/gss_verify_mic.3                  |     8 +-
 head/lib/libgssapi/gss_wrap.3                        |    14 +-
 head/lib/libgssapi/gss_wrap_size_limit.3             |     8 +-
 head/lib/libgssapi/gssapi.3                          |     4 +-
 head/lib/libgssapi/mech.5                            |    12 +-
 head/lib/libjail/jail.c                              |    60 +-
 head/lib/libkiconv/Makefile                          |    11 +-
 head/lib/libkiconv/xlat16_iconv.c                    |    12 +-
 head/lib/libkvm/kvm_getpcpu.3                        |     6 +-
 head/lib/libmagic/Makefile                           |     7 +-
 head/lib/libmagic/config.h                           |     4 +-
 head/lib/libmd/Makefile                              |    31 +-
 head/lib/libmd/md2.copyright                         |    17 -
 head/lib/libmd/md2.h                                 |    46 -
 head/lib/libmd/md2c.c                                |   211 ---
 head/lib/libmd/mdX.3                                 |    14 +-
 head/lib/libnandfs/Makefile                          |     9 +
 head/lib/libnandfs/libnandfs.h                       |    65 +
 head/lib/libnandfs/nandfs.c                          |   247 ++++
 head/lib/libncp/ncpl_nls.c                           |    78 +-
 head/lib/libpam/libpam/Makefile                      |    19 +-
 head/lib/libpam/modules/pam_exec/pam_exec.8          |     6 +-
 head/lib/libpam/modules/pam_ssh/pam_ssh.c            |     4 +-
 head/lib/libpcap/Makefile                            |    11 +-
 head/lib/libpcap/config.h                            |    36 +-
 head/lib/libpmc/pmc.3                                |    24 +-
 head/lib/libprocstat/cd9660.c                        |     6 +-
 head/lib/libprocstat/common_kvm.c                    |     6 +-
 head/lib/libprocstat/libprocstat.3                   |     4 +-
 head/lib/libprocstat/libprocstat.c                   |    19 +-
 head/lib/libradius/libradius.3                       |    10 +-
 head/lib/librpcsec_gss/rpc_gss_get_error.3           |     4 +-
 head/lib/librpcsec_gss/rpc_gss_get_mech_info.3       |     4 +-
 head/lib/librpcsec_gss/rpc_gss_get_principal_name.3  |     4 +-
 head/lib/librpcsec_gss/rpc_gss_get_versions.3        |     4 +-
 head/lib/librpcsec_gss/rpc_gss_getcred.3             |     4 +-
 head/lib/librpcsec_gss/rpc_gss_is_installed.3        |     4 +-
 head/lib/librpcsec_gss/rpc_gss_max_data_length.3     |     4 +-
 head/lib/librpcsec_gss/rpc_gss_mech_to_oid.3         |     4 +-
 head/lib/librpcsec_gss/rpc_gss_oid_to_mech.3         |     4 +-
 head/lib/librpcsec_gss/rpc_gss_qop_to_num.3          |     4 +-
 head/lib/librpcsec_gss/rpc_gss_seccreate.3           |     6 +-
 head/lib/librpcsec_gss/rpc_gss_set_callback.3        |     4 +-
 head/lib/librpcsec_gss/rpc_gss_set_defaults.3        |     4 +-
 head/lib/librpcsec_gss/rpc_gss_set_svc_name.3        |     4 +-
 head/lib/librpcsec_gss/rpc_gss_svc_max_data_length.3 |     4 +-
 head/lib/libstand/Makefile                           |    23 +-
 head/lib/libstand/bswap.c                            |     4 +-
 head/lib/libstand/nandfs.c                           |  1041 ++++++++++++++++++
 head/lib/libstand/stand.h                            |     3 +-
 head/lib/libstdbuf/Makefile                          |    12 +
 head/lib/libstdbuf/libstdbuf.3                       |   102 +
 head/lib/libstdbuf/stdbuf.c                          |   115 +
 head/lib/libtacplus/libtacplus.3                     |     4 +-
 head/lib/libthr/thread/thr_getschedparam.c           |    33 +-
 head/lib/libthr/thread/thr_info.c                    |     8 +-
 head/lib/libthr/thread/thr_init.c                    |     6 +-
 head/lib/libthr/thread/thr_mutex.c                   |     3 +-
 head/lib/libthr/thread/thr_private.h                 |     3 +-
 head/lib/libthr/thread/thr_setprio.c                 |    46 +-
 head/lib/libthr/thread/thr_setschedparam.c           |    53 +-
 head/lib/libthr/thread/thr_sleepq.c                  |    24 +-
 head/lib/libusb/Makefile                             |    10 +-
 head/lib/libusb/libusb.3                             |    38 +-
 head/lib/libusb/libusb.h                             |     6 +-
 head/lib/libusb/libusb10.c                           |    37 +-
 head/lib/libusb/libusb10_desc.c                      |    21 +-
 head/lib/libusb/libusb10_io.c                        |    12 +-
 head/lib/libusb/libusb20.3                           |    21 +-
 head/lib/libusbhid/parse.c                           |     4 +-
 head/lib/libutil/Makefile                            |     7 +-
 head/lib/libutil/auth.3                              |    56 -
 head/lib/libutil/auth.c                              |    38 +-
 head/lib/libutil/auth.conf.5                         |    35 -
 head/lib/libutil/login.conf.5                        |    11 +-
 head/lib/libutil/property.3                          |     4 +-
 head/lib/libutil/pw_util.c                           |    21 +-
 head/lib/libz/ChangeLog                              |   203 +++-
 head/lib/libz/FAQ                                    |    12 +-
 head/lib/libz/FREEBSD-upgrade                        |     2 +-
 head/lib/libz/Makefile                               |    12 +-
 head/lib/libz/README                                 |    24 +-
 head/lib/libz/Symbol.map                             |     9 +-
 head/lib/libz/Versions.def                           |     5 +-
 head/lib/libz/adler32.c                              |    70 +-
 head/lib/libz/contrib/asm686/match.S                 |    16 +-
 head/lib/libz/crc32.c                                |    83 +-
 head/lib/libz/crc32.h                                |     2 +-
 head/lib/libz/deflate.c                              |   257 +++-
 head/lib/libz/deflate.h                              |    10 +-
 head/lib/libz/doc/algorithm.txt                      |     2 +-
 head/lib/libz/example.c                              |   565 ---------
 head/lib/libz/gzguts.h                               |    87 +-
 head/lib/libz/gzlib.c                                |   167 ++-
 head/lib/libz/gzread.c                               |   420 +++----
 head/lib/libz/gzwrite.c                              |   148 +-
 head/lib/libz/infback.c                              |    14 +-
 head/lib/libz/inffixed.h                             |     6 +-
 head/lib/libz/inflate.c                              |    90 +-
 head/lib/libz/inftrees.c                             |    46 +-
 head/lib/libz/minigzip.c                             |   440 -------
 head/lib/libz/test/example.c                         |   601 ++++++++++
 head/lib/libz/test/infcover.c                        |   671 +++++++++++
 head/lib/libz/test/minigzip.c                        |   631 ++++++++++
 head/lib/libz/trees.c                                |    40 +-
 head/lib/libz/zconf.h                                |   198 ++-
 head/lib/libz/zlib.3                                 |    18 +-
 head/lib/libz/zlib.h                                 |   307 +++-
 head/lib/libz/zopen.c                                |    12 +-
 head/lib/libz/zutil.c                                |    24 +-
 head/lib/libz/zutil.h                                |    98 +-
 head/lib/msun/Makefile                               |     4 +-
 head/lib/msun/Symbol.map                             |     3 +-
 head/lib/msun/ld128/s_expl.c                         |   260 ++++
 head/lib/msun/ld80/s_expl.c                          |   304 +++++
 head/lib/msun/man/cexp.3                             |     4 +-
 head/lib/msun/man/complex.3                          |     4 +-
 head/lib/msun/man/exp.3                              |    16 +-
 head/lib/msun/src/e_exp.c                            |     6 +-
 head/lib/msun/src/math.h                             |    79 +-
 head/lib/msun/src/math_private.h                     |    43 +-
 head/lib/msun/src/s_fabsl.c                          |     4 +-
 340 files changed, 9582 insertions(+), 4722 deletions(-)

diffs (24950 lines):

diff -r d46effa10a19 -r 7449ca4973e7 head/lib/Makefile
--- a/head/lib/Makefile	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/Makefile	Wed Jul 25 16:23:00 2012 +0300
@@ -1,5 +1,5 @@
 #	@(#)Makefile	8.1 (Berkeley) 6/4/93
-# $FreeBSD: head/lib/Makefile 233413 2012-03-24 05:18:27Z gonzo $
+# $FreeBSD: head/lib/Makefile 235537 2012-05-17 10:11:18Z gber $
 
 .include <bsd.own.mk>
 
@@ -88,6 +88,7 @@
 	libmemstat \
 	${_libmilter} \
 	${_libmp} \
+	${_libnandfs} \
 	${_libncp} \
 	${_libngatm} \
 	libopie \
@@ -104,6 +105,7 @@
 	${_libsmdb} \
 	${_libsmutil} \
 	libstand \
+	libstdbuf \
 	libstdthreads \
 	${_libtelnet} \
 	${_libthr} \
@@ -174,6 +176,10 @@
 _libthr=	libthr
 .endif
 
+.if ${MK_NAND} != "no"
+_libnandfs=	libnandfs
+.endif
+
 .if ${MK_NETGRAPH} != "no"
 _libnetgraph=	libnetgraph
 .endif
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/bind/dns/code.h
--- a/head/lib/bind/dns/code.h	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/bind/dns/code.h	Wed Jul 25 16:23:00 2012 +0300
@@ -1,4 +1,4 @@
-/* $FreeBSD: head/lib/bind/dns/code.h 233914 2012-04-05 04:29:35Z dougb $ */
+/* $FreeBSD: head/lib/bind/dns/code.h 236196 2012-05-28 19:47:56Z dougb $ */
 
 /*
  * Copyright (C) 2004-2012 Internet Systems Consortium, Inc. ("ISC")
@@ -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 -r d46effa10a19 -r 7449ca4973e7 head/lib/bind/dns/dns/enumtype.h
--- a/head/lib/bind/dns/dns/enumtype.h	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/bind/dns/dns/enumtype.h	Wed Jul 25 16:23:00 2012 +0300
@@ -1,4 +1,4 @@
-/* $FreeBSD: head/lib/bind/dns/dns/enumtype.h 233914 2012-04-05 04:29:35Z dougb $ */
+/* $FreeBSD: head/lib/bind/dns/dns/enumtype.h 236196 2012-05-28 19:47:56Z dougb $ */
 
 /*
  * Copyright (C) 2004-2012 Internet Systems Consortium, Inc. ("ISC")
@@ -78,6 +78,7 @@
 	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 @@
 #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 -r d46effa10a19 -r 7449ca4973e7 head/lib/bind/dns/dns/rdatastruct.h
--- a/head/lib/bind/dns/dns/rdatastruct.h	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/bind/dns/dns/rdatastruct.h	Wed Jul 25 16:23:00 2012 +0300
@@ -1,4 +1,4 @@
-/* $FreeBSD: head/lib/bind/dns/dns/rdatastruct.h 233914 2012-04-05 04:29:35Z dougb $ */
+/* $FreeBSD: head/lib/bind/dns/dns/rdatastruct.h 236196 2012-05-28 19:47:56Z dougb $ */
 
 /*
  * Copyright (C) 2004-2012 Internet Systems Consortium, Inc. ("ISC")
@@ -1840,6 +1840,41 @@
 
 #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 -r d46effa10a19 -r 7449ca4973e7 head/lib/clang/Makefile
--- a/head/lib/clang/Makefile	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/clang/Makefile	Wed Jul 25 16:23:00 2012 +0300
@@ -1,4 +1,4 @@
-# $FreeBSD: head/lib/clang/Makefile 234353 2012-04-16 21:23:25Z dim $
+# $FreeBSD: head/lib/clang/Makefile 234982 2012-05-03 20:41:21Z dim $
 
 .include <bsd.own.mk>
 
@@ -12,7 +12,6 @@
 	libclangedit \
 	libclangfrontend \
 	libclangfrontendtool \
-	libclangindex \
 	libclanglex \
 	libclangparse \
 	libclangrewrite \
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/clang/clang.build.mk
--- a/head/lib/clang/clang.build.mk	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/clang/clang.build.mk	Wed Jul 25 16:23:00 2012 +0300
@@ -1,4 +1,4 @@
-# $FreeBSD: head/lib/clang/clang.build.mk 234356 2012-04-16 21:36:55Z dim $
+# $FreeBSD: head/lib/clang/clang.build.mk 234982 2012-05-03 20:41:21Z dim $
 
 CLANG_SRCS=${LLVM_SRCS}/tools/clang
 
@@ -11,12 +11,6 @@
 # LLVM is not strict aliasing safe as of 12/31/2011
 CFLAGS+= -fno-strict-aliasing
 
-# Work around an issue on 32-bit PowerPC, where the clang executable can get
-# too big, causing 'relocation truncated to fit' errors at link time.
-.if ${MACHINE_ARCH} == "powerpc"
-CFLAGS+=-mlongcall
-.endif
-
 TARGET_ARCH?=	${MACHINE_ARCH}
 CFLAGS+=-DLLVM_DEFAULT_TARGET_TRIPLE=\"${TARGET_ARCH:C/amd64/x86_64/}-unknown-freebsd10.0\"
 
@@ -31,9 +25,7 @@
 CXXFLAGS+=-fno-rtti
 .endif
 
-.ifdef TOOLS_PREFIX
-CFLAGS+=-DCLANG_PREFIX=\"${TOOLS_PREFIX}\"
-.endif
+CFLAGS+=-DDEFAULT_SYSROOT=\"${TOOLS_PREFIX}\"
 
 .PATH:	${LLVM_SRCS}/${SRCDIR}
 
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/clang/include/Makefile
--- a/head/lib/clang/include/Makefile	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/clang/include/Makefile	Wed Jul 25 16:23:00 2012 +0300
@@ -1,21 +1,27 @@
-# $FreeBSD: head/lib/clang/include/Makefile 234353 2012-04-16 21:23:25Z dim $
+# $FreeBSD: head/lib/clang/include/Makefile 235058 2012-05-05 15:35:22Z dim $
 
 .PATH: ${.CURDIR}/../../../contrib/llvm/tools/clang/lib/Headers
 
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/clang/include/clang/Basic/Version.inc
--- a/head/lib/clang/include/clang/Basic/Version.inc	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/clang/include/clang/Basic/Version.inc	Wed Jul 25 16:23:00 2012 +0300
@@ -1,10 +1,10 @@
-/* $FreeBSD: head/lib/clang/include/clang/Basic/Version.inc 234353 2012-04-16 21:23:25Z dim $ */
+/* $FreeBSD: head/lib/clang/include/clang/Basic/Version.inc 235864 2012-05-23 21:48:49Z dim $ */
 
 #define	CLANG_VERSION		3.1
 #define	CLANG_VERSION_MAJOR	3
 #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 -r d46effa10a19 -r 7449ca4973e7 head/lib/clang/include/clang/Config/config.h
--- a/head/lib/clang/include/clang/Config/config.h	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/clang/include/clang/Config/config.h	Wed Jul 25 16:23:00 2012 +0300
@@ -1,4 +1,4 @@
-/* $FreeBSD: head/lib/clang/include/clang/Config/config.h 234353 2012-04-16 21:23:25Z dim $ */
+/* $FreeBSD: head/lib/clang/include/clang/Config/config.h 234982 2012-05-03 20:41:21Z dim $ */
 /* tools/clang/include/clang/Config/config.h.  Generated from config.h.in by configure.  */
 /* include/clang/Config/config.h.in. */
 
@@ -11,10 +11,16 @@
 /* Relative directory for resource files */
 #define CLANG_RESOURCE_DIR ""
 
+/* 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 ""
 
-/* Directories clang will search for headers */
-#define C_INCLUDE_DIRS ""
-
 #endif
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/clang/include/llvm/Config/config.h
--- a/head/lib/clang/include/llvm/Config/config.h	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/clang/include/llvm/Config/config.h	Wed Jul 25 16:23:00 2012 +0300
@@ -1,4 +1,4 @@
-/* $FreeBSD: head/lib/clang/include/llvm/Config/config.h 234353 2012-04-16 21:23:25Z dim $ */
+/* $FreeBSD: head/lib/clang/include/llvm/Config/config.h 235864 2012-05-23 21:48:49Z dim $ */
 /* include/llvm/Config/config.h.  Generated from config.h.in by configure.  */
 /* include/llvm/Config/config.h.in.  Generated from autoconf/configure.ac by autoheader.  */
 
@@ -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 -r d46effa10a19 -r 7449ca4973e7 head/lib/clang/libclangindex/Makefile
--- a/head/lib/clang/libclangindex/Makefile	Wed Jul 25 16:21:35 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,23 +0,0 @@
-# $FreeBSD: head/lib/clang/libclangindex/Makefile 234353 2012-04-16 21:23:25Z dim $
-
-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 -r d46effa10a19 -r 7449ca4973e7 head/lib/clang/libclangsema/Makefile
--- a/head/lib/clang/libclangsema/Makefile	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/clang/libclangsema/Makefile	Wed Jul 25 16:23:00 2012 +0300
@@ -1,4 +1,4 @@
-# $FreeBSD: head/lib/clang/libclangsema/Makefile 234353 2012-04-16 21:23:25Z dim $
+# $FreeBSD: head/lib/clang/libclangsema/Makefile 234982 2012-05-03 20:41:21Z dim $
 
 LIB=	clangsema
 
@@ -36,6 +36,7 @@
 	SemaOverload.cpp \
 	SemaPseudoObject.cpp \
 	SemaStmt.cpp \
+	SemaStmtAttr.cpp \
 	SemaTemplate.cpp \
 	SemaTemplateDeduction.cpp \
 	SemaTemplateInstantiate.cpp \
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/clang/libllvmruntimedyld/Makefile
--- a/head/lib/clang/libllvmruntimedyld/Makefile	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/clang/libllvmruntimedyld/Makefile	Wed Jul 25 16:23:00 2012 +0300
@@ -1,9 +1,10 @@
-# $FreeBSD: head/lib/clang/libllvmruntimedyld/Makefile 234353 2012-04-16 21:23:25Z dim $
+# $FreeBSD: head/lib/clang/libllvmruntimedyld/Makefile 234982 2012-05-03 20:41:21Z dim $
 
 LIB=	llvmruntimedyld
 
 SRCDIR=	lib/ExecutionEngine/RuntimeDyld
-SRCS=	RuntimeDyld.cpp \
+SRCS=	GDBRegistrar.cpp \
+	RuntimeDyld.cpp \
 	RuntimeDyldELF.cpp \
 	RuntimeDyldMachO.cpp
 
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/clang/libllvmsupport/Makefile
--- a/head/lib/clang/libllvmsupport/Makefile	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/clang/libllvmsupport/Makefile	Wed Jul 25 16:23:00 2012 +0300
@@ -1,4 +1,4 @@
-# $FreeBSD: head/lib/clang/libllvmsupport/Makefile 234353 2012-04-16 21:23:25Z dim $
+# $FreeBSD: head/lib/clang/libllvmsupport/Makefile 234982 2012-05-03 20:41:21Z dim $
 
 .include <bsd.own.mk>
 
@@ -30,6 +30,7 @@
 	IntervalMap.cpp \
 	IntEqClasses.cpp \
 	IntrusiveRefCntPtr.cpp \
+	Locale.cpp \
 	LockFileManager.cpp \
 	ManagedStatic.cpp \
 	Memory.cpp \
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/csu/powerpc/Makefile
--- a/head/lib/csu/powerpc/Makefile	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/csu/powerpc/Makefile	Wed Jul 25 16:23:00 2012 +0300
@@ -1,4 +1,4 @@
-# $FreeBSD: head/lib/csu/powerpc/Makefile 234502 2012-04-20 21:00:39Z dim $
+# $FreeBSD: head/lib/csu/powerpc/Makefile 234596 2012-04-23 06:33:27Z dim $
 
 .PATH: ${.CURDIR}/../common
 
@@ -6,8 +6,7 @@
 OBJS=		${SRCS:N*.h:R:S/$/.o/g}
 OBJS+=		Scrt1.o gcrt1.o
 CFLAGS+=	-I${.CURDIR}/../common \
-		-I${.CURDIR}/../../libc/include \
-		-mlongcall
+		-I${.CURDIR}/../../libc/include
 
 all: ${OBJS}
 
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libbluetooth/bluetooth.3
--- a/head/lib/libbluetooth/bluetooth.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libbluetooth/bluetooth.3	Wed Jul 25 16:23:00 2012 +0300
@@ -23,7 +23,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\" $Id: bluetooth.3,v 1.5 2003/05/20 23:04:30 max Exp $
-.\" $FreeBSD: head/lib/libbluetooth/bluetooth.3 233648 2012-03-29 05:02:12Z eadler $
+.\" $FreeBSD: head/lib/libbluetooth/bluetooth.3 235286 2012-05-11 20:06:46Z gjb $
 .\"
 .Dd April 9, 2009
 .Dt BLUETOOTH 3
@@ -494,7 +494,8 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc++/Makefile
--- a/head/lib/libc++/Makefile	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc++/Makefile	Wed Jul 25 16:23:00 2012 +0300
@@ -1,156 +1,163 @@
-# $FreeBSD: head/lib/libc++/Makefile 233098 2012-03-17 22:12:09Z peter $
+# $FreeBSD: head/lib/libc++/Makefile 236444 2012-06-02 11:07:19Z dim $
 
-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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/Makefile
--- a/head/lib/libc/Makefile	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/Makefile	Wed Jul 25 16:23:00 2012 +0300
@@ -1,5 +1,5 @@
 #	@(#)Makefile	8.2 (Berkeley) 2/3/94
-# $FreeBSD: head/lib/libc/Makefile 234370 2012-04-17 07:22:14Z jasone $
+# $FreeBSD: head/lib/libc/Makefile 235720 2012-05-21 08:10:42Z gleb $
 
 SHLIBDIR?= /lib
 
@@ -26,7 +26,9 @@
 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 @@
 #
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/amd64/sys/Makefile.inc
--- a/head/lib/libc/amd64/sys/Makefile.inc	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/amd64/sys/Makefile.inc	Wed Jul 25 16:23:00 2012 +0300
@@ -1,7 +1,8 @@
 #	from: Makefile.inc,v 1.1 1993/09/03 19:04:23 jtc Exp
-# $FreeBSD$
+# $FreeBSD: head/lib/libc/amd64/sys/Makefile.inc 237434 2012-06-22 07:13:30Z kib $
 
-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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/amd64/sys/__vdso_gettc.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/lib/libc/amd64/sys/__vdso_gettc.c	Wed Jul 25 16:23:00 2012 +0300
@@ -0,0 +1,49 @@
+/*-
+ * Copyright (c) 2012 Konstantin Belousov <kib at 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: head/lib/libc/amd64/sys/__vdso_gettc.c 237434 2012-06-22 07:13:30Z kib $");
+
+#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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/arm/Symbol.map
--- a/head/lib/libc/arm/Symbol.map	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/arm/Symbol.map	Wed Jul 25 16:23:00 2012 +0300
@@ -1,5 +1,5 @@
 /*
- * $FreeBSD: head/lib/libc/arm/Symbol.map 232497 2012-03-04 15:25:11Z cognet $
+ * $FreeBSD: head/lib/libc/arm/Symbol.map 237110 2012-06-15 03:57:16Z kientzle $
  */
 
 /*
@@ -33,6 +33,10 @@
 	sbrk;
 };
 
+FBSD_1.3 {
+	__flt_rounds;
+};
+
 FBSDprivate_1.0 {
 	/* PSEUDO syscalls */
 	__sys_getlogin;
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/compat-43/sigpause.2
--- a/head/lib/libc/compat-43/sigpause.2	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/compat-43/sigpause.2	Wed Jul 25 16:23:00 2012 +0300
@@ -26,7 +26,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)sigpause.2	8.1 (Berkeley) 6/2/93
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/libc/compat-43/sigpause.2 235140 2012-05-08 18:56:21Z gjb $
 .\"
 .\" Part of the content of the man page was derived from
 .\" The Open Group Base Specifications Issue 7
@@ -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 @@
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/gen/Makefile.inc
--- a/head/lib/libc/gen/Makefile.inc	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/gen/Makefile.inc	Wed Jul 25 16:23:00 2012 +0300
@@ -1,5 +1,5 @@
 #	@(#)Makefile.inc	8.6 (Berkeley) 5/4/95
-# $FreeBSD: head/lib/libc/gen/Makefile.inc 232392 2012-03-02 13:19:56Z kib $
+# $FreeBSD: head/lib/libc/gen/Makefile.inc 235647 2012-05-19 12:44:27Z gleb $
 
 # machine-independent gen sources
 .PATH: ${.CURDIR}/${LIBC_ARCH}/gen ${.CURDIR}/gen
@@ -9,7 +9,7 @@
 	_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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/gen/Symbol.map
--- a/head/lib/libc/gen/Symbol.map	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/gen/Symbol.map	Wed Jul 25 16:23:00 2012 +0300
@@ -1,5 +1,5 @@
 /*
- * $FreeBSD: head/lib/libc/gen/Symbol.map 230429 2012-01-21 18:00:28Z kib $
+ * $FreeBSD: head/lib/libc/gen/Symbol.map 235647 2012-05-19 12:44:27Z gleb $
  */
 
 FBSD_1.0 {
@@ -382,6 +382,7 @@
 };
 
 FBSD_1.3 {
+	dirfd;
 	 fdlopen;
 	__FreeBSD_libc_enter_restricted_mode;
 	getcontextx;
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/gen/arc4random.c
--- a/head/lib/libc/gen/arc4random.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/gen/arc4random.c	Wed Jul 25 16:23:00 2012 +0300
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/libc/gen/arc4random.c 227520 2011-11-15 05:49:24Z das $");
+__FBSDID("$FreeBSD: head/lib/libc/gen/arc4random.c 238118 2012-07-04 19:51:25Z pjd $");
 
 #include "namespace.h"
 #include <fcntl.h>
@@ -39,6 +39,7 @@
 #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 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 @@
 	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_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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/gen/aux.c
--- a/head/lib/libc/gen/aux.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/gen/aux.c	Wed Jul 25 16:23:00 2012 +0300
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/libc/gen/aux.c 231868 2012-02-17 10:49:29Z kib $");
+__FBSDID("$FreeBSD: head/lib/libc/gen/aux.c 237434 2012-06-22 07:13:30Z kib $");
 
 #include "namespace.h"
 #include <elf.h>
@@ -66,6 +66,7 @@
 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 @@
 		case AT_NCPUS:
 			ncpus = aux->a_un.a_val;
 			break;
+
+		case AT_TIMEKEEP:
+			timekeep = aux->a_un.a_ptr;
+			break;
 		}
 	}
 }
@@ -163,6 +168,16 @@
 		} 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/gen/closedir.c
--- a/head/lib/libc/gen/closedir.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/gen/closedir.c	Wed Jul 25 16:23:00 2012 +0300
@@ -31,7 +31,7 @@
 static char sccsid[] = "@(#)closedir.c	8.1 (Berkeley) 6/10/93";
 #endif /* LIBC_SCCS and not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/libc/gen/closedir.c 232393 2012-03-02 14:05:50Z ru $");
+__FBSDID("$FreeBSD: head/lib/libc/gen/closedir.c 235647 2012-05-19 12:44:27Z gleb $");
 
 #include "namespace.h"
 #include <sys/types.h>
@@ -42,6 +42,7 @@
 #include "un-namespace.h"
 
 #include "libc_private.h"
+#include "gen-private.h"
 #include "telldir.h"
 
 /*
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/gen/directory.3
--- a/head/lib/libc/gen/directory.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/gen/directory.3	Wed Jul 25 16:23:00 2012 +0300
@@ -26,9 +26,9 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)directory.3	8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: head/lib/libc/gen/directory.3 231299 2012-02-09 20:49:03Z eadler $
+.\" $FreeBSD: head/lib/libc/gen/directory.3 238141 2012-07-05 17:02:20Z brooks $
 .\"
-.Dd April 16, 2008
+.Dd July 5, 2012
 .Dt DIRECTORY 3
 .Os
 .Sh NAME
@@ -153,7 +153,7 @@
 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 @@
 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 @@
 .Fn fdopendir
 function appeared in
 .Fx 8.0 .
+.Sh BUGS
+The invalidation of
+.Fn telldir
+tokens when calling
+.Fn seekdir
+is non-standard.
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/gen/dirfd.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/lib/libc/gen/dirfd.c	Wed Jul 25 16:23:00 2012 +0300
@@ -0,0 +1,45 @@
+/*-
+ * Copyright (c) 2011 Gleb Kurtsou <gleb at 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: head/lib/libc/gen/dirfd.c 235649 2012-05-19 14:30:49Z gleb $
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/lib/libc/gen/dirfd.c 235649 2012-05-19 14:30:49Z gleb $");
+
+#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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/gen/err.3
--- a/head/lib/libc/gen/err.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/gen/err.3	Wed Jul 25 16:23:00 2012 +0300
@@ -26,9 +26,9 @@
 .\" SUCH DAMAGE.
 .\"
 .\"	From: @(#)err.3	8.1 (Berkeley) 6/9/93
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/libc/gen/err.3 234714 2012-04-26 19:21:58Z eadler $
 .\"
-.Dd March 6, 1999
+.Dd March 29, 2012
 .Dt ERR 3
 .Os
 .Sh NAME
@@ -212,6 +212,18 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/gen/fstab.c
--- a/head/lib/libc/gen/fstab.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/gen/fstab.c	Wed Jul 25 16:23:00 2012 +0300
@@ -31,7 +31,7 @@
 static char sccsid[] = "@(#)fstab.c	8.1 (Berkeley) 6/4/93";
 #endif /* LIBC_SCCS and not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/libc/gen/fstab.c 233300 2012-03-22 09:51:31Z pluknet $");
+__FBSDID("$FreeBSD: head/lib/libc/gen/fstab.c 237061 2012-06-14 12:28:43Z kib $");
 
 #include "namespace.h"
 #include <sys/param.h>
@@ -39,6 +39,7 @@
 #include <sys/stat.h>
 
 #include <errno.h>
+#include <fcntl.h>
 #include <fstab.h>
 #include <paths.h>
 #include <stdio.h>
@@ -246,6 +247,8 @@
 int 
 setfsent()
 {
+	int fd;
+
 	if (_fs_fp) {
 		rewind(_fs_fp);
 		LineNo = 0;
@@ -257,11 +260,18 @@
 		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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/gen/fts-compat.c
--- a/head/lib/libc/gen/fts-compat.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/gen/fts-compat.c	Wed Jul 25 16:23:00 2012 +0300
@@ -36,7 +36,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/gen/fts-compat.c 235647 2012-05-19 12:44:27Z gleb $");
 
 #include "namespace.h"
 #include <sys/param.h>
@@ -52,6 +52,8 @@
 #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 @@
 	 */
 	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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/gen/fts.c
--- a/head/lib/libc/gen/fts.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/gen/fts.c	Wed Jul 25 16:23:00 2012 +0300
@@ -36,7 +36,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/libc/gen/fts.c 231891 2012-02-18 00:55:54Z delphij $");
+__FBSDID("$FreeBSD: head/lib/libc/gen/fts.c 235647 2012-05-19 12:44:27Z gleb $");
 
 #include "namespace.h"
 #include <sys/param.h>
@@ -52,6 +52,8 @@
 #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 @@
 	 */
 	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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/gen/gen-private.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/lib/libc/gen/gen-private.h	Wed Jul 25 16:23:00 2012 +0300
@@ -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: head/lib/libc/gen/gen-private.h 235647 2012-05-19 12:44:27Z gleb $
+ */
+
+#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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/gen/getcwd.c
--- a/head/lib/libc/gen/getcwd.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/gen/getcwd.c	Wed Jul 25 16:23:00 2012 +0300
@@ -31,7 +31,7 @@
 static char sccsid[] = "@(#)getcwd.c	8.5 (Berkeley) 2/7/95";
 #endif /* LIBC_SCCS and not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/gen/getcwd.c 235647 2012-05-19 12:44:27Z gleb $");
 
 #include "namespace.h"
 #include <sys/param.h>
@@ -46,6 +46,8 @@
 #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 @@
 
 	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 @@
 		}
 
 		/* 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 @@
 					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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/gen/getnetgrent.c
--- a/head/lib/libc/gen/getnetgrent.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/gen/getnetgrent.c	Wed Jul 25 16:23:00 2012 +0300
@@ -34,7 +34,7 @@
 static char sccsid[] = "@(#)getnetgrent.c	8.2 (Berkeley) 4/27/95";
 #endif /* LIBC_SCCS and not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/libc/gen/getnetgrent.c 229938 2012-01-10 19:54:53Z ghelmer $");
+__FBSDID("$FreeBSD: head/lib/libc/gen/getnetgrent.c 237160 2012-06-16 13:11:10Z kib $");
 
 #include <ctype.h>
 #include <stdio.h>
@@ -161,8 +161,7 @@
 	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 @@
 		 * 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 @@
 			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 @@
 		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 @@
 	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 @@
 		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 @@
 
 	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 @@
 	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 @@
 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 @@
 			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 @@
 	/* 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 @@
 			 * 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 @@
 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 @@
 #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 @@
 				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 @@
 			free(result);
 		}
 #else
+	linep = NULL;
 	while (fgets(line, LINSIZ, netf) != NULL) {
 #endif
 		pos = (char *)&line;
@@ -576,8 +585,14 @@
 			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 @@
 				} 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 @@
 	 */
 	rewind(netf);
 #endif
-	return ((struct linelist *)0);
+	return (NULL);
 }
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/gen/opendir.c
--- a/head/lib/libc/gen/opendir.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/gen/opendir.c	Wed Jul 25 16:23:00 2012 +0300
@@ -31,7 +31,7 @@
 static char sccsid[] = "@(#)opendir.c	8.8 (Berkeley) 5/1/95";
 #endif /* LIBC_SCCS and not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/libc/gen/opendir.c 232385 2012-03-02 10:03:38Z ru $");
+__FBSDID("$FreeBSD: head/lib/libc/gen/opendir.c 235647 2012-05-19 12:44:27Z gleb $");
 
 #include "namespace.h"
 #include <sys/param.h>
@@ -46,6 +46,7 @@
 #include <unistd.h>
 #include "un-namespace.h"
 
+#include "gen-private.h"
 #include "telldir.h"
 
 static DIR * __opendir_common(int, const char *, int);
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/gen/posix_spawnattr_getflags.3
--- a/head/lib/libc/gen/posix_spawnattr_getflags.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/gen/posix_spawnattr_getflags.3	Wed Jul 25 16:23:00 2012 +0300
@@ -32,7 +32,7 @@
 .\" the referee document.  The original Standard can be obtained online at
 .\"	http://www.opengroup.org/unix/online.html.
 .\"
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/libc/gen/posix_spawnattr_getflags.3 236438 2012-06-02 08:47:26Z joel $
 .\"
 .Dd March 24, 2008
 .Dt POSIX_SPAWNATTR_GETFLAGS 3
@@ -70,7 +70,7 @@
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/gen/readdir.c
--- a/head/lib/libc/gen/readdir.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/gen/readdir.c	Wed Jul 25 16:23:00 2012 +0300
@@ -31,7 +31,7 @@
 static char sccsid[] = "@(#)readdir.c	8.3 (Berkeley) 9/29/94";
 #endif /* LIBC_SCCS and not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/gen/readdir.c 235647 2012-05-19 12:44:27Z gleb $");
 
 #include "namespace.h"
 #include <sys/param.h>
@@ -42,6 +42,7 @@
 #include "un-namespace.h"
 
 #include "libc_private.h"
+#include "gen-private.h"
 #include "telldir.h"
 
 /*
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/gen/rewinddir.c
--- a/head/lib/libc/gen/rewinddir.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/gen/rewinddir.c	Wed Jul 25 16:23:00 2012 +0300
@@ -31,11 +31,12 @@
 static char sccsid[] = "@(#)rewinddir.c	8.1 (Berkeley) 6/8/93";
 #endif /* LIBC_SCCS and not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/gen/rewinddir.c 235647 2012-05-19 12:44:27Z gleb $");
 
 #include <sys/types.h>
 #include <dirent.h>
 
+#include "gen-private.h"
 #include "telldir.h"
 
 void
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/gen/seekdir.c
--- a/head/lib/libc/gen/seekdir.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/gen/seekdir.c	Wed Jul 25 16:23:00 2012 +0300
@@ -31,7 +31,7 @@
 static char sccsid[] = "@(#)seekdir.c	8.1 (Berkeley) 6/4/93";
 #endif /* LIBC_SCCS and not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/gen/seekdir.c 235647 2012-05-19 12:44:27Z gleb $");
 
 #include "namespace.h"
 #include <sys/param.h>
@@ -40,6 +40,7 @@
 #include "un-namespace.h"
 
 #include "libc_private.h"
+#include "gen-private.h"
 #include "telldir.h"
 
 /*
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/gen/signal.3
--- a/head/lib/libc/gen/signal.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/gen/signal.3	Wed Jul 25 16:23:00 2012 +0300
@@ -26,7 +26,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)signal.3	8.3 (Berkeley) 4/19/94
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/libc/gen/signal.3 237156 2012-06-16 06:38:11Z joel $
 .\"
 .Dd June 7, 2004
 .Dt 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 @@
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/gen/sysconf.c
--- a/head/lib/libc/gen/sysconf.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/gen/sysconf.c	Wed Jul 25 16:23:00 2012 +0300
@@ -34,7 +34,7 @@
 static char sccsid[] = "@(#)sysconf.c	8.2 (Berkeley) 3/20/94";
 #endif /* LIBC_SCCS and not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/libc/gen/sysconf.c 223136 2011-06-16 02:22:24Z davidxu $");
+__FBSDID("$FreeBSD: head/lib/libc/gen/sysconf.c 237660 2012-06-27 20:32:45Z kib $");
 
 #include <sys/param.h>
 #include <sys/time.h>
@@ -42,6 +42,7 @@
 #include <sys/resource.h>
 #include <sys/socket.h>
 
+#include <elf.h>
 #include <errno.h>
 #include <limits.h>
 #include <paths.h>
@@ -51,6 +52,7 @@
 
 #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 @@
 
 	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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/gen/syslog.c
--- a/head/lib/libc/gen/syslog.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/gen/syslog.c	Wed Jul 25 16:23:00 2012 +0300
@@ -31,7 +31,7 @@
 static char sccsid[] = "@(#)syslog.c	8.5 (Berkeley) 4/29/95";
 #endif /* LIBC_SCCS and not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/libc/gen/syslog.c 228193 2011-12-02 01:06:33Z obrien $");
+__FBSDID("$FreeBSD: head/lib/libc/gen/syslog.c 237523 2012-06-24 07:03:22Z eadler $");
 
 #include "namespace.h"
 #include <sys/types.h>
@@ -413,8 +413,10 @@
 closelog(void)
 {
 	THREAD_LOCK();
-	(void)_close(LogFile);
-	LogFile = -1;
+	if (LogFile != -1) {
+		(void)_close(LogFile);
+		LogFile = -1;
+	}
 	LogTag = NULL;
 	status = NOCONN;
 	THREAD_UNLOCK();
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/gen/telldir.c
--- a/head/lib/libc/gen/telldir.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/gen/telldir.c	Wed Jul 25 16:23:00 2012 +0300
@@ -31,7 +31,7 @@
 static char sccsid[] = "@(#)telldir.c	8.1 (Berkeley) 6/4/93";
 #endif /* LIBC_SCCS and not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/gen/telldir.c 235647 2012-05-19 12:44:27Z gleb $");
 
 #include "namespace.h"
 #include <sys/param.h>
@@ -43,6 +43,7 @@
 #include "un-namespace.h"
 
 #include "libc_private.h"
+#include "gen-private.h"
 #include "telldir.h"
 
 /*
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/gen/tls.c
--- a/head/lib/libc/gen/tls.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/gen/tls.c	Wed Jul 25 16:23:00 2012 +0300
@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- *	$FreeBSD: head/lib/libc/gen/tls.c 234370 2012-04-17 07:22:14Z jasone $
+ *	$FreeBSD: head/lib/libc/gen/tls.c 234569 2012-04-22 08:49:13Z jasone $
  */
 
 /*
@@ -40,9 +40,9 @@
 #include "libc_private.h"
 
 /* Provided by jemalloc to avoid bootstrapping issues. */
-void	*a0malloc(size_t size);
-void	*a0calloc(size_t num, size_t size);
-void	a0free(void *ptr);
+void	*__jemalloc_a0malloc(size_t size);
+void	*__jemalloc_a0calloc(size_t num, size_t size);
+void	__jemalloc_a0free(void *ptr);
 
 __weak_reference(__libc_allocate_tls, _rtld_allocate_tls);
 __weak_reference(__libc_free_tls, _rtld_free_tls);
@@ -125,8 +125,8 @@
 
 	tls = (Elf_Addr **)((Elf_Addr)tcb + tcbsize - TLS_TCB_SIZE);
 	dtv = tls[0];
-	a0free(dtv);
-	a0free(tcb);
+	__jemalloc_a0free(dtv);
+	__jemalloc_a0free(tcb);
 }
 
 /*
@@ -142,18 +142,18 @@
 	if (oldtcb != NULL && tcbsize == TLS_TCB_SIZE)
 		return (oldtcb);
 
-	tcb = a0calloc(1, tls_static_space + tcbsize - TLS_TCB_SIZE);
+	tcb = __jemalloc_a0calloc(1, tls_static_space + tcbsize - TLS_TCB_SIZE);
 	tls = (Elf_Addr **)(tcb + tcbsize - TLS_TCB_SIZE);
 
 	if (oldtcb != NULL) {
 		memcpy(tls, oldtcb, tls_static_space);
-		a0free(oldtcb);
+		__jemalloc_a0free(oldtcb);
 
 		/* Adjust the DTV. */
 		dtv = tls[0];
 		dtv[2] = (Elf_Addr)tls + TLS_TCB_SIZE;
 	} else {
-		dtv = a0malloc(3 * sizeof(Elf_Addr));
+		dtv = __jemalloc_a0malloc(3 * sizeof(Elf_Addr));
 		tls[0] = dtv;
 		dtv[0] = 1;
 		dtv[1] = 1;
@@ -194,8 +194,8 @@
 	dtv = ((Elf_Addr**)tcb)[1];
 	tlsend = (Elf_Addr) tcb;
 	tlsstart = tlsend - size;
-	a0free((void*) tlsstart);
-	a0free(dtv);
+	__jemalloc_a0free((void*) tlsstart);
+	__jemalloc_a0free(dtv);
 }
 
 /*
@@ -213,8 +213,8 @@
 
 	if (tcbsize < 2 * sizeof(Elf_Addr))
 		tcbsize = 2 * sizeof(Elf_Addr);
-	tls = a0calloc(1, size + tcbsize);
-	dtv = a0malloc(3 * sizeof(Elf_Addr));
+	tls = __jemalloc_a0calloc(1, size + tcbsize);
+	dtv = __jemalloc_a0malloc(3 * sizeof(Elf_Addr));
 
 	segbase = (Elf_Addr)(tls + size);
 	((Elf_Addr*)segbase)[0] = segbase;
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/gmon/gmon.c
--- a/head/lib/libc/gmon/gmon.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/gmon/gmon.c	Wed Jul 25 16:23:00 2012 +0300
@@ -31,7 +31,7 @@
 static char sccsid[] = "@(#)gmon.c	8.1 (Berkeley) 6/4/93";
 #endif
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/gmon/gmon.c 234819 2012-04-29 22:19:58Z eadler $");
 
 #include "namespace.h"
 #include <sys/param.h>
@@ -157,7 +157,12 @@
 	}
 
 	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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/gmon/moncontrol.3
--- a/head/lib/libc/gmon/moncontrol.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/gmon/moncontrol.3	Wed Jul 25 16:23:00 2012 +0300
@@ -26,7 +26,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"	@(#)moncontrol.3	8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/libc/gmon/moncontrol.3 235327 2012-05-12 07:52:45Z joel $
 .\"
 .Dd June 14, 2004
 .Dt MONCONTROL 3
@@ -98,6 +98,13 @@
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/i386/gen/getcontextx.c
--- a/head/lib/libc/i386/gen/getcontextx.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/i386/gen/getcontextx.c	Wed Jul 25 16:23:00 2012 +0300
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/libc/i386/gen/getcontextx.c 230864 2012-02-01 13:33:53Z kib $");
+__FBSDID("$FreeBSD: head/lib/libc/i386/gen/getcontextx.c 238328 2012-07-10 01:47:11Z davidxu $");
 
 #include <sys/types.h>
 #include <sys/ucontext.h>
@@ -68,7 +68,7 @@
 			    "	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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/i386/sys/Makefile.inc
--- a/head/lib/libc/i386/sys/Makefile.inc	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/i386/sys/Makefile.inc	Wed Jul 25 16:23:00 2012 +0300
@@ -1,11 +1,12 @@
 #	from: Makefile.inc,v 1.1 1993/09/03 19:04:23 jtc Exp
-# $FreeBSD$
+# $FreeBSD: head/lib/libc/i386/sys/Makefile.inc 237434 2012-06-22 07:13:30Z kib $
 
 .if !defined(COMPAT_32BIT)
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/i386/sys/__vdso_gettc.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/lib/libc/i386/sys/__vdso_gettc.c	Wed Jul 25 16:23:00 2012 +0300
@@ -0,0 +1,50 @@
+/*-
+ * Copyright (c) 2012 Konstantin Belousov <kib at 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: head/lib/libc/i386/sys/__vdso_gettc.c 237434 2012-06-22 07:13:30Z kib $");
+
+#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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/include/libc_private.h
--- a/head/lib/libc/include/libc_private.h	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/include/libc_private.h	Wed Jul 25 16:23:00 2012 +0300
@@ -26,7 +26,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: head/lib/libc/include/libc_private.h 231868 2012-02-17 10:49:29Z kib $
+ * $FreeBSD: head/lib/libc/include/libc_private.h 237434 2012-06-22 07:13:30Z kib $
  *
  * Private definitions for libc, libc_r and libpthread.
  *
@@ -34,6 +34,7 @@
 
 #ifndef _LIBC_PRIVATE_H_
 #define _LIBC_PRIVATE_H_
+#include <sys/_types.h>
 #include <sys/_pthreadtypes.h>
 
 /*
@@ -81,6 +82,19 @@
 #define	FLOCKFILE(fp)		if (__isthreaded) _FLOCKFILE(fp)
 #define	FUNLOCKFILE(fp)		if (__isthreaded) _funlockfile(fp)
 
+struct _spinlock;
+extern struct _spinlock __stdio_thread_lock;
+#define STDIO_THREAD_LOCK()				\
+do {							\
+	if (__isthreaded)				\
+		_SPINLOCK(&__stdio_thread_lock);	\
+} while (0)
+#define STDIO_THREAD_UNLOCK()				\
+do {							\
+	if (__isthreaded)				\
+		_SPINUNLOCK(&__stdio_thread_lock);	\
+} while (0)
+
 /*
  * Indexes into the pthread jump table.
  *
@@ -232,6 +246,12 @@
 /* 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/include/port_before.h
--- a/head/lib/libc/include/port_before.h	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/include/port_before.h	Wed Jul 25 16:23:00 2012 +0300
@@ -1,4 +1,4 @@
-/* $FreeBSD$ */
+/* $FreeBSD: head/lib/libc/include/port_before.h 236695 2012-06-06 21:16:26Z dim $ */
 
 #ifndef _PORT_BEFORE_H_
 #define _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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/locale/Symbol.map
--- a/head/lib/libc/locale/Symbol.map	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/locale/Symbol.map	Wed Jul 25 16:23:00 2012 +0300
@@ -1,5 +1,5 @@
 /*
- * $FreeBSD: head/lib/libc/locale/Symbol.map 232926 2012-03-13 14:14:13Z theraven $
+ * $FreeBSD: head/lib/libc/locale/Symbol.map 234578 2012-04-22 18:51:38Z theraven $
  */
 
 FBSD_1.0 {
@@ -60,13 +60,9 @@
 	nextwctype;
 	nl_langinfo;
 	__maskrune;
-	__maskrune_l;
 	__sbmaskrune;
-	__sbmaskrune_l;
 	__istype;
-	__istype_l;
 	__sbistype;
-	__sbistype_l;
 	__isctype;
 	__toupper;
 	__sbtoupper;
@@ -197,6 +193,10 @@
 	wcstoul_l;
 	wcstoull_l;
 	wcstoumax_l;
+	__sbistype_l;
+	__maskrune_l;
+	__sbmaskrune_l;
+	__istype_l;
 	__runes_for_locale;
 	_ThreadRuneLocale;
 };
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/locale/collate.c
--- a/head/lib/libc/locale/collate.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/locale/collate.c	Wed Jul 25 16:23:00 2012 +0300
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/libc/locale/collate.c 232601 2012-03-06 12:53:44Z theraven $");
+__FBSDID("$FreeBSD: head/lib/libc/locale/collate.c 238182 2012-07-06 20:16:22Z theraven $");
 
 #include "namespace.h"
 #include <arpa/inet.h>
@@ -56,11 +56,11 @@
  * 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 @@
 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 @@
 
 	/* '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 @@
 			break;
 		}
 	}
-	__collate_load_error = 0;
+	table->__collate_load_error = 0;
 
 	return (_LDP_LOADED);
 }
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/locale/ctype_l.3
--- a/head/lib/libc/locale/ctype_l.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/locale/ctype_l.3	Wed Jul 25 16:23:00 2012 +0300
@@ -25,7 +25,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD: head/lib/libc/locale/ctype_l.3 233648 2012-03-29 05:02:12Z eadler $
+.\" $FreeBSD: head/lib/libc/locale/ctype_l.3 237939 2012-07-01 22:18:20Z jilles $
 .\"
 .Dd March 6, 2012
 .Dt CTYPE_L 3
@@ -135,4 +135,17 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/locale/duplocale.3
--- a/head/lib/libc/locale/duplocale.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/locale/duplocale.3	Wed Jul 25 16:23:00 2012 +0300
@@ -25,7 +25,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD: head/lib/libc/locale/duplocale.3 233518 2012-03-26 19:06:59Z joel $
+.\" $FreeBSD: head/lib/libc/locale/duplocale.3 235286 2012-05-11 20:06:46Z gjb $
 .\"
 .Dd September 17 2011
 .Dt DUPLOCALE 3
@@ -44,10 +44,10 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/locale/freelocale.3
--- a/head/lib/libc/locale/freelocale.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/locale/freelocale.3	Wed Jul 25 16:23:00 2012 +0300
@@ -25,7 +25,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD: head/lib/libc/locale/freelocale.3 228199 2011-12-02 11:55:09Z obrien $
+.\" $FreeBSD: head/lib/libc/locale/freelocale.3 235286 2012-05-11 20:06:46Z gjb $
 .Dd September 17 2011
 .Dt FREELOCALE 3
 .Os
@@ -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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/locale/newlocale.3
--- a/head/lib/libc/locale/newlocale.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/locale/newlocale.3	Wed Jul 25 16:23:00 2012 +0300
@@ -25,7 +25,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD: head/lib/libc/locale/newlocale.3 233994 2012-04-07 09:26:21Z joel $
+.\" $FreeBSD: head/lib/libc/locale/newlocale.3 235286 2012-05-11 20:06:46Z gjb $
 .Dd September 17 2011
 .Dt NEWLOCALE 3
 .Os
@@ -51,7 +51,7 @@
 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 @@
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/locale/querylocale.3
--- a/head/lib/libc/locale/querylocale.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/locale/querylocale.3	Wed Jul 25 16:23:00 2012 +0300
@@ -25,14 +25,14 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD: head/lib/libc/locale/querylocale.3 228199 2011-12-02 11:55:09Z obrien $
+.\" $FreeBSD: head/lib/libc/locale/querylocale.3 235286 2012-05-11 20:06:46Z gjb $
 .\"
 .Dd September 17 2011
 .Dt QUERYLOCALE 3
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/locale/setrunelocale.c
--- a/head/lib/libc/locale/setrunelocale.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/locale/setrunelocale.c	Wed Jul 25 16:23:00 2012 +0300
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/libc/locale/setrunelocale.c 232498 2012-03-04 15:31:13Z theraven $");
+__FBSDID("$FreeBSD: head/lib/libc/locale/setrunelocale.c 238182 2012-07-06 20:16:22Z theraven $");
 
 #define __RUNETYPE_INTERNAL 1
 
@@ -67,7 +67,6 @@
 
 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 @@
 	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 @@
 	 * 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 @@
 
 	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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/locale/toupper.c
--- a/head/lib/libc/locale/toupper.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/locale/toupper.c	Wed Jul 25 16:23:00 2012 +0300
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/libc/locale/toupper.c 227753 2011-11-20 14:45:42Z theraven $");
+__FBSDID("$FreeBSD: head/lib/libc/locale/toupper.c 235239 2012-05-10 20:03:34Z dim $");
 
 #include <ctype.h>
 #include <stdio.h>
@@ -51,7 +51,7 @@
 {
 	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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/locale/uselocale.3
--- a/head/lib/libc/locale/uselocale.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/locale/uselocale.3	Wed Jul 25 16:23:00 2012 +0300
@@ -25,14 +25,14 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD: head/lib/libc/locale/uselocale.3 228199 2011-12-02 11:55:09Z obrien $
+.\" $FreeBSD: head/lib/libc/locale/uselocale.3 235286 2012-05-11 20:06:46Z gjb $
 .\"
 .Dd September 17 2011
 .Dt USELOCALE 3
 .Os
 .Sh NAME
 .Nm uselocale
-.Nd Sets a thread-local locale.
+.Nd Sets a thread-local locale
 .Sh LIBRARY
 .Lb libc
 .Sh SYNOPSIS
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/locale/xlocale.3
--- a/head/lib/libc/locale/xlocale.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/locale/xlocale.3	Wed Jul 25 16:23:00 2012 +0300
@@ -25,14 +25,14 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD: head/lib/libc/locale/xlocale.3 233466 2012-03-25 16:00:56Z joel $
+.\" $FreeBSD: head/lib/libc/locale/xlocale.3 235286 2012-05-11 20:06:46Z gjb $
 .\"
 .Dd September 17 2011
 .Dt XLOCALE 3
 .Os
 .Sh NAME
 .Nm xlocale
-.Nd Thread-safe extended locale support.
+.Nd Thread-safe extended locale support
 .Sh LIBRARY
 .Lb libc
 .Sh SYNOPSIS
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/net/Makefile.inc
--- a/head/lib/libc/net/Makefile.inc	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/net/Makefile.inc	Wed Jul 25 16:23:00 2012 +0300
@@ -1,5 +1,5 @@
 #	from @(#)Makefile.inc	8.2 (Berkeley) 9/5/93
-# $FreeBSD$
+# $FreeBSD: head/lib/libc/net/Makefile.inc 237402 2012-06-21 15:47:06Z obrien $
 
 # machine-independent net sources
 .PATH: ${.CURDIR}/net
@@ -36,7 +36,7 @@
 
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/net/Symbol.map
--- a/head/lib/libc/net/Symbol.map	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/net/Symbol.map	Wed Jul 25 16:23:00 2012 +0300
@@ -1,5 +1,5 @@
 /*
- * $FreeBSD: head/lib/libc/net/Symbol.map 226111 2011-10-07 15:05:24Z ed $
+ * $FreeBSD: head/lib/libc/net/Symbol.map 234716 2012-04-26 19:56:06Z tuexen $
  */
 
 FBSD_1.0 {
@@ -143,6 +143,11 @@
 	setsourcefilter;
 };
 
+FBSD_1.3 {
+	sctp_recvv;
+	sctp_sendv;
+};
+
 FBSDprivate_1.0 {
 	_nsdispatch;
 	_nsyyerror;	/* generated from nslexer.l */
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/net/getaddrinfo.c
--- a/head/lib/libc/net/getaddrinfo.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/net/getaddrinfo.c	Wed Jul 25 16:23:00 2012 +0300
@@ -54,7 +54,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/libc/net/getaddrinfo.c 233770 2012-04-02 07:42:17Z delphij $");
+__FBSDID("$FreeBSD: head/lib/libc/net/getaddrinfo.c 238599 2012-07-18 15:52:09Z emax $");
 
 #include "namespace.h"
 #include <sys/types.h>
@@ -155,7 +155,6 @@
 	int e_af;
 	int e_socktype;
 	int e_protocol;
-	const char *e_protostr;
 	int e_wild;
 #define WILD_AF(ex)		((ex)->e_wild & 0x01)
 #define WILD_SOCKTYPE(ex)	((ex)->e_wild & 0x02)
@@ -164,21 +163,21 @@
 
 static const struct explore explore[] = {
 #if 0
-	{ PF_LOCAL, ANY, ANY, NULL, 0x01 },
+	{ PF_LOCAL, ANY, ANY, 0x01 },
 #endif
 #ifdef INET6
-	{ PF_INET6, SOCK_DGRAM, IPPROTO_UDP, "udp", 0x07 },
-	{ PF_INET6, SOCK_STREAM, IPPROTO_TCP, "tcp", 0x07 },
-	{ PF_INET6, SOCK_STREAM, IPPROTO_SCTP, "sctp", 0x03 },
-	{ PF_INET6, SOCK_SEQPACKET, IPPROTO_SCTP, "sctp", 0x07 },
-	{ PF_INET6, SOCK_RAW, ANY, NULL, 0x05 },
+	{ PF_INET6, SOCK_DGRAM, IPPROTO_UDP, 0x07 },
+	{ PF_INET6, SOCK_STREAM, IPPROTO_TCP, 0x07 },
+	{ PF_INET6, SOCK_STREAM, IPPROTO_SCTP, 0x03 },
+	{ PF_INET6, SOCK_SEQPACKET, IPPROTO_SCTP, 0x07 },
+	{ PF_INET6, SOCK_RAW, ANY, 0x05 },
 #endif
-	{ PF_INET, SOCK_DGRAM, IPPROTO_UDP, "udp", 0x07 },
-	{ PF_INET, SOCK_STREAM, IPPROTO_TCP, "tcp", 0x07 },
-	{ PF_INET, SOCK_STREAM, IPPROTO_SCTP, "sctp", 0x03 },
-	{ PF_INET, SOCK_SEQPACKET, IPPROTO_SCTP, "sctp", 0x07 },
-	{ PF_INET, SOCK_RAW, ANY, NULL, 0x05 },
-	{ -1, 0, 0, NULL, 0 },
+	{ PF_INET, SOCK_DGRAM, IPPROTO_UDP, 0x07 },
+	{ PF_INET, SOCK_STREAM, IPPROTO_TCP, 0x07 },
+	{ PF_INET, SOCK_STREAM, IPPROTO_SCTP, 0x03 },
+	{ PF_INET, SOCK_SEQPACKET, IPPROTO_SCTP, 0x07 },
+	{ PF_INET, SOCK_RAW, ANY, 0x05 },
+	{ -1, 0, 0, 0 },
 };
 
 #ifdef INET6
@@ -464,7 +463,7 @@
 		}
 		error = get_portmatch(pai, servname);
 		if (error)
-			ERR(error);
+			goto bad;
 
 		*pai = ai0;
 	}
@@ -693,6 +692,8 @@
 
 	if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), NULL, &l, NULL, 0) < 0)
 		return (0);
+	if (l == 0)
+		return (0);
 	if ((buf = malloc(l)) == NULL)
 		return (0);
 	if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), buf, &l, NULL, 0) < 0) {
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/net/if_indextoname.c
--- a/head/lib/libc/net/if_indextoname.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/net/if_indextoname.c	Wed Jul 25 16:23:00 2012 +0300
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/net/if_indextoname.c 235640 2012-05-19 02:39:43Z marcel $");
 
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -70,7 +70,7 @@
 	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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/net/if_nameindex.c
--- a/head/lib/libc/net/if_nameindex.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/net/if_nameindex.c	Wed Jul 25 16:23:00 2012 +0300
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/net/if_nameindex.c 235640 2012-05-19 02:39:43Z marcel $");
 
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -123,7 +123,7 @@
 		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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/net/if_nametoindex.c
--- a/head/lib/libc/net/if_nametoindex.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/net/if_nametoindex.c	Wed Jul 25 16:23:00 2012 +0300
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/libc/net/if_nametoindex.c 234329 2012-04-15 23:56:03Z eadler $");
+__FBSDID("$FreeBSD: head/lib/libc/net/if_nametoindex.c 235640 2012-05-19 02:39:43Z marcel $");
 
 #include "namespace.h"
 #include <sys/types.h>
@@ -90,7 +90,7 @@
 		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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/net/nsdispatch.3
--- a/head/lib/libc/net/nsdispatch.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/net/nsdispatch.3	Wed Jul 25 16:23:00 2012 +0300
@@ -30,7 +30,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.\" $FreeBSD: head/lib/libc/net/nsdispatch.3 233576 2012-03-27 20:39:49Z joel $
+.\" $FreeBSD: head/lib/libc/net/nsdispatch.3 235401 2012-05-13 14:28:00Z joel $
 .\"
 .Dd April 4, 2010
 .Dt NSDISPATCH 3
@@ -173,11 +173,11 @@
 #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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/net/nsparser.y
--- a/head/lib/libc/net/nsparser.y	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/net/nsparser.y	Wed Jul 25 16:23:00 2012 +0300
@@ -38,12 +38,13 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/net/nsparser.y 235767 2012-05-22 01:28:32Z kevlo $");
 
 #include "namespace.h"
 #define _NS_PRIVATE
 #include <nsswitch.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <syslog.h>
 #include "un-namespace.h"
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/net/sctp_connectx.3
--- a/head/lib/libc/net/sctp_connectx.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/net/sctp_connectx.3	Wed Jul 25 16:23:00 2012 +0300
@@ -29,14 +29,14 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD: head/lib/libc/net/sctp_connectx.3 233648 2012-03-29 05:02:12Z eadler $
+.\" $FreeBSD: head/lib/libc/net/sctp_connectx.3 235286 2012-05-11 20:06:46Z gjb $
 .\"
 .Dd June 19, 2007
 .Dt SCTP_CONNECTX 3
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/net/sctp_recvmsg.3
--- a/head/lib/libc/net/sctp_recvmsg.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/net/sctp_recvmsg.3	Wed Jul 25 16:23:00 2012 +0300
@@ -29,7 +29,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD: head/lib/libc/net/sctp_recvmsg.3 233648 2012-03-29 05:02:12Z eadler $
+.\" $FreeBSD: head/lib/libc/net/sctp_recvmsg.3 235286 2012-05-11 20:06:46Z gjb $
 .\"
 .Dd August 13, 2007
 .Dt SCTP_RECVMSG 3
@@ -66,7 +66,7 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/net/sctp_sys_calls.c
--- a/head/lib/libc/net/sctp_sys_calls.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/net/sctp_sys_calls.c	Wed Jul 25 16:23:00 2012 +0300
@@ -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:
@@ -31,7 +31,8 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/libc/net/sctp_sys_calls.c 228630 2011-12-17 14:55:19Z tuexen $");
+__FBSDID("$FreeBSD: head/lib/libc/net/sctp_sys_calls.c 235827 2012-05-23 10:35:40Z tuexen $");
+
 #include <stdio.h>
 #include <string.h>
 #include <errno.h>
@@ -800,7 +801,6 @@
 	}
 	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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/net/sourcefilter.3
--- a/head/lib/libc/net/sourcefilter.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/net/sourcefilter.3	Wed Jul 25 16:23:00 2012 +0300
@@ -22,7 +22,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD: head/lib/libc/net/sourcefilter.3 233648 2012-03-29 05:02:12Z eadler $
+.\" $FreeBSD: head/lib/libc/net/sourcefilter.3 235286 2012-05-11 20:06:46Z gjb $
 .\"
 .Dd February 13, 2009
 .Dt SOURCEFILTER 3
@@ -158,7 +158,7 @@
 .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 @@
 .Sh SEE ALSO
 .Xr ip 4 ,
 .Xr ip6 4 ,
-.Xr multicast 4,
+.Xr multicast 4 ,
 .Xr ifmcstat 8
 .Rs
 .%A D. Thaler
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/net/sourcefilter.c
--- a/head/lib/libc/net/sourcefilter.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/net/sourcefilter.c	Wed Jul 25 16:23:00 2012 +0300
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/net/sourcefilter.c 235640 2012-05-19 02:39:43Z marcel $");
 
 #include "namespace.h"
 
@@ -120,7 +120,7 @@
 		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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/posix1e/acl_delete_entry.3
--- a/head/lib/libc/posix1e/acl_delete_entry.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/posix1e/acl_delete_entry.3	Wed Jul 25 16:23:00 2012 +0300
@@ -23,14 +23,14 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/libc/posix1e/acl_delete_entry.3 235286 2012-05-11 20:06:46Z gjb $
 .\"
 .Dd June 25, 2009
 .Dt ACL_DELETE_ENTRY 3
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/posix1e/mac_prepare.3
--- a/head/lib/libc/posix1e/mac_prepare.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/posix1e/mac_prepare.3	Wed Jul 25 16:23:00 2012 +0300
@@ -28,7 +28,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/libc/posix1e/mac_prepare.3 235400 2012-05-13 14:16:04Z joel $
 .\"
 .Dd August 22, 2003
 .Dt MAC_PREPARE 3
@@ -64,7 +64,7 @@
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/powerpc/Symbol.map
--- a/head/lib/libc/powerpc/Symbol.map	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/powerpc/Symbol.map	Wed Jul 25 16:23:00 2012 +0300
@@ -1,5 +1,5 @@
 /*
- * $FreeBSD: head/lib/libc/powerpc/Symbol.map 226606 2011-10-21 06:40:36Z das $
+ * $FreeBSD: head/lib/libc/powerpc/Symbol.map 236006 2012-05-25 16:30:42Z marcel $
  */
 
 /*
@@ -38,6 +38,10 @@
 	vfork;
 };
 
+FBSD_1.3 {
+	__eabi;
+};
+
 FBSDprivate_1.0 {
 	/* PSEUDO syscalls */
 	__sys_getlogin;
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/powerpc/gen/Makefile.inc
--- a/head/lib/libc/powerpc/gen/Makefile.inc	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/powerpc/gen/Makefile.inc	Wed Jul 25 16:23:00 2012 +0300
@@ -1,6 +1,6 @@
-# $FreeBSD: head/lib/libc/powerpc/gen/Makefile.inc 230429 2012-01-21 18:00:28Z kib $
+# $FreeBSD: head/lib/libc/powerpc/gen/Makefile.inc 235929 2012-05-24 20:12:46Z marcel $
 
-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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/powerpc/gen/eabi.S
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/lib/libc/powerpc/gen/eabi.S	Wed Jul 25 16:23:00 2012 +0300
@@ -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: head/lib/libc/powerpc/gen/eabi.S 235929 2012-05-24 20:12:46Z marcel $");
+
+ENTRY(__eabi)
+	blr
+
+	.section .note.GNU-stack,"",%progbits
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/rpc/auth_unix.c
--- a/head/lib/libc/rpc/auth_unix.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/rpc/auth_unix.c	Wed Jul 25 16:23:00 2012 +0300
@@ -34,7 +34,7 @@
 static char *sccsid = "@(#)auth_unix.c	2.2 88/08/01 4.0 RPCSRC";
 #endif
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/rpc/auth_unix.c 235143 2012-05-08 19:47:52Z kib $");
 
 /*
  * auth_unix.c, Implements UNIX style authentication parameters.
@@ -185,6 +185,7 @@
 AUTH *
 authunix_create_default()
 {
+	AUTH *auth;
 	int ngids;
 	long ngids_max;
 	char machname[MAXHOSTNAMELEN + 1];
@@ -207,8 +208,10 @@
 	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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/rpc/getnetpath.c
--- a/head/lib/libc/rpc/getnetpath.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/rpc/getnetpath.c	Wed Jul 25 16:23:00 2012 +0300
@@ -34,7 +34,7 @@
 static char sccsid[] = "@(#)getnetpath.c	1.11 91/12/19 SMI";
 #endif
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/rpc/getnetpath.c 238483 2012-07-15 11:52:24Z brueffer $");
 
 /*
  * Copyright (c) 1989 by Sun Microsystems, Inc.
@@ -99,9 +99,8 @@
 	return (NULL);
     }
     if ((np_sessionp->nc_handlep = setnetconfig()) == NULL) {
-	free(np_sessionp);
 	syslog (LOG_ERR, "rpc: failed to open " NETCONFIG);
-    	return (NULL);
+	goto failed;
     }
     np_sessionp->valid = NP_VALID;
     np_sessionp->ncp_list = NULL;
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/rpc/publickey.3
--- a/head/lib/libc/rpc/publickey.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/rpc/publickey.3	Wed Jul 25 16:23:00 2012 +0300
@@ -1,5 +1,5 @@
 .\" @(#)publickey.3r	2.1 88/08/07 4.0 RPCSRC
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/libc/rpc/publickey.3 235286 2012-05-11 20:06:46Z gjb $
 .\"
 .Dd October 6, 1987
 .Dt PUBLICKEY 3
@@ -35,14 +35,14 @@
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/rpc/svc.c
--- a/head/lib/libc/rpc/svc.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/rpc/svc.c	Wed Jul 25 16:23:00 2012 +0300
@@ -34,7 +34,7 @@
 static char *sccsid = "@(#)svc.c	2.4 88/08/11 4.0 RPCSRC";
 #endif
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/rpc/svc.c 234769 2012-04-28 18:57:27Z kib $");
 
 /*
  * svc.c, Server-side remote procedure call interface.
@@ -108,8 +108,10 @@
 	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 @@
 	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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/rpc/svc_raw.c
--- a/head/lib/libc/rpc/svc_raw.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/rpc/svc_raw.c	Wed Jul 25 16:23:00 2012 +0300
@@ -38,7 +38,7 @@
 static char sccsid[] = "@(#)svc_raw.c 1.25 89/01/31 Copyr 1984 Sun Micro";
 #endif
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/rpc/svc_raw.c 234769 2012-04-28 18:57:27Z kib $");
 
 /*
  * svc_raw.c,   This a toy for simple testing and timing.
@@ -96,10 +96,22 @@
 			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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/stdio/Makefile.inc
--- a/head/lib/libc/stdio/Makefile.inc	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/stdio/Makefile.inc	Wed Jul 25 16:23:00 2012 +0300
@@ -1,5 +1,5 @@
 #	@(#)Makefile.inc	8.3 (Berkeley) 4/17/94
-# $FreeBSD$
+# $FreeBSD: head/lib/libc/stdio/Makefile.inc 235848 2012-05-23 17:13:30Z issyl0 $
 
 # stdio sources
 .PATH: ${.CURDIR}/stdio
@@ -36,7 +36,8 @@
 	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 @@
 	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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/stdio/fclose.c
--- a/head/lib/libc/stdio/fclose.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/stdio/fclose.c	Wed Jul 25 16:23:00 2012 +0300
@@ -34,13 +34,14 @@
 static char sccsid[] = "@(#)fclose.c	8.1 (Berkeley) 6/4/93";
 #endif /* LIBC_SCCS and not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/stdio/fclose.c 234657 2012-04-24 17:51:36Z kib $");
 
 #include "namespace.h"
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include "un-namespace.h"
+#include <spinlock.h>
 #include "libc_private.h"
 #include "local.h"
 
@@ -65,7 +66,20 @@
 		FREELB(fp);
 	fp->_file = -1;
 	fp->_r = fp->_w = 0;	/* Mess up if reaccessed. */
+
+	/*
+	 * Lock the spinlock used to protect __sglue list walk in
+	 * __sfp().  The __sfp() uses fp->_flags == 0 test as an
+	 * indication of the unused FILE.
+	 *
+	 * Taking the lock prevents possible compiler or processor
+	 * reordering of the writes performed before the final _flags
+	 * cleanup, making sure that we are done with the FILE before
+	 * it is considered available.
+	 */
+	STDIO_THREAD_LOCK();
 	fp->_flags = 0;		/* Release this FILE for reuse. */
+	STDIO_THREAD_UNLOCK();
 	FUNLOCKFILE(fp);
 	return (r);
 }
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/stdio/fgets.3
--- a/head/lib/libc/stdio/fgets.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/stdio/fgets.3	Wed Jul 25 16:23:00 2012 +0300
@@ -30,9 +30,9 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)fgets.3	8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/libc/stdio/fgets.3 235202 2012-05-09 17:27:49Z eadler $
 .\"
-.Dd June 4, 1993
+.Dd May 5, 2012
 .Dt FGETS 3
 .Os
 .Sh NAME
@@ -154,5 +154,3 @@
 It is strongly suggested that the
 .Fn fgets
 function be used in all cases.
-(See
-the FSA.)
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/stdio/fgetwc.c
--- a/head/lib/libc/stdio/fgetwc.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/stdio/fgetwc.c	Wed Jul 25 16:23:00 2012 +0300
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/libc/stdio/fgetwc.c 227753 2011-11-20 14:45:42Z theraven $");
+__FBSDID("$FreeBSD: head/lib/libc/stdio/fgetwc.c 234799 2012-04-29 16:28:39Z das $");
 
 #include "namespace.h"
 #include <errno.h>
@@ -59,6 +59,7 @@
 
 	return (r);
 }
+
 wint_t
 fgetwc(FILE *fp)
 {
@@ -66,40 +67,45 @@
 }
 
 /*
- * 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/stdio/findfp.c
--- a/head/lib/libc/stdio/findfp.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/stdio/findfp.c	Wed Jul 25 16:23:00 2012 +0300
@@ -34,7 +34,7 @@
 static char sccsid[] = "@(#)findfp.c	8.2 (Berkeley) 1/4/94";
 #endif /* LIBC_SCCS and not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/stdio/findfp.c 234657 2012-04-24 17:51:36Z kib $");
 
 #include <sys/param.h>
 #include <machine/atomic.h>
@@ -82,9 +82,7 @@
 
 static struct glue *	moreglue(int);
 
-static spinlock_t thread_lock = _SPINLOCK_INITIALIZER;
-#define THREAD_LOCK()	if (__isthreaded) _SPINLOCK(&thread_lock)
-#define THREAD_UNLOCK()	if (__isthreaded) _SPINUNLOCK(&thread_lock)
+spinlock_t __stdio_thread_lock = _SPINLOCK_INITIALIZER;
 
 #if NOT_YET
 #define	SET_GLUE_PTR(ptr, val)	atomic_set_rel_ptr(&(ptr), (uintptr_t)(val))
@@ -127,22 +125,22 @@
 	/*
 	 * The list must be locked because a FILE may be updated.
 	 */
-	THREAD_LOCK();
+	STDIO_THREAD_LOCK();
 	for (g = &__sglue; g != NULL; g = g->next) {
 		for (fp = g->iobs, n = g->niobs; --n >= 0; fp++)
 			if (fp->_flags == 0)
 				goto found;
 	}
-	THREAD_UNLOCK();	/* don't hold lock while malloc()ing. */
+	STDIO_THREAD_UNLOCK();	/* don't hold lock while malloc()ing. */
 	if ((g = moreglue(NDYNAMIC)) == NULL)
 		return (NULL);
-	THREAD_LOCK();		/* reacquire the lock */
+	STDIO_THREAD_LOCK();	/* reacquire the lock */
 	SET_GLUE_PTR(lastglue->next, g); /* atomically append glue to list */
 	lastglue = g;		/* not atomic; only accessed when locked */
 	fp = g->iobs;
 found:
 	fp->_flags = 1;		/* reserve this slot; caller sets real flags */
-	THREAD_UNLOCK();
+	STDIO_THREAD_UNLOCK();
 	fp->_p = NULL;		/* no current pointer */
 	fp->_w = 0;		/* nothing to read or write */
 	fp->_r = 0;
@@ -183,10 +181,10 @@
 	for (g = &__sglue; (n -= g->niobs) > 0 && g->next; g = g->next)
 		/* void */;
 	if ((n > 0) && ((g = moreglue(n)) != NULL)) {
-		THREAD_LOCK();
+		STDIO_THREAD_LOCK();
 		SET_GLUE_PTR(lastglue->next, g);
 		lastglue = g;
-		THREAD_UNLOCK();
+		STDIO_THREAD_UNLOCK();
 	}
 }
 
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/stdio/fpurge.c
--- a/head/lib/libc/stdio/fpurge.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/stdio/fpurge.c	Wed Jul 25 16:23:00 2012 +0300
@@ -34,7 +34,7 @@
 static char sccsid[] = "@(#)fpurge.c	8.1 (Berkeley) 6/4/93";
 #endif /* LIBC_SCCS and not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/stdio/fpurge.c 236288 2012-05-30 04:06:38Z eadler $");
 
 #include "namespace.h"
 #include <errno.h>
@@ -62,7 +62,7 @@
 			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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/stdio/local.h
--- a/head/lib/libc/stdio/local.h	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/stdio/local.h	Wed Jul 25 16:23:00 2012 +0300
@@ -35,7 +35,7 @@
  * SUCH DAMAGE.
  *
  *	@(#)local.h	8.3 (Berkeley) 7/3/94
- * $FreeBSD: head/lib/libc/stdio/local.h 227753 2011-11-20 14:45:42Z theraven $
+ * $FreeBSD: head/lib/libc/stdio/local.h 234799 2012-04-29 16:28:39Z das $
  */
 
 #include <sys/types.h>	/* for off_t */
@@ -56,7 +56,7 @@
 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 @@
 		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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/stdio/printf_l.3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/lib/libc/stdio/printf_l.3	Wed Jul 25 16:23:00 2012 +0300
@@ -0,0 +1,80 @@
+.\" Copyright (c) 2012 Isabell Long <issyl0 at 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: head/lib/libc/stdio/printf_l.3 235848 2012-05-23 17:13:30Z issyl0 $
+.\"
+.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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/stdio/scanf.3
--- a/head/lib/libc/stdio/scanf.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/stdio/scanf.3	Wed Jul 25 16:23:00 2012 +0300
@@ -30,7 +30,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)scanf.3	8.2 (Berkeley) 12/11/93
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/libc/stdio/scanf.3 235363 2012-05-12 20:27:13Z joel $
 .\"
 .Dd January 4, 2003
 .Dt SCANF 3
@@ -370,10 +370,10 @@
 (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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/stdio/scanf_l.3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/lib/libc/stdio/scanf_l.3	Wed Jul 25 16:23:00 2012 +0300
@@ -0,0 +1,70 @@
+.\" Copyright (c) 2012 Isabell Long <issyl0 at 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: head/lib/libc/stdio/scanf_l.3 235848 2012-05-23 17:13:30Z issyl0 $
+.\"
+.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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/stdio/setbuf.3
--- a/head/lib/libc/stdio/setbuf.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/stdio/setbuf.3	Wed Jul 25 16:23:00 2012 +0300
@@ -30,7 +30,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)setbuf.3	8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/libc/stdio/setbuf.3 234773 2012-04-28 21:50:30Z jlh $
 .\"
 .Dd June 4, 1993
 .Dt SETBUF 3
@@ -83,6 +83,9 @@
 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 @@
 .Fn setvbuf
 would have returned.
 .Sh SEE ALSO
+.Xr stdbuf 1 ,
 .Xr fclose 3 ,
 .Xr fopen 3 ,
 .Xr fread 3 ,
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/stdio/vfscanf.c
--- a/head/lib/libc/stdio/vfscanf.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/stdio/vfscanf.c	Wed Jul 25 16:23:00 2012 +0300
@@ -39,7 +39,7 @@
 static char sccsid[] = "@(#)vfscanf.c	8.1 (Berkeley) 6/4/93";
 #endif /* LIBC_SCCS and not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/libc/stdio/vfscanf.c 227753 2011-11-20 14:45:42Z theraven $");
+__FBSDID("$FreeBSD: head/lib/libc/stdio/vfscanf.c 234836 2012-04-30 11:28:17Z dumbbell $");
 
 #include "namespace.h"
 #include <ctype.h>
@@ -107,6 +107,335 @@
 __weak_reference(__vfscanf, vfscanf);
 
 /*
+ * Conversion functions are passed a pointer to this object instead of
+ * a real parameter to indicate that the assignment-suppression (*)
+ * flag was specified.  We could use a NULL pointer to indicate this,
+ * but that would mask bugs in applications that call scanf() with a
+ * NULL pointer.
+ */
+static const int suppress;
+#define	SUPPRESS_PTR	((void *)&suppress)
+
+static const mbstate_t initial_mbs;
+
+/*
+ * The following conversion functions return the number of characters consumed,
+ * or -1 on input failure.  Character class conversion returns 0 on match
+ * failure.
+ */
+
+static __inline int
+convert_char(FILE *fp, char * p, int width)
+{
+	int n;
+
+	if (p == SUPPRESS_PTR) {
+		size_t sum = 0;
+		for (;;) {
+			if ((n = fp->_r) < width) {
+				sum += n;
+				width -= n;
+				fp->_p += n;
+				if (__srefill(fp)) {
+					if (sum == 0)
+						return (-1);
+					break;
+				}
+			} else {
+				sum += width;
+				fp->_r -= width;
+				fp->_p += width;
+				break;
+			}
+		}
+		return (sum);
+	} else {
+		size_t r = __fread(p, 1, width, fp);
+
+		if (r == 0)
+			return (-1);
+		return (r);
+	}
+}
+
+static __inline int
+convert_wchar(FILE *fp, wchar_t *wcp, int width, locale_t locale)
+{
+	mbstate_t mbs;
+	int n, nread;
+	wint_t wi;
+
+	mbs = initial_mbs;
+	n = 0;
+	while (width-- != 0 &&
+	    (wi = __fgetwc_mbs(fp, &mbs, &nread, locale)) != WEOF) {
+		if (wcp != SUPPRESS_PTR)
+			*wcp++ = (wchar_t)wi;
+		n += nread;
+	}
+	if (n == 0)
+		return (-1);
+	return (n);
+}
+
+static __inline int
+convert_ccl(FILE *fp, char * p, int width, const char *ccltab)
+{
+	char *p0;
+	int n;
+
+	if (p == SUPPRESS_PTR) {
+		n = 0;
+		while (ccltab[*fp->_p]) {
+			n++, fp->_r--, fp->_p++;
+			if (--width == 0)
+				break;
+			if (fp->_r <= 0 && __srefill(fp)) {
+				if (n == 0)
+					return (-1);
+				break;
+			}
+		}
+	} else {
+		p0 = p;
+		while (ccltab[*fp->_p]) {
+			fp->_r--;
+			*p++ = *fp->_p++;
+			if (--width == 0)
+				break;
+			if (fp->_r <= 0 && __srefill(fp)) {
+				if (p == p0)
+					return (-1);
+				break;
+			}
+		}
+		n = p - p0;
+		if (n == 0)
+			return (0);
+		*p = 0;
+	}
+	return (n);
+}
+
+static __inline int
+convert_wccl(FILE *fp, wchar_t *wcp, int width, const char *ccltab,
+    locale_t locale)
+{
+	mbstate_t mbs;
+	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 && 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;
+	}
+	return (n);
+}
+
+static __inline int
+convert_string(FILE *fp, char * p, int width)
+{
+	char *p0;
+	int n;
+
+	if (p == SUPPRESS_PTR) {
+		n = 0;
+		while (!isspace(*fp->_p)) {
+			n++, fp->_r--, fp->_p++;
+			if (--width == 0)
+				break;
+			if (fp->_r <= 0 && __srefill(fp))
+				break;
+		}
+	} else {
+		p0 = p;
+		while (!isspace(*fp->_p)) {
+			fp->_r--;
+			*p++ = *fp->_p++;
+			if (--width == 0)
+				break;
+			if (fp->_r <= 0 && __srefill(fp))
+				break;
+		}
+		*p = 0;
+		n = p - p0;
+	}
+	return (n);
+}
+
+static __inline int
+convert_wstring(FILE *fp, wchar_t *wcp, int width, locale_t locale)
+{
+	mbstate_t mbs;
+	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';
+	}
+	return (n);
+}
+
+/*
+ * Read an integer, storing it in buf.  The only relevant bit in the
+ * flags argument is PFXOK.
+ *
+ * Return 0 on a match failure, and the number of characters read
+ * otherwise.
+ */
+static __inline int
+parseint(FILE *fp, char * __restrict buf, int width, int base, int flags)
+{
+	/* `basefix' is used to avoid `if' tests */
+	static const short basefix[17] =
+		{ 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
+	char *p;
+	int c;
+
+	flags |= SIGNOK | NDIGITS | NZDIGITS;
+	for (p = buf; width; width--) {
+		c = *fp->_p;
+		/*
+		 * Switch on the character; `goto ok' if we accept it
+		 * as a part of number.
+		 */
+		switch (c) {
+
+		/*
+		 * The digit 0 is always legal, but is special.  For
+		 * %i conversions, if no digits (zero or nonzero) have
+		 * been scanned (only signs), we will have base==0.
+		 * In that case, we should set it to 8 and enable 0x
+		 * prefixing.  Also, if we have not scanned zero
+		 * digits before this, do not turn off prefixing
+		 * (someone else will turn it off if we have scanned
+		 * any nonzero digits).
+		 */
+		case '0':
+			if (base == 0) {
+				base = 8;
+				flags |= PFXOK;
+			}
+			if (flags & NZDIGITS)
+				flags &= ~(SIGNOK|NZDIGITS|NDIGITS);
+			else
+				flags &= ~(SIGNOK|PFXOK|NDIGITS);
+			goto ok;
+
+		/* 1 through 7 always legal */
+		case '1': case '2': case '3':
+		case '4': case '5': case '6': case '7':
+			base = basefix[base];
+			flags &= ~(SIGNOK | PFXOK | NDIGITS);
+			goto ok;
+
+		/* digits 8 and 9 ok iff decimal or hex */
+		case '8': case '9':
+			base = basefix[base];
+			if (base <= 8)
+				break;	/* not legal here */
+			flags &= ~(SIGNOK | PFXOK | NDIGITS);
+			goto ok;
+
+		/* letters ok iff hex */
+		case 'A': case 'B': case 'C':
+		case 'D': case 'E': case 'F':
+		case 'a': case 'b': case 'c':
+		case 'd': case 'e': case 'f':
+			/* no need to fix base here */
+			if (base <= 10)
+				break;	/* not legal here */
+			flags &= ~(SIGNOK | PFXOK | NDIGITS);
+			goto ok;
+
+		/* sign ok only as first character */
+		case '+': case '-':
+			if (flags & SIGNOK) {
+				flags &= ~SIGNOK;
+				flags |= HAVESIGN;
+				goto ok;
+			}
+			break;
+
+		/*
+		 * x ok iff flag still set & 2nd char (or 3rd char if
+		 * we have a sign).
+		 */
+		case 'x': case 'X':
+			if (flags & PFXOK && p ==
+			    buf + 1 + !!(flags & HAVESIGN)) {
+				base = 16;	/* if %i */
+				flags &= ~PFXOK;
+				goto ok;
+			}
+			break;
+		}
+
+		/*
+		 * If we got here, c is not a legal character for a
+		 * number.  Stop accumulating digits.
+		 */
+		break;
+	ok:
+		/*
+		 * c is legal: store it and look at the next.
+		 */
+		*p++ = c;
+		if (--fp->_r > 0)
+			fp->_p++;
+		else if (__srefill(fp))
+			break;		/* EOF */
+	}
+	/*
+	 * If we had only a sign, it is no good; push back the sign.
+	 * If the number ends in `x', it was [sign] '0' 'x', so push
+	 * back the x and treat it as [sign] '0'.
+	 */
+	if (flags & NDIGITS) {
+		if (p > buf)
+			(void) __ungetc(*(u_char *)--p, fp);
+		return (0);
+	}
+	c = ((u_char *)p)[-1];
+	if (c == 'x' || c == 'X') {
+		--p;
+		(void) __ungetc(c, fp);
+	}
+	return (p - buf);
+}
+
+/*
  * __vfscanf - MT-safe version
  */
 int
@@ -137,27 +466,18 @@
 int
 __svfscanf(FILE *fp, locale_t locale, const char *fmt0, va_list ap)
 {
+#define	GETARG(type)	((flags & SUPPRESS) ? SUPPRESS_PTR : va_arg(ap, type))
 	const u_char *fmt = (const u_char *)fmt0;
 	int c;			/* character from format, or conversion */
 	size_t width;		/* field width, or 0 */
-	char *p;		/* points into all kinds of strings */
-	int n;			/* handy integer */
 	int flags;		/* flags as defined above */
-	char *p0;		/* saves original value of p when necessary */
 	int nassigned;		/* number of fields assigned */
 	int nconversions;	/* number of conversions */
+	int nr;			/* characters read by the current conversion */
 	int nread;		/* number of characters consumed from fp */
 	int base;		/* base argument to conversion function */
 	char ccltab[256];	/* character class table for %[...] */
-	char buf[BUF];		/* buffer for numeric and mb conversions */
-	wchar_t *wcp;		/* handy wide character pointer */
-	size_t nconv;		/* length of multibyte sequence converted */
-	static const mbstate_t initial;
-	mbstate_t mbs;
-
-	/* `basefix' is used to avoid `if' tests in the integer scanner */
-	static short basefix[17] =
-		{ 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
+	char buf[BUF];		/* buffer for numeric conversions */
 
 	ORIENT(fp, -1);
 
@@ -300,7 +620,6 @@
 			break;
 
 		case 'n':
-			nconversions++;
 			if (flags & SUPPRESS)	/* ??? */
 				continue;
 			if (flags & SHORTSHORT)
@@ -366,178 +685,32 @@
 			if (width == 0)
 				width = 1;
 			if (flags & LONG) {
-				if ((flags & SUPPRESS) == 0)
-					wcp = va_arg(ap, wchar_t *);
-				else
-					wcp = NULL;
-				n = 0;
-				while (width != 0) {
-					if (n == MB_CUR_MAX) {
-						fp->_flags |= __SERR;
-						goto input_failure;
-					}
-					buf[n++] = *fp->_p;
-					fp->_p++;
-					fp->_r--;
-					mbs = initial;
-					nconv = mbrtowc(wcp, buf, n, &mbs);
-					if (nconv == (size_t)-1) {
-						fp->_flags |= __SERR;
-						goto input_failure;
-					}
-					if (nconv == 0 && !(flags & SUPPRESS))
-						*wcp = L'\0';
-					if (nconv != (size_t)-2) {
-						nread += n;
-						width--;
-						if (!(flags & SUPPRESS))
-							wcp++;
-						n = 0;
-					}
-					if (fp->_r <= 0 && __srefill(fp)) {
-						if (n != 0) {
-							fp->_flags |= __SERR;
-							goto input_failure;
-						}
-						break;
-					}
-				}
-				if (!(flags & SUPPRESS))
-					nassigned++;
-			} else if (flags & SUPPRESS) {
-				size_t sum = 0;
-				for (;;) {
-					if ((n = fp->_r) < width) {
-						sum += n;
-						width -= n;
-						fp->_p += n;
-						if (__srefill(fp)) {
-							if (sum == 0)
-							    goto input_failure;
-							break;
-						}
-					} else {
-						sum += width;
-						fp->_r -= width;
-						fp->_p += width;
-						break;
-					}
-				}
-				nread += sum;
+				nr = convert_wchar(fp, GETARG(wchar_t *),
+				    width, locale);
 			} else {
-				size_t r = __fread((void *)va_arg(ap, char *), 1,
-				    width, fp);
-
-				if (r == 0)
-					goto input_failure;
-				nread += r;
-				nassigned++;
+				nr = convert_char(fp, GETARG(char *), width);
 			}
-			nconversions++;
+			if (nr < 0)
+				goto input_failure;
 			break;
 
 		case CT_CCL:
 			/* scan a (nonempty) character class (sets NOSKIP) */
 			if (width == 0)
 				width = (size_t)~0;	/* `infinity' */
-			/* take only those things in the class */
 			if (flags & LONG) {
-				wchar_t twc;
-				int nchars;
-
-				if ((flags & SUPPRESS) == 0)
-					wcp = va_arg(ap, wchar_t *);
-				else
-					wcp = &twc;
-				n = 0;
-				nchars = 0;
-				while (width != 0) {
-					if (n == MB_CUR_MAX) {
-						fp->_flags |= __SERR;
-						goto input_failure;
-					}
-					buf[n++] = *fp->_p;
-					fp->_p++;
-					fp->_r--;
-					mbs = initial;
-					nconv = mbrtowc(wcp, buf, n, &mbs);
-					if (nconv == (size_t)-1) {
-						fp->_flags |= __SERR;
-						goto input_failure;
-					}
-					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;
-						}
-						nread += n;
-						width--;
-						if (!(flags & SUPPRESS))
-							wcp++;
-						nchars++;
-						n = 0;
-					}
-					if (fp->_r <= 0 && __srefill(fp)) {
-						if (n != 0) {
-							fp->_flags |= __SERR;
-							goto input_failure;
-						}
-						break;
-					}
-				}
-				if (n != 0) {
-					fp->_flags |= __SERR;
+				nr = convert_wccl(fp, GETARG(wchar_t *), width,
+				    ccltab, locale);
+			} else {
+				nr = convert_ccl(fp, GETARG(char *), width,
+				    ccltab);
+			}
+			if (nr <= 0) {
+				if (nr < 0)
 					goto input_failure;
-				}
-				n = nchars;
-				if (n == 0)
+				else /* nr == 0 */
 					goto match_failure;
-				if (!(flags & SUPPRESS)) {
-					*wcp = L'\0';
-					nassigned++;
-				}
-			} else if (flags & SUPPRESS) {
-				n = 0;
-				while (ccltab[*fp->_p]) {
-					n++, fp->_r--, fp->_p++;
-					if (--width == 0)
-						break;
-					if (fp->_r <= 0 && __srefill(fp)) {
-						if (n == 0)
-							goto input_failure;
-						break;
-					}
-				}
-				if (n == 0)
-					goto match_failure;
-			} else {
-				p0 = p = va_arg(ap, char *);
-				while (ccltab[*fp->_p]) {
-					fp->_r--;
-					*p++ = *fp->_p++;
-					if (--width == 0)
-						break;
-					if (fp->_r <= 0 && __srefill(fp)) {
-						if (p == p0)
-							goto input_failure;
-						break;
-					}
-				}
-				n = p - p0;
-				if (n == 0)
-					goto match_failure;
-				*p = 0;
-				nassigned++;
 			}
-			nread += n;
-			nconversions++;
 			break;
 
 		case CT_STRING:
@@ -545,82 +718,14 @@
 			if (width == 0)
 				width = (size_t)~0;
 			if (flags & LONG) {
-				wchar_t twc;
-
-				if ((flags & SUPPRESS) == 0)
-					wcp = va_arg(ap, wchar_t *);
-				else
-					wcp = &twc;
-				n = 0;
-				while (!isspace(*fp->_p) && width != 0) {
-					if (n == MB_CUR_MAX) {
-						fp->_flags |= __SERR;
-						goto input_failure;
-					}
-					buf[n++] = *fp->_p;
-					fp->_p++;
-					fp->_r--;
-					mbs = initial;
-					nconv = mbrtowc(wcp, buf, n, &mbs);
-					if (nconv == (size_t)-1) {
-						fp->_flags |= __SERR;
-						goto input_failure;
-					}
-					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 (!(flags & SUPPRESS))
-							wcp++;
-						n = 0;
-					}
-					if (fp->_r <= 0 && __srefill(fp)) {
-						if (n != 0) {
-							fp->_flags |= __SERR;
-							goto input_failure;
-						}
-						break;
-					}
-				}
-				if (!(flags & SUPPRESS)) {
-					*wcp = L'\0';
-					nassigned++;
-				}
-			} else if (flags & SUPPRESS) {
-				n = 0;
-				while (!isspace(*fp->_p)) {
-					n++, fp->_r--, fp->_p++;
-					if (--width == 0)
-						break;
-					if (fp->_r <= 0 && __srefill(fp))
-						break;
-				}
-				nread += n;
+				nr = convert_wstring(fp, GETARG(wchar_t *),
+				    width, locale);
 			} else {
-				p0 = p = va_arg(ap, char *);
-				while (!isspace(*fp->_p)) {
-					fp->_r--;
-					*p++ = *fp->_p++;
-					if (--width == 0)
-						break;
-					if (fp->_r <= 0 && __srefill(fp))
-						break;
-				}
-				*p = 0;
-				nread += p - p0;
-				nassigned++;
+				nr = convert_string(fp, GETARG(char *), width);
 			}
-			nconversions++;
-			continue;
+			if (nr < 0)
+				goto input_failure;
+			break;
 
 		case CT_INT:
 			/* scan an integer as if by the conversion function */
@@ -633,122 +738,13 @@
 				width = sizeof(buf) - 2;
 			width++;
 #endif
-			flags |= SIGNOK | NDIGITS | NZDIGITS;
-			for (p = buf; width; width--) {
-				c = *fp->_p;
-				/*
-				 * Switch on the character; `goto ok'
-				 * if we accept it as a part of number.
-				 */
-				switch (c) {
-
-				/*
-				 * The digit 0 is always legal, but is
-				 * special.  For %i conversions, if no
-				 * digits (zero or nonzero) have been
-				 * scanned (only signs), we will have
-				 * base==0.  In that case, we should set
-				 * it to 8 and enable 0x prefixing.
-				 * Also, if we have not scanned zero digits
-				 * before this, do not turn off prefixing
-				 * (someone else will turn it off if we
-				 * have scanned any nonzero digits).
-				 */
-				case '0':
-					if (base == 0) {
-						base = 8;
-						flags |= PFXOK;
-					}
-					if (flags & NZDIGITS)
-					    flags &= ~(SIGNOK|NZDIGITS|NDIGITS);
-					else
-					    flags &= ~(SIGNOK|PFXOK|NDIGITS);
-					goto ok;
-
-				/* 1 through 7 always legal */
-				case '1': case '2': case '3':
-				case '4': case '5': case '6': case '7':
-					base = basefix[base];
-					flags &= ~(SIGNOK | PFXOK | NDIGITS);
-					goto ok;
-
-				/* digits 8 and 9 ok iff decimal or hex */
-				case '8': case '9':
-					base = basefix[base];
-					if (base <= 8)
-						break;	/* not legal here */
-					flags &= ~(SIGNOK | PFXOK | NDIGITS);
-					goto ok;
-
-				/* letters ok iff hex */
-				case 'A': case 'B': case 'C':
-				case 'D': case 'E': case 'F':
-				case 'a': case 'b': case 'c':
-				case 'd': case 'e': case 'f':
-					/* no need to fix base here */
-					if (base <= 10)
-						break;	/* not legal here */
-					flags &= ~(SIGNOK | PFXOK | NDIGITS);
-					goto ok;
-
-				/* sign ok only as first character */
-				case '+': case '-':
-					if (flags & SIGNOK) {
-						flags &= ~SIGNOK;
-						flags |= HAVESIGN;
-						goto ok;
-					}
-					break;
-					
-				/*
-				 * x ok iff flag still set & 2nd char (or
-				 * 3rd char if we have a sign).
-				 */
-				case 'x': case 'X':
-					if (flags & PFXOK && p ==
-					    buf + 1 + !!(flags & HAVESIGN)) {
-						base = 16;	/* if %i */
-						flags &= ~PFXOK;
-						goto ok;
-					}
-					break;
-				}
-
-				/*
-				 * If we got here, c is not a legal character
-				 * for a number.  Stop accumulating digits.
-				 */
-				break;
-		ok:
-				/*
-				 * c is legal: store it and look at the next.
-				 */
-				*p++ = c;
-				if (--fp->_r > 0)
-					fp->_p++;
-				else if (__srefill(fp))
-					break;		/* EOF */
-			}
-			/*
-			 * If we had only a sign, it is no good; push
-			 * back the sign.  If the number ends in `x',
-			 * it was [sign] '0' 'x', so push back the x
-			 * and treat it as [sign] '0'.
-			 */
-			if (flags & NDIGITS) {
-				if (p > buf)
-					(void) __ungetc(*(u_char *)--p, fp);
+			nr = parseint(fp, buf, width, base, flags);
+			if (nr == 0)
 				goto match_failure;
-			}
-			c = ((u_char *)p)[-1];
-			if (c == 'x' || c == 'X') {
-				--p;
-				(void) __ungetc(c, fp);
-			}
 			if ((flags & SUPPRESS) == 0) {
 				uintmax_t res;
 
-				*p = 0;
+				buf[nr] = '\0';
 				if ((flags & UNSIGNED) == 0)
 				    res = strtoimax_l(buf, (char **)NULL, base, locale);
 				else
@@ -772,10 +768,7 @@
 					*va_arg(ap, size_t *) = res;
 				else
 					*va_arg(ap, int *) = res;
-				nassigned++;
 			}
-			nread += p - buf;
-			nconversions++;
 			break;
 
 #ifndef NO_FLOATING_POINT
@@ -783,26 +776,30 @@
 			/* scan a floating point number as if by strtod */
 			if (width == 0 || width > sizeof(buf) - 1)
 				width = sizeof(buf) - 1;
-			if ((width = parsefloat(fp, buf, buf + width, locale)) == 0)
+			nr = parsefloat(fp, buf, buf + width, locale);
+			if (nr == 0)
 				goto match_failure;
 			if ((flags & SUPPRESS) == 0) {
 				if (flags & LONGDBL) {
-					long double res = strtold_l(buf, &p, locale);
+					long double res = strtold_l(buf, NULL,
+					    locale);
 					*va_arg(ap, long double *) = res;
 				} else if (flags & LONG) {
-					double res = strtod_l(buf, &p, locale);
+					double res = strtod_l(buf, NULL,
+					    locale);
 					*va_arg(ap, double *) = res;
 				} else {
-					float res = strtof_l(buf, &p, locale);
+					float res = strtof_l(buf, NULL, locale);
 					*va_arg(ap, float *) = res;
 				}
-				nassigned++;
 			}
-			nread += width;
-			nconversions++;
 			break;
 #endif /* !NO_FLOATING_POINT */
 		}
+		if (!(flags & SUPPRESS))
+			nassigned++;
+		nread += nr;
+		nconversions++;
 	}
 input_failure:
 	return (nconversions != 0 ? nassigned : EOF);
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/stdio/vfwscanf.c
--- a/head/lib/libc/stdio/vfwscanf.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/stdio/vfwscanf.c	Wed Jul 25 16:23:00 2012 +0300
@@ -41,7 +41,7 @@
 #endif /* LIBC_SCCS and not lint */
 #endif
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/libc/stdio/vfwscanf.c 227753 2011-11-20 14:45:42Z theraven $");
+__FBSDID("$FreeBSD: head/lib/libc/stdio/vfwscanf.c 234836 2012-04-30 11:28:17Z dumbbell $");
 
 #include "namespace.h"
 #include <ctype.h>
@@ -101,13 +101,324 @@
 static int parsefloat(FILE *, wchar_t *, wchar_t *, locale_t);
 #endif
 
-#define	INCCL(_c)	\
-	(cclcompl ? (wmemchr(ccls, (_c), ccle - ccls) == NULL) : \
-	(wmemchr(ccls, (_c), ccle - ccls) != NULL))
+struct ccl {
+	const wchar_t *start;	/* character class start */
+	const wchar_t *end;	/* character class end */
+	int compl;		/* ccl is complemented? */
+};
+
+static __inline int
+inccl(const struct ccl *ccl, wint_t wi)
+{
+
+	if (ccl->compl) {
+		return (wmemchr(ccl->start, wi, ccl->end - ccl->start)
+		    == NULL);
+	} else {
+		return (wmemchr(ccl->start, wi, ccl->end - ccl->start) != NULL);
+	}
+}
+
+/*
+ * Conversion functions are passed a pointer to this object instead of
+ * a real parameter to indicate that the assignment-suppression (*)
+ * flag was specified.  We could use a NULL pointer to indicate this,
+ * but that would mask bugs in applications that call scanf() with a
+ * NULL pointer.
+ */
+static const int suppress;
+#define	SUPPRESS_PTR	((void *)&suppress)
 
 static const mbstate_t initial_mbs;
 
 /*
+ * The following conversion functions return the number of characters consumed,
+ * or -1 on input failure.  Character class conversion returns 0 on match
+ * failure.
+ */
+
+static __inline int
+convert_char(FILE *fp, char * mbp, int width, locale_t locale)
+{
+	mbstate_t mbs;
+	size_t nconv;
+	wint_t wi;
+	int n;
+
+	n = 0;
+	mbs = initial_mbs;
+	while (width-- != 0 && (wi = __fgetwc(fp, locale)) != WEOF) {
+		if (mbp != SUPPRESS_PTR) {
+			nconv = wcrtomb(mbp, wi, &mbs);
+			if (nconv == (size_t)-1)
+				return (-1);
+			mbp += nconv;
+		}
+		n++;
+	}
+	if (n == 0)
+		return (-1);
+	return (n);
+}
+
+static __inline int
+convert_wchar(FILE *fp, wchar_t *wcp, int width, locale_t locale)
+{
+	wint_t wi;
+	int n;
+
+	n = 0;
+	while (width-- != 0 && (wi = __fgetwc(fp, locale)) != WEOF) {
+		if (wcp != SUPPRESS_PTR)
+			*wcp++ = (wchar_t)wi;
+		n++;
+	}
+	if (n == 0)
+		return (-1);
+	return (n);
+}
+
+static __inline int
+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;
+
+	n = 0;
+	mbs = initial_mbs;
+	while ((wi = __fgetwc(fp, locale)) != WEOF &&
+	    width-- != 0 && inccl(ccl, wi)) {
+		if (mbp != SUPPRESS_PTR) {
+			nconv = wcrtomb(mbp, wi, &mbs);
+			if (nconv == (size_t)-1)
+				return (-1);
+			mbp += nconv;
+		}
+		n++;
+	}
+	if (wi != WEOF)
+		__ungetwc(wi, fp, locale);
+	if (mbp != SUPPRESS_PTR)
+		*mbp = 0;
+	return (n);
+}
+
+static __inline int
+convert_wccl(FILE *fp, wchar_t *wcp, int width, const struct ccl *ccl,
+    locale_t locale)
+{
+	wchar_t *wcp0;
+	wint_t wi;
+	int n;
+
+	if (wcp == SUPPRESS_PTR) {
+		n = 0;
+		while ((wi = __fgetwc(fp, locale)) != WEOF &&
+		    width-- != 0 && inccl(ccl, wi))
+			n++;
+		if (wi != WEOF)
+			__ungetwc(wi, fp, locale);
+	} else {
+		wcp0 = wcp;
+		while ((wi = __fgetwc(fp, locale)) != WEOF &&
+		    width-- != 0 && inccl(ccl, wi))
+			*wcp++ = (wchar_t)wi;
+		if (wi != WEOF)
+			__ungetwc(wi, fp, locale);
+		n = wcp - wcp0;
+		if (n == 0)
+			return (0);
+		*wcp = 0;
+	}
+	return (n);
+}
+
+static __inline int
+convert_string(FILE *fp, char * mbp, int width, locale_t locale)
+{
+	mbstate_t mbs;
+	size_t nconv;
+	wint_t wi;
+	int nread;
+
+	mbs = initial_mbs;
+	nread = 0;
+	while ((wi = __fgetwc(fp, locale)) != WEOF && width-- != 0 &&
+	    !iswspace(wi)) {
+		if (mbp != SUPPRESS_PTR) {
+			nconv = wcrtomb(mbp, wi, &mbs);
+			if (nconv == (size_t)-1)
+				return (-1);
+			mbp += nconv;
+		}
+		nread++;
+	}
+	if (wi != WEOF)
+		__ungetwc(wi, fp, locale);
+	if (mbp != SUPPRESS_PTR)
+		*mbp = 0;
+	return (nread);
+}
+
+static __inline int
+convert_wstring(FILE *fp, wchar_t *wcp, int width, locale_t locale)
+{
+	wchar_t *wcp0;
+	wint_t wi;
+	int nread;
+
+	nread = 0;
+	if (wcp == SUPPRESS_PTR) {
+		while ((wi = __fgetwc(fp, locale)) != WEOF &&
+		    width-- != 0 && !iswspace(wi))
+			nread++;
+		if (wi != WEOF)
+			__ungetwc(wi, fp, locale);
+	} else {
+		wcp0 = wcp;
+		while ((wi = __fgetwc(fp, locale)) != WEOF &&
+		    width-- != 0 && !iswspace(wi)) {
+			*wcp++ = (wchar_t)wi;
+			nread++;
+		}
+		if (wi != WEOF)
+			__ungetwc(wi, fp, locale);
+		*wcp = '\0';
+	}
+	return (nread);
+}
+
+/*
+ * Read an integer, storing it in buf.  The only relevant bit in the
+ * flags argument is PFXOK.
+ *
+ * Return 0 on a match failure, and the number of characters read
+ * otherwise.
+ */
+static __inline int
+parseint(FILE *fp, wchar_t *buf, int width, int base, int flags,
+    locale_t locale)
+{
+	/* `basefix' is used to avoid `if' tests */
+	static const short basefix[17] =
+		{ 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
+	wchar_t *wcp;
+	int c;
+
+	flags |= SIGNOK | NDIGITS | NZDIGITS;
+	for (wcp = buf; width; width--) {
+		c = __fgetwc(fp, locale);
+		/*
+		 * Switch on the character; `goto ok' if we accept it
+		 * as a part of number.
+		 */
+		switch (c) {
+
+		/*
+		 * The digit 0 is always legal, but is special.  For
+		 * %i conversions, if no digits (zero or nonzero) have
+		 * been scanned (only signs), we will have base==0.
+		 * In that case, we should set it to 8 and enable 0x
+		 * prefixing.  Also, if we have not scanned zero
+		 * digits before this, do not turn off prefixing
+		 * (someone else will turn it off if we have scanned
+		 * any nonzero digits).
+		 */
+		case '0':
+			if (base == 0) {
+				base = 8;
+				flags |= PFXOK;
+			}
+			if (flags & NZDIGITS)
+				flags &= ~(SIGNOK|NZDIGITS|NDIGITS);
+			else
+				flags &= ~(SIGNOK|PFXOK|NDIGITS);
+			goto ok;
+
+		/* 1 through 7 always legal */
+		case '1': case '2': case '3':
+		case '4': case '5': case '6': case '7':
+			base = basefix[base];
+			flags &= ~(SIGNOK | PFXOK | NDIGITS);
+			goto ok;
+
+		/* digits 8 and 9 ok iff decimal or hex */
+		case '8': case '9':
+			base = basefix[base];
+			if (base <= 8)
+				break;	/* not legal here */
+			flags &= ~(SIGNOK | PFXOK | NDIGITS);
+			goto ok;
+
+		/* letters ok iff hex */
+		case 'A': case 'B': case 'C':
+		case 'D': case 'E': case 'F':
+		case 'a': case 'b': case 'c':
+		case 'd': case 'e': case 'f':
+			/* no need to fix base here */
+			if (base <= 10)
+				break;	/* not legal here */
+			flags &= ~(SIGNOK | PFXOK | NDIGITS);
+			goto ok;
+
+		/* sign ok only as first character */
+		case '+': case '-':
+			if (flags & SIGNOK) {
+				flags &= ~SIGNOK;
+				flags |= HAVESIGN;
+				goto ok;
+			}
+			break;
+
+		/*
+		 * x ok iff flag still set & 2nd char (or 3rd char if
+		 * we have a sign).
+		 */
+		case 'x': case 'X':
+			if (flags & PFXOK && wcp ==
+			    buf + 1 + !!(flags & HAVESIGN)) {
+				base = 16;	/* if %i */
+				flags &= ~PFXOK;
+				goto ok;
+			}
+			break;
+		}
+
+		/*
+		 * If we got here, c is not a legal character for a
+		 * number.  Stop accumulating digits.
+		 */
+		if (c != WEOF)
+			__ungetwc(c, fp, locale);
+		break;
+	ok:
+		/*
+		 * c is legal: store it and look at the next.
+		 */
+		*wcp++ = (wchar_t)c;
+	}
+	/*
+	 * If we had only a sign, it is no good; push back the sign.
+	 * If the number ends in `x', it was [sign] '0' 'x', so push
+	 * back the x and treat it as [sign] '0'.
+	 */
+	if (flags & NDIGITS) {
+		if (wcp > buf)
+			__ungetwc(*--wcp, fp, locale);
+		return (0);
+	}
+	c = wcp[-1];
+	if (c == 'x' || c == 'X') {
+		--wcp;
+		__ungetwc(c, fp, locale);
+	}
+	return (wcp - buf);
+}
+
+/*
  * MT-safe version.
  */
 int
@@ -136,34 +447,23 @@
 __vfwscanf(FILE * __restrict fp, locale_t locale,
 		const wchar_t * __restrict fmt, va_list ap)
 {
+#define	GETARG(type)	((flags & SUPPRESS) ? SUPPRESS_PTR : va_arg(ap, type))
 	wint_t c;		/* character from format, or conversion */
 	size_t width;		/* field width, or 0 */
-	wchar_t *p;		/* points into all kinds of strings */
-	int n;			/* handy integer */
 	int flags;		/* flags as defined above */
-	wchar_t *p0;		/* saves original value of p when necessary */
 	int nassigned;		/* number of fields assigned */
 	int nconversions;	/* number of conversions */
+	int nr;			/* characters read by the current conversion */
 	int nread;		/* number of characters consumed from fp */
 	int base;		/* base argument to conversion function */
+	struct ccl ccl;		/* character class info */
 	wchar_t buf[BUF];	/* buffer for numeric conversions */
-	const wchar_t *ccls;	/* character class start */
-	const wchar_t *ccle;	/* character class end */
-	int cclcompl;		/* ccl is complemented? */
 	wint_t wi;		/* handy wint_t */
-	char *mbp;		/* multibyte string pointer for %c %s %[ */
-	size_t nconv;		/* number of bytes in mb. conversion */
-	char mbbuf[MB_LEN_MAX];	/* temporary mb. character buffer */
-	mbstate_t mbs;
-
-	/* `basefix' is used to avoid `if' tests in the integer scanner */
-	static short basefix[17] =
-		{ 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
 
 	nassigned = 0;
 	nconversions = 0;
 	nread = 0;
-	ccls = ccle = NULL;
+	ccl.start = ccl.end = NULL;
 	for (;;) {
 		c = *fmt++;
 		if (c == 0)
@@ -171,7 +471,7 @@
 		if (iswspace(c)) {
 			while ((c = __fgetwc(fp, locale)) != WEOF &&
 			    iswspace_l(c, locale))
-				;
+				nread++;
 			if (c != WEOF)
 				__ungetwc(c, fp, locale);
 			continue;
@@ -283,17 +583,17 @@
 			break;
 
 		case '[':
-			ccls = fmt;
+			ccl.start = fmt;
 			if (*fmt == '^') {
-				cclcompl = 1;
+				ccl.compl = 1;
 				fmt++;
 			} else
-				cclcompl = 0;
+				ccl.compl = 0;
 			if (*fmt == ']')
 				fmt++;
 			while (*fmt != '\0' && *fmt != ']')
 				fmt++;
-			ccle = fmt;
+			ccl.end = fmt;
 			fmt++;
 			flags |= NOSKIP;
 			c = CT_CCL;
@@ -315,7 +615,6 @@
 			break;
 
 		case 'n':
-			nconversions++;
 			if (flags & SUPPRESS)	/* ??? */
 				continue;
 			if (flags & SHORTSHORT)
@@ -368,57 +667,14 @@
 			if (width == 0)
 				width = 1;
 			if (flags & LONG) {
-				if (!(flags & SUPPRESS))
-					p = va_arg(ap, wchar_t *);
-				n = 0;
-				while (width-- != 0 &&
-				    (wi = __fgetwc(fp, locale)) != WEOF) {
-					if (!(flags & SUPPRESS))
-						*p++ = (wchar_t)wi;
-					n++;
-				}
-				if (n == 0)
-					goto input_failure;
-				nread += n;
-				if (!(flags & SUPPRESS))
-					nassigned++;
+				nr = convert_wchar(fp, GETARG(wchar_t *), width,
+				    locale);
 			} else {
-				if (!(flags & SUPPRESS))
-					mbp = va_arg(ap, char *);
-				n = 0;
-				mbs = initial_mbs;
-				while (width != 0 &&
-				    (wi = __fgetwc(fp, locale)) != WEOF) {
-					if (width >= MB_CUR_MAX &&
-					    !(flags & SUPPRESS)) {
-						nconv = wcrtomb(mbp, wi, &mbs);
-						if (nconv == (size_t)-1)
-							goto input_failure;
-					} else {
-						nconv = wcrtomb(mbbuf, wi,
-						    &mbs);
-						if (nconv == (size_t)-1)
-							goto input_failure;
-						if (nconv > width) {
-							__ungetwc(wi, fp, locale);
-							break;
-						}
-						if (!(flags & SUPPRESS))
-							memcpy(mbp, mbbuf,
-							    nconv);
-					}
-					if (!(flags & SUPPRESS))
-						mbp += nconv;
-					width -= nconv;
-					n++;
-				}
-				if (n == 0)
-					goto input_failure;
-				nread += n;
-				if (!(flags & SUPPRESS))
-					nassigned++;
+				nr = convert_char(fp, GETARG(char *), width,
+				    locale);
 			}
-			nconversions++;
+			if (nr < 0)
+				goto input_failure;
 			break;
 
 		case CT_CCL:
@@ -426,246 +682,49 @@
 			if (width == 0)
 				width = (size_t)~0;	/* `infinity' */
 			/* take only those things in the class */
-			if ((flags & SUPPRESS) && (flags & LONG)) {
-				n = 0;
-				while ((wi = __fgetwc(fp, locale)) != WEOF &&
-				    width-- != 0 && INCCL(wi))
-					n++;
-				if (wi != WEOF)
-					__ungetwc(wi, fp, locale);
-				if (n == 0)
+			if (flags & LONG) {
+				nr = convert_wccl(fp, GETARG(wchar_t *), width,
+				    &ccl, locale);
+			} else {
+				nr = convert_ccl(fp, GETARG(char *), width,
+				    &ccl, locale);
+			}
+			if (nr <= 0) {
+				if (nr < 0)
+					goto input_failure;
+				else /* nr == 0 */
 					goto match_failure;
-			} else if (flags & LONG) {
-				p0 = p = va_arg(ap, wchar_t *);
-				while ((wi = __fgetwc(fp, locale)) != WEOF &&
-				    width-- != 0 && INCCL(wi))
-					*p++ = (wchar_t)wi;
-				if (wi != WEOF)
-					__ungetwc(wi, fp, locale);
-				n = p - p0;
-				if (n == 0)
-					goto match_failure;
-				*p = 0;
-				nassigned++;
-			} else {
-				if (!(flags & SUPPRESS))
-					mbp = va_arg(ap, char *);
-				n = 0;
-				mbs = initial_mbs;
-				while ((wi = __fgetwc(fp, locale)) != WEOF &&
-				    width != 0 && INCCL(wi)) {
-					if (width >= MB_CUR_MAX &&
-					   !(flags & SUPPRESS)) {
-						nconv = wcrtomb(mbp, wi, &mbs);
-						if (nconv == (size_t)-1)
-							goto input_failure;
-					} else {
-						nconv = wcrtomb(mbbuf, wi,
-						    &mbs);
-						if (nconv == (size_t)-1)
-							goto input_failure;
-						if (nconv > width)
-							break;
-						if (!(flags & SUPPRESS))
-							memcpy(mbp, mbbuf,
-							    nconv);
-					}
-					if (!(flags & SUPPRESS))
-						mbp += nconv;
-					width -= nconv;
-					n++;
-				}
-				if (wi != WEOF)
-					__ungetwc(wi, fp, locale);
-				if (!(flags & SUPPRESS)) {
-					*mbp = 0;
-					nassigned++;
-				}
 			}
-			nread += n;
-			nconversions++;
 			break;
 
 		case CT_STRING:
 			/* like CCL, but zero-length string OK, & no NOSKIP */
 			if (width == 0)
 				width = (size_t)~0;
-			if ((flags & SUPPRESS) && (flags & LONG)) {
-				while ((wi = __fgetwc(fp, locale)) != WEOF &&
-				    width-- != 0 &&
-				    !iswspace(wi))
-					nread++;
-				if (wi != WEOF)
-					__ungetwc(wi, fp, locale);
-			} else if (flags & LONG) {
-				p0 = p = va_arg(ap, wchar_t *);
-				while ((wi = __fgetwc(fp, locale)) != WEOF &&
-				    width-- != 0 &&
-				    !iswspace(wi)) {
-					*p++ = (wchar_t)wi;
-					nread++;
-				}
-				if (wi != WEOF)
-					__ungetwc(wi, fp, locale);
-				*p = '\0';
-				nassigned++;
+			if (flags & LONG) {
+				nr = convert_wstring(fp, GETARG(wchar_t *),
+				    width, locale);
 			} else {
-				if (!(flags & SUPPRESS))
-					mbp = va_arg(ap, char *);
-				mbs = initial_mbs;
-				while ((wi = __fgetwc(fp, locale)) != WEOF &&
-				    width != 0 &&
-				    !iswspace(wi)) {
-					if (width >= MB_CUR_MAX &&
-					    !(flags & SUPPRESS)) {
-						nconv = wcrtomb(mbp, wi, &mbs);
-						if (nconv == (size_t)-1)
-							goto input_failure;
-					} else {
-						nconv = wcrtomb(mbbuf, wi,
-						    &mbs);
-						if (nconv == (size_t)-1)
-							goto input_failure;
-						if (nconv > width)
-							break;
-						if (!(flags & SUPPRESS))
-							memcpy(mbp, mbbuf,
-							    nconv);
-					}
-					if (!(flags & SUPPRESS))
-						mbp += nconv;
-					width -= nconv;
-					nread++;
-				}
-				if (wi != WEOF)
-					__ungetwc(wi, fp, locale);
-				if (!(flags & SUPPRESS)) {
-					*mbp = 0;
-					nassigned++;
-				}
+				nr = convert_string(fp, GETARG(char *), width,
+				    locale);
 			}
-			nconversions++;
-			continue;
+			if (nr < 0)
+				goto input_failure;
+			break;
 
 		case CT_INT:
 			/* scan an integer as if by the conversion function */
 			if (width == 0 || width > sizeof(buf) /
 			    sizeof(*buf) - 1)
 				width = sizeof(buf) / sizeof(*buf) - 1;
-			flags |= SIGNOK | NDIGITS | NZDIGITS;
-			for (p = buf; width; width--) {
-				c = __fgetwc(fp, locale);
-				/*
-				 * Switch on the character; `goto ok'
-				 * if we accept it as a part of number.
-				 */
-				switch (c) {
 
-				/*
-				 * The digit 0 is always legal, but is
-				 * special.  For %i conversions, if no
-				 * digits (zero or nonzero) have been
-				 * scanned (only signs), we will have
-				 * base==0.  In that case, we should set
-				 * it to 8 and enable 0x prefixing.
-				 * Also, if we have not scanned zero digits
-				 * before this, do not turn off prefixing
-				 * (someone else will turn it off if we
-				 * have scanned any nonzero digits).
-				 */
-				case '0':
-					if (base == 0) {
-						base = 8;
-						flags |= PFXOK;
-					}
-					if (flags & NZDIGITS)
-					    flags &= ~(SIGNOK|NZDIGITS|NDIGITS);
-					else
-					    flags &= ~(SIGNOK|PFXOK|NDIGITS);
-					goto ok;
-
-				/* 1 through 7 always legal */
-				case '1': case '2': case '3':
-				case '4': case '5': case '6': case '7':
-					base = basefix[base];
-					flags &= ~(SIGNOK | PFXOK | NDIGITS);
-					goto ok;
-
-				/* digits 8 and 9 ok iff decimal or hex */
-				case '8': case '9':
-					base = basefix[base];
-					if (base <= 8)
-						break;	/* not legal here */
-					flags &= ~(SIGNOK | PFXOK | NDIGITS);
-					goto ok;
-
-				/* letters ok iff hex */
-				case 'A': case 'B': case 'C':
-				case 'D': case 'E': case 'F':
-				case 'a': case 'b': case 'c':
-				case 'd': case 'e': case 'f':
-					/* no need to fix base here */
-					if (base <= 10)
-						break;	/* not legal here */
-					flags &= ~(SIGNOK | PFXOK | NDIGITS);
-					goto ok;
-
-				/* sign ok only as first character */
-				case '+': case '-':
-					if (flags & SIGNOK) {
-						flags &= ~SIGNOK;
-						flags |= HAVESIGN;
-						goto ok;
-					}
-					break;
-					
-				/*
-				 * x ok iff flag still set & 2nd char (or
-				 * 3rd char if we have a sign).
-				 */
-				case 'x': case 'X':
-					if (flags & PFXOK && p ==
-					    buf + 1 + !!(flags & HAVESIGN)) {
-						base = 16;	/* if %i */
-						flags &= ~PFXOK;
-						goto ok;
-					}
-					break;
-				}
-
-				/*
-				 * If we got here, c is not a legal character
-				 * for a number.  Stop accumulating digits.
-				 */
-				if (c != WEOF)
-					__ungetwc(c, fp, locale);
-				break;
-		ok:
-				/*
-				 * c is legal: store it and look at the next.
-				 */
-				*p++ = (wchar_t)c;
-			}
-			/*
-			 * If we had only a sign, it is no good; push
-			 * back the sign.  If the number ends in `x',
-			 * it was [sign] '0' 'x', so push back the x
-			 * and treat it as [sign] '0'.
-			 */
-			if (flags & NDIGITS) {
-				if (p > buf)
-					__ungetwc(*--p, fp, locale);
+			nr = parseint(fp, buf, width, base, flags, locale);
+			if (nr == 0)
 				goto match_failure;
-			}
-			c = p[-1];
-			if (c == 'x' || c == 'X') {
-				--p;
-				__ungetwc(c, fp, locale);
-			}
 			if ((flags & SUPPRESS) == 0) {
 				uintmax_t res;
 
-				*p = 0;
+				buf[nr] = L'\0';
 				if ((flags & UNSIGNED) == 0)
 				    res = wcstoimax(buf, NULL, base);
 				else
@@ -689,10 +748,7 @@
 					*va_arg(ap, size_t *) = res;
 				else
 					*va_arg(ap, int *) = res;
-				nassigned++;
 			}
-			nread += p - buf;
-			nconversions++;
 			break;
 
 #ifndef NO_FLOATING_POINT
@@ -701,26 +757,28 @@
 			if (width == 0 || width > sizeof(buf) /
 			    sizeof(*buf) - 1)
 				width = sizeof(buf) / sizeof(*buf) - 1;
-			if ((width = parsefloat(fp, buf, buf + width, locale)) == 0)
+			nr = parsefloat(fp, buf, buf + width, locale);
+			if (nr == 0)
 				goto match_failure;
 			if ((flags & SUPPRESS) == 0) {
 				if (flags & LONGDBL) {
-					long double res = wcstold(buf, &p);
+					long double res = wcstold(buf, NULL);
 					*va_arg(ap, long double *) = res;
 				} else if (flags & LONG) {
-					double res = wcstod(buf, &p);
+					double res = wcstod(buf, NULL);
 					*va_arg(ap, double *) = res;
 				} else {
-					float res = wcstof(buf, &p);
+					float res = wcstof(buf, NULL);
 					*va_arg(ap, float *) = res;
 				}
-				nassigned++;
 			}
-			nread += width;
-			nconversions++;
 			break;
 #endif /* !NO_FLOATING_POINT */
 		}
+		if (!(flags & SUPPRESS))
+			nassigned++;
+		nread += nr;
+		nconversions++;
 	}
 input_failure:
 	return (nconversions != 0 ? nassigned : EOF);
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/stdio/wscanf.3
--- a/head/lib/libc/stdio/wscanf.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/stdio/wscanf.3	Wed Jul 25 16:23:00 2012 +0300
@@ -31,7 +31,7 @@
 .\"
 .\"     @(#)scanf.3	8.2 (Berkeley) 12/11/93
 .\" FreeBSD: src/lib/libc/stdio/scanf.3,v 1.24 2003/06/28 09:03:25 das Exp
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/libc/stdio/wscanf.3 235363 2012-05-12 20:27:13Z joel $
 .\"
 .Dd July 5, 2003
 .Dt WSCANF 3
@@ -365,10 +365,10 @@
 (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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/stdio/xprintf.c
--- a/head/lib/libc/stdio/xprintf.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/stdio/xprintf.c	Wed Jul 25 16:23:00 2012 +0300
@@ -30,7 +30,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: head/lib/libc/stdio/xprintf.c 238111 2012-07-04 17:35:07Z pjd $
  */
 
 #include "namespace.h"
@@ -651,7 +651,7 @@
 }
 
 int
-register_printf_render_std(const unsigned char *specs)
+register_printf_render_std(const char *specs)
 {
 
 	for (; *specs != '\0'; specs++) {
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/stdlib/Makefile.inc
--- a/head/lib/libc/stdlib/Makefile.inc	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/stdlib/Makefile.inc	Wed Jul 25 16:23:00 2012 +0300
@@ -1,5 +1,5 @@
 #	from @(#)Makefile.inc	8.3 (Berkeley) 2/4/95
-# $FreeBSD: head/lib/libc/stdlib/Makefile.inc 234370 2012-04-17 07:22:14Z jasone $
+# $FreeBSD: head/lib/libc/stdlib/Makefile.inc 237573 2012-06-25 21:51:40Z issyl0 $
 
 # machine-independent stdlib sources
 .PATH: ${.CURDIR}/${LIBC_ARCH}/stdlib ${.CURDIR}/stdlib
@@ -42,6 +42,7 @@
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/stdlib/getenv.3
--- a/head/lib/libc/stdlib/getenv.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/stdlib/getenv.3	Wed Jul 25 16:23:00 2012 +0300
@@ -30,7 +30,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)getenv.3	8.2 (Berkeley) 12/11/93
-.\" $FreeBSD: head/lib/libc/stdlib/getenv.3 233648 2012-03-29 05:02:12Z eadler $
+.\" $FreeBSD: head/lib/libc/stdlib/getenv.3 235286 2012-05-11 20:06:46Z gjb $
 .\"
 .Dd June 20, 2007
 .Dt GETENV 3
@@ -152,7 +152,8 @@
 is a
 .Dv NULL
 pointer,
-.Fa string is without an
+.Fa string
+is without an
 .Dq Li \&=
 character or
 .Dq Li \&=
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/stdlib/getopt_long.c
--- a/head/lib/libc/stdlib/getopt_long.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/stdlib/getopt_long.c	Wed Jul 25 16:23:00 2012 +0300
@@ -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
@@ -62,7 +55,7 @@
 #endif /* LIBC_SCCS and not lint */
 #endif
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/stdlib/getopt_long.c 236936 2012-06-11 22:25:20Z delphij $");
 
 #include <err.h>
 #include <errno.h>
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/stdlib/realpath.3
--- a/head/lib/libc/stdlib/realpath.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/stdlib/realpath.3	Wed Jul 25 16:23:00 2012 +0300
@@ -29,9 +29,9 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)realpath.3	8.2 (Berkeley) 2/16/94
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/libc/stdlib/realpath.3 235266 2012-05-11 11:29:08Z kib $
 .\"
-.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 @@
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/stdlib/realpath.c
--- a/head/lib/libc/stdlib/realpath.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/stdlib/realpath.c	Wed Jul 25 16:23:00 2012 +0300
@@ -30,7 +30,7 @@
 static char sccsid[] = "@(#)realpath.c	8.1 (Berkeley) 2/16/94";
 #endif /* LIBC_SCCS and not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/libc/stdlib/realpath.c 227090 2011-11-04 19:56:34Z ed $");
+__FBSDID("$FreeBSD: head/lib/libc/stdlib/realpath.c 236618 2012-06-05 16:16:33Z ache $");
 
 #include "namespace.h"
 #include <sys/param.h>
@@ -54,7 +54,7 @@
 	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 @@
 		errno = ENOENT;
 		return (NULL);
 	}
-	serrno = errno;
 	if (resolved == NULL) {
 		resolved = malloc(PATH_MAX);
 		if (resolved == NULL)
@@ -132,8 +131,29 @@
 			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 @@
 		}
 
 		/*
-		 * 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 @@
 			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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/stdlib/strfmon.3
--- a/head/lib/libc/stdlib/strfmon.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/stdlib/strfmon.3	Wed Jul 25 16:23:00 2012 +0300
@@ -22,9 +22,9 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/libc/stdlib/strfmon.3 237591 2012-06-26 05:34:31Z joel $
 .\"
-.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 @@
 .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 @@
 .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 @@
 function
 conforms to
 .St -p1003.1-2001 .
+The
+.Fn strfmon_l
+function conforms to
+.St -p1003.1-2008 .
 .Sh AUTHORS
 .An -nosplit
 The
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/stdtime/Makefile.inc
--- a/head/lib/libc/stdtime/Makefile.inc	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/stdtime/Makefile.inc	Wed Jul 25 16:23:00 2012 +0300
@@ -1,5 +1,5 @@
 #	Makefile.inc,v 1.2 1994/09/13 21:26:01 wollman Exp
-# $FreeBSD$
+# $FreeBSD: head/lib/libc/stdtime/Makefile.inc 237573 2012-06-25 21:51:40Z issyl0 $
 
 .PATH:	${.CURDIR}/stdtime ${.CURDIR}/../locale \
 	${.CURDIR}/../../contrib/tzcode/stdtime
@@ -18,4 +18,6 @@
 	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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/stdtime/strftime.3
--- a/head/lib/libc/stdtime/strftime.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/stdtime/strftime.3	Wed Jul 25 16:23:00 2012 +0300
@@ -30,9 +30,9 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)strftime.3	8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/libc/stdtime/strftime.3 237573 2012-06-25 21:51:40Z issyl0 $
 .\"
-.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 @@
 .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 @@
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/stdtime/strftime.c
--- a/head/lib/libc/stdtime/strftime.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/stdtime/strftime.c	Wed Jul 25 16:23:00 2012 +0300
@@ -37,7 +37,7 @@
 static const char	sccsid[] = "@(#)strftime.c	5.4 (Berkeley) 3/14/89";
 #endif /* LIBC_SCCS and not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/libc/stdtime/strftime.c 227753 2011-11-20 14:45:42Z theraven $");
+__FBSDID("$FreeBSD: head/lib/libc/stdtime/strftime.c 237211 2012-06-17 21:40:13Z jilles $");
 
 #include "tzfile.h"
 #include <fcntl.h>
@@ -67,7 +67,7 @@
 #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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/stdtime/strptime.3
--- a/head/lib/libc/stdtime/strptime.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/stdtime/strptime.3	Wed Jul 25 16:23:00 2012 +0300
@@ -23,9 +23,9 @@
 .\" (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$
+.\" $FreeBSD: head/lib/libc/stdtime/strptime.3 237573 2012-06-25 21:51:40Z issyl0 $
 .\" "
-.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 @@
 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 @@
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/string/Makefile.inc
--- a/head/lib/libc/string/Makefile.inc	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/string/Makefile.inc	Wed Jul 25 16:23:00 2012 +0300
@@ -1,5 +1,5 @@
 #	@(#)Makefile.inc	8.1 (Berkeley) 6/4/93
-# $FreeBSD: head/lib/libc/string/Makefile.inc 229368 2012-01-03 07:14:01Z ed $
+# $FreeBSD: head/lib/libc/string/Makefile.inc 237409 2012-06-21 18:28:48Z issyl0 $
 
 .PATH: ${.CURDIR}/${LIBC_ARCH}/string ${.CURDIR}/string
 
@@ -42,10 +42,13 @@
 	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+=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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/string/strcasecmp.3
--- a/head/lib/libc/string/strcasecmp.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/string/strcasecmp.3	Wed Jul 25 16:23:00 2012 +0300
@@ -28,7 +28,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)strcasecmp.3	8.1 (Berkeley) 6/9/93
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/libc/string/strcasecmp.3 237393 2012-06-21 12:52:15Z issyl0 $
 .\"
 .Dd June 9, 1993
 .Dt 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 @@
 .Pp
 The
 .Fn strncasecmp
-compares at most
+function compares at most
 .Fa len
 characters.
+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
+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 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/string/strcoll.3
--- a/head/lib/libc/string/strcoll.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/string/strcoll.3	Wed Jul 25 16:23:00 2012 +0300
@@ -30,7 +30,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)strcoll.3	8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/libc/string/strcoll.3 237393 2012-06-21 12:52:15Z issyl0 $
 .\"
 .Dd June 4, 1993
 .Dt 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 @@
 .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 @@
 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 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/string/strlcpy.3
--- a/head/lib/libc/string/strlcpy.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/string/strlcpy.3	Wed Jul 25 16:23:00 2012 +0300
@@ -25,7 +25,7 @@
 .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 .\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/libc/string/strlcpy.3 235286 2012-05-11 20:06:46Z gjb $
 .\"
 .Dd June 22, 1998
 .Dt STRLCPY 3
@@ -169,7 +169,7 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/string/strstr.3
--- a/head/lib/libc/string/strstr.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/string/strstr.3	Wed Jul 25 16:23:00 2012 +0300
@@ -31,7 +31,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)strstr.3	8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/libc/string/strstr.3 237393 2012-06-21 12:52:15Z issyl0 $
 .\"
 .Dd October 11, 2001
 .Dt 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 @@
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/string/strxfrm.3
--- a/head/lib/libc/string/strxfrm.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/string/strxfrm.3	Wed Jul 25 16:23:00 2012 +0300
@@ -30,7 +30,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)strxfrm.3	8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/libc/string/strxfrm.3 237393 2012-06-21 12:52:15Z issyl0 $
 .\"
 .Dd June 4, 1993
 .Dt 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 @@
 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 @@
 function
 conforms to
 .St -isoC .
+The
+.Fn strxfrm_l
+function conforms to
+.St -p1003.1-2008 .
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/sys/Makefile.inc
--- a/head/lib/libc/sys/Makefile.inc	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/sys/Makefile.inc	Wed Jul 25 16:23:00 2012 +0300
@@ -1,5 +1,5 @@
 #	@(#)Makefile.inc	8.3 (Berkeley) 10/24/94
-# $FreeBSD: head/lib/libc/sys/Makefile.inc 232574 2012-03-05 20:59:34Z pjd $
+# $FreeBSD: head/lib/libc/sys/Makefile.inc 237434 2012-06-22 07:13:30Z kib $
 
 # sys sources
 .PATH: ${.CURDIR}/${LIBC_ARCH}/sys ${.CURDIR}/sys
@@ -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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/sys/Symbol.map
--- a/head/lib/libc/sys/Symbol.map	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/sys/Symbol.map	Wed Jul 25 16:23:00 2012 +0300
@@ -1,5 +1,5 @@
 /*
- * $FreeBSD: head/lib/libc/sys/Symbol.map 227776 2011-11-21 01:26:10Z lstewart $
+ * $FreeBSD: head/lib/libc/sys/Symbol.map 238345 2012-07-10 08:31:28Z lstewart $
  */
 
 /*
@@ -365,9 +365,6 @@
 	cap_getmode;
 	cap_new;
 	cap_getrights;
-	ffclock_getcounter;
-	ffclock_getestimate;
-	ffclock_setestimate;
 	getloginclass;
 	pdfork;
 	pdgetpid;
@@ -382,6 +379,9 @@
 };
 
 FBSD_1.3 {
+	ffclock_getcounter;
+	ffclock_getestimate;
+	ffclock_setestimate;
 	posix_fadvise;
 };
 
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/sys/__vdso_gettimeofday.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/lib/libc/sys/__vdso_gettimeofday.c	Wed Jul 25 16:23:00 2012 +0300
@@ -0,0 +1,142 @@
+/*-
+ * Copyright (c) 2012 Konstantin Belousov <kib at 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: head/lib/libc/sys/__vdso_gettimeofday.c 237434 2012-06-22 07:13:30Z kib $");
+
+#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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/sys/clock_gettime.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/lib/libc/sys/clock_gettime.c	Wed Jul 25 16:23:00 2012 +0300
@@ -0,0 +1,52 @@
+/*-
+ * Copyright (c) 2012 Konstantin Belousov <kib at 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: head/lib/libc/sys/clock_gettime.c 237434 2012-06-22 07:13:30Z kib $");
+
+#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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/sys/fcntl.2
--- a/head/lib/libc/sys/fcntl.2	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/sys/fcntl.2	Wed Jul 25 16:23:00 2012 +0300
@@ -26,9 +26,9 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)fcntl.2	8.2 (Berkeley) 1/12/94
-.\" $FreeBSD: head/lib/libc/sys/fcntl.2 234131 2012-04-11 14:08:09Z eadler $
+.\" $FreeBSD: head/lib/libc/sys/fcntl.2 238615 2012-07-19 10:23:59Z kib $
 .\"
-.Dd January 28, 2012
+.Dd July 18, 2012
 .Dt FCNTL 2
 .Os
 .Sh NAME
@@ -54,7 +54,7 @@
 .Fn fcntl
 can take an additional third argument
 .Fa "int arg" .
-.Bl -tag -width F_GETOWNX
+.Bl -tag -width F_DUPFD_CLOEXEC
 .It Dv F_DUPFD
 Return a new descriptor as follows:
 .Pp
@@ -73,11 +73,22 @@
 Same file status flags (i.e., both file descriptors
 share the same file status flags).
 .It
-The close-on-exec flag associated with the new file descriptor
-is set to remain open across
+The close-on-exec flag
+.Dv FD_CLOEXEC
+associated with the new file descriptor is cleared, so the file descriptor is
+to remain open across
 .Xr execve 2
 system calls.
 .El
+.It Dv F_DUPFD_CLOEXEC
+Like
+.Dv F_DUPFD ,
+but the
+.Dv FD_CLOEXEC
+flag associated with the new file descriptor is set, so the file descriptor
+is closed when
+.Xr execve 2
+system call executes.
 .It Dv F_DUP2FD
 It is functionally equivalent to
 .Bd -literal -offset indent
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/sys/fcntl.c
--- a/head/lib/libc/sys/fcntl.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/sys/fcntl.c	Wed Jul 25 16:23:00 2012 +0300
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/sys/fcntl.c 238667 2012-07-21 13:02:11Z kib $");
 
 #include <fcntl.h>
 #include <stdarg.h>
@@ -41,7 +41,7 @@
 {
 	va_list args;
 	long arg;
-	struct oflock ofl;
+	struct __oflock ofl;
 	struct flock *flp;
 	int res;
 
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/sys/ffclock.2
--- a/head/lib/libc/sys/ffclock.2	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/sys/ffclock.2	Wed Jul 25 16:23:00 2012 +0300
@@ -25,7 +25,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD: head/lib/libc/sys/ffclock.2 227776 2011-11-21 01:26:10Z lstewart $
+.\" $FreeBSD: head/lib/libc/sys/ffclock.2 235140 2012-05-08 18:56:21Z gjb $
 .\"
 .Dd November 21, 2011
 .Dt 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 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/sys/gettimeofday.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/lib/libc/sys/gettimeofday.c	Wed Jul 25 16:23:00 2012 +0300
@@ -0,0 +1,51 @@
+/*-
+ * Copyright (c) 2012 Konstantin Belousov <kib at 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: head/lib/libc/sys/gettimeofday.c 237434 2012-06-22 07:13:30Z kib $");
+
+#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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/sys/jail.2
--- a/head/lib/libc/sys/jail.2	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/sys/jail.2	Wed Jul 25 16:23:00 2012 +0300
@@ -23,7 +23,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD: head/lib/libc/sys/jail.2 233648 2012-03-29 05:02:12Z eadler $
+.\" $FreeBSD: head/lib/libc/sys/jail.2 234712 2012-04-26 17:36:05Z jamie $
 .\"
 .Dd February 8, 2012
 .Dt JAIL 2
@@ -247,44 +247,6 @@
 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 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/sys/ktrace.2
--- a/head/lib/libc/sys/ktrace.2	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/sys/ktrace.2	Wed Jul 25 16:23:00 2012 +0300
@@ -26,7 +26,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)ktrace.2	8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: head/lib/libc/sys/ktrace.2 233665 2012-03-29 16:02:40Z joel $
+.\" $FreeBSD: head/lib/libc/sys/ktrace.2 235140 2012-05-08 18:56:21Z gjb $
 .\"
 .Dd October 10, 2011
 .Dt KTRACE 2
@@ -127,7 +127,7 @@
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/sys/lseek.2
--- a/head/lib/libc/sys/lseek.2	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/sys/lseek.2	Wed Jul 25 16:23:00 2012 +0300
@@ -26,9 +26,9 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)lseek.2	8.3 (Berkeley) 4/19/94
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/libc/sys/lseek.2 236042 2012-05-26 05:25:55Z kib $
 .\"
-.Dd April 5, 2007
+.Dd May 26, 2012
 .Dt LSEEK 2
 .Os
 .Sh NAME
@@ -92,9 +92,9 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/sys/msgsnd.2
--- a/head/lib/libc/sys/msgsnd.2	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/sys/msgsnd.2	Wed Jul 25 16:23:00 2012 +0300
@@ -29,7 +29,7 @@
 .\" (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$
+.\" $FreeBSD: head/lib/libc/sys/msgsnd.2 235140 2012-05-08 18:56:21Z gjb $
 .\"
 .Dd July 9, 2009
 .Dt MSGSND 2
@@ -139,7 +139,7 @@
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/sys/pathconf.2
--- a/head/lib/libc/sys/pathconf.2	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/sys/pathconf.2	Wed Jul 25 16:23:00 2012 +0300
@@ -26,7 +26,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"	@(#)pathconf.2	8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: head/lib/libc/sys/pathconf.2 233648 2012-03-29 05:02:12Z eadler $
+.\" $FreeBSD: head/lib/libc/sys/pathconf.2 235140 2012-05-08 18:56:21Z gjb $
 .\"
 .Dd July 7, 2009
 .Dt PATHCONF 2
@@ -165,7 +165,7 @@
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/sys/pdfork.2
--- a/head/lib/libc/sys/pdfork.2	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/sys/pdfork.2	Wed Jul 25 16:23:00 2012 +0300
@@ -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
@@ -26,7 +26,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD: head/lib/libc/sys/pdfork.2 232158 2012-02-25 15:21:43Z gjb $
+.\" $FreeBSD: head/lib/libc/sys/pdfork.2 234830 2012-04-30 08:00:52Z rwatson $
 .\"
 .Dd February 25, 2012
 .Dt PDFORK 2
@@ -57,7 +57,7 @@
 .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 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/sys/posix_fadvise.2
--- a/head/lib/libc/sys/posix_fadvise.2	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/sys/posix_fadvise.2	Wed Jul 25 16:23:00 2012 +0300
@@ -26,9 +26,9 @@
 .\" SUCH DAMAGE.
 .\"
 .\"	@(#)madvise.2	8.1 (Berkeley) 6/9/93
-.\" $FreeBSD: head/lib/libc/sys/posix_fadvise.2 233462 2012-03-25 12:13:24Z joel $
+.\" $FreeBSD: head/lib/libc/sys/posix_fadvise.2 237274 2012-06-19 18:42:24Z jhb $
 .\"
-.Dd February 25, 2012
+.Dd June 19, 2012
 .Dt POSIX_FADVISE 2
 .Os
 .Sh NAME
@@ -84,10 +84,9 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/sys/read.2
--- a/head/lib/libc/sys/read.2	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/sys/read.2	Wed Jul 25 16:23:00 2012 +0300
@@ -26,7 +26,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)read.2	8.4 (Berkeley) 2/26/94
-.\" $FreeBSD: head/lib/libc/sys/read.2 230456 2012-01-22 11:15:48Z pjd $
+.\" $FreeBSD: head/lib/libc/sys/read.2 234820 2012-04-29 22:23:00Z eadler $
 .\"
 .Dd January 22, 2012
 .Dt READ 2
@@ -164,6 +164,8 @@
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/sys/rtprio.2
--- a/head/lib/libc/sys/rtprio.2	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/sys/rtprio.2	Wed Jul 25 16:23:00 2012 +0300
@@ -52,7 +52,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD: head/lib/libc/sys/rtprio.2 228910 2011-12-27 10:34:00Z delphij $
+.\" $FreeBSD: head/lib/libc/sys/rtprio.2 235140 2012-05-08 18:56:21Z gjb $
 .\"
 .Dd December 27, 2011
 .Dt RTPRIO 2
@@ -132,7 +132,8 @@
 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 @@
 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 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/sys/setfib.2
--- a/head/lib/libc/sys/setfib.2	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/sys/setfib.2	Wed Jul 25 16:23:00 2012 +0300
@@ -22,7 +22,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD: head/lib/libc/sys/setfib.2 233161 2012-03-19 05:08:09Z bjk $
+.\" $FreeBSD: head/lib/libc/sys/setfib.2 235340 2012-05-12 16:08:05Z joel $
 .\"
 .Dd March 19, 2012
 .Dt SETFIB 2
@@ -51,8 +51,9 @@
 .Va net.fibs
 sysctl.
 The system maximum is set in the kernel configuration file with
-.Pp
-.Dl options	ROUTETABLES= Ns Em N
+.Bd -ragged -offset indent
+.Cd "options ROUTETABLES=" Ns Em N
+.Ed
 .Pp
 or in
 .Pa /boot/loader.conf
@@ -94,7 +95,8 @@
 .Fx
 extension however similar extensions
 have been added to many other
-.Ux style kernels.
+.Ux
+style kernels.
 .Sh HISTORY
 The
 .Fn setfib
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/sys/shm_open.2
--- a/head/lib/libc/sys/shm_open.2	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/sys/shm_open.2	Wed Jul 25 16:23:00 2012 +0300
@@ -26,7 +26,7 @@
 .\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD: head/lib/libc/sys/shm_open.2 233462 2012-03-25 12:13:24Z joel $
+.\" $FreeBSD: head/lib/libc/sys/shm_open.2 235140 2012-05-08 18:56:21Z gjb $
 .\"
 .Dd March 20, 2007
 .Dt SHM_OPEN 2
@@ -88,7 +88,7 @@
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/sys/sigqueue.2
--- a/head/lib/libc/sys/sigqueue.2	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/sys/sigqueue.2	Wed Jul 25 16:23:00 2012 +0300
@@ -25,7 +25,7 @@
 .\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 .\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.\" $FreeBSD: head/lib/libc/sys/sigqueue.2 232778 2012-03-10 10:54:52Z trasz $
+.\" $FreeBSD: head/lib/libc/sys/sigqueue.2 235140 2012-05-08 18:56:21Z gjb $
 .\"
 .Dd March 10, 2012
 .Dt SIGQUEUE 2
@@ -141,7 +141,7 @@
 The
 .Fn sigqueue
 system call conforms to
-.St -p1003.1-2004
+.St -p1003.1-2004 .
 .Sh HISTORY
 Support for
 .Tn POSIX
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/sys/stat.2
--- a/head/lib/libc/sys/stat.2	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/sys/stat.2	Wed Jul 25 16:23:00 2012 +0300
@@ -26,9 +26,9 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)stat.2	8.4 (Berkeley) 5/1/95
-.\" $FreeBSD: head/lib/libc/sys/stat.2 227622 2011-11-17 13:14:07Z kib $
+.\" $FreeBSD: head/lib/libc/sys/stat.2 236441 2012-06-02 10:50:25Z ed $
 .\"
-.Dd November 17, 2011
+.Dd June 2, 2012
 .Dt STAT 2
 .Os
 .Sh NAME
@@ -431,7 +431,7 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/sys/timer_create.2
--- a/head/lib/libc/sys/timer_create.2	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/sys/timer_create.2	Wed Jul 25 16:23:00 2012 +0300
@@ -25,7 +25,7 @@
 .\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 .\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.\" $FreeBSD: head/lib/libc/sys/timer_create.2 226790 2011-10-26 14:26:10Z pluknet $
+.\" $FreeBSD: head/lib/libc/sys/timer_create.2 235140 2012-05-08 18:56:21Z gjb $
 .\"
 .Dd January 12, 2009
 .Dt TIMER_CREATE 2
@@ -157,7 +157,7 @@
 The
 .Fn timer_create
 system call conforms to
-.St -p1003.1-2004
+.St -p1003.1-2004 .
 .Sh HISTORY
 Support for
 .Tn POSIX
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/sys/timer_delete.2
--- a/head/lib/libc/sys/timer_delete.2	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/sys/timer_delete.2	Wed Jul 25 16:23:00 2012 +0300
@@ -25,7 +25,7 @@
 .\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 .\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/libc/sys/timer_delete.2 235140 2012-05-08 18:56:21Z gjb $
 .\"
 .Dd September 11, 2000
 .Dt TIMER_DELETE 2
@@ -72,7 +72,7 @@
 The
 .Fn timer_delete
 system call conforms to
-.St -p1003.1-2004
+.St -p1003.1-2004 .
 .Sh HISTORY
 Support for
 .Tn POSIX
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/sys/timer_settime.2
--- a/head/lib/libc/sys/timer_settime.2	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/sys/timer_settime.2	Wed Jul 25 16:23:00 2012 +0300
@@ -25,7 +25,7 @@
 .\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 .\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/libc/sys/timer_settime.2 235140 2012-05-08 18:56:21Z gjb $
 .\"
 .Dd September 11, 2000
 .Dt TIMER_SETTIME 2
@@ -257,7 +257,7 @@
 and
 .Fn timer_settime
 system calls conform to
-.St -p1003.1-2004
+.St -p1003.1-2004 .
 .Sh HISTORY
 Support for
 .Tn POSIX
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libc/sys/unlink.2
--- a/head/lib/libc/sys/unlink.2	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libc/sys/unlink.2	Wed Jul 25 16:23:00 2012 +0300
@@ -26,7 +26,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)unlink.2	8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/libc/sys/unlink.2 235140 2012-05-08 18:56:21Z gjb $
 .\"
 .Dd April 25, 2010
 .Dt UNLINK 2
@@ -157,7 +157,7 @@
 .Fn unlink ,
 the
 .Fn unlinkat
-may fail if
+may fail if:
 .Bl -tag -width Er
 .It Bq Er EBADF
 The
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libcompiler_rt/Makefile
--- a/head/lib/libcompiler_rt/Makefile	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libcompiler_rt/Makefile	Wed Jul 25 16:23:00 2012 +0300
@@ -1,4 +1,4 @@
-# $FreeBSD: head/lib/libcompiler_rt/Makefile 229135 2011-12-31 19:01:48Z ed $
+# $FreeBSD: head/lib/libcompiler_rt/Makefile 235487 2012-05-15 22:47:34Z marius $
 
 .include <bsd.own.mk>
 
@@ -176,7 +176,7 @@
 . 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libcrypt/Makefile
--- a/head/lib/libcrypt/Makefile	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libcrypt/Makefile	Wed Jul 25 16:23:00 2012 +0300
@@ -1,5 +1,5 @@
 #
-# $FreeBSD: head/lib/libcrypt/Makefile 221142 2011-04-27 21:33:56Z obrien $
+# $FreeBSD: head/lib/libcrypt/Makefile 236967 2012-06-12 17:14:19Z des $
 #
 
 SHLIBDIR?=	/lib
@@ -26,11 +26,7 @@
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libcrypt/crypt.3
--- a/head/lib/libcrypt/crypt.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libcrypt/crypt.3	Wed Jul 25 16:23:00 2012 +0300
@@ -27,7 +27,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD: head/lib/libcrypt/crypt.3 234132 2012-04-11 14:12:28Z eadler $
+.\" $FreeBSD: head/lib/libcrypt/crypt.3 236967 2012-06-12 17:14:19Z des $
 .\"
 .Dd April 9, 2011
 .Dt CRYPT 3
@@ -196,7 +196,7 @@
 .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 @@
 .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 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libcrypt/crypt.c
--- a/head/lib/libcrypt/crypt.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libcrypt/crypt.c	Wed Jul 25 16:23:00 2012 +0300
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/libcrypt/crypt.c 221471 2011-05-05 01:09:42Z obrien $");
+__FBSDID("$FreeBSD: head/lib/libcrypt/crypt.c 236967 2012-06-12 17:14:19Z des $");
 
 #include <sys/types.h>
 #include <string.h>
@@ -79,23 +79,23 @@
 	}
 };
 
+#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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libcxxrt/Makefile
--- a/head/lib/libcxxrt/Makefile	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libcxxrt/Makefile	Wed Jul 25 16:23:00 2012 +0300
@@ -1,26 +1,26 @@
-# $FreeBSD: head/lib/libcxxrt/Makefile 233174 2012-03-19 11:53:33Z theraven $
+# $FreeBSD: head/lib/libcxxrt/Makefile 236442 2012-06-02 11:00:48Z dim $
 
-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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libcxxrt/Version.map
--- a/head/lib/libcxxrt/Version.map	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libcxxrt/Version.map	Wed Jul 25 16:23:00 2012 +0300
@@ -1,4 +1,4 @@
-# $FreeBSD: head/lib/libcxxrt/Version.map 233235 2012-03-20 17:58:15Z theraven $
+# $FreeBSD: head/lib/libcxxrt/Version.map 236890 2012-06-11 15:40:57Z theraven $
 # Define the same version as the libsupc++ from gcc 4.2.1 so that we can use
 # libcxxrt as a drop-in replacement.
 
@@ -306,11 +306,6 @@
         "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 @@
     __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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libedit/chared.c
--- a/head/lib/libedit/chared.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libedit/chared.c	Wed Jul 25 16:23:00 2012 +0300
@@ -29,14 +29,14 @@
  * 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)
 static char sccsid[] = "@(#)chared.c	8.1 (Berkeley) 6/4/93";
 #endif /* not lint && not SCCSID */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libedit/chared.c 238178 2012-07-06 19:30:50Z pfg $");
 
 /*
  * chared.c: Character editor utilities
@@ -59,12 +59,12 @@
 {
 	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 @@
 {
 	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 @@
 	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 @@
 {
 
 	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 @@
 {
 
 	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 @@
 		/* 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 @@
 }
 
 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 @@
  *	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 @@
 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 @@
 
 		case '\010':	/* Delete and backspace */
 		case '\177':
-			if (len <= 0) {
+			if (len == 0) {
 				len = -1;
 				break;
 			}
@@ -749,7 +746,7 @@
 	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 @@
 		     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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libedit/chared.h
--- a/head/lib/libedit/chared.h	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libedit/chared.h	Wed Jul 25 16:23:00 2012 +0300
@@ -30,8 +30,8 @@
  * SUCH DAMAGE.
  *
  *	@(#)chared.h	8.1 (Berkeley) 6/4/93
- *	$NetBSD: chared.h,v 1.17 2006/03/06 21:11:56 christos Exp $
- * $FreeBSD$
+ *	$NetBSD: chared.h,v 1.18 2009/02/15 21:55:23 christos Exp $
+ * $FreeBSD: head/lib/libedit/chared.h 238178 2012-07-06 19:30:50Z pfg $
  */
 
 /*
@@ -70,7 +70,7 @@
  * 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libedit/common.c
--- a/head/lib/libedit/common.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libedit/common.c	Wed Jul 25 16:23:00 2012 +0300
@@ -36,7 +36,7 @@
 static char sccsid[] = "@(#)common.c	8.1 (Berkeley) 6/4/93";
 #endif /* not lint && not SCCSID */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libedit/common.c 237448 2012-06-22 18:01:22Z pfg $");
 
 /*
  * common.c: Common Editor functions
@@ -905,7 +905,7 @@
 	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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libedit/edit/readline/Makefile
--- a/head/lib/libedit/edit/readline/Makefile	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libedit/edit/readline/Makefile	Wed Jul 25 16:23:00 2012 +0300
@@ -1,8 +1,7 @@
 # Copyright (c) 2011 David E O'Brien
-# $FreeBSD: head/lib/libedit/edit/readline/Makefile 228116 2011-11-29 06:21:01Z fjoe $
+# $FreeBSD: head/lib/libedit/edit/readline/Makefile 234690 2012-04-26 00:51:43Z obrien $
 
-INCS=	readline.h history.h
-INCSLINKS=	readline.h ${INCSDIR}/tilde.h
+INCS=	readline.h history.h tilde.h
 
 INCSDIR= ${INCLUDEDIR}/edit/readline
 
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libedit/edit/readline/tilde.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/lib/libedit/edit/readline/tilde.h	Wed Jul 25 16:23:00 2012 +0300
@@ -0,0 +1,32 @@
+/*-
+ * Copyright (c) 2011 David E. O'Brien
+ * 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 author nor the names of contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * 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 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: head/lib/libedit/edit/readline/tilde.h 234690 2012-04-26 00:51:43Z obrien $
+ */
+
+#include <edit/readline/readline.h>
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libedit/editline.3
--- a/head/lib/libedit/editline.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libedit/editline.3	Wed Jul 25 16:23:00 2012 +0300
@@ -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.
@@ -26,9 +26,9 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/libedit/editline.3 238378 2012-07-11 22:20:19Z pfg $
 .\"
-.Dd January 12, 2007
+.Dd July 5, 2009
 .Dt EDITLINE 3
 .Os
 .Sh NAME
@@ -162,6 +162,14 @@
 Returns the line read if successful, or
 .Dv NULL
 if no characters were read or if an error occurred.
+If an error occurred,
+.Fa count
+is set to \-1 and
+.Dv errno
+contains the error code that caused it.
+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 +230,30 @@
 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 +287,43 @@
 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 +365,8 @@
 .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 +438,22 @@
 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 +618,11 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libedit/editrc.5
--- a/head/lib/libedit/editrc.5	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libedit/editrc.5	Wed Jul 25 16:23:00 2012 +0300
@@ -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.
@@ -26,7 +26,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/libedit/editrc.5 237525 2012-06-24 07:54:28Z joel $
 .\"
 .Dd October 18, 2003
 .Dt EDITRC 5
@@ -89,16 +89,8 @@
 .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 @@
 .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 @@
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libedit/el.c
--- a/head/lib/libedit/el.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libedit/el.c	Wed Jul 25 16:23:00 2012 +0300
@@ -29,14 +29,14 @@
  * 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)
 static char sccsid[] = "@(#)el.c	8.2 (Berkeley) 1/3/94";
 #endif /* not lint && not SCCSID */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libedit/el.c 237448 2012-06-22 18:01:22Z pfg $");
 
 /*
  * el.c: EditLine interface functions
@@ -48,6 +48,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include <stdarg.h>
+#include <ctype.h>
 #include "el.h"
 
 #define	HAVE_ISSETUGID
@@ -156,9 +157,21 @@
 
 	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 @@
 		break;
 	}
 
+	case EL_REFRESH:
+		re_clear_display(el);
+		re_refresh(el);
+		term__flush(el);
+		break;
+
 	default:
 		rv = -1;
 		break;
@@ -335,9 +354,13 @@
 
 	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 @@
 		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 @@
 	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 @@
 		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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libedit/el.h
--- a/head/lib/libedit/el.h	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libedit/el.h	Wed Jul 25 16:23:00 2012 +0300
@@ -31,7 +31,7 @@
  *
  *	@(#)el.h	8.1 (Berkeley) 6/4/93
  *	$NetBSD: el.h,v 1.17 2006/12/15 22:13:33 christos Exp $
- * $FreeBSD$
+ * $FreeBSD: head/lib/libedit/el.h 238378 2012-07-11 22:20:19Z pfg $
  */
 
 /*
@@ -115,6 +115,7 @@
 	FILE		 *el_errfile;	/* Stdio stuff			*/
 	int		  el_infd;	/* Input file descriptor	*/
 	int		  el_flags;	/* Various flags.		*/
+	int		  el_errno;	/* Local copy of errno		*/
 	coord_t		  el_cursor;	/* Cursor location		*/
 	char		**el_display;	/* Real screen image = what is there */
 	char		**el_vdisplay;	/* Virtual screen image = what we see */
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libedit/histedit.h
--- a/head/lib/libedit/histedit.h	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libedit/histedit.h	Wed Jul 25 16:23:00 2012 +0300
@@ -31,7 +31,7 @@
  *
  *	@(#)histedit.h	8.2 (Berkeley) 1/3/94
  *	$NetBSD: histedit.h,v 1.32 2007/06/10 20:20:28 christos Exp $
- * $FreeBSD: head/lib/libedit/histedit.h 228473 2011-12-13 14:53:26Z ed $
+ * $FreeBSD: head/lib/libedit/histedit.h 237448 2012-06-22 18:01:22Z pfg $
  */
 
 /*
@@ -131,10 +131,10 @@
 #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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libedit/history.c
--- a/head/lib/libedit/history.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libedit/history.c	Wed Jul 25 16:23:00 2012 +0300
@@ -29,14 +29,14 @@
  * 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)
 static char sccsid[] = "@(#)history.c	8.1 (Berkeley) 6/4/93";
 #endif /* not lint && not SCCSID */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libedit/history.c 237448 2012-06-22 18:01:22Z pfg $");
 
 /*
  * hist.c: History access functions
@@ -116,6 +116,7 @@
  */
 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_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_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 @@
 }
 
 
+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 @@
 	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 @@
 		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 @@
 		(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 @@
 }
 
 
+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 @@
 		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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libedit/key.c
--- a/head/lib/libedit/key.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libedit/key.c	Wed Jul 25 16:23:00 2012 +0300
@@ -29,14 +29,14 @@
  * 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)
 static char sccsid[] = "@(#)key.c	8.1 (Berkeley) 6/4/93";
 #endif /* not lint && not SCCSID */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libedit/key.c 237448 2012-06-22 18:01:22Z pfg $");
 
 /*
  * key.c: This module contains the procedures for maintaining
@@ -86,8 +86,8 @@
 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 @@
  *	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 @@
 		/* 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 @@
  *	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 @@
 		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__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 @@
 	if (ch == 0) {
 		ADDC('^');
 		ADDC('@');
-		return b - sb;
+		return (int)(b - sb);
 	}
 	if (iscntrl(ch)) {
 		ADDC('^');
@@ -648,15 +649,15 @@
 		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 @@
 	}
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libedit/key.h
--- a/head/lib/libedit/key.h	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libedit/key.h	Wed Jul 25 16:23:00 2012 +0300
@@ -31,7 +31,7 @@
  *
  *	@(#)key.h	8.1 (Berkeley) 6/4/93
  *	$NetBSD: key.h,v 1.10 2006/03/23 20:22:51 christos Exp $
- * $FreeBSD$
+ * $FreeBSD: head/lib/libedit/key.h 237448 2012-06-22 18:01:22Z pfg $
  */
 
 /*
@@ -76,8 +76,8 @@
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libedit/makelist
--- a/head/lib/libedit/makelist	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libedit/makelist	Wed Jul 25 16:23:00 2012 +0300
@@ -1,6 +1,6 @@
 #!/bin/sh -
-#	$NetBSD: makelist,v 1.10 2005/08/08 14:04:49 christos Exp $
-# $FreeBSD$
+#	$NetBSD: makelist,v 1.11 2005/10/22 16:45:03 christos Exp $
+# $FreeBSD: head/lib/libedit/makelist 238624 2012-07-19 19:15:47Z pfg $
 #
 # Copyright (c) 1992, 1993
 #	The Regents of the University of California.  All rights reserved.
@@ -141,7 +141,7 @@
 #
 -fh)
     cat $FILES | $AWK '/el_action_t/ { print $3 }' | \
-    sort | LC_ALL=C tr 'a-z' 'A-Z' | $AWK '
+    sort | LC_ALL=C tr '[:lower:]' '[:upper:]' | $AWK '
 	BEGIN {
 	    printf("/* Automatically generated file, do not edit */\n");
 	    printf("#ifndef _h_fcns_c\n#define _h_fcns_c\n");
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libedit/prompt.c
--- a/head/lib/libedit/prompt.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libedit/prompt.c	Wed Jul 25 16:23:00 2012 +0300
@@ -36,7 +36,7 @@
 static char sccsid[] = "@(#)prompt.c	8.1 (Berkeley) 6/4/93";
 #endif /* not lint && not SCCSID */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libedit/prompt.c 237448 2012-06-22 18:01:22Z pfg $");
 
 /*
  * prompt.c: Prompt printing functions
@@ -85,14 +85,23 @@
 {
 	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 @@
 	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,39 +141,52 @@
  *	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 || op == EL_PROMPT_ESC)
+		p = &el->el_prompt;
+	else
+		p = &el->el_rprompt;
+
+	if (prf == NULL) {
+		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;
+}
+
+
+/* prompt_get():
+ *	Retrieve the prompt printing function
+ */
+protected int
+prompt_get(EditLine *el, el_pfunc_t *prf, char *c, int op)
+{
+	el_prompt_t *p;
+
+	if (prf == NULL)
+		return -1;
+
 	if (op == EL_PROMPT)
 		p = &el->el_prompt;
 	else
 		p = &el->el_rprompt;
-	if (prf == NULL) {
-		if (op == EL_PROMPT)
-			p->p_func = prompt_default;
-		else
-			p->p_func = prompt_default_r;
-	} else
-		p->p_func = prf;
-	p->p_pos.v = 0;
-	p->p_pos.h = 0;
-	return (0);
+
+	*prf = el->el_rprompt.p_func;
+
+	if (c)
+		*c = p->p_ignore;
+
+	return 0;
 }
-
-
-/* prompt_get():
- *	Retrieve the prompt printing function
- */
-protected int
-prompt_get(EditLine *el, el_pfunc_t *prf, int op)
-{
-
-	if (prf == NULL)
-		return (-1);
-	if (op == EL_PROMPT)
-		*prf = el->el_prompt.p_func;
-	else
-		*prf = el->el_rprompt.p_func;
-	return (0);
-}
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libedit/prompt.h
--- a/head/lib/libedit/prompt.h	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libedit/prompt.h	Wed Jul 25 16:23:00 2012 +0300
@@ -31,7 +31,7 @@
  *
  *	@(#)prompt.h	8.1 (Berkeley) 6/4/93
  *	$NetBSD: prompt.h,v 1.6 2003/08/07 16:44:32 agc Exp $
- * $FreeBSD$
+ * $FreeBSD: head/lib/libedit/prompt.h 237448 2012-06-22 18:01:22Z pfg $
  */
 
 /*
@@ -47,11 +47,13 @@
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libedit/read.c
--- a/head/lib/libedit/read.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libedit/read.c	Wed Jul 25 16:23:00 2012 +0300
@@ -29,14 +29,14 @@
  * 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)
 static char sccsid[] = "@(#)read.c	8.1 (Berkeley) 6/4/93";
 #endif /* not lint && not SCCSID */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/libedit/read.c 220370 2011-04-05 18:41:01Z obrien $");
+__FBSDID("$FreeBSD: head/lib/libedit/read.c 238378 2012-07-11 22:20:19Z pfg $");
 
 /*
  * read.c: Clean this junk up! This is horrible code.
@@ -222,7 +222,7 @@
 		ma->level--;
 	}
 	term_beep(el);
-	term__flush();
+	term__flush(el);
 }
 
 
@@ -235,9 +235,12 @@
 	el_action_t cmd;
 	int num;
 
+	el->el_errno = 0;
 	do {
-		if ((num = el_getc(el, ch)) != 1)	/* if EOF or error */
+		if ((num = el_getc(el, ch)) != 1) {	/* if EOF or error */
+			el->el_errno = num == 0 ? 0 : errno;
 			return (num);
+		}
 
 #ifdef	KANJI
 		if ((*ch & 0200)) {
@@ -286,18 +289,25 @@
 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)
+ again:
+	el->el_signal->sig_no = 0;
+	while ((num_read = read(el->el_infd, cp, 1)) == -1) {
+		if (el->el_signal->sig_no == SIGCONT) {
+			sig_set(el);
+			el_set(el, EL_REFRESH);
+			goto again;
+		}
 		if (!tried && read__fixio(el->el_infd, errno) == 0)
 			tried = 1;
 		else {
 			*cp = '\0';
 			return (-1);
 		}
-
-	return (num_read);
+	}
+	return (int)num_read;
 }
 
 /* read_pop():
@@ -309,8 +319,9 @@
 	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 +334,7 @@
 	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 +393,7 @@
 	re_refresh(el);		/* print the prompt */
 
 	if (el->el_flags & UNBUFFERED)
-		term__flush();
+		term__flush(el);
 }
 
 protected void
@@ -402,10 +413,15 @@
 	int num;		/* how many chars we have read at NL */
 	char ch;
 	int crlf = 0;
+	int nrb;
 #ifdef FIONREAD
 	c_macro_t *ma = &el->el_chared.c_macro;
 #endif /* FIONREAD */
 
+	if (nread == NULL)
+		nread = &nrb;
+	*nread = 0;
+
 	if (el->el_flags & NO_TTY) {
 		char *cp = el->el_line.buffer;
 		size_t idx;
@@ -424,12 +440,13 @@
 			if (cp[-1] == '\r' || cp[-1] == '\n')
 				break;
 		}
+		if (num == -1)
+			el->el_errno = errno;
 
 		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);
+		goto done;
 	}
 
 
@@ -440,8 +457,8 @@
 		(void) ioctl(el->el_infd, FIONREAD, (ioctl_t) & chrs);
 		if (chrs == 0) {
 			if (tty_rawmode(el) < 0) {
-				if (nread)
-					*nread = 0;
+				errno = 0;
+				*nread = 0;
 				return (NULL);
 			}
 		}
@@ -454,12 +471,13 @@
 	if (el->el_flags & EDIT_DISABLED) {
 		char *cp;
 		size_t idx;
+
 		if ((el->el_flags & UNBUFFERED) == 0)
 			cp = el->el_line.buffer;
 		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 +487,6 @@
 					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)
@@ -479,11 +495,13 @@
 				break;
 		}
 
+		if (num == -1) {
+			el->el_errno = errno;
+		}
+
 		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);
+		goto done;
 	}
 
 	for (num = OKCMD; num == OKCMD;) {	/* while still editing this
@@ -499,7 +517,7 @@
 #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 +599,7 @@
 			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 +620,7 @@
 			    "*** editor ERROR ***\r\n\n");
 #endif /* DEBUG_READ */
 			term_beep(el);
-			term__flush();
+			term__flush(el);
 			break;
 		}
 		el->el_state.argument = 1;
@@ -612,15 +630,21 @@
 			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);
-		if (nread)
-			*nread = num;
+		*nread = num != -1 ? num : 0;
 	} 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);
+done:
+	if (*nread == 0) {
+		if (num == -1) {
+			*nread = -1;
+			errno = el->el_errno;
+		}
+		return NULL;
+	} else
+		return el->el_line.buffer;
 }
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libedit/refresh.c
--- a/head/lib/libedit/refresh.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libedit/refresh.c	Wed Jul 25 16:23:00 2012 +0300
@@ -29,14 +29,14 @@
  * 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)
 static char sccsid[] = "@(#)refresh.c	8.1 (Berkeley) 6/4/93";
 #endif /* not lint && not SCCSID */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libedit/refresh.c 237448 2012-06-22 18:01:22Z pfg $");
 
 /*
  * refresh.c: Lower level screen refreshing functions
@@ -49,6 +49,7 @@
 
 #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 @@
 #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 @@
 	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 @@
 
 	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. */
+		el->el_vdisplay[el->el_refresh.r_cursor.v][el->el_term.t_size.h]
+		    = '\0';
+		re_nextline(el);
+	}
 
-		/*
-		 * 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());
-	}
 }
 
 
@@ -298,7 +307,7 @@
 			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 @@
 {
 
 	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 @@
 	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 @@
          * 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 @@
 	/*
          * 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 @@
 		/*
 		 * 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 @@
 				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 @@
 		/*
 		 * 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 @@
 				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 @@
 			/*
 		         * 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 @@
 		 * 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 @@
 			/*
 		         * 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 @@
 		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 @@
 		         * 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 @@
 				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 @@
          */
 	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 @@
 		         * 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 @@
 	/* 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 @@
 	/* now go there */
 	term_move_to_line(el, v);
 	term_move_to_char(el, h);
-	term__flush();
+	term__flush(el);
 }
 
 
@@ -1020,7 +1030,7 @@
 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 @@
 			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_fastputc(el, (int)(((((unsigned int)c) >> 3) & 7) + '0'));
 		re_fastputc(el, (c & 7) + '0');
 	}
-	term__flush();
+	term__flush(el);
 }
 
 
@@ -1121,17 +1131,16 @@
 
 	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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libedit/search.c
--- a/head/lib/libedit/search.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libedit/search.c	Wed Jul 25 16:23:00 2012 +0300
@@ -29,14 +29,14 @@
  * 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)
 static char sccsid[] = "@(#)search.c	8.1 (Berkeley) 6/4/93";
 #endif /* not lint && not SCCSID */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libedit/search.c 237448 2012-06-22 18:01:22Z pfg $");
 
 /*
  * search.c: History and character search functions
@@ -207,7 +207,7 @@
 	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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libedit/sig.c
--- a/head/lib/libedit/sig.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libedit/sig.c	Wed Jul 25 16:23:00 2012 +0300
@@ -29,14 +29,14 @@
  * 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.15 2009/02/19 15:20:22 christos Exp $
  */
 
 #if !defined(lint) && !defined(SCCSID)
 static char sccsid[] = "@(#)sig.c	8.1 (Berkeley) 6/4/93";
 #endif /* not lint && not SCCSID */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libedit/sig.c 238378 2012-07-11 22:20:19Z pfg $");
 
 /*
  * sig.c: Signal handling stuff.
@@ -73,12 +73,14 @@
 	(void) sigaddset(&nset, signo);
 	(void) sigprocmask(SIG_BLOCK, &nset, &oset);
 
+	sel->el_signal->sig_no = signo;
+
 	switch (signo) {
 	case SIGCONT:
 		tty_rawmode(sel);
 		if (ed_redisplay(sel, 0) == CC_REFRESH)
 			re_refresh(sel);
-		term__flush();
+		term__flush(sel);
 		break;
 
 	case SIGWINCH:
@@ -94,7 +96,10 @@
 		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 +111,29 @@
 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);
+	(void) sigprocmask(SIG_BLOCK, nset, &oset);
 
-#define	SIGSIZE (sizeof(sighdl) / sizeof(sighdl[0]) * sizeof(el_signalhandler_t))
-
-	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 +155,21 @@
 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;
+	nsa.sa_flags = 0;
+	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;
 		/* 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 +182,17 @@
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libedit/sig.h
--- a/head/lib/libedit/sig.h	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libedit/sig.h	Wed Jul 25 16:23:00 2012 +0300
@@ -30,8 +30,8 @@
  * SUCH DAMAGE.
  *
  *	@(#)sig.h	8.1 (Berkeley) 6/4/93
- *	$NetBSD: sig.h,v 1.5 2003/08/07 16:44:33 agc Exp $
- * $FreeBSD$
+ *	$NetBSD: sig.h,v 1.8 2009/02/19 15:20:22 christos Exp $
+ * $FreeBSD: head/lib/libedit/sig.h 238378 2012-07-11 22:20:19Z pfg $
  */
 
 /*
@@ -51,15 +51,18 @@
 #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;
+	volatile sig_atomic_t sig_no;
+} *el_signal_t;
 
 protected void	sig_end(EditLine*);
 protected int	sig_init(EditLine*);
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libedit/term.c
--- a/head/lib/libedit/term.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libedit/term.c	Wed Jul 25 16:23:00 2012 +0300
@@ -29,14 +29,14 @@
  * 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)
 static char sccsid[] = "@(#)term.c	8.2 (Berkeley) 4/30/95";
 #endif /* not lint && not SCCSID */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libedit/term.c 237448 2012-06-22 18:01:22Z pfg $");
 
 /*
  * term.c: Editor/termcap-curses interface
@@ -261,9 +261,13 @@
 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 @@
 #endif /* DEBUG_SCREEN */
 }
 
-
 /* term_init():
  *	Initialize the terminal stuff
  */
@@ -337,7 +340,6 @@
 	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 @@
 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 @@
 						/* 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 @@
 			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 @@
 	}
 					/* 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 @@
 			    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 @@
 		}
 	} 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 @@
 		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 @@
 
 	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 @@
 				 * 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 @@
 				    (((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 @@
  *	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 @@
 				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 @@
 	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 @@
 	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 @@
 	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 @@
 
 	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 @@
 {
 	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 @@
 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_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 @@
 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 @@
 				    *argv);
 			return (-1);
 		}
-		(void) tputs(scap, 1, term__putc);
+		term_tputs(el, scap, 1);
 		break;
 	case 1:
 		argv++;
@@ -1613,7 +1636,7 @@
 				    *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 @@
 				    *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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libedit/term.h
--- a/head/lib/libedit/term.h	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libedit/term.h	Wed Jul 25 16:23:00 2012 +0300
@@ -31,7 +31,7 @@
  *
  *	@(#)term.h	8.1 (Berkeley) 6/4/93
  *	$NetBSD: term.h,v 1.18 2006/11/24 00:01:17 christos Exp $
- * $FreeBSD$
+ * $FreeBSD: head/lib/libedit/term.h 237448 2012-06-22 18:01:22Z pfg $
  */
 
 /*
@@ -85,7 +85,7 @@
 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_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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libedit/tokenizer.c
--- a/head/lib/libedit/tokenizer.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libedit/tokenizer.c	Wed Jul 25 16:23:00 2012 +0300
@@ -29,14 +29,14 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- *	$NetBSD: tokenizer.c,v 1.14 2003/12/05 13:37:48 lukem Exp $
+ *	$NetBSD: tokenizer.c,v 1.15 2009/02/15 21:55:23 christos Exp $
  */
 
 #if !defined(lint) && !defined(SCCSID)
 static char sccsid[] = "@(#)tokenizer.c	8.1 (Berkeley) 6/4/93";
 #endif /* not lint && not SCCSID */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libedit/tokenizer.c 238624 2012-07-19 19:15:47Z pfg $");
 
 /*
  * tokenize.c: Bourne shell like tokenizer
@@ -198,7 +198,7 @@
 			ptr = "";
 		if (ptr == line->cursor) {
 			cc = tok->argc;
-			co = tok->wptr - tok->wstart;
+			co = (int)(tok->wptr - tok->wstart);
 		}
 		switch (*ptr) {
 		case '\'':
@@ -417,7 +417,7 @@
  tok_line_outok:
 	if (cc == -1 && co == -1) {
 		cc = tok->argc;
-		co = tok->wptr - tok->wstart;
+		co = (int)(tok->wptr - tok->wstart);
 	}
 	if (cursorc != NULL)
 		*cursorc = cc;
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libedit/tty.c
--- a/head/lib/libedit/tty.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libedit/tty.c	Wed Jul 25 16:23:00 2012 +0300
@@ -29,14 +29,14 @@
  * 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)
 static char sccsid[] = "@(#)tty.c	8.1 (Berkeley) 6/4/93";
 #endif /* not lint && not SCCSID */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libedit/tty.c 237448 2012-06-22 18:01:22Z pfg $");
 
 /*
  * tty.c: tty interface stuff
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libedit/vi.c
--- a/head/lib/libedit/vi.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libedit/vi.c	Wed Jul 25 16:23:00 2012 +0300
@@ -29,14 +29,14 @@
  * 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)
 static char sccsid[] = "@(#)vi.c	8.1 (Berkeley) 6/4/93";
 #endif /* not lint && not SCCSID */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libedit/vi.c 237448 2012-06-22 18:01:22Z pfg $");
 
 /*
  * vi.c: Vi mode commands.
@@ -63,7 +63,7 @@
 		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 @@
 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 @@
 	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 @@
 
 	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 @@
 
 	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 @@
 	/* 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 @@
 	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 @@
 {
 	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 @@
 {
 
 	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 @@
 {
 	int fd;
 	pid_t pid;
-	int st;
+	ssize_t st;
+	int status;
 	char tempfile[] = "/tmp/histedit.XXXXXXXXXX";
 	char *cp;
 
@@ -1006,7 +1008,7 @@
 	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 @@
 		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 @@
 		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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libelf/Makefile
--- a/head/lib/libelf/Makefile	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libelf/Makefile	Wed Jul 25 16:23:00 2012 +0300
@@ -1,4 +1,4 @@
-# $FreeBSD: head/lib/libelf/Makefile 221569 2011-05-07 01:05:31Z obrien $
+# $FreeBSD: head/lib/libelf/Makefile 238741 2012-07-24 16:03:28Z ache $
 
 LIB=	elf
 
@@ -55,9 +55,22 @@
 	${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: ${.CURDIR}/../../sys/${.TARGET}
+	mkdir -p ${.OBJDIR}/sys
+	ln -sf ${.CURDIR}/../../sys/${.TARGET} ${.TARGET}
 
 SHLIB_MAJOR=	1
 
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libelf/elf.3
--- a/head/lib/libelf/elf.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libelf/elf.3	Wed Jul 25 16:23:00 2012 +0300
@@ -21,7 +21,7 @@
 .\" out of the use of this software, even if advised of the possibility of
 .\" such damage.
 .\"
-.\" $FreeBSD: head/lib/libelf/elf.3 233648 2012-03-29 05:02:12Z eadler $
+.\" $FreeBSD: head/lib/libelf/elf.3 236438 2012-06-02 08:47:26Z joel $
 .\"
 .Dd October 21, 2007
 .Dt ELF 3
@@ -385,9 +385,9 @@
 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 @@
 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 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 @@
 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 @@
 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 @@
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libelf/elf_begin.3
--- a/head/lib/libelf/elf_begin.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libelf/elf_begin.3	Wed Jul 25 16:23:00 2012 +0300
@@ -21,7 +21,7 @@
 .\" out of the use of this software, even if advised of the possibility of
 .\" such damage.
 .\"
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/libelf/elf_begin.3 236626 2012-06-05 18:19:52Z joel $
 .\"
 .Dd June 20, 2010
 .Dt ELF_BEGIN 3
@@ -252,7 +252,7 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libelf/elf_getdata.3
--- a/head/lib/libelf/elf_getdata.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libelf/elf_getdata.3	Wed Jul 25 16:23:00 2012 +0300
@@ -21,7 +21,7 @@
 .\" out of the use of this software, even if advised of the possibility of
 .\" such damage.
 .\"
-.\" $FreeBSD: head/lib/libelf/elf_getdata.3 233648 2012-03-29 05:02:12Z eadler $
+.\" $FreeBSD: head/lib/libelf/elf_getdata.3 235286 2012-05-11 20:06:46Z gjb $
 .\"
 .Dd January 26, 2011
 .Dt ELF_GETDATA 3
@@ -144,7 +144,7 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libelf/elf_strptr.3
--- a/head/lib/libelf/elf_strptr.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libelf/elf_strptr.3	Wed Jul 25 16:23:00 2012 +0300
@@ -21,7 +21,7 @@
 .\" out of the use of this software, even if advised of the possibility of
 .\" such damage.
 .\"
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/libelf/elf_strptr.3 235286 2012-05-11 20:06:46Z gjb $
 .\"
 .Dd December 16, 2006
 .Dt ELF_STRPTR 3
@@ -64,7 +64,7 @@
 .It Bq Er ELF_E_ARGUMENT
 Argument
 .Ar elf
-was NULL
+was NULL.
 .It Bq Er ELF_E_ARGUMENT
 Argument
 .Ar elf
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libelf/gelf.3
--- a/head/lib/libelf/gelf.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libelf/gelf.3	Wed Jul 25 16:23:00 2012 +0300
@@ -21,7 +21,7 @@
 .\" out of the use of this software, even if advised of the possibility of
 .\" such damage.
 .\"
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/libelf/gelf.3 236438 2012-06-02 08:47:26Z joel $
 .\"
 .Dd September 1, 2006
 .Dt GELF 3
@@ -115,7 +115,7 @@
 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 @@
 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 @@
 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 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 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libelf/gelf_getphdr.3
--- a/head/lib/libelf/gelf_getphdr.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libelf/gelf_getphdr.3	Wed Jul 25 16:23:00 2012 +0300
@@ -21,7 +21,7 @@
 .\" out of the use of this software, even if advised of the possibility of
 .\" such damage.
 .\"
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/libelf/gelf_getphdr.3 235286 2012-05-11 20:06:46Z gjb $
 .\"
 .Dd October 21, 2007
 .Dt GELF_GETPHDR 3
@@ -66,7 +66,7 @@
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libelf/gelf_newehdr.3
--- a/head/lib/libelf/gelf_newehdr.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libelf/gelf_newehdr.3	Wed Jul 25 16:23:00 2012 +0300
@@ -21,7 +21,7 @@
 .\" out of the use of this software, even if advised of the possibility of
 .\" such damage.
 .\"
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/libelf/gelf_newehdr.3 235286 2012-05-11 20:06:46Z gjb $
 .\"
 .Dd October 22, 2007
 .Dt GELF_NEWEHDR 3
@@ -58,7 +58,8 @@
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libfetch/common.c
--- a/head/lib/libfetch/common.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libfetch/common.c	Wed Jul 25 16:23:00 2012 +0300
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/libfetch/common.c 230478 2012-01-23 09:23:07Z des $");
+__FBSDID("$FreeBSD: head/lib/libfetch/common.c 236193 2012-05-28 19:22:23Z jilles $");
 
 #include <sys/param.h>
 #include <sys/socket.h>
@@ -209,11 +209,13 @@
 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 @@
 	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 @@
 			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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libfetch/common.h
--- a/head/lib/libfetch/common.h	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libfetch/common.h	Wed Jul 25 16:23:00 2012 +0300
@@ -25,7 +25,7 @@
  * (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: head/lib/libfetch/common.h 230307 2012-01-18 15:13:21Z des $
+ * $FreeBSD: head/lib/libfetch/common.h 238405 2012-07-12 19:30:53Z jkim $
  */
 
 #ifndef _COMMON_H_INCLUDED
@@ -63,7 +63,7 @@
 	SSL		*ssl;		/* SSL handle */
 	SSL_CTX		*ssl_ctx;	/* SSL context */
 	X509		*ssl_cert;	/* server certificate */
-	SSL_METHOD	*ssl_meth;	/* SSL method */
+	const SSL_METHOD *ssl_meth;	/* SSL method */
 #endif
 	int		 ref;		/* reference count */
 };
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libfetch/http.c
--- a/head/lib/libfetch/http.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libfetch/http.c	Wed Jul 25 16:23:00 2012 +0300
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/libfetch/http.c 230307 2012-01-18 15:13:21Z des $");
+__FBSDID("$FreeBSD: head/lib/libfetch/http.c 234838 2012-04-30 12:12:48Z des $");
 
 /*
  * The following copyright applies to the base64 code:
@@ -1779,7 +1779,9 @@
 					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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libgpib/gpib.3
--- a/head/lib/libgpib/gpib.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libgpib/gpib.3	Wed Jul 25 16:23:00 2012 +0300
@@ -22,7 +22,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD: head/lib/libgpib/gpib.3 233462 2012-03-25 12:13:24Z joel $
+.\" $FreeBSD: head/lib/libgpib/gpib.3 236438 2012-06-02 08:47:26Z joel $
 .\"
 .Dd February 1, 2010
 .Dt GPIB 3
@@ -207,7 +207,8 @@
 .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 @@
 .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 @@
 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 @@
 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 @@
 .Pp
 The function
 .Fn ibwrtkey
-is obsolete, and not implemented
+is obsolete, and not implemented.
 .Pp
 The function
 .Fn ibxtrc
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libgssapi/gss_accept_sec_context.3
--- a/head/lib/libgssapi/gss_accept_sec_context.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libgssapi/gss_accept_sec_context.3	Wed Jul 25 16:23:00 2012 +0300
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\"	$FreeBSD: head/lib/libgssapi/gss_accept_sec_context.3 233510 2012-03-26 15:18:14Z joel $
+.\"	$FreeBSD: head/lib/libgssapi/gss_accept_sec_context.3 236746 2012-06-08 12:09:00Z joel $
 .\"
 .\" The following commands are required for all man pages.
 .Dd January 26, 2010
@@ -212,7 +212,7 @@
 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 @@
 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 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libgssapi/gss_acquire_cred.3
--- a/head/lib/libgssapi/gss_acquire_cred.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libgssapi/gss_acquire_cred.3	Wed Jul 25 16:23:00 2012 +0300
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\"	$FreeBSD$
+.\"	$FreeBSD: head/lib/libgssapi/gss_acquire_cred.3 236746 2012-06-08 12:09:00Z joel $
 .\"
 .\" The following commands are required for all man pages.
 .Dd January 26, 2010
@@ -126,7 +126,7 @@
 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 @@
 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 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libgssapi/gss_add_cred.3
--- a/head/lib/libgssapi/gss_add_cred.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libgssapi/gss_add_cred.3	Wed Jul 25 16:23:00 2012 +0300
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\"	$FreeBSD$
+.\"	$FreeBSD: head/lib/libgssapi/gss_add_cred.3 236746 2012-06-08 12:09:00Z joel $
 .\"
 .\" The following commands are required for all man pages.
 .Dd January 26, 2010
@@ -170,7 +170,7 @@
 .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 @@
 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 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libgssapi/gss_add_oid_set_member.3
--- a/head/lib/libgssapi/gss_add_oid_set_member.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libgssapi/gss_add_oid_set_member.3	Wed Jul 25 16:23:00 2012 +0300
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\"	$FreeBSD$
+.\"	$FreeBSD: head/lib/libgssapi/gss_add_oid_set_member.3 236746 2012-06-08 12:09:00Z joel $
 .\"
 .\" The following commands are required for all man pages.
 .Dd January 26, 2010
@@ -71,7 +71,7 @@
 .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 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 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libgssapi/gss_canonicalize_name.3
--- a/head/lib/libgssapi/gss_canonicalize_name.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libgssapi/gss_canonicalize_name.3	Wed Jul 25 16:23:00 2012 +0300
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\"	$FreeBSD$
+.\"	$FreeBSD: head/lib/libgssapi/gss_canonicalize_name.3 236746 2012-06-08 12:09:00Z joel $
 .\"
 .\" The following commands are required for all man pages.
 .Dd January 26, 2010
@@ -62,7 +62,7 @@
 .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 @@
 .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 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libgssapi/gss_compare_name.3
--- a/head/lib/libgssapi/gss_compare_name.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libgssapi/gss_compare_name.3	Wed Jul 25 16:23:00 2012 +0300
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\"	$FreeBSD$
+.\"	$FreeBSD: head/lib/libgssapi/gss_compare_name.3 236746 2012-06-08 12:09:00Z joel $
 .\"
 .\" The following commands are required for all man pages.
 .Dd January 26, 2010
@@ -54,7 +54,7 @@
 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 @@
 .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 @@
 .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 @@
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libgssapi/gss_context_time.3
--- a/head/lib/libgssapi/gss_context_time.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libgssapi/gss_context_time.3	Wed Jul 25 16:23:00 2012 +0300
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\"	$FreeBSD$
+.\"	$FreeBSD: head/lib/libgssapi/gss_context_time.3 236746 2012-06-08 12:09:00Z joel $
 .\"
 .\" The following commands are required for all man pages.
 .Dd January 26, 2010
@@ -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 @@
 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_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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libgssapi/gss_create_empty_oid_set.3
--- a/head/lib/libgssapi/gss_create_empty_oid_set.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libgssapi/gss_create_empty_oid_set.3	Wed Jul 25 16:23:00 2012 +0300
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\"	$FreeBSD$
+.\"	$FreeBSD: head/lib/libgssapi/gss_create_empty_oid_set.3 236746 2012-06-08 12:09:00Z joel $
 .\"
 .\" The following commands are required for all man pages.
 .Dd January 26, 2010
@@ -51,7 +51,7 @@
 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 @@
 .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 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libgssapi/gss_delete_sec_context.3
--- a/head/lib/libgssapi/gss_delete_sec_context.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libgssapi/gss_delete_sec_context.3	Wed Jul 25 16:23:00 2012 +0300
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\"	$FreeBSD$
+.\"	$FreeBSD: head/lib/libgssapi/gss_delete_sec_context.3 236746 2012-06-08 12:09:00Z joel $
 .\"
 .\" The following commands are required for all man pages.
 .Dd January 26, 2010
@@ -88,7 +88,7 @@
 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 @@
 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 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libgssapi/gss_display_name.3
--- a/head/lib/libgssapi/gss_display_name.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libgssapi/gss_display_name.3	Wed Jul 25 16:23:00 2012 +0300
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\"	$FreeBSD$
+.\"	$FreeBSD: head/lib/libgssapi/gss_display_name.3 236746 2012-06-08 12:09:00Z joel $
 .\"
 .\" The following commands are required for all man pages.
 .Dd January 26, 2010
@@ -76,7 +76,7 @@
 .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 @@
 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 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libgssapi/gss_display_status.3
--- a/head/lib/libgssapi/gss_display_status.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libgssapi/gss_display_status.3	Wed Jul 25 16:23:00 2012 +0300
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\"	$FreeBSD$
+.\"	$FreeBSD: head/lib/libgssapi/gss_display_status.3 236746 2012-06-08 12:09:00Z joel $
 .\"
 .\" The following commands are required for all man pages.
 .Dd January 26, 2010
@@ -111,13 +111,13 @@
 } 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 @@
 .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 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libgssapi/gss_duplicate_name.3
--- a/head/lib/libgssapi/gss_duplicate_name.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libgssapi/gss_duplicate_name.3	Wed Jul 25 16:23:00 2012 +0300
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\"	$FreeBSD$
+.\"	$FreeBSD: head/lib/libgssapi/gss_duplicate_name.3 236746 2012-06-08 12:09:00Z joel $
 .\"
 .\" The following commands are required for all man pages.
 .Dd January 26, 2010
@@ -57,7 +57,7 @@
 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 @@
 .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 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libgssapi/gss_export_name.3
--- a/head/lib/libgssapi/gss_export_name.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libgssapi/gss_export_name.3	Wed Jul 25 16:23:00 2012 +0300
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\"	$FreeBSD$
+.\"	$FreeBSD: head/lib/libgssapi/gss_export_name.3 236746 2012-06-08 12:09:00Z joel $
 .\"
 .\" The following commands are required for all man pages.
 .Dd January 26, 2010
@@ -58,7 +58,7 @@
 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 @@
 .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 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libgssapi/gss_export_sec_context.3
--- a/head/lib/libgssapi/gss_export_sec_context.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libgssapi/gss_export_sec_context.3	Wed Jul 25 16:23:00 2012 +0300
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\"	$FreeBSD$
+.\"	$FreeBSD: head/lib/libgssapi/gss_export_sec_context.3 236746 2012-06-08 12:09:00Z joel $
 .\"
 .\" The following commands are required for all man pages.
 .Dd January 26, 2010
@@ -100,7 +100,7 @@
 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 @@
 .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 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libgssapi/gss_get_mic.3
--- a/head/lib/libgssapi/gss_get_mic.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libgssapi/gss_get_mic.3	Wed Jul 25 16:23:00 2012 +0300
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\"	$FreeBSD$
+.\"	$FreeBSD: head/lib/libgssapi/gss_get_mic.3 236746 2012-06-08 12:09:00Z joel $
 .\"
 .\" The following commands are required for all man pages.
 .Dd January 26, 2010
@@ -81,7 +81,7 @@
 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 @@
 .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 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libgssapi/gss_import_name.3
--- a/head/lib/libgssapi/gss_import_name.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libgssapi/gss_import_name.3	Wed Jul 25 16:23:00 2012 +0300
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\"	$FreeBSD$
+.\"	$FreeBSD: head/lib/libgssapi/gss_import_name.3 236746 2012-06-08 12:09:00Z joel $
 .\"
 .\" The following commands are required for all man pages.
 .Dd January 26, 2010
@@ -59,7 +59,7 @@
 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 @@
 .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 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libgssapi/gss_import_sec_context.3
--- a/head/lib/libgssapi/gss_import_sec_context.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libgssapi/gss_import_sec_context.3	Wed Jul 25 16:23:00 2012 +0300
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\"	$FreeBSD$
+.\"	$FreeBSD: head/lib/libgssapi/gss_import_sec_context.3 236746 2012-06-08 12:09:00Z joel $
 .\"
 .\" The following commands are required for all man pages.
 .Dd January 26, 2010
@@ -50,7 +50,7 @@
 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 @@
 .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 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libgssapi/gss_indicate_mechs.3
--- a/head/lib/libgssapi/gss_indicate_mechs.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libgssapi/gss_indicate_mechs.3	Wed Jul 25 16:23:00 2012 +0300
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\"	$FreeBSD$
+.\"	$FreeBSD: head/lib/libgssapi/gss_indicate_mechs.3 236746 2012-06-08 12:09:00Z joel $
 .\"
 .\" The following commands are required for all man pages.
 .Dd January 26, 2010
@@ -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 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libgssapi/gss_init_sec_context.3
--- a/head/lib/libgssapi/gss_init_sec_context.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libgssapi/gss_init_sec_context.3	Wed Jul 25 16:23:00 2012 +0300
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\"	$FreeBSD$
+.\"	$FreeBSD: head/lib/libgssapi/gss_init_sec_context.3 236746 2012-06-08 12:09:00Z joel $
 .\"
 .\" The following commands are required for all man pages.
 .Dd January 26, 2010
@@ -233,7 +233,7 @@
 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 @@
 .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 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libgssapi/gss_inquire_context.3
--- a/head/lib/libgssapi/gss_inquire_context.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libgssapi/gss_inquire_context.3	Wed Jul 25 16:23:00 2012 +0300
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\"	$FreeBSD$
+.\"	$FreeBSD: head/lib/libgssapi/gss_inquire_context.3 236746 2012-06-08 12:09:00Z joel $
 .\"
 .\" The following commands are required for all man pages.
 .Dd January 26, 2010
@@ -55,7 +55,7 @@
 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 @@
 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 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libgssapi/gss_inquire_cred.3
--- a/head/lib/libgssapi/gss_inquire_cred.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libgssapi/gss_inquire_cred.3	Wed Jul 25 16:23:00 2012 +0300
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\"	$FreeBSD$
+.\"	$FreeBSD: head/lib/libgssapi/gss_inquire_cred.3 236746 2012-06-08 12:09:00Z joel $
 .\"
 .\" The following commands are required for all man pages.
 .Dd January 26, 2010
@@ -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 @@
 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 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libgssapi/gss_inquire_cred_by_mech.3
--- a/head/lib/libgssapi/gss_inquire_cred_by_mech.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libgssapi/gss_inquire_cred_by_mech.3	Wed Jul 25 16:23:00 2012 +0300
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\"	$FreeBSD$
+.\"	$FreeBSD: head/lib/libgssapi/gss_inquire_cred_by_mech.3 236746 2012-06-08 12:09:00Z joel $
 .\"
 .\" The following commands are required for all man pages.
 .Dd January 26, 2010
@@ -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 @@
 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 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libgssapi/gss_inquire_mechs_for_name.3
--- a/head/lib/libgssapi/gss_inquire_mechs_for_name.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libgssapi/gss_inquire_mechs_for_name.3	Wed Jul 25 16:23:00 2012 +0300
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\"	$FreeBSD$
+.\"	$FreeBSD: head/lib/libgssapi/gss_inquire_mechs_for_name.3 236746 2012-06-08 12:09:00Z joel $
 .\"
 .\" The following commands are required for all man pages.
 .Dd January 26, 2010
@@ -68,7 +68,7 @@
 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 @@
 .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 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libgssapi/gss_inquire_names_for_mech.3
--- a/head/lib/libgssapi/gss_inquire_names_for_mech.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libgssapi/gss_inquire_names_for_mech.3	Wed Jul 25 16:23:00 2012 +0300
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\"	$FreeBSD$
+.\"	$FreeBSD: head/lib/libgssapi/gss_inquire_names_for_mech.3 236746 2012-06-08 12:09:00Z joel $
 .\"
 .\" The following commands are required for all man pages.
 .Dd January 26, 2010
@@ -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 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libgssapi/gss_process_context_token.3
--- a/head/lib/libgssapi/gss_process_context_token.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libgssapi/gss_process_context_token.3	Wed Jul 25 16:23:00 2012 +0300
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\"	$FreeBSD$
+.\"	$FreeBSD: head/lib/libgssapi/gss_process_context_token.3 236746 2012-06-08 12:09:00Z joel $
 .\"
 .\" The following commands are required for all man pages.
 .Dd January 26, 2010
@@ -71,7 +71,7 @@
 .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 @@
 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 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libgssapi/gss_release_buffer.3
--- a/head/lib/libgssapi/gss_release_buffer.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libgssapi/gss_release_buffer.3	Wed Jul 25 16:23:00 2012 +0300
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\"	$FreeBSD: head/lib/libgssapi/gss_release_buffer.3 233648 2012-03-29 05:02:12Z eadler $
+.\"	$FreeBSD: head/lib/libgssapi/gss_release_buffer.3 236746 2012-06-08 12:09:00Z joel $
 .\"
 .\" The following commands are required for all man pages.
 .Dd January 26, 2010
@@ -55,7 +55,7 @@
 .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 @@
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libgssapi/gss_release_cred.3
--- a/head/lib/libgssapi/gss_release_cred.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libgssapi/gss_release_cred.3	Wed Jul 25 16:23:00 2012 +0300
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\"	$FreeBSD$
+.\"	$FreeBSD: head/lib/libgssapi/gss_release_cred.3 236746 2012-06-08 12:09:00Z joel $
 .\"
 .\" The following commands are required for all man pages.
 .Dd January 26, 2010
@@ -50,7 +50,7 @@
 .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 @@
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libgssapi/gss_release_name.3
--- a/head/lib/libgssapi/gss_release_name.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libgssapi/gss_release_name.3	Wed Jul 25 16:23:00 2012 +0300
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\"	$FreeBSD$
+.\"	$FreeBSD: head/lib/libgssapi/gss_release_name.3 236746 2012-06-08 12:09:00Z joel $
 .\"
 .\" The following commands are required for all man pages.
 .Dd January 26, 2010
@@ -48,21 +48,21 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libgssapi/gss_release_oid_set.3
--- a/head/lib/libgssapi/gss_release_oid_set.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libgssapi/gss_release_oid_set.3	Wed Jul 25 16:23:00 2012 +0300
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\"	$FreeBSD: head/lib/libgssapi/gss_release_oid_set.3 233648 2012-03-29 05:02:12Z eadler $
+.\"	$FreeBSD: head/lib/libgssapi/gss_release_oid_set.3 236746 2012-06-08 12:09:00Z joel $
 .\"
 .\" The following commands are required for all man pages.
 .Dd January 26, 2010
@@ -55,19 +55,19 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libgssapi/gss_test_oid_set_member.3
--- a/head/lib/libgssapi/gss_test_oid_set_member.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libgssapi/gss_test_oid_set_member.3	Wed Jul 25 16:23:00 2012 +0300
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\"	$FreeBSD$
+.\"	$FreeBSD: head/lib/libgssapi/gss_test_oid_set_member.3 236746 2012-06-08 12:09:00Z joel $
 .\"
 .\" The following commands are required for all man pages.
 .Dd January 26, 2010
@@ -54,7 +54,7 @@
 .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 @@
 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 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libgssapi/gss_unwrap.3
--- a/head/lib/libgssapi/gss_unwrap.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libgssapi/gss_unwrap.3	Wed Jul 25 16:23:00 2012 +0300
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\"	$FreeBSD$
+.\"	$FreeBSD: head/lib/libgssapi/gss_unwrap.3 236746 2012-06-08 12:09:00Z joel $
 .\"
 .\" The following commands are required for all man pages.
 .Dd January 26, 2010
@@ -90,7 +90,7 @@
 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 @@
 .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 @@
 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 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libgssapi/gss_verify_mic.3
--- a/head/lib/libgssapi/gss_verify_mic.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libgssapi/gss_verify_mic.3	Wed Jul 25 16:23:00 2012 +0300
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\"	$FreeBSD$
+.\"	$FreeBSD: head/lib/libgssapi/gss_verify_mic.3 236746 2012-06-08 12:09:00Z joel $
 .\"
 .\" The following commands are required for all man pages.
 .Dd January 26, 2010
@@ -81,7 +81,7 @@
 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 @@
 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 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libgssapi/gss_wrap.3
--- a/head/lib/libgssapi/gss_wrap.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libgssapi/gss_wrap.3	Wed Jul 25 16:23:00 2012 +0300
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\"	$FreeBSD$
+.\"	$FreeBSD: head/lib/libgssapi/gss_wrap.3 236746 2012-06-08 12:09:00Z joel $
 .\"
 .\" The following commands are required for all man pages.
 .Dd January 26, 2010
@@ -85,13 +85,13 @@
 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 @@
 .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 @@
 .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 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libgssapi/gss_wrap_size_limit.3
--- a/head/lib/libgssapi/gss_wrap_size_limit.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libgssapi/gss_wrap_size_limit.3	Wed Jul 25 16:23:00 2012 +0300
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\"	$FreeBSD$
+.\"	$FreeBSD: head/lib/libgssapi/gss_wrap_size_limit.3 236746 2012-06-08 12:09:00Z joel $
 .\"
 .\" The following commands are required for all man pages.
 .Dd January 26, 2010
@@ -83,7 +83,7 @@
 .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 @@
 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 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libgssapi/gssapi.3
--- a/head/lib/libgssapi/gssapi.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libgssapi/gssapi.3	Wed Jul 25 16:23:00 2012 +0300
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\"	$FreeBSD$
+.\"	$FreeBSD: head/lib/libgssapi/gssapi.3 236746 2012-06-08 12:09:00Z joel $
 .\"
 .Dd January 26, 2010
 .Dt GSSAPI 3
@@ -219,7 +219,7 @@
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libgssapi/mech.5
--- a/head/lib/libgssapi/mech.5	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libgssapi/mech.5	Wed Jul 25 16:23:00 2012 +0300
@@ -22,7 +22,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD: head/lib/libgssapi/mech.5 233648 2012-03-29 05:02:12Z eadler $
+.\" $FreeBSD: head/lib/libgssapi/mech.5 236746 2012-06-08 12:09:00Z joel $
 .Dd January 26, 2010
 .Dt MECH 5
 .Os
@@ -39,17 +39,17 @@
 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 @@
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libjail/jail.c
--- a/head/lib/libjail/jail.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libjail/jail.c	Wed Jul 25 16:23:00 2012 +0300
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/libjail/jail.c 232342 2012-03-01 15:09:41Z jamie $");
+__FBSDID("$FreeBSD: head/lib/libjail/jail.c 235799 2012-05-22 18:30:32Z jamie $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -853,9 +853,9 @@
 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 @@
 	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 @@
 	/* 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 @@
 			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 @@
 	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 @@
 		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 @@
 			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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libkiconv/Makefile
--- a/head/lib/libkiconv/Makefile	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libkiconv/Makefile	Wed Jul 25 16:23:00 2012 +0300
@@ -1,7 +1,10 @@
-# $FreeBSD$
+# $FreeBSD: head/lib/libkiconv/Makefile 236972 2012-06-12 20:24:57Z dim $
+
+SHLIBDIR?=	/lib
+
+.include <bsd.own.mk>
 
 LIB=		kiconv
-SHLIBDIR?=	/lib
 SRCS=		kiconv_sysctl.c xlat16_iconv.c xlat16_sysctl.c
 SRCS+=		quirks.c
 
@@ -17,4 +20,8 @@
 
 WARNS?=		1
 
+.if ${MK_ICONV} == "no"
+CFLAGS+=	-DICONV_DLOPEN
+.endif
+
 .include <bsd.lib.mk>
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libkiconv/xlat16_iconv.c
--- a/head/lib/libkiconv/xlat16_iconv.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libkiconv/xlat16_iconv.c	Wed Jul 25 16:23:00 2012 +0300
@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: head/lib/libkiconv/xlat16_iconv.c 227650 2011-11-18 03:05:20Z kevlo $
+ * $FreeBSD: head/lib/libkiconv/xlat16_iconv.c 236028 2012-05-25 22:07:13Z gabor $
  */
 
 /*
@@ -60,10 +60,18 @@
 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 @@
 	return (error);
 }
 
+#ifdef ICONV_DLOPEN
 static int
 my_iconv_init(void)
 {
@@ -327,6 +336,7 @@
 
 	return (0);
 }
+#endif
 
 static size_t
 my_iconv_char(iconv_t cd, const u_char **ibuf, size_t * ilen, u_char **obuf,
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libkvm/kvm_getpcpu.3
--- a/head/lib/libkvm/kvm_getpcpu.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libkvm/kvm_getpcpu.3	Wed Jul 25 16:23:00 2012 +0300
@@ -26,7 +26,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/libkvm/kvm_getpcpu.3 235286 2012-05-11 20:06:46Z gjb $
 .\"
 .Dd February 28, 2010
 .Dt KVM_GETPCPU 3
@@ -114,7 +114,7 @@
 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 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libmagic/Makefile
--- a/head/lib/libmagic/Makefile	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libmagic/Makefile	Wed Jul 25 16:23:00 2012 +0300
@@ -1,4 +1,4 @@
-# $FreeBSD: head/lib/libmagic/Makefile 234449 2012-04-19 03:20:13Z obrien $
+# $FreeBSD: head/lib/libmagic/Makefile 235638 2012-05-19 02:30:10Z marcel $
 # Copyright (c) David E. O'Brien, 2000-2004, 2006, 2009
 
 CONTRDIR=	${.CURDIR}/../../contrib/file
@@ -39,8 +39,9 @@
 
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libmagic/config.h
--- a/head/lib/libmagic/config.h	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libmagic/config.h	Wed Jul 25 16:23:00 2012 +0300
@@ -1,4 +1,4 @@
-/* $FreeBSD: head/lib/libmagic/config.h 234449 2012-04-19 03:20:13Z obrien $ */
+/* $FreeBSD: head/lib/libmagic/config.h 235638 2012-05-19 02:30:10Z marcel $ */
 
 /* config.h.  Generated from config.h.in by configure.  */
 /* config.h.in.  Generated from configure.ac by autoheader.  */
@@ -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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libmd/Makefile
--- a/head/lib/libmd/Makefile	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libmd/Makefile	Wed Jul 25 16:23:00 2012 +0300
@@ -1,20 +1,18 @@
-# $FreeBSD: head/lib/libmd/Makefile 220496 2011-04-09 13:56:29Z markm $
+# $FreeBSD: head/lib/libmd/Makefile 234746 2012-04-28 02:48:51Z obrien $
 
 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 @@
 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 @@
 	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 @@
 	@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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libmd/md2.copyright
--- a/head/lib/libmd/md2.copyright	Wed Jul 25 16:21:35 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libmd/md2.h
--- a/head/lib/libmd/md2.h	Wed Jul 25 16:21:35 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libmd/md2c.c
--- a/head/lib/libmd/md2c.c	Wed Jul 25 16:21:35 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libmd/mdX.3
--- a/head/lib/libmd/mdX.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libmd/mdX.3	Wed Jul 25 16:23:00 2012 +0300
@@ -6,7 +6,7 @@
 .\" this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
 .\" ----------------------------------------------------------------------------
 .\"
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/libmd/mdX.3 234746 2012-04-28 02:48:51Z obrien $
 .\"
 .Dd February 11, 1999
 .Dt MDX 3
@@ -52,8 +52,7 @@
 .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 @@
 .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 @@
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libnandfs/Makefile
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/lib/libnandfs/Makefile	Wed Jul 25 16:23:00 2012 +0300
@@ -0,0 +1,9 @@
+# $FreeBSD: head/lib/libnandfs/Makefile 235537 2012-05-17 10:11:18Z gber $
+
+LIB=	nandfs
+SRCS+=	nandfs.c
+INCS=	libnandfs.h
+
+CFLAGS += -I${.CURDIR}
+
+.include <bsd.lib.mk>
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libnandfs/libnandfs.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/lib/libnandfs/libnandfs.h	Wed Jul 25 16:23:00 2012 +0300
@@ -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: head/lib/libnandfs/libnandfs.h 235537 2012-05-17 10:11:18Z gber $
+ */
+
+#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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libnandfs/nandfs.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/lib/libnandfs/nandfs.c	Wed Jul 25 16:23:00 2012 +0300
@@ -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: head/lib/libnandfs/nandfs.c 235537 2012-05-17 10:11:18Z gber $");
+
+#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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libncp/ncpl_nls.c
--- a/head/lib/libncp/ncpl_nls.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libncp/ncpl_nls.c	Wed Jul 25 16:23:00 2012 +0300
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libncp/ncpl_nls.c 236376 2012-06-01 03:59:08Z eadler $");
 
 /*
  * Languages support. Currently is very primitive.
@@ -200,6 +200,79 @@
 	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 @@
 	{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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libpam/libpam/Makefile
--- a/head/lib/libpam/libpam/Makefile	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libpam/libpam/Makefile	Wed Jul 25 16:23:00 2012 +0300
@@ -33,7 +33,7 @@
 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 # SUCH DAMAGE.
 #
-# $FreeBSD: head/lib/libpam/libpam/Makefile 228692 2011-12-18 17:22:45Z des $
+# $FreeBSD: head/lib/libpam/libpam/Makefile 236109 2012-05-26 17:10:16Z des $
 
 OPENPAM=	${.CURDIR}/../../../contrib/openpam
 .PATH: ${OPENPAM}/include ${OPENPAM}/lib ${OPENPAM}/doc/man
@@ -47,16 +47,22 @@
 	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 @@
 	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 @@
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libpam/modules/pam_exec/pam_exec.8
--- a/head/lib/libpam/modules/pam_exec/pam_exec.8	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libpam/modules/pam_exec/pam_exec.8	Wed Jul 25 16:23:00 2012 +0300
@@ -30,7 +30,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD: head/lib/libpam/modules/pam_exec/pam_exec.8 233507 2012-03-26 12:18:15Z dumbbell $
+.\" $FreeBSD: head/lib/libpam/modules/pam_exec/pam_exec.8 235873 2012-05-24 02:24:03Z wblock $
 .\"
 .Dd February 8, 2012
 .Dt PAM_EXEC 8
@@ -131,10 +131,10 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libpam/modules/pam_ssh/pam_ssh.c
--- a/head/lib/libpam/modules/pam_ssh/pam_ssh.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libpam/modules/pam_ssh/pam_ssh.c	Wed Jul 25 16:23:00 2012 +0300
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/libpam/modules/pam_ssh/pam_ssh.c 227757 2011-11-20 15:18:49Z des $");
+__FBSDID("$FreeBSD: head/lib/libpam/modules/pam_ssh/pam_ssh.c 236106 2012-05-26 17:03:45Z des $");
 
 #include <sys/param.h>
 #include <sys/wait.h>
@@ -112,7 +112,7 @@
 	 * 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libpcap/Makefile
--- a/head/lib/libpcap/Makefile	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libpcap/Makefile	Wed Jul 25 16:23:00 2012 +0300
@@ -1,5 +1,5 @@
 # Makefile for libpcap
-# $FreeBSD: head/lib/libpcap/Makefile 225227 2011-08-28 09:26:48Z kib $
+# $FreeBSD: head/lib/libpcap/Makefile 235426 2012-05-14 05:12:56Z delphij $
 
 SHLIBDIR?= /lib
 
@@ -37,8 +37,6 @@
 	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 @@
 	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 @@
 	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 @@
 	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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libpcap/config.h
--- a/head/lib/libpcap/config.h	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libpcap/config.h	Wed Jul 25 16:23:00 2012 +0300
@@ -1,4 +1,4 @@
-/* $FreeBSD$ */
+/* $FreeBSD: head/lib/libpcap/config.h 235426 2012-05-14 05:12:56Z delphij $ */
 /* This is an edited copy of the config.h generated by configure. */
 
 /* config.h.  Generated from config.h.in by configure.  */
@@ -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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libpmc/pmc.3
--- a/head/lib/libpmc/pmc.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libpmc/pmc.3	Wed Jul 25 16:23:00 2012 +0300
@@ -21,7 +21,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD: head/lib/libpmc/pmc.3 233628 2012-03-28 20:58:30Z fabient $
+.\" $FreeBSD: head/lib/libpmc/pmc.3 236438 2012-06-02 08:47:26Z joel $
 .\"
 .Dd November 24, 2008
 .Dt PMC 3
@@ -111,7 +111,7 @@
 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 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 @@
 .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 @@
 .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 @@
 .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 @@
 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 @@
 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 @@
 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 @@
 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 @@
 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 @@
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libprocstat/cd9660.c
--- a/head/lib/libprocstat/cd9660.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libprocstat/cd9660.c	Wed Jul 25 16:23:00 2012 +0300
@@ -41,7 +41,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/libprocstat/cd9660.c 221807 2011-05-12 10:11:39Z stas $");
+__FBSDID("$FreeBSD: head/lib/libprocstat/cd9660.c 235602 2012-05-18 10:15:46Z gleb $");
 
 #include <sys/param.h>
 #include <sys/stat.h>
@@ -84,7 +84,7 @@
 	}
 	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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libprocstat/common_kvm.c
--- a/head/lib/libprocstat/common_kvm.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libprocstat/common_kvm.c	Wed Jul 25 16:23:00 2012 +0300
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/libprocstat/common_kvm.c 231384 2012-02-10 13:47:40Z ed $");
+__FBSDID("$FreeBSD: head/lib/libprocstat/common_kvm.c 235602 2012-05-18 10:15:46Z gleb $");
 
 #include <sys/param.h>
 #include <sys/user.h>
@@ -99,9 +99,9 @@
 	 * 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libprocstat/libprocstat.3
--- a/head/lib/libprocstat/libprocstat.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libprocstat/libprocstat.3	Wed Jul 25 16:23:00 2012 +0300
@@ -22,7 +22,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD: head/lib/libprocstat/libprocstat.3 233760 2012-04-01 18:22:48Z jhb $
+.\" $FreeBSD: head/lib/libprocstat/libprocstat.3 235286 2012-05-11 20:06:46Z gjb $
 .\"
 .Dd April 1, 2012
 .Dt LIBPROCSTAT 3
@@ -203,7 +203,7 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libprocstat/libprocstat.c
--- a/head/lib/libprocstat/libprocstat.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libprocstat/libprocstat.c	Wed Jul 25 16:23:00 2012 +0300
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/libprocstat/libprocstat.c 233760 2012-04-01 18:22:48Z jhb $");
+__FBSDID("$FreeBSD: head/lib/libprocstat/libprocstat.c 236717 2012-06-07 15:54:52Z jhb $");
 
 #include <sys/param.h>
 #include <sys/time.h>
@@ -881,6 +881,8 @@
 {
 	struct shmfd shmfd;
 	void *shmfdp;
+	char *path;
+	int i;
 
 	assert(kd);
 	assert(shm);
@@ -896,6 +898,21 @@
 	}
 	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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libradius/libradius.3
--- a/head/lib/libradius/libradius.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libradius/libradius.3	Wed Jul 25 16:23:00 2012 +0300
@@ -23,7 +23,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD: head/lib/libradius/libradius.3 231564 2012-02-12 18:29:56Z ed $
+.\" $FreeBSD: head/lib/libradius/libradius.3 235286 2012-05-11 20:06:46Z gjb $
 .\"
 .Dd August 5, 2009
 .Dt LIBRADIUS 3
@@ -108,8 +108,7 @@
 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 @@
 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 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/librpcsec_gss/rpc_gss_get_error.3
--- a/head/lib/librpcsec_gss/rpc_gss_get_error.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/librpcsec_gss/rpc_gss_get_error.3	Wed Jul 25 16:23:00 2012 +0300
@@ -23,7 +23,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/librpcsec_gss/rpc_gss_get_error.3 236668 2012-06-06 08:07:47Z joel $
 .Dd January 26, 2010
 .Dt RPC_GSS_GET_ERROR 3
 .Os
@@ -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 -r d46effa10a19 -r 7449ca4973e7 head/lib/librpcsec_gss/rpc_gss_get_mech_info.3
--- a/head/lib/librpcsec_gss/rpc_gss_get_mech_info.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/librpcsec_gss/rpc_gss_get_mech_info.3	Wed Jul 25 16:23:00 2012 +0300
@@ -23,7 +23,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/librpcsec_gss/rpc_gss_get_mech_info.3 236668 2012-06-06 08:07:47Z joel $
 .Dd January 26, 2010
 .Dt RPC_GSS_GET_MECH_INFO 3
 .Os
@@ -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 -r d46effa10a19 -r 7449ca4973e7 head/lib/librpcsec_gss/rpc_gss_get_principal_name.3
--- a/head/lib/librpcsec_gss/rpc_gss_get_principal_name.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/librpcsec_gss/rpc_gss_get_principal_name.3	Wed Jul 25 16:23:00 2012 +0300
@@ -23,7 +23,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/librpcsec_gss/rpc_gss_get_principal_name.3 236668 2012-06-06 08:07:47Z joel $
 .Dd January 26, 2010
 .Dt RPC_GSS_GET_PRINCIPAL_NAME 3
 .Os
@@ -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 -r d46effa10a19 -r 7449ca4973e7 head/lib/librpcsec_gss/rpc_gss_get_versions.3
--- a/head/lib/librpcsec_gss/rpc_gss_get_versions.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/librpcsec_gss/rpc_gss_get_versions.3	Wed Jul 25 16:23:00 2012 +0300
@@ -23,7 +23,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/librpcsec_gss/rpc_gss_get_versions.3 236668 2012-06-06 08:07:47Z joel $
 .Dd January 26, 2010
 .Dt RPC_GSS_GET_VERSIONS 3
 .Os
@@ -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 -r d46effa10a19 -r 7449ca4973e7 head/lib/librpcsec_gss/rpc_gss_getcred.3
--- a/head/lib/librpcsec_gss/rpc_gss_getcred.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/librpcsec_gss/rpc_gss_getcred.3	Wed Jul 25 16:23:00 2012 +0300
@@ -23,7 +23,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/librpcsec_gss/rpc_gss_getcred.3 236668 2012-06-06 08:07:47Z joel $
 .Dd January 26, 2010
 .Dt RPC_GSS_GETCRED 3
 .Os
@@ -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 -r d46effa10a19 -r 7449ca4973e7 head/lib/librpcsec_gss/rpc_gss_is_installed.3
--- a/head/lib/librpcsec_gss/rpc_gss_is_installed.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/librpcsec_gss/rpc_gss_is_installed.3	Wed Jul 25 16:23:00 2012 +0300
@@ -23,7 +23,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/librpcsec_gss/rpc_gss_is_installed.3 236668 2012-06-06 08:07:47Z joel $
 .Dd January 26, 2010
 .Dt RPC_GSS_IS_INSTALLED 3
 .Os
@@ -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 -r d46effa10a19 -r 7449ca4973e7 head/lib/librpcsec_gss/rpc_gss_max_data_length.3
--- a/head/lib/librpcsec_gss/rpc_gss_max_data_length.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/librpcsec_gss/rpc_gss_max_data_length.3	Wed Jul 25 16:23:00 2012 +0300
@@ -23,7 +23,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/librpcsec_gss/rpc_gss_max_data_length.3 236668 2012-06-06 08:07:47Z joel $
 .Dd January 26, 2010
 .Dt RPC_GSS_MAX_DATA_LENGTH 3
 .Os
@@ -41,7 +41,7 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/librpcsec_gss/rpc_gss_mech_to_oid.3
--- a/head/lib/librpcsec_gss/rpc_gss_mech_to_oid.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/librpcsec_gss/rpc_gss_mech_to_oid.3	Wed Jul 25 16:23:00 2012 +0300
@@ -23,7 +23,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/librpcsec_gss/rpc_gss_mech_to_oid.3 236668 2012-06-06 08:07:47Z joel $
 .Dd January 26, 2010
 .Dt RPC_GSS_MECH_TO_OID 3
 .Os
@@ -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 -r d46effa10a19 -r 7449ca4973e7 head/lib/librpcsec_gss/rpc_gss_oid_to_mech.3
--- a/head/lib/librpcsec_gss/rpc_gss_oid_to_mech.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/librpcsec_gss/rpc_gss_oid_to_mech.3	Wed Jul 25 16:23:00 2012 +0300
@@ -23,7 +23,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/librpcsec_gss/rpc_gss_oid_to_mech.3 236668 2012-06-06 08:07:47Z joel $
 .Dd January 26, 2010
 .Dt RPC_GSS_OID_TO_MECH 3
 .Os
@@ -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 -r d46effa10a19 -r 7449ca4973e7 head/lib/librpcsec_gss/rpc_gss_qop_to_num.3
--- a/head/lib/librpcsec_gss/rpc_gss_qop_to_num.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/librpcsec_gss/rpc_gss_qop_to_num.3	Wed Jul 25 16:23:00 2012 +0300
@@ -23,7 +23,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/librpcsec_gss/rpc_gss_qop_to_num.3 236668 2012-06-06 08:07:47Z joel $
 .Dd January 26, 2010
 .Dt RPC_GSS_QOP_TO_NUM 3
 .Os
@@ -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 -r d46effa10a19 -r 7449ca4973e7 head/lib/librpcsec_gss/rpc_gss_seccreate.3
--- a/head/lib/librpcsec_gss/rpc_gss_seccreate.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/librpcsec_gss/rpc_gss_seccreate.3	Wed Jul 25 16:23:00 2012 +0300
@@ -23,7 +23,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD: head/lib/librpcsec_gss/rpc_gss_seccreate.3 233648 2012-03-29 05:02:12Z eadler $
+.\" $FreeBSD: head/lib/librpcsec_gss/rpc_gss_seccreate.3 236668 2012-06-06 08:07:47Z joel $
 .Dd January 26, 2010
 .Dt RPC_GSS_SECCREATE 3
 .Os
@@ -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 @@
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/librpcsec_gss/rpc_gss_set_callback.3
--- a/head/lib/librpcsec_gss/rpc_gss_set_callback.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/librpcsec_gss/rpc_gss_set_callback.3	Wed Jul 25 16:23:00 2012 +0300
@@ -23,7 +23,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/librpcsec_gss/rpc_gss_set_callback.3 236668 2012-06-06 08:07:47Z joel $
 .Dd January 26, 2010
 .Dt RPC_GSS_SET_CALLBACK 3
 .Os
@@ -62,7 +62,7 @@
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/librpcsec_gss/rpc_gss_set_defaults.3
--- a/head/lib/librpcsec_gss/rpc_gss_set_defaults.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/librpcsec_gss/rpc_gss_set_defaults.3	Wed Jul 25 16:23:00 2012 +0300
@@ -23,7 +23,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/librpcsec_gss/rpc_gss_set_defaults.3 236668 2012-06-06 08:07:47Z joel $
 .Dd January 26, 2010
 .Dt RPC_GSS_SET_DEFAULTS 3
 .Os
@@ -45,7 +45,7 @@
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/librpcsec_gss/rpc_gss_set_svc_name.3
--- a/head/lib/librpcsec_gss/rpc_gss_set_svc_name.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/librpcsec_gss/rpc_gss_set_svc_name.3	Wed Jul 25 16:23:00 2012 +0300
@@ -23,7 +23,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/librpcsec_gss/rpc_gss_set_svc_name.3 236668 2012-06-06 08:07:47Z joel $
 .Dd January 26, 2010
 .Dt RPC_GSS_SET_SVC_NAME 3
 .Os
@@ -47,7 +47,7 @@
 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 at hostname
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/librpcsec_gss/rpc_gss_svc_max_data_length.3
--- a/head/lib/librpcsec_gss/rpc_gss_svc_max_data_length.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/librpcsec_gss/rpc_gss_svc_max_data_length.3	Wed Jul 25 16:23:00 2012 +0300
@@ -23,7 +23,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/librpcsec_gss/rpc_gss_svc_max_data_length.3 236668 2012-06-06 08:07:47Z joel $
 .Dd January 26, 2010
 .Dt RPC_GSS_SVC_MAX_DATA_LENGTH 3
 .Os
@@ -41,7 +41,7 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libstand/Makefile
--- a/head/lib/libstand/Makefile	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libstand/Makefile	Wed Jul 25 16:23:00 2012 +0300
@@ -1,4 +1,4 @@
-# $FreeBSD: head/lib/libstand/Makefile 229368 2012-01-03 07:14:01Z ed $
+# $FreeBSD: head/lib/libstand/Makefile 237410 2012-06-21 21:47:08Z delphij $
 # Originally from	$NetBSD: Makefile,v 1.21 1997/10/26 22:08:38 lukem Exp $
 #
 # Notes:
@@ -38,7 +38,7 @@
 .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 @@
 # 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+=	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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libstand/bswap.c
--- a/head/lib/libstand/bswap.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libstand/bswap.c	Wed Jul 25 16:23:00 2012 +0300
@@ -4,7 +4,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/libstand/bswap.c 222908 2011-06-10 01:13:15Z rodrigc $");
+__FBSDID("$FreeBSD: head/lib/libstand/bswap.c 235939 2012-05-24 21:44:46Z obrien $");
 
 #if defined(LIBC_SCCS) && !defined(lint)
 static char *rcsid = "$NetBSD: bswap32.c,v 1.1 1997/10/09 15:42:33 bouyer Exp $";
@@ -31,7 +31,7 @@
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libstand/nandfs.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/lib/libstand/nandfs.c	Wed Jul 25 16:23:00 2012 +0300
@@ -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: head/lib/libstand/nandfs.c 235537 2012-05-17 10:11:18Z gber $");
+
+#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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libstand/stand.h
--- a/head/lib/libstand/stand.h	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libstand/stand.h	Wed Jul 25 16:23:00 2012 +0300
@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: head/lib/libstand/stand.h 223905 2011-07-10 07:25:34Z avatar $
+ * $FreeBSD: head/lib/libstand/stand.h 235537 2012-05-17 10:11:18Z gber $
  * From	$NetBSD: stand.h,v 1.22 1997/06/26 19:17:40 drochner Exp $	
  */
 
@@ -118,6 +118,7 @@
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libstdbuf/Makefile
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/lib/libstdbuf/Makefile	Wed Jul 25 16:23:00 2012 +0300
@@ -0,0 +1,12 @@
+# $FreeBSD: head/lib/libstdbuf/Makefile 234772 2012-04-28 20:52:20Z jlh $
+
+.include <bsd.own.mk>
+
+LIB=		stdbuf
+SRCS=		stdbuf.c
+SHLIB_MAJOR=	1
+MAN=		libstdbuf.3
+
+WARNS?=		6
+
+.include <bsd.lib.mk>
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libstdbuf/libstdbuf.3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/lib/libstdbuf/libstdbuf.3	Wed Jul 25 16:23:00 2012 +0300
@@ -0,0 +1,102 @@
+.\" Copyright (c) 2012 Jeremie Le Hen <jlh at 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: head/lib/libstdbuf/libstdbuf.3 234773 2012-04-28 21:50:30Z jlh $
+.\"
+.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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libstdbuf/stdbuf.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/lib/libstdbuf/stdbuf.c	Wed Jul 25 16:23:00 2012 +0300
@@ -0,0 +1,115 @@
+/*-
+ * Copyright (c) 2012 Jeremie Le Hen <jlh at 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: head/lib/libstdbuf/stdbuf.c 234772 2012-04-28 20:52:20Z jlh $
+ */
+
+#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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libtacplus/libtacplus.3
--- a/head/lib/libtacplus/libtacplus.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libtacplus/libtacplus.3	Wed Jul 25 16:23:00 2012 +0300
@@ -22,7 +22,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD: head/lib/libtacplus/libtacplus.3 233648 2012-03-29 05:02:12Z eadler $
+.\" $FreeBSD: head/lib/libtacplus/libtacplus.3 235286 2012-05-11 20:06:46Z gjb $
 .\"
 .Dd December 11, 2009
 .Dt LIBTACPLUS 3
@@ -380,7 +380,7 @@
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libthr/thread/thr_getschedparam.c
--- a/head/lib/libthr/thread/thr_getschedparam.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libthr/thread/thr_getschedparam.c	Wed Jul 25 16:23:00 2012 +0300
@@ -29,7 +29,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: head/lib/libthr/thread/thr_getschedparam.c 238645 2012-07-20 05:47:12Z davidxu $
  */
 
 #include "namespace.h"
@@ -48,30 +48,21 @@
 	struct sched_param *param)
 {
 	struct pthread *curthread = _get_curthread();
-	int ret;
+	int ret = 0;
 
 	if (policy == NULL || param == NULL)
 		return (EINVAL);
 
-	if (pthread == curthread) {
-		/*
-		 * Avoid searching the thread list when it is the current
-		 * thread.
-		 */
+	/*
+	 * Avoid searching the thread list when it is the current
+	 * thread.
+	 */
+	if (pthread == curthread)
 		THR_LOCK(curthread);
-		*policy = curthread->attr.sched_policy;
-		param->sched_priority = curthread->attr.prio;
-		THR_UNLOCK(curthread);
-		ret = 0;
-	}
-	/* Find the thread in the list of active threads. */
-	else if ((ret = _thr_ref_add(curthread, pthread, /*include dead*/0))
-	    == 0) {
-		THR_THREAD_LOCK(curthread, pthread);
-		*policy = pthread->attr.sched_policy;
-		param->sched_priority = pthread->attr.prio;
-		THR_THREAD_UNLOCK(curthread, pthread);
-		_thr_ref_delete(curthread, pthread);
-	}
+	else if ((ret = _thr_find_thread(curthread, pthread, /*include dead*/0)))
+		return (ret);
+	*policy = pthread->attr.sched_policy;
+	param->sched_priority = pthread->attr.prio;
+	THR_THREAD_UNLOCK(curthread, pthread);
 	return (ret);
 }
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libthr/thread/thr_info.c
--- a/head/lib/libthr/thread/thr_info.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libthr/thread/thr_info.c	Wed Jul 25 16:23:00 2012 +0300
@@ -26,7 +26,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: head/lib/libthr/thread/thr_info.c 238644 2012-07-20 03:37:19Z davidxu $
  */
 
 #include "namespace.h"
@@ -51,16 +51,12 @@
 		if (thr_set_name(thread->tid, name))
 			ret = errno;
 	} else {
-		if (_thr_ref_add(curthread, thread, 0) == 0) {
-			THR_THREAD_LOCK(curthread, thread);
+		if ((ret=_thr_find_thread(curthread, thread, 0)) == 0) {
 			if (thread->state != PS_DEAD) {
 				if (thr_set_name(thread->tid, name))
 					ret = errno;
 			}
 			THR_THREAD_UNLOCK(curthread, thread);
-			_thr_ref_delete(curthread, thread);
-		} else {
-			ret = ESRCH;
 		}
 	}
 #if 0
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libthr/thread/thr_init.c
--- a/head/lib/libthr/thread/thr_init.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libthr/thread/thr_init.c	Wed Jul 25 16:23:00 2012 +0300
@@ -30,7 +30,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: head/lib/libthr/thread/thr_init.c 223294 2011-06-19 13:35:36Z kan $
+ * $FreeBSD: head/lib/libthr/thread/thr_init.c 234947 2012-05-03 09:17:31Z davidxu $
  */
 
 #include "namespace.h"
@@ -112,6 +112,7 @@
 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 @@
 		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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libthr/thread/thr_mutex.c
--- a/head/lib/libthr/thread/thr_mutex.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libthr/thread/thr_mutex.c	Wed Jul 25 16:23:00 2012 +0300
@@ -30,7 +30,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: head/lib/libthr/thread/thr_mutex.c 236135 2012-05-27 01:24:51Z davidxu $
  */
 
 #include "namespace.h"
@@ -538,6 +538,7 @@
 	switch (PMUTEX_TYPE(m->m_flags)) {
 	case PTHREAD_MUTEX_ERRORCHECK:
 	case PTHREAD_MUTEX_NORMAL:
+	case PTHREAD_MUTEX_ADAPTIVE_NP:
 		ret = EBUSY; 
 		break;
 
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libthr/thread/thr_private.h
--- a/head/lib/libthr/thread/thr_private.h	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libthr/thread/thr_private.h	Wed Jul 25 16:23:00 2012 +0300
@@ -26,7 +26,7 @@
  * (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: head/lib/libthr/thread/thr_private.h 234424 2012-04-18 16:29:55Z gnn $
+ * $FreeBSD: head/lib/libthr/thread/thr_private.h 234947 2012-05-03 09:17:31Z davidxu $
  */
 
 #ifndef _THR_PRIVATE_H
@@ -710,6 +710,7 @@
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libthr/thread/thr_setprio.c
--- a/head/lib/libthr/thread/thr_setprio.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libthr/thread/thr_setprio.c	Wed Jul 25 16:23:00 2012 +0300
@@ -26,7 +26,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: head/lib/libthr/thread/thr_setprio.c 238642 2012-07-20 03:22:17Z davidxu $
  */
 
 #include "namespace.h"
@@ -45,38 +45,22 @@
 	int	ret;
 
 	param.sched_priority = prio;
-	if (pthread == curthread) {
+	if (pthread == curthread)
 		THR_LOCK(curthread);
-		if (curthread->attr.sched_policy == SCHED_OTHER ||
-		    curthread->attr.prio == prio) {
-			curthread->attr.prio = prio;
-			ret = 0;
-		} else {
-			ret = _thr_setscheduler(curthread->tid,
-			    curthread->attr.sched_policy, &param);
-			if (ret == -1)
-				ret = errno;
-			else 
-				curthread->attr.prio = prio;
-		}
-		THR_UNLOCK(curthread);
-	} else if ((ret = _thr_ref_add(curthread, pthread, /*include dead*/0))
-		== 0) {
-		THR_THREAD_LOCK(curthread, pthread);
-		if (pthread->attr.sched_policy == SCHED_OTHER ||
-		    pthread->attr.prio == prio) {
+	else if ((ret = _thr_find_thread(curthread, pthread, /*include dead*/0)))
+		return (ret);
+	if (pthread->attr.sched_policy == SCHED_OTHER ||
+	    pthread->attr.prio == prio) {
+		pthread->attr.prio = prio;
+		ret = 0;
+	} else {
+		ret = _thr_setscheduler(pthread->tid,
+			pthread->attr.sched_policy, &param);
+		if (ret == -1)
+			ret = errno;
+		else
 			pthread->attr.prio = prio;
-			ret = 0;
-		} else {
-			ret = _thr_setscheduler(pthread->tid,
-				curthread->attr.sched_policy, &param);
-			if (ret == -1)
-				ret = errno;
-			else
-				pthread->attr.prio = prio;
-		}
-		THR_THREAD_UNLOCK(curthread, pthread);
-		_thr_ref_delete(curthread, pthread);
 	}
+	THR_THREAD_UNLOCK(curthread, pthread);
 	return (ret);
 }
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libthr/thread/thr_setschedparam.c
--- a/head/lib/libthr/thread/thr_setschedparam.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libthr/thread/thr_setschedparam.c	Wed Jul 25 16:23:00 2012 +0300
@@ -29,7 +29,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: head/lib/libthr/thread/thr_setschedparam.c 238642 2012-07-20 03:22:17Z davidxu $
  */
 
 #include "namespace.h"
@@ -53,42 +53,25 @@
 	struct pthread	*curthread = _get_curthread();
 	int	ret;
 
-	if (pthread == curthread) {
+	if (pthread == curthread)
 		THR_LOCK(curthread);
-		if (curthread->attr.sched_policy == policy &&
-		    (policy == SCHED_OTHER ||
-		     curthread->attr.prio == param->sched_priority)) {
-			pthread->attr.prio = param->sched_priority;
-			THR_UNLOCK(curthread);
-			return (0);
-		}
-		ret = _thr_setscheduler(curthread->tid, policy, param);
-		if (ret == -1)
-			ret = errno;
-		else {
-			curthread->attr.sched_policy = policy;
-			curthread->attr.prio = param->sched_priority;
-		}
-		THR_UNLOCK(curthread);
-	} else if ((ret = _thr_ref_add(curthread, pthread, /*include dead*/0))
-		== 0) {
-		THR_THREAD_LOCK(curthread, pthread);
-		if (pthread->attr.sched_policy == policy &&
-		    (policy == SCHED_OTHER ||
-		     pthread->attr.prio == param->sched_priority)) {
-			pthread->attr.prio = param->sched_priority;
-			THR_THREAD_UNLOCK(curthread, pthread);
-			return (0);
-		}
-		ret = _thr_setscheduler(pthread->tid, policy, param);
-		if (ret == -1)
-			ret = errno;
-		else {
-			pthread->attr.sched_policy = policy;
-			pthread->attr.prio = param->sched_priority;
-		}
+	else if ((ret = _thr_find_thread(curthread, pthread,
+		 /*include dead*/0)) != 0)
+		return (ret);
+	if (pthread->attr.sched_policy == policy &&
+	    (policy == SCHED_OTHER ||
+	     pthread->attr.prio == param->sched_priority)) {
+		pthread->attr.prio = param->sched_priority;
 		THR_THREAD_UNLOCK(curthread, pthread);
-		_thr_ref_delete(curthread, pthread);
+		return (0);
 	}
+	ret = _thr_setscheduler(pthread->tid, policy, param);
+	if (ret == -1)
+		ret = errno;
+	else {
+		pthread->attr.sched_policy = policy;
+		pthread->attr.prio = param->sched_priority;
+	}
+	THR_THREAD_UNLOCK(curthread, pthread);
 	return (ret);
 }
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libthr/thread/thr_sleepq.c
--- a/head/lib/libthr/thread/thr_sleepq.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libthr/thread/thr_sleepq.c	Wed Jul 25 16:23:00 2012 +0300
@@ -23,7 +23,7 @@
  * (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$
+ * $FreeBSD: head/lib/libthr/thread/thr_sleepq.c 235218 2012-05-10 09:30:37Z davidxu $
  */
 
 #include <stdlib.h>
@@ -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 @@
 	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 @@
 	}
 	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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libusb/Makefile
--- a/head/lib/libusb/Makefile	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libusb/Makefile	Wed Jul 25 16:23:00 2012 +0300
@@ -1,11 +1,11 @@
 #
-# $FreeBSD: head/lib/libusb/Makefile 234193 2012-04-12 18:06:30Z hselasky $
+# $FreeBSD: head/lib/libusb/Makefile 236944 2012-06-12 07:28:25Z hselasky $
 #
 # Makefile for the FreeBSD specific LibUSB 2.0
 #
 
 LIB=		usb
-SHLIB_MAJOR=	2
+SHLIB_MAJOR=	3
 SHLIB_MINOR=	0
 SRCS=		libusb20.c
 SRCS+=		libusb20_desc.c
@@ -18,6 +18,9 @@
 
 WARNS?=		2
 
+DPADD=		${LIBPTHREAD}
+LDADD=		-lpthread
+
 MLINKS+=	libusb.3 usb.3
 
 # libusb 0.1 compat
@@ -70,10 +73,11 @@
 MLINKS += libusb.3 libusb_detach_kernel_driver_np.3
 MLINKS += libusb.3 libusb_attach_kernel_driver.3
 MLINKS += libusb.3 libusb_get_device_descriptor.3
-MLINKS += libusb.3 libsub_get_active_config_descriptor.3
+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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libusb/libusb.3
--- a/head/lib/libusb/libusb.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libusb/libusb.3	Wed Jul 25 16:23:00 2012 +0300
@@ -24,9 +24,9 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD: head/lib/libusb/libusb.3 234193 2012-04-12 18:06:30Z hselasky $
+.\" $FreeBSD: head/lib/libusb/libusb.3 235286 2012-05-11 20:06:46Z gjb $
 .\"
-.Dd April 12, 2012
+.Dd May 7, 2012
 .Dt LIBUSB 3
 .Os
 .Sh NAME
@@ -100,12 +100,12 @@
 .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 @@
 .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 @@
 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 @@
 .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 @@
 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 @@
 .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,13 +279,13 @@
 .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.
 .Pp
 .Ft int
-.Fn libsub_get_active_config_descriptor "libusb_device *dev" "struct libusb_config_descriptor **config"
+.Fn libusb_get_active_config_descriptor "libusb_device *dev" "struct libusb_config_descriptor **config"
 Get the USB configuration descriptor for the active configuration.
 Returns 0 on
 success, LIBUSB_ERROR_NOT_FOUND if the device is in
@@ -314,6 +314,12 @@
 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 @@
 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 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libusb/libusb.h
--- a/head/lib/libusb/libusb.h	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libusb/libusb.h	Wed Jul 25 16:23:00 2012 +0300
@@ -1,4 +1,4 @@
-/* $FreeBSD: head/lib/libusb/libusb.h 234193 2012-04-12 18:06:30Z hselasky $ */
+/* $FreeBSD: head/lib/libusb/libusb.h 235128 2012-05-07 14:07:13Z hselasky $ */
 /*-
  * Copyright (c) 2009 Sylvestre Gallon. All rights reserved.
  *
@@ -340,7 +340,7 @@
 typedef struct libusb_transfer {
 	libusb_device_handle *dev_handle;
 	uint8_t	flags;
-	uint32_t endpoint;
+	uint8_t endpoint;
 	uint8_t type;
 	uint32_t timeout;
 	enum libusb_transfer_status status;
@@ -349,7 +349,6 @@
 	libusb_transfer_cb_fn callback;
 	void   *user_data;
 	uint8_t *buffer;
-	void *os_priv;
 	int	num_iso_packets;
 	struct libusb_iso_packet_descriptor iso_packet_desc[0];
 }	libusb_transfer __aligned(sizeof(void *));
@@ -399,6 +398,7 @@
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libusb/libusb10.c
--- a/head/lib/libusb/libusb10.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libusb/libusb10.c	Wed Jul 25 16:23:00 2012 +0300
@@ -1,4 +1,4 @@
-/* $FreeBSD: head/lib/libusb/libusb10.c 234491 2012-04-20 14:29:45Z hselasky $ */
+/* $FreeBSD: head/lib/libusb/libusb10.c 236944 2012-06-12 07:28:25Z hselasky $ */
 /*-
  * Copyright (c) 2009 Sylvestre Gallon. All rights reserved.
  * Copyright (c) 2009 Hans Petter Selasky. All rights reserved.
@@ -92,6 +92,7 @@
 libusb_init(libusb_context **context)
 {
 	struct libusb_context *ctx;
+	pthread_condattr_t attr;
 	char *debug;
 	int ret;
 
@@ -110,8 +111,28 @@
 	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;
 
@@ -1322,7 +1343,7 @@
 	struct libusb20_transfer *pxfer1;
 	struct libusb_super_transfer *sxfer;
 	struct libusb_device *dev;
-	uint32_t endpoint;
+	uint8_t endpoint;
 	int err;
 
 	if (uxfer == NULL)
@@ -1333,9 +1354,6 @@
 
 	endpoint = uxfer->endpoint;
 
-	if (endpoint > 255)
-		return (LIBUSB_ERROR_INVALID_PARAM);
-
 	dev = libusb_get_device(uxfer->dev_handle);
 
 	DPRINTF(dev->ctx, LIBUSB_DEBUG_FUNCTION, "libusb_submit_transfer enter");
@@ -1385,7 +1403,7 @@
 	struct libusb20_transfer *pxfer1;
 	struct libusb_super_transfer *sxfer;
 	struct libusb_device *dev;
-	uint32_t endpoint;
+	uint8_t endpoint;
 	int retval;
 
 	if (uxfer == NULL)
@@ -1397,9 +1415,6 @@
 
 	endpoint = uxfer->endpoint;
 
-	if (endpoint > 255)
-		return (LIBUSB_ERROR_INVALID_PARAM);
-
 	dev = libusb_get_device(uxfer->dev_handle);
 
 	DPRINTF(dev->ctx, LIBUSB_DEBUG_FUNCTION, "libusb_cancel_transfer enter");
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libusb/libusb10_desc.c
--- a/head/lib/libusb/libusb10_desc.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libusb/libusb10_desc.c	Wed Jul 25 16:23:00 2012 +0300
@@ -1,4 +1,4 @@
-/* $FreeBSD: head/lib/libusb/libusb10_desc.c 234491 2012-04-20 14:29:45Z hselasky $ */
+/* $FreeBSD: head/lib/libusb/libusb10_desc.c 235128 2012-05-07 14:07:13Z hselasky $ */
 /*-
  * Copyright (c) 2009 Sylvestre Gallon. All rights reserved.
  *
@@ -294,6 +294,25 @@
 }
 
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libusb/libusb10_io.c
--- a/head/lib/libusb/libusb10_io.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libusb/libusb10_io.c	Wed Jul 25 16:23:00 2012 +0300
@@ -1,4 +1,4 @@
-/* $FreeBSD: head/lib/libusb/libusb10_io.c 234491 2012-04-20 14:29:45Z hselasky $ */
+/* $FreeBSD: head/lib/libusb/libusb10_io.c 236944 2012-06-12 07:28:25Z hselasky $ */
 /*-
  * Copyright (c) 2009 Sylvestre Gallon. All rights reserved.
  *
@@ -307,12 +307,16 @@
 		    &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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libusb/libusb20.3
--- a/head/lib/libusb/libusb20.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libusb/libusb20.3	Wed Jul 25 16:23:00 2012 +0300
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD: head/lib/libusb/libusb20.3 233667 2012-03-29 16:07:22Z joel $
+.\" $FreeBSD: head/lib/libusb/libusb20.3 236438 2012-06-02 08:47:26Z joel $
 .\"
 .Dd October 14, 2010
 .Dt LIBUSB20 3
@@ -331,7 +331,7 @@
 .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 @@
 .
 .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 @@
 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 @@
 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 @@
 .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 @@
 .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 @@
 .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 @@
 .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 @@
 .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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libusbhid/parse.c
--- a/head/lib/libusbhid/parse.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libusbhid/parse.c	Wed Jul 25 16:23:00 2012 +0300
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/libusbhid/parse.c 225839 2011-09-28 14:52:25Z mav $");
+__FBSDID("$FreeBSD: head/lib/libusbhid/parse.c 235510 2012-05-16 17:51:56Z mav $");
 
 #include <assert.h>
 #include <stdlib.h>
@@ -392,7 +392,7 @@
 				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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libutil/Makefile
--- a/head/lib/libutil/Makefile	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libutil/Makefile	Wed Jul 25 16:23:00 2012 +0300
@@ -1,5 +1,5 @@
 #	@(#)Makefile	8.1 (Berkeley) 6/4/93
-#	$FreeBSD: head/lib/libutil/Makefile 230016 2012-01-12 15:45:08Z ghelmer $
+#	$FreeBSD: head/lib/libutil/Makefile 236965 2012-06-12 17:02:53Z des $
 
 SHLIBDIR?= /lib
 
@@ -25,14 +25,13 @@
 
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libutil/auth.3
--- a/head/lib/libutil/auth.3	Wed Jul 25 16:21:35 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libutil/auth.c
--- a/head/lib/libutil/auth.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libutil/auth.c	Wed Jul 25 16:23:00 2012 +0300
@@ -29,42 +29,16 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libutil/auth.c 236965 2012-06-12 17:02:53Z des $");
 
-#include <sys/types.h>
-#include <fcntl.h>
+#include <stdlib.h>
+
 #include <libutil.h>
-#include <paths.h>
-#include <syslog.h>
-#include <unistd.h>
-
-static properties P;
-
-static int
-initauthconf(const char *path)
-{
-    int fd;
-
-    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;
-}
 
 char *
 auth_getval(const char *name)
 {
-    if (!P && initauthconf(_PATH_AUTHCONF))
-	return NULL;
-    else
-	return property_find(P, name);
+
+	(void)name;
+	return (NULL);
 }
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libutil/auth.conf.5
--- a/head/lib/libutil/auth.conf.5	Wed Jul 25 16:21:35 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libutil/login.conf.5
--- a/head/lib/libutil/login.conf.5	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libutil/login.conf.5	Wed Jul 25 16:23:00 2012 +0300
@@ -17,7 +17,7 @@
 .\" 5. Modifications may be freely made to this file providing the above
 .\"    conditions are met.
 .\"
-.\" $FreeBSD: head/lib/libutil/login.conf.5 233698 2012-03-30 12:34:34Z joel $
+.\" $FreeBSD: head/lib/libutil/login.conf.5 237269 2012-06-19 14:46:18Z des $
 .\"
 .Dd July 8, 2011
 .Dt LOGIN.CONF 5
@@ -209,7 +209,8 @@
 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 @@
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libutil/property.3
--- a/head/lib/libutil/property.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libutil/property.3	Wed Jul 25 16:23:00 2012 +0300
@@ -23,7 +23,7 @@
 .\" (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: head/lib/libutil/property.3 230234 2012-01-16 21:25:41Z ghelmer $
+.\" $FreeBSD: head/lib/libutil/property.3 236965 2012-06-12 17:02:53Z des $
 .\" "
 .Dd October 7, 1998
 .Dt PROPERTIES 3
@@ -90,8 +90,6 @@
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libutil/pw_util.c
--- a/head/lib/libutil/pw_util.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libutil/pw_util.c	Wed Jul 25 16:23:00 2012 +0300
@@ -39,7 +39,7 @@
 static const char sccsid[] = "@(#)pw_util.c	8.3 (Berkeley) 4/2/94";
 #endif
 static const char rcsid[] =
-  "$FreeBSD: head/lib/libutil/pw_util.c 231383 2012-02-10 13:40:32Z ed $";
+  "$FreeBSD: head/lib/libutil/pw_util.c 237268 2012-06-19 11:39:56Z bapt $";
 #endif /* not lint */
 
 /*
@@ -437,14 +437,21 @@
 	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 @@
 		 */
 
 		*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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libz/ChangeLog
--- a/head/lib/libz/ChangeLog	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libz/ChangeLog	Wed Jul 25 16:23:00 2012 +0300
@@ -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 @@
 - 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libz/FAQ
--- a/head/lib/libz/FAQ	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libz/FAQ	Wed Jul 25 16:23:00 2012 +0300
@@ -44,8 +44,8 @@
 
  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 @@
 
 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 @@
     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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libz/FREEBSD-upgrade
--- a/head/lib/libz/FREEBSD-upgrade	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libz/FREEBSD-upgrade	Wed Jul 25 16:23:00 2012 +0300
@@ -1,4 +1,4 @@
-$FreeBSD$
+$FreeBSD: head/lib/libz/FREEBSD-upgrade 146082 2005-05-11 03:50:50Z kientzle $
 
 ZLib 1.2.2
 
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libz/Makefile
--- a/head/lib/libz/Makefile	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libz/Makefile	Wed Jul 25 16:23:00 2012 +0300
@@ -35,12 +35,12 @@
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libz/README
--- a/head/lib/libz/README	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libz/README	Wed Jul 25 16:23:00 2012 +0300
@@ -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 at 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 at gzip.org>, or to Gilles Vollant
@@ -31,7 +31,7 @@
 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 @@
 
 A Python interface to zlib written by A.M. Kuchling <amk at 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 @@
 
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libz/Symbol.map
--- a/head/lib/libz/Symbol.map	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libz/Symbol.map	Wed Jul 25 16:23:00 2012 +0300
@@ -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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libz/Versions.def
--- a/head/lib/libz/Versions.def	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libz/Versions.def	Wed Jul 25 16:23:00 2012 +0300
@@ -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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libz/adler32.c
--- a/head/lib/libz/adler32.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libz/adler32.c	Wed Jul 25 16:23:00 2012 +0300
@@ -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 @@
 #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
+/* 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 { \
+        CHOP(a); \
+        if (a >= BASE) a -= BASE; \
+    } while (0)
 #  define MOD(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); \
-        if (a >= BASE) a -= BASE; \
+        CHOP(a); \
+        MOD28(a); \
     } while (0)
-#  define MOD4(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); \
+#  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 @@
         }
         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 @@
     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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libz/contrib/asm686/match.S
--- a/head/lib/libz/contrib/asm686/match.S	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libz/contrib/asm686/match.S	Wed Jul 25 16:23:00 2012 +0300
@@ -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 @@
 /* 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 @@
 /* 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libz/crc32.c
--- a/head/lib/libz/crc32.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libz/crc32.c	Wed Jul 25 16:23:00 2012 +0300
@@ -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 at 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()
 {
-    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 @@
         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 @@
            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 @@
         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 @@
 #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 @@
 /* =========================================================================
  * 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 @@
 
 #ifdef BYFOUR
     if (sizeof(void *) == sizeof(ptrdiff_t)) {
-        u4 endian;
+        z_crc_t endian;
 
         endian = 1;
         if (*((unsigned char *)(&endian)))
@@ -266,17 +249,17 @@
     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 @@
     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 @@
         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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libz/crc32.h
--- a/head/lib/libz/crc32.h	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libz/crc32.h	Wed Jul 25 16:23:00 2012 +0300
@@ -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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libz/deflate.c
--- a/head/lib/libz/deflate.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libz/deflate.c	Wed Jul 25 16:23:00 2012 +0300
@@ -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 @@
 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 @@
 
     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 @@
     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;
+    wrap = s->wrap;
+    if (wrap == 2 || (wrap == 1 && s->status != INIT_STATE) || s->lookahead)
         return Z_STREAM_ERROR;
 
-    s = strm->state;
-    if (s->wrap)
+    /* 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 (length < MIN_MATCH) return Z_OK;
-    if (length > s->w_size) {
-        length = s->w_size;
-        dictionary += dictLength - length; /* use the tail of the dictionary */
+    /* 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 @@
     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 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 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 @@
      * 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 @@
                     if (s->lookahead == 0) {
                         s->strstart = 0;
                         s->block_start = 0L;
+                        s->insert = 0;
                     }
                 }
             }
@@ -945,12 +1027,12 @@
 
     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 @@
     }
     /* 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 @@
 
     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 @@
     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 @@
     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 @@
 #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 @@
         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 @@
             s->high_water += init;
         }
     }
+
+    Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD,
+           "not enough room for search");
 }
 
 /* ===========================================================================
@@ -1506,8 +1606,14 @@
             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 @@
         }
         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 @@
         _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 @@
     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 @@
                 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 @@
         }
         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 @@
         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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libz/deflate.h
--- a/head/lib/libz/deflate.h	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libz/deflate.h	Wed Jul 25 16:23:00 2012 +0300
@@ -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 @@
     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 @@
     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 @@
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libz/doc/algorithm.txt
--- a/head/lib/libz/doc/algorithm.txt	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libz/doc/algorithm.txt	Wed Jul 25 16:23:00 2012 +0300
@@ -206,4 +206,4 @@
 pp. 337-343.
 
 ``DEFLATE Compressed Data Format Specification'' available in
-http://www.ietf.org/rfc/rfc1951.txt
+http://tools.ietf.org/html/rfc1951
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libz/example.c
--- a/head/lib/libz/example.c	Wed Jul 25 16:21:35 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,565 +0,0 @@
-/* example.c -- usage example of the zlib compression library
- * Copyright (C) 1995-2006 Jean-loup Gailly.
- * For conditions of distribution and use, see copyright notice in zlib.h
- */
-
-/* @(#) $Id$ */
-
-#include "zlib.h"
-#include <stdio.h>
-
-#ifdef STDC
-#  include <string.h>
-#  include <stdlib.h>
-#endif
-
-#if defined(VMS) || defined(RISCOS)
-#  define TESTFILE "foo-gz"
-#else
-#  define TESTFILE "foo.gz"
-#endif
-
-#define CHECK_ERR(err, msg) { \
-    if (err != Z_OK) { \
-        fprintf(stderr, "%s error: %d\n", msg, err); \
-        exit(1); \
-    } \
-}
-
-const char hello[] = "hello, hello!";
-/* "hello world" would be more standard, but the repeated "hello"
- * stresses the compression code better, sorry...
- */
-
-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));
-void test_large_deflate OF((Byte *compr, uLong comprLen,
-                            Byte *uncompr, uLong uncomprLen));
-void test_large_inflate OF((Byte *compr, uLong comprLen,
-                            Byte *uncompr, uLong uncomprLen));
-void test_flush         OF((Byte *compr, uLong *comprLen));
-void test_sync          OF((Byte *compr, uLong comprLen,
-                            Byte *uncompr, uLong uncomprLen));
-void test_dict_deflate  OF((Byte *compr, uLong comprLen));
-void test_dict_inflate  OF((Byte *compr, uLong comprLen,
-                            Byte *uncompr, uLong uncomprLen));
-int  main               OF((int argc, char *argv[]));
-
-/* ===========================================================================
- * Test compress() and uncompress()
- */
-void test_compress(compr, comprLen, uncompr, uncomprLen)
-    Byte *compr, *uncompr;
-    uLong comprLen, uncomprLen;
-{
-    int err;
-    uLong len = (uLong)strlen(hello)+1;
-
-    err = compress(compr, &comprLen, (const Bytef*)hello, len);
-    CHECK_ERR(err, "compress");
-
-    strcpy((char*)uncompr, "garbage");
-
-    err = uncompress(uncompr, &uncomprLen, compr, comprLen);
-    CHECK_ERR(err, "uncompress");
-
-    if (strcmp((char*)uncompr, hello)) {
-        fprintf(stderr, "bad uncompress\n");
-        exit(1);
-    } else {
-        printf("uncompress(): %s\n", (char *)uncompr);
-    }
-}
-
-/* ===========================================================================
- * Test read/write of .gz files
- */
-void test_gzio(fname, uncompr, uncomprLen)
-    const char *fname; /* compressed file name */
-    Byte *uncompr;
-    uLong uncomprLen;
-{
-#ifdef NO_GZCOMPRESS
-    fprintf(stderr, "NO_GZCOMPRESS -- gz* functions cannot compress\n");
-#else
-    int err;
-    int len = (int)strlen(hello)+1;
-    gzFile file;
-    z_off_t pos;
-
-    file = gzopen(fname, "wb");
-    if (file == NULL) {
-        fprintf(stderr, "gzopen error\n");
-        exit(1);
-    }
-    gzputc(file, 'h');
-    if (gzputs(file, "ello") != 4) {
-        fprintf(stderr, "gzputs err: %s\n", gzerror(file, &err));
-        exit(1);
-    }
-    if (gzprintf(file, ", %s!", "hello") != 8) {
-        fprintf(stderr, "gzprintf err: %s\n", gzerror(file, &err));
-        exit(1);
-    }
-    gzseek(file, 1L, SEEK_CUR); /* add one zero byte */
-    gzclose(file);
-
-    file = gzopen(fname, "rb");
-    if (file == NULL) {
-        fprintf(stderr, "gzopen error\n");
-        exit(1);
-    }
-    strcpy((char*)uncompr, "garbage");
-
-    if (gzread(file, uncompr, (unsigned)uncomprLen) != len) {
-        fprintf(stderr, "gzread err: %s\n", gzerror(file, &err));
-        exit(1);
-    }
-    if (strcmp((char*)uncompr, hello)) {
-        fprintf(stderr, "bad gzread: %s\n", (char*)uncompr);
-        exit(1);
-    } else {
-        printf("gzread(): %s\n", (char*)uncompr);
-    }
-
-    pos = gzseek(file, -8L, SEEK_CUR);
-    if (pos != 6 || gztell(file) != pos) {
-        fprintf(stderr, "gzseek error, pos=%ld, gztell=%ld\n",
-                (long)pos, (long)gztell(file));
-        exit(1);
-    }
-
-    if (gzgetc(file) != ' ') {
-        fprintf(stderr, "gzgetc error\n");
-        exit(1);
-    }
-
-    if (gzungetc(' ', file) != ' ') {
-        fprintf(stderr, "gzungetc error\n");
-        exit(1);
-    }
-
-    gzgets(file, (char*)uncompr, (int)uncomprLen);
-    if (strlen((char*)uncompr) != 7) { /* " hello!" */
-        fprintf(stderr, "gzgets err after gzseek: %s\n", gzerror(file, &err));
-        exit(1);
-    }
-    if (strcmp((char*)uncompr, hello + 6)) {
-        fprintf(stderr, "bad gzgets after gzseek\n");
-        exit(1);
-    } else {
-        printf("gzgets() after gzseek: %s\n", (char*)uncompr);
-    }
-
-    gzclose(file);
-#endif
-}
-
-/* ===========================================================================
- * Test deflate() with small buffers
- */
-void test_deflate(compr, comprLen)
-    Byte *compr;
-    uLong comprLen;
-{
-    z_stream c_stream; /* compression stream */
-    int err;
-    uLong len = (uLong)strlen(hello)+1;
-
-    c_stream.zalloc = (alloc_func)0;
-    c_stream.zfree = (free_func)0;
-    c_stream.opaque = (voidpf)0;
-
-    err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
-    CHECK_ERR(err, "deflateInit");
-
-    c_stream.next_in  = (Bytef*)hello;
-    c_stream.next_out = compr;
-
-    while (c_stream.total_in != len && c_stream.total_out < comprLen) {
-        c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */
-        err = deflate(&c_stream, Z_NO_FLUSH);
-        CHECK_ERR(err, "deflate");
-    }
-    /* Finish the stream, still forcing small buffers: */
-    for (;;) {
-        c_stream.avail_out = 1;
-        err = deflate(&c_stream, Z_FINISH);
-        if (err == Z_STREAM_END) break;
-        CHECK_ERR(err, "deflate");
-    }
-
-    err = deflateEnd(&c_stream);
-    CHECK_ERR(err, "deflateEnd");
-}
-
-/* ===========================================================================
- * Test inflate() with small buffers
- */
-void test_inflate(compr, comprLen, uncompr, uncomprLen)
-    Byte *compr, *uncompr;
-    uLong comprLen, uncomprLen;
-{
-    int err;
-    z_stream d_stream; /* decompression stream */
-
-    strcpy((char*)uncompr, "garbage");
-
-    d_stream.zalloc = (alloc_func)0;
-    d_stream.zfree = (free_func)0;
-    d_stream.opaque = (voidpf)0;
-
-    d_stream.next_in  = compr;
-    d_stream.avail_in = 0;
-    d_stream.next_out = uncompr;
-
-    err = inflateInit(&d_stream);
-    CHECK_ERR(err, "inflateInit");
-
-    while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen) {
-        d_stream.avail_in = d_stream.avail_out = 1; /* force small buffers */
-        err = inflate(&d_stream, Z_NO_FLUSH);
-        if (err == Z_STREAM_END) break;
-        CHECK_ERR(err, "inflate");
-    }
-
-    err = inflateEnd(&d_stream);
-    CHECK_ERR(err, "inflateEnd");
-
-    if (strcmp((char*)uncompr, hello)) {
-        fprintf(stderr, "bad inflate\n");
-        exit(1);
-    } else {
-        printf("inflate(): %s\n", (char *)uncompr);
-    }
-}
-
-/* ===========================================================================
- * Test deflate() with large buffers and dynamic change of compression level
- */
-void test_large_deflate(compr, comprLen, uncompr, uncomprLen)
-    Byte *compr, *uncompr;
-    uLong comprLen, uncomprLen;
-{
-    z_stream c_stream; /* compression stream */
-    int err;
-
-    c_stream.zalloc = (alloc_func)0;
-    c_stream.zfree = (free_func)0;
-    c_stream.opaque = (voidpf)0;
-
-    err = deflateInit(&c_stream, Z_BEST_SPEED);
-    CHECK_ERR(err, "deflateInit");
-
-    c_stream.next_out = compr;
-    c_stream.avail_out = (uInt)comprLen;
-
-    /* At this point, uncompr is still mostly zeroes, so it should compress
-     * very well:
-     */
-    c_stream.next_in = uncompr;
-    c_stream.avail_in = (uInt)uncomprLen;
-    err = deflate(&c_stream, Z_NO_FLUSH);
-    CHECK_ERR(err, "deflate");
-    if (c_stream.avail_in != 0) {
-        fprintf(stderr, "deflate not greedy\n");
-        exit(1);
-    }
-
-    /* Feed in already compressed data and switch to no compression: */
-    deflateParams(&c_stream, Z_NO_COMPRESSION, Z_DEFAULT_STRATEGY);
-    c_stream.next_in = compr;
-    c_stream.avail_in = (uInt)comprLen/2;
-    err = deflate(&c_stream, Z_NO_FLUSH);
-    CHECK_ERR(err, "deflate");
-
-    /* Switch back to compressing mode: */
-    deflateParams(&c_stream, Z_BEST_COMPRESSION, Z_FILTERED);
-    c_stream.next_in = uncompr;
-    c_stream.avail_in = (uInt)uncomprLen;
-    err = deflate(&c_stream, Z_NO_FLUSH);
-    CHECK_ERR(err, "deflate");
-
-    err = deflate(&c_stream, Z_FINISH);
-    if (err != Z_STREAM_END) {
-        fprintf(stderr, "deflate should report Z_STREAM_END\n");
-        exit(1);
-    }
-    err = deflateEnd(&c_stream);
-    CHECK_ERR(err, "deflateEnd");
-}
-
-/* ===========================================================================
- * Test inflate() with large buffers
- */
-void test_large_inflate(compr, comprLen, uncompr, uncomprLen)
-    Byte *compr, *uncompr;
-    uLong comprLen, uncomprLen;
-{
-    int err;
-    z_stream d_stream; /* decompression stream */
-
-    strcpy((char*)uncompr, "garbage");
-
-    d_stream.zalloc = (alloc_func)0;
-    d_stream.zfree = (free_func)0;
-    d_stream.opaque = (voidpf)0;
-
-    d_stream.next_in  = compr;
-    d_stream.avail_in = (uInt)comprLen;
-
-    err = inflateInit(&d_stream);
-    CHECK_ERR(err, "inflateInit");
-
-    for (;;) {
-        d_stream.next_out = uncompr;            /* discard the output */
-        d_stream.avail_out = (uInt)uncomprLen;
-        err = inflate(&d_stream, Z_NO_FLUSH);
-        if (err == Z_STREAM_END) break;
-        CHECK_ERR(err, "large inflate");
-    }
-
-    err = inflateEnd(&d_stream);
-    CHECK_ERR(err, "inflateEnd");
-
-    if (d_stream.total_out != 2*uncomprLen + comprLen/2) {
-        fprintf(stderr, "bad large inflate: %ld\n", d_stream.total_out);
-        exit(1);
-    } else {
-        printf("large_inflate(): OK\n");
-    }
-}
-
-/* ===========================================================================
- * Test deflate() with full flush
- */
-void test_flush(compr, comprLen)
-    Byte *compr;
-    uLong *comprLen;
-{
-    z_stream c_stream; /* compression stream */
-    int err;
-    uInt len = (uInt)strlen(hello)+1;
-
-    c_stream.zalloc = (alloc_func)0;
-    c_stream.zfree = (free_func)0;
-    c_stream.opaque = (voidpf)0;
-
-    err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
-    CHECK_ERR(err, "deflateInit");
-
-    c_stream.next_in  = (Bytef*)hello;
-    c_stream.next_out = compr;
-    c_stream.avail_in = 3;
-    c_stream.avail_out = (uInt)*comprLen;
-    err = deflate(&c_stream, Z_FULL_FLUSH);
-    CHECK_ERR(err, "deflate");
-
-    compr[3]++; /* force an error in first compressed block */
-    c_stream.avail_in = len - 3;
-
-    err = deflate(&c_stream, Z_FINISH);
-    if (err != Z_STREAM_END) {
-        CHECK_ERR(err, "deflate");
-    }
-    err = deflateEnd(&c_stream);
-    CHECK_ERR(err, "deflateEnd");
-
-    *comprLen = c_stream.total_out;
-}
-
-/* ===========================================================================
- * Test inflateSync()
- */
-void test_sync(compr, comprLen, uncompr, uncomprLen)
-    Byte *compr, *uncompr;
-    uLong comprLen, uncomprLen;
-{
-    int err;
-    z_stream d_stream; /* decompression stream */
-
-    strcpy((char*)uncompr, "garbage");
-
-    d_stream.zalloc = (alloc_func)0;
-    d_stream.zfree = (free_func)0;
-    d_stream.opaque = (voidpf)0;
-
-    d_stream.next_in  = compr;
-    d_stream.avail_in = 2; /* just read the zlib header */
-
-    err = inflateInit(&d_stream);
-    CHECK_ERR(err, "inflateInit");
-
-    d_stream.next_out = uncompr;
-    d_stream.avail_out = (uInt)uncomprLen;
-
-    inflate(&d_stream, Z_NO_FLUSH);
-    CHECK_ERR(err, "inflate");
-
-    d_stream.avail_in = (uInt)comprLen-2;   /* read all compressed data */
-    err = inflateSync(&d_stream);           /* but skip the damaged part */
-    CHECK_ERR(err, "inflateSync");
-
-    err = inflate(&d_stream, Z_FINISH);
-    if (err != Z_DATA_ERROR) {
-        fprintf(stderr, "inflate should report DATA_ERROR\n");
-        /* Because of incorrect adler32 */
-        exit(1);
-    }
-    err = inflateEnd(&d_stream);
-    CHECK_ERR(err, "inflateEnd");
-
-    printf("after inflateSync(): hel%s\n", (char *)uncompr);
-}
-
-/* ===========================================================================
- * Test deflate() with preset dictionary
- */
-void test_dict_deflate(compr, comprLen)
-    Byte *compr;
-    uLong comprLen;
-{
-    z_stream c_stream; /* compression stream */
-    int err;
-
-    c_stream.zalloc = (alloc_func)0;
-    c_stream.zfree = (free_func)0;
-    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));
-    CHECK_ERR(err, "deflateSetDictionary");
-
-    dictId = c_stream.adler;
-    c_stream.next_out = compr;
-    c_stream.avail_out = (uInt)comprLen;
-
-    c_stream.next_in = (Bytef*)hello;
-    c_stream.avail_in = (uInt)strlen(hello)+1;
-
-    err = deflate(&c_stream, Z_FINISH);
-    if (err != Z_STREAM_END) {
-        fprintf(stderr, "deflate should report Z_STREAM_END\n");
-        exit(1);
-    }
-    err = deflateEnd(&c_stream);
-    CHECK_ERR(err, "deflateEnd");
-}
-
-/* ===========================================================================
- * Test inflate() with a preset dictionary
- */
-void test_dict_inflate(compr, comprLen, uncompr, uncomprLen)
-    Byte *compr, *uncompr;
-    uLong comprLen, uncomprLen;
-{
-    int err;
-    z_stream d_stream; /* decompression stream */
-
-    strcpy((char*)uncompr, "garbage");
-
-    d_stream.zalloc = (alloc_func)0;
-    d_stream.zfree = (free_func)0;
-    d_stream.opaque = (voidpf)0;
-
-    d_stream.next_in  = compr;
-    d_stream.avail_in = (uInt)comprLen;
-
-    err = inflateInit(&d_stream);
-    CHECK_ERR(err, "inflateInit");
-
-    d_stream.next_out = uncompr;
-    d_stream.avail_out = (uInt)uncomprLen;
-
-    for (;;) {
-        err = inflate(&d_stream, Z_NO_FLUSH);
-        if (err == Z_STREAM_END) break;
-        if (err == Z_NEED_DICT) {
-            if (d_stream.adler != dictId) {
-                fprintf(stderr, "unexpected dictionary");
-                exit(1);
-            }
-            err = inflateSetDictionary(&d_stream, (const Bytef*)dictionary,
-                                       sizeof(dictionary));
-        }
-        CHECK_ERR(err, "inflate with dict");
-    }
-
-    err = inflateEnd(&d_stream);
-    CHECK_ERR(err, "inflateEnd");
-
-    if (strcmp((char*)uncompr, hello)) {
-        fprintf(stderr, "bad inflate with dict\n");
-        exit(1);
-    } else {
-        printf("inflate with dictionary: %s\n", (char *)uncompr);
-    }
-}
-
-/* ===========================================================================
- * Usage:  example [output.gz  [input.gz]]
- */
-
-int main(argc, argv)
-    int argc;
-    char *argv[];
-{
-    Byte *compr, *uncompr;
-    uLong comprLen = 10000*sizeof(int); /* don't overflow on MSDOS */
-    uLong uncomprLen = comprLen;
-    static const char* myVersion = ZLIB_VERSION;
-
-    if (zlibVersion()[0] != myVersion[0]) {
-        fprintf(stderr, "incompatible zlib version\n");
-        exit(1);
-
-    } else if (strcmp(zlibVersion(), ZLIB_VERSION) != 0) {
-        fprintf(stderr, "warning: different zlib version\n");
-    }
-
-    printf("zlib version %s = 0x%04x, compile flags = 0x%lx\n",
-            ZLIB_VERSION, ZLIB_VERNUM, zlibCompileFlags());
-
-    compr    = (Byte*)calloc((uInt)comprLen, 1);
-    uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
-    /* compr and uncompr are cleared to avoid reading uninitialized
-     * data and to ensure that uncompr compresses well.
-     */
-    if (compr == Z_NULL || uncompr == Z_NULL) {
-        printf("out of memory\n");
-        exit(1);
-    }
-    test_compress(compr, comprLen, uncompr, uncomprLen);
-
-    test_gzio((argc > 1 ? argv[1] : TESTFILE),
-              uncompr, uncomprLen);
-
-    test_deflate(compr, comprLen);
-    test_inflate(compr, comprLen, uncompr, uncomprLen);
-
-    test_large_deflate(compr, comprLen, uncompr, uncomprLen);
-    test_large_inflate(compr, comprLen, uncompr, uncomprLen);
-
-    test_flush(compr, &comprLen);
-    test_sync(compr, comprLen, uncompr, uncomprLen);
-    comprLen = uncomprLen;
-
-    test_dict_deflate(compr, comprLen);
-    test_dict_inflate(compr, comprLen, uncompr, uncomprLen);
-
-    free(compr);
-    free(uncompr);
-
-    return 0;
-}
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libz/gzguts.h
--- a/head/lib/libz/gzguts.h	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libz/gzguts.h	Wed Jul 25 16:23:00 2012 +0300
@@ -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 how;                /* 0: get header, 1: copy, 2: decompress */
+    z_off64_t start;        /* where the gzip data started, for rewinding */
     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 */
+    int past;               /* true if read requested past end */
         /* just for writing */
     int level;              /* compression level */
     int strategy;           /* compression strategy */
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libz/gzlib.c
--- a/head/lib/libz/gzlib.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libz/gzlib.c	Wed Jul 25 16:23:00 2012 +0300
@@ -1,22 +1,26 @@
 /* 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
  */
 
-/* $FreeBSD$ */
+/* $FreeBSD: head/lib/libz/gzlib.c 237410 2012-06-21 21:47:08Z delphij $ */
 
 #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 @@
 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 @@
     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 @@
                 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 @@
                 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 @@
         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
-            (state->mode == GZ_READ ?
-                O_RDONLY :
-                (O_WRONLY | O_CREAT | (
-                    state->mode == GZ_WRITE ?
-                        O_TRUNC :
-                        O_APPEND))),
-            0666);
+#ifdef O_CLOEXEC
+        (cloexec ? O_CLOEXEC : 0) |
+#endif
+        (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 @@
 }
 
 /* -- 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 @@
         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 @@
     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 @@
         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 @@
 
     /* 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 @@
 
     /* 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 @@
         state->seek = 1;
         state->skip = offset;
     }
-    return state->pos + offset;
+    return state->x.pos + offset;
 }
 
 /* -- see zlib.h -- */
@@ -376,7 +454,7 @@
         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 @@
         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 @@
         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 @@
         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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libz/gzread.c
--- a/head/lib/libz/gzread.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libz/gzread.c	Wed Jul 25 16:23:00 2012 +0300
@@ -1,9 +1,9 @@
 /* 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
  */
 
-/* $FreeBSD$ */
+/* $FreeBSD: head/lib/libz/gzread.c 237410 2012-06-21 21:47:08Z delphij $ */
 
 #include "gzguts.h"
 #include <unistd.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 @@
    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 @@
         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 @@
         }
     }
 
-    /* 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;
     }
 
-    /* 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;
+    /* 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, 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 @@
 }
 
 /* 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 @@
         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 @@
         }
         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 @@
     /* 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 @@
         /* 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 @@
     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 @@
     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 @@
             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 @@
 }
 
 /* -- see zlib.h -- */
+#undef gzgetc
 int ZEXPORT gzgetc(file)
     gzFile file;
 {
@@ -465,15 +394,16 @@
         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 @@
     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 @@
         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 @@
         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 @@
         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 @@
     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 @@
         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 gzclose_r(file)
     gzFile file;
 {
-    int ret;
+    int ret, err;
     gz_statep state;
 
     /* get internal structure */
@@ -648,9 +583,10 @@
         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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libz/gzwrite.c
--- a/head/lib/libz/gzwrite.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libz/gzwrite.c	Wed Jul 25 16:23:00 2012 +0300
@@ -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: head/lib/libz/gzwrite.c 237410 2012-06-21 21:47:08Z delphij $ */
+
 #include "gzguts.h"
 #include <unistd.h>
 
@@ -19,44 +21,55 @@
     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 @@
     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 @@
            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 @@
                 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 @@
         }
         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 @@
     /* 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 @@
                 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 @@
         /* 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 @@
         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 @@
     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 @@
     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 @@
     /* 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 @@
     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 @@
     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 @@
     /* 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 gzclose_w(file)
     gzFile file;
 {
-    int ret = 0;
+    int ret = Z_OK;
     gz_statep state;
 
     /* get internal structure */
@@ -516,17 +545,24 @@
     /* 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libz/infback.c
--- a/head/lib/libz/infback.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libz/infback.c	Wed Jul 25 16:23:00 2012 +0300
@@ -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 @@
         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 @@
                     PULLBYTE();
                 }
                 if (here.val < 16) {
-                    NEEDBITS(here.bits);
                     DROPBITS(here.bits);
                     state->lens[state->have++] = here.val;
                 }
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libz/inffixed.h
--- a/head/lib/libz/inffixed.h	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libz/inffixed.h	Wed Jul 25 16:23:00 2012 +0300
@@ -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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libz/inflate.c
--- a/head/lib/libz/inflate.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libz/inflate.c	Wed Jul 25 16:23:00 2012 +0300
@@ -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 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 @@
     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 @@
     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 @@
     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 @@
     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 @@
         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 @@
 #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 @@
                     PULLBYTE();
                 }
                 if (here.val < 16) {
-                    NEEDBITS(here.bits);
                     DROPBITS(here.bits);
                     state->lens[state->have++] = here.val;
                 }
@@ -1170,7 +1184,7 @@
 #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 @@
      */
   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 @@
 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 @@
     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 @@
     }
 
     /* 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libz/inftrees.c
--- a/head/lib/libz/inftrees.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libz/inftrees.c	Wed Jul 25 16:23:00 2012 +0300
@@ -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 @@
         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 @@
         }
     }
 
-    /*
-       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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libz/minigzip.c
--- a/head/lib/libz/minigzip.c	Wed Jul 25 16:21:35 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,440 +0,0 @@
-/* minigzip.c -- simulate gzip using the zlib compression library
- * Copyright (C) 1995-2006, 2010 Jean-loup Gailly.
- * For conditions of distribution and use, see copyright notice in zlib.h
- */
-
-/*
- * minigzip is a minimal implementation of the gzip utility. This is
- * only an example of using zlib and isn't meant to replace the
- * full-featured gzip. No attempt is made to deal with file systems
- * limiting names to 14 or 8+3 characters, etc... Error checking is
- * very limited. So use minigzip only for testing; use gzip for the
- * real thing. On MSDOS, use only on file names without extension
- * or in pipe mode.
- */
-
-/* @(#) $Id$ */
-
-#include "zlib.h"
-#include <stdio.h>
-
-#ifdef STDC
-#  include <string.h>
-#  include <stdlib.h>
-#endif
-
-#ifdef USE_MMAP
-#  include <sys/types.h>
-#  include <sys/mman.h>
-#  include <sys/stat.h>
-#endif
-
-#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
-#  include <fcntl.h>
-#  include <io.h>
-#  ifdef UNDER_CE
-#    include <stdlib.h>
-#  endif
-#  define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
-#else
-#  define SET_BINARY_MODE(file)
-#endif
-
-#ifdef VMS
-#  define unlink delete
-#  define GZ_SUFFIX "-gz"
-#endif
-#ifdef RISCOS
-#  define unlink remove
-#  define GZ_SUFFIX "-gz"
-#  define fileno(file) file->__file
-#endif
-#if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
-#  include <unix.h> /* for fileno */
-#endif
-
-#if !defined(Z_HAVE_UNISTD_H) && !defined(_LARGEFILE64_SOURCE)
-#ifndef WIN32 /* unlink already in stdio.h for WIN32 */
-  extern int unlink OF((const char *));
-#endif
-#endif
-
-#if defined(UNDER_CE)
-#  include <windows.h>
-#  define perror(s) pwinerror(s)
-
-/* Map the Windows error number in ERROR to a locale-dependent error
-   message string and return a pointer to it.  Typically, the values
-   for ERROR come from GetLastError.
-
-   The string pointed to shall not be modified by the application,
-   but may be overwritten by a subsequent call to strwinerror
-
-   The strwinerror function does not change the current setting
-   of GetLastError.  */
-
-static char *strwinerror (error)
-     DWORD error;
-{
-    static char buf[1024];
-
-    wchar_t *msgbuf;
-    DWORD lasterr = GetLastError();
-    DWORD chars = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
-        | FORMAT_MESSAGE_ALLOCATE_BUFFER,
-        NULL,
-        error,
-        0, /* Default language */
-        (LPVOID)&msgbuf,
-        0,
-        NULL);
-    if (chars != 0) {
-        /* If there is an \r\n appended, zap it.  */
-        if (chars >= 2
-            && msgbuf[chars - 2] == '\r' && msgbuf[chars - 1] == '\n') {
-            chars -= 2;
-            msgbuf[chars] = 0;
-        }
-
-        if (chars > sizeof (buf) - 1) {
-            chars = sizeof (buf) - 1;
-            msgbuf[chars] = 0;
-        }
-
-        wcstombs(buf, msgbuf, chars + 1);
-        LocalFree(msgbuf);
-    }
-    else {
-        sprintf(buf, "unknown win32 error (%ld)", error);
-    }
-
-    SetLastError(lasterr);
-    return buf;
-}
-
-static void pwinerror (s)
-    const char *s;
-{
-    if (s && *s)
-        fprintf(stderr, "%s: %s\n", s, strwinerror(GetLastError ()));
-    else
-        fprintf(stderr, "%s\n", strwinerror(GetLastError ()));
-}
-
-#endif /* UNDER_CE */
-
-#ifndef GZ_SUFFIX
-#  define GZ_SUFFIX ".gz"
-#endif
-#define SUFFIX_LEN (sizeof(GZ_SUFFIX)-1)
-
-#define BUFLEN      16384
-#define MAX_NAME_LEN 1024
-
-#ifdef MAXSEG_64K
-#  define local static
-   /* Needed for systems with limitation on stack size. */
-#else
-#  define local
-#endif
-
-char *prog;
-
-void error            OF((const char *msg));
-void gz_compress      OF((FILE   *in, gzFile out));
-#ifdef USE_MMAP
-int  gz_compress_mmap OF((FILE   *in, gzFile out));
-#endif
-void gz_uncompress    OF((gzFile in, FILE   *out));
-void file_compress    OF((char  *file, char *mode));
-void file_uncompress  OF((char  *file));
-int  main             OF((int argc, char *argv[]));
-
-/* ===========================================================================
- * Display error message and exit
- */
-void error(msg)
-    const char *msg;
-{
-    fprintf(stderr, "%s: %s\n", prog, msg);
-    exit(1);
-}
-
-/* ===========================================================================
- * Compress input to output then close both files.
- */
-
-void gz_compress(in, out)
-    FILE   *in;
-    gzFile out;
-{
-    local char buf[BUFLEN];
-    int len;
-    int err;
-
-#ifdef USE_MMAP
-    /* Try first compressing with mmap. If mmap fails (minigzip used in a
-     * pipe), use the normal fread loop.
-     */
-    if (gz_compress_mmap(in, out) == Z_OK) return;
-#endif
-    for (;;) {
-        len = (int)fread(buf, 1, sizeof(buf), in);
-        if (ferror(in)) {
-            perror("fread");
-            exit(1);
-        }
-        if (len == 0) break;
-
-        if (gzwrite(out, buf, (unsigned)len) != len) error(gzerror(out, &err));
-    }
-    fclose(in);
-    if (gzclose(out) != Z_OK) error("failed gzclose");
-}
-
-#ifdef USE_MMAP /* MMAP version, Miguel Albrecht <malbrech at eso.org> */
-
-/* Try compressing the input file at once using mmap. Return Z_OK if
- * if success, Z_ERRNO otherwise.
- */
-int gz_compress_mmap(in, out)
-    FILE   *in;
-    gzFile out;
-{
-    int len;
-    int err;
-    int ifd = fileno(in);
-    caddr_t buf;    /* mmap'ed buffer for the entire input file */
-    off_t buf_len;  /* length of the input file */
-    struct stat sb;
-
-    /* Determine the size of the file, needed for mmap: */
-    if (fstat(ifd, &sb) < 0) return Z_ERRNO;
-    buf_len = sb.st_size;
-    if (buf_len <= 0) return Z_ERRNO;
-
-    /* Now do the actual mmap: */
-    buf = mmap((caddr_t) 0, buf_len, PROT_READ, MAP_SHARED, ifd, (off_t)0);
-    if (buf == (caddr_t)(-1)) return Z_ERRNO;
-
-    /* Compress the whole file at once: */
-    len = gzwrite(out, (char *)buf, (unsigned)buf_len);
-
-    if (len != (int)buf_len) error(gzerror(out, &err));
-
-    munmap(buf, buf_len);
-    fclose(in);
-    if (gzclose(out) != Z_OK) error("failed gzclose");
-    return Z_OK;
-}
-#endif /* USE_MMAP */
-
-/* ===========================================================================
- * Uncompress input to output then close both files.
- */
-void gz_uncompress(in, out)
-    gzFile in;
-    FILE   *out;
-{
-    local char buf[BUFLEN];
-    int len;
-    int err;
-
-    for (;;) {
-        len = gzread(in, buf, sizeof(buf));
-        if (len < 0) error (gzerror(in, &err));
-        if (len == 0) break;
-
-        if ((int)fwrite(buf, 1, (unsigned)len, out) != len) {
-            error("failed fwrite");
-        }
-    }
-    if (fclose(out)) error("failed fclose");
-
-    if (gzclose(in) != Z_OK) error("failed gzclose");
-}
-
-
-/* ===========================================================================
- * Compress the given file: create a corresponding .gz file and remove the
- * original.
- */
-void file_compress(file, mode)
-    char  *file;
-    char  *mode;
-{
-    local char outfile[MAX_NAME_LEN];
-    FILE  *in;
-    gzFile out;
-
-    if (strlen(file) + strlen(GZ_SUFFIX) >= sizeof(outfile)) {
-        fprintf(stderr, "%s: filename too long\n", prog);
-        exit(1);
-    }
-
-    strcpy(outfile, file);
-    strcat(outfile, GZ_SUFFIX);
-
-    in = fopen(file, "rb");
-    if (in == NULL) {
-        perror(file);
-        exit(1);
-    }
-    out = gzopen(outfile, mode);
-    if (out == NULL) {
-        fprintf(stderr, "%s: can't gzopen %s\n", prog, outfile);
-        exit(1);
-    }
-    gz_compress(in, out);
-
-    unlink(file);
-}
-
-
-/* ===========================================================================
- * Uncompress the given file and remove the original.
- */
-void file_uncompress(file)
-    char  *file;
-{
-    local char buf[MAX_NAME_LEN];
-    char *infile, *outfile;
-    FILE  *out;
-    gzFile in;
-    size_t len = strlen(file);
-
-    if (len + strlen(GZ_SUFFIX) >= sizeof(buf)) {
-        fprintf(stderr, "%s: filename too long\n", prog);
-        exit(1);
-    }
-
-    strcpy(buf, file);
-
-    if (len > SUFFIX_LEN && strcmp(file+len-SUFFIX_LEN, GZ_SUFFIX) == 0) {
-        infile = file;
-        outfile = buf;
-        outfile[len-3] = '\0';
-    } else {
-        outfile = file;
-        infile = buf;
-        strcat(infile, GZ_SUFFIX);
-    }
-    in = gzopen(infile, "rb");
-    if (in == NULL) {
-        fprintf(stderr, "%s: can't gzopen %s\n", prog, infile);
-        exit(1);
-    }
-    out = fopen(outfile, "wb");
-    if (out == NULL) {
-        perror(file);
-        exit(1);
-    }
-
-    gz_uncompress(in, out);
-
-    unlink(infile);
-}
-
-
-/* ===========================================================================
- * Usage:  minigzip [-c] [-d] [-f] [-h] [-r] [-1 to -9] [files...]
- *   -c : write to standard output
- *   -d : decompress
- *   -f : compress with Z_FILTERED
- *   -h : compress with Z_HUFFMAN_ONLY
- *   -r : compress with Z_RLE
- *   -1 to -9 : compression level
- */
-
-int main(argc, argv)
-    int argc;
-    char *argv[];
-{
-    int copyout = 0;
-    int uncompr = 0;
-    gzFile file;
-    char *bname, outmode[20];
-
-    strcpy(outmode, "wb6 ");
-
-    prog = argv[0];
-    bname = strrchr(argv[0], '/');
-    if (bname)
-      bname++;
-    else
-      bname = argv[0];
-    argc--, argv++;
-
-    if (!strcmp(bname, "gunzip"))
-      uncompr = 1;
-    else if (!strcmp(bname, "zcat"))
-      copyout = uncompr = 1;
-
-    while (argc > 0) {
-      if (strcmp(*argv, "-c") == 0)
-        copyout = 1;
-      else if (strcmp(*argv, "-d") == 0)
-        uncompr = 1;
-      else if (strcmp(*argv, "-f") == 0)
-        outmode[3] = 'f';
-      else if (strcmp(*argv, "-h") == 0)
-        outmode[3] = 'h';
-      else if (strcmp(*argv, "-r") == 0)
-        outmode[3] = 'R';
-      else if ((*argv)[0] == '-' && (*argv)[1] >= '1' && (*argv)[1] <= '9' &&
-               (*argv)[2] == 0)
-        outmode[2] = (*argv)[1];
-      else
-        break;
-      argc--, argv++;
-    }
-    if (outmode[3] == ' ')
-        outmode[3] = 0;
-    if (argc == 0) {
-        SET_BINARY_MODE(stdin);
-        SET_BINARY_MODE(stdout);
-        if (uncompr) {
-            file = gzdopen(fileno(stdin), "rb");
-            if (file == NULL) error("can't gzdopen stdin");
-            gz_uncompress(file, stdout);
-        } else {
-            file = gzdopen(fileno(stdout), outmode);
-            if (file == NULL) error("can't gzdopen stdout");
-            gz_compress(stdin, file);
-        }
-    } else {
-        if (copyout) {
-            SET_BINARY_MODE(stdout);
-        }
-        do {
-            if (uncompr) {
-                if (copyout) {
-                    file = gzopen(*argv, "rb");
-                    if (file == NULL)
-                        fprintf(stderr, "%s: can't gzopen %s\n", prog, *argv);
-                    else
-                        gz_uncompress(file, stdout);
-                } else {
-                    file_uncompress(*argv);
-                }
-            } else {
-                if (copyout) {
-                    FILE * in = fopen(*argv, "rb");
-
-                    if (in == NULL) {
-                        perror(*argv);
-                    } else {
-                        file = gzdopen(fileno(stdout), outmode);
-                        if (file == NULL) error("can't gzdopen stdout");
-
-                        gz_compress(in, file);
-                    }
-
-                } else {
-                    file_compress(*argv, outmode);
-                }
-            }
-        } while (argv++, --argc);
-    }
-    return 0;
-}
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libz/test/example.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/lib/libz/test/example.c	Wed Jul 25 16:23:00 2012 +0300
@@ -0,0 +1,601 @@
+/* example.c -- usage example of the zlib compression library
+ * Copyright (C) 1995-2006, 2011 Jean-loup Gailly.
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* @(#) $Id$ */
+
+#include "zlib.h"
+#include <stdio.h>
+
+#ifdef STDC
+#  include <string.h>
+#  include <stdlib.h>
+#endif
+
+#if defined(VMS) || defined(RISCOS)
+#  define TESTFILE "foo-gz"
+#else
+#  define TESTFILE "foo.gz"
+#endif
+
+#define CHECK_ERR(err, msg) { \
+    if (err != Z_OK) { \
+        fprintf(stderr, "%s error: %d\n", msg, err); \
+        exit(1); \
+    } \
+}
+
+const char hello[] = "hello, hello!";
+/* "hello world" would be more standard, but the repeated "hello"
+ * stresses the compression code better, sorry...
+ */
+
+const char dictionary[] = "hello";
+uLong dictId; /* Adler32 value of the dictionary */
+
+void test_deflate       OF((Byte *compr, uLong comprLen));
+void test_inflate       OF((Byte *compr, uLong comprLen,
+                            Byte *uncompr, uLong uncomprLen));
+void test_large_deflate OF((Byte *compr, uLong comprLen,
+                            Byte *uncompr, uLong uncomprLen));
+void test_large_inflate OF((Byte *compr, uLong comprLen,
+                            Byte *uncompr, uLong uncomprLen));
+void test_flush         OF((Byte *compr, uLong *comprLen));
+void test_sync          OF((Byte *compr, uLong comprLen,
+                            Byte *uncompr, uLong uncomprLen));
+void test_dict_deflate  OF((Byte *compr, uLong comprLen));
+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()
+ */
+void test_compress(compr, comprLen, uncompr, uncomprLen)
+    Byte *compr, *uncompr;
+    uLong comprLen, uncomprLen;
+{
+    int err;
+    uLong len = (uLong)strlen(hello)+1;
+
+    err = compress(compr, &comprLen, (const Bytef*)hello, len);
+    CHECK_ERR(err, "compress");
+
+    strcpy((char*)uncompr, "garbage");
+
+    err = uncompress(uncompr, &uncomprLen, compr, comprLen);
+    CHECK_ERR(err, "uncompress");
+
+    if (strcmp((char*)uncompr, hello)) {
+        fprintf(stderr, "bad uncompress\n");
+        exit(1);
+    } else {
+        printf("uncompress(): %s\n", (char *)uncompr);
+    }
+}
+
+/* ===========================================================================
+ * Test read/write of .gz files
+ */
+void test_gzio(fname, uncompr, uncomprLen)
+    const char *fname; /* compressed file name */
+    Byte *uncompr;
+    uLong uncomprLen;
+{
+#ifdef NO_GZCOMPRESS
+    fprintf(stderr, "NO_GZCOMPRESS -- gz* functions cannot compress\n");
+#else
+    int err;
+    int len = (int)strlen(hello)+1;
+    gzFile file;
+    z_off_t pos;
+
+    file = gzopen(fname, "wb");
+    if (file == NULL) {
+        fprintf(stderr, "gzopen error\n");
+        exit(1);
+    }
+    gzputc(file, 'h');
+    if (gzputs(file, "ello") != 4) {
+        fprintf(stderr, "gzputs err: %s\n", gzerror(file, &err));
+        exit(1);
+    }
+    if (gzprintf(file, ", %s!", "hello") != 8) {
+        fprintf(stderr, "gzprintf err: %s\n", gzerror(file, &err));
+        exit(1);
+    }
+    gzseek(file, 1L, SEEK_CUR); /* add one zero byte */
+    gzclose(file);
+
+    file = gzopen(fname, "rb");
+    if (file == NULL) {
+        fprintf(stderr, "gzopen error\n");
+        exit(1);
+    }
+    strcpy((char*)uncompr, "garbage");
+
+    if (gzread(file, uncompr, (unsigned)uncomprLen) != len) {
+        fprintf(stderr, "gzread err: %s\n", gzerror(file, &err));
+        exit(1);
+    }
+    if (strcmp((char*)uncompr, hello)) {
+        fprintf(stderr, "bad gzread: %s\n", (char*)uncompr);
+        exit(1);
+    } else {
+        printf("gzread(): %s\n", (char*)uncompr);
+    }
+
+    pos = gzseek(file, -8L, SEEK_CUR);
+    if (pos != 6 || gztell(file) != pos) {
+        fprintf(stderr, "gzseek error, pos=%ld, gztell=%ld\n",
+                (long)pos, (long)gztell(file));
+        exit(1);
+    }
+
+    if (gzgetc(file) != ' ') {
+        fprintf(stderr, "gzgetc error\n");
+        exit(1);
+    }
+
+    if (gzungetc(' ', file) != ' ') {
+        fprintf(stderr, "gzungetc error\n");
+        exit(1);
+    }
+
+    gzgets(file, (char*)uncompr, (int)uncomprLen);
+    if (strlen((char*)uncompr) != 7) { /* " hello!" */
+        fprintf(stderr, "gzgets err after gzseek: %s\n", gzerror(file, &err));
+        exit(1);
+    }
+    if (strcmp((char*)uncompr, hello + 6)) {
+        fprintf(stderr, "bad gzgets after gzseek\n");
+        exit(1);
+    } else {
+        printf("gzgets() after gzseek: %s\n", (char*)uncompr);
+    }
+
+    gzclose(file);
+#endif
+}
+
+#endif /* Z_SOLO */
+
+/* ===========================================================================
+ * Test deflate() with small buffers
+ */
+void test_deflate(compr, comprLen)
+    Byte *compr;
+    uLong comprLen;
+{
+    z_stream c_stream; /* compression stream */
+    int err;
+    uLong len = (uLong)strlen(hello)+1;
+
+    c_stream.zalloc = zalloc;
+    c_stream.zfree = zfree;
+    c_stream.opaque = (voidpf)0;
+
+    err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
+    CHECK_ERR(err, "deflateInit");
+
+    c_stream.next_in  = (Bytef*)hello;
+    c_stream.next_out = compr;
+
+    while (c_stream.total_in != len && c_stream.total_out < comprLen) {
+        c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */
+        err = deflate(&c_stream, Z_NO_FLUSH);
+        CHECK_ERR(err, "deflate");
+    }
+    /* Finish the stream, still forcing small buffers: */
+    for (;;) {
+        c_stream.avail_out = 1;
+        err = deflate(&c_stream, Z_FINISH);
+        if (err == Z_STREAM_END) break;
+        CHECK_ERR(err, "deflate");
+    }
+
+    err = deflateEnd(&c_stream);
+    CHECK_ERR(err, "deflateEnd");
+}
+
+/* ===========================================================================
+ * Test inflate() with small buffers
+ */
+void test_inflate(compr, comprLen, uncompr, uncomprLen)
+    Byte *compr, *uncompr;
+    uLong comprLen, uncomprLen;
+{
+    int err;
+    z_stream d_stream; /* decompression stream */
+
+    strcpy((char*)uncompr, "garbage");
+
+    d_stream.zalloc = zalloc;
+    d_stream.zfree = zfree;
+    d_stream.opaque = (voidpf)0;
+
+    d_stream.next_in  = compr;
+    d_stream.avail_in = 0;
+    d_stream.next_out = uncompr;
+
+    err = inflateInit(&d_stream);
+    CHECK_ERR(err, "inflateInit");
+
+    while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen) {
+        d_stream.avail_in = d_stream.avail_out = 1; /* force small buffers */
+        err = inflate(&d_stream, Z_NO_FLUSH);
+        if (err == Z_STREAM_END) break;
+        CHECK_ERR(err, "inflate");
+    }
+
+    err = inflateEnd(&d_stream);
+    CHECK_ERR(err, "inflateEnd");
+
+    if (strcmp((char*)uncompr, hello)) {
+        fprintf(stderr, "bad inflate\n");
+        exit(1);
+    } else {
+        printf("inflate(): %s\n", (char *)uncompr);
+    }
+}
+
+/* ===========================================================================
+ * Test deflate() with large buffers and dynamic change of compression level
+ */
+void test_large_deflate(compr, comprLen, uncompr, uncomprLen)
+    Byte *compr, *uncompr;
+    uLong comprLen, uncomprLen;
+{
+    z_stream c_stream; /* compression stream */
+    int err;
+
+    c_stream.zalloc = zalloc;
+    c_stream.zfree = zfree;
+    c_stream.opaque = (voidpf)0;
+
+    err = deflateInit(&c_stream, Z_BEST_SPEED);
+    CHECK_ERR(err, "deflateInit");
+
+    c_stream.next_out = compr;
+    c_stream.avail_out = (uInt)comprLen;
+
+    /* At this point, uncompr is still mostly zeroes, so it should compress
+     * very well:
+     */
+    c_stream.next_in = uncompr;
+    c_stream.avail_in = (uInt)uncomprLen;
+    err = deflate(&c_stream, Z_NO_FLUSH);
+    CHECK_ERR(err, "deflate");
+    if (c_stream.avail_in != 0) {
+        fprintf(stderr, "deflate not greedy\n");
+        exit(1);
+    }
+
+    /* Feed in already compressed data and switch to no compression: */
+    deflateParams(&c_stream, Z_NO_COMPRESSION, Z_DEFAULT_STRATEGY);
+    c_stream.next_in = compr;
+    c_stream.avail_in = (uInt)comprLen/2;
+    err = deflate(&c_stream, Z_NO_FLUSH);
+    CHECK_ERR(err, "deflate");
+
+    /* Switch back to compressing mode: */
+    deflateParams(&c_stream, Z_BEST_COMPRESSION, Z_FILTERED);
+    c_stream.next_in = uncompr;
+    c_stream.avail_in = (uInt)uncomprLen;
+    err = deflate(&c_stream, Z_NO_FLUSH);
+    CHECK_ERR(err, "deflate");
+
+    err = deflate(&c_stream, Z_FINISH);
+    if (err != Z_STREAM_END) {
+        fprintf(stderr, "deflate should report Z_STREAM_END\n");
+        exit(1);
+    }
+    err = deflateEnd(&c_stream);
+    CHECK_ERR(err, "deflateEnd");
+}
+
+/* ===========================================================================
+ * Test inflate() with large buffers
+ */
+void test_large_inflate(compr, comprLen, uncompr, uncomprLen)
+    Byte *compr, *uncompr;
+    uLong comprLen, uncomprLen;
+{
+    int err;
+    z_stream d_stream; /* decompression stream */
+
+    strcpy((char*)uncompr, "garbage");
+
+    d_stream.zalloc = zalloc;
+    d_stream.zfree = zfree;
+    d_stream.opaque = (voidpf)0;
+
+    d_stream.next_in  = compr;
+    d_stream.avail_in = (uInt)comprLen;
+
+    err = inflateInit(&d_stream);
+    CHECK_ERR(err, "inflateInit");
+
+    for (;;) {
+        d_stream.next_out = uncompr;            /* discard the output */
+        d_stream.avail_out = (uInt)uncomprLen;
+        err = inflate(&d_stream, Z_NO_FLUSH);
+        if (err == Z_STREAM_END) break;
+        CHECK_ERR(err, "large inflate");
+    }
+
+    err = inflateEnd(&d_stream);
+    CHECK_ERR(err, "inflateEnd");
+
+    if (d_stream.total_out != 2*uncomprLen + comprLen/2) {
+        fprintf(stderr, "bad large inflate: %ld\n", d_stream.total_out);
+        exit(1);
+    } else {
+        printf("large_inflate(): OK\n");
+    }
+}
+
+/* ===========================================================================
+ * Test deflate() with full flush
+ */
+void test_flush(compr, comprLen)
+    Byte *compr;
+    uLong *comprLen;
+{
+    z_stream c_stream; /* compression stream */
+    int err;
+    uInt len = (uInt)strlen(hello)+1;
+
+    c_stream.zalloc = zalloc;
+    c_stream.zfree = zfree;
+    c_stream.opaque = (voidpf)0;
+
+    err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
+    CHECK_ERR(err, "deflateInit");
+
+    c_stream.next_in  = (Bytef*)hello;
+    c_stream.next_out = compr;
+    c_stream.avail_in = 3;
+    c_stream.avail_out = (uInt)*comprLen;
+    err = deflate(&c_stream, Z_FULL_FLUSH);
+    CHECK_ERR(err, "deflate");
+
+    compr[3]++; /* force an error in first compressed block */
+    c_stream.avail_in = len - 3;
+
+    err = deflate(&c_stream, Z_FINISH);
+    if (err != Z_STREAM_END) {
+        CHECK_ERR(err, "deflate");
+    }
+    err = deflateEnd(&c_stream);
+    CHECK_ERR(err, "deflateEnd");
+
+    *comprLen = c_stream.total_out;
+}
+
+/* ===========================================================================
+ * Test inflateSync()
+ */
+void test_sync(compr, comprLen, uncompr, uncomprLen)
+    Byte *compr, *uncompr;
+    uLong comprLen, uncomprLen;
+{
+    int err;
+    z_stream d_stream; /* decompression stream */
+
+    strcpy((char*)uncompr, "garbage");
+
+    d_stream.zalloc = zalloc;
+    d_stream.zfree = zfree;
+    d_stream.opaque = (voidpf)0;
+
+    d_stream.next_in  = compr;
+    d_stream.avail_in = 2; /* just read the zlib header */
+
+    err = inflateInit(&d_stream);
+    CHECK_ERR(err, "inflateInit");
+
+    d_stream.next_out = uncompr;
+    d_stream.avail_out = (uInt)uncomprLen;
+
+    inflate(&d_stream, Z_NO_FLUSH);
+    CHECK_ERR(err, "inflate");
+
+    d_stream.avail_in = (uInt)comprLen-2;   /* read all compressed data */
+    err = inflateSync(&d_stream);           /* but skip the damaged part */
+    CHECK_ERR(err, "inflateSync");
+
+    err = inflate(&d_stream, Z_FINISH);
+    if (err != Z_DATA_ERROR) {
+        fprintf(stderr, "inflate should report DATA_ERROR\n");
+        /* Because of incorrect adler32 */
+        exit(1);
+    }
+    err = inflateEnd(&d_stream);
+    CHECK_ERR(err, "inflateEnd");
+
+    printf("after inflateSync(): hel%s\n", (char *)uncompr);
+}
+
+/* ===========================================================================
+ * Test deflate() with preset dictionary
+ */
+void test_dict_deflate(compr, comprLen)
+    Byte *compr;
+    uLong comprLen;
+{
+    z_stream c_stream; /* compression stream */
+    int err;
+
+    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, (int)sizeof(dictionary));
+    CHECK_ERR(err, "deflateSetDictionary");
+
+    dictId = c_stream.adler;
+    c_stream.next_out = compr;
+    c_stream.avail_out = (uInt)comprLen;
+
+    c_stream.next_in = (Bytef*)hello;
+    c_stream.avail_in = (uInt)strlen(hello)+1;
+
+    err = deflate(&c_stream, Z_FINISH);
+    if (err != Z_STREAM_END) {
+        fprintf(stderr, "deflate should report Z_STREAM_END\n");
+        exit(1);
+    }
+    err = deflateEnd(&c_stream);
+    CHECK_ERR(err, "deflateEnd");
+}
+
+/* ===========================================================================
+ * Test inflate() with a preset dictionary
+ */
+void test_dict_inflate(compr, comprLen, uncompr, uncomprLen)
+    Byte *compr, *uncompr;
+    uLong comprLen, uncomprLen;
+{
+    int err;
+    z_stream d_stream; /* decompression stream */
+
+    strcpy((char*)uncompr, "garbage");
+
+    d_stream.zalloc = zalloc;
+    d_stream.zfree = zfree;
+    d_stream.opaque = (voidpf)0;
+
+    d_stream.next_in  = compr;
+    d_stream.avail_in = (uInt)comprLen;
+
+    err = inflateInit(&d_stream);
+    CHECK_ERR(err, "inflateInit");
+
+    d_stream.next_out = uncompr;
+    d_stream.avail_out = (uInt)uncomprLen;
+
+    for (;;) {
+        err = inflate(&d_stream, Z_NO_FLUSH);
+        if (err == Z_STREAM_END) break;
+        if (err == Z_NEED_DICT) {
+            if (d_stream.adler != dictId) {
+                fprintf(stderr, "unexpected dictionary");
+                exit(1);
+            }
+            err = inflateSetDictionary(&d_stream, (const Bytef*)dictionary,
+                                       (int)sizeof(dictionary));
+        }
+        CHECK_ERR(err, "inflate with dict");
+    }
+
+    err = inflateEnd(&d_stream);
+    CHECK_ERR(err, "inflateEnd");
+
+    if (strcmp((char*)uncompr, hello)) {
+        fprintf(stderr, "bad inflate with dict\n");
+        exit(1);
+    } else {
+        printf("inflate with dictionary: %s\n", (char *)uncompr);
+    }
+}
+
+/* ===========================================================================
+ * Usage:  example [output.gz  [input.gz]]
+ */
+
+int main(argc, argv)
+    int argc;
+    char *argv[];
+{
+    Byte *compr, *uncompr;
+    uLong comprLen = 10000*sizeof(int); /* don't overflow on MSDOS */
+    uLong uncomprLen = comprLen;
+    static const char* myVersion = ZLIB_VERSION;
+
+    if (zlibVersion()[0] != myVersion[0]) {
+        fprintf(stderr, "incompatible zlib version\n");
+        exit(1);
+
+    } else if (strcmp(zlibVersion(), ZLIB_VERSION) != 0) {
+        fprintf(stderr, "warning: different zlib version\n");
+    }
+
+    printf("zlib version %s = 0x%04x, compile flags = 0x%lx\n",
+            ZLIB_VERSION, ZLIB_VERNUM, zlibCompileFlags());
+
+    compr    = (Byte*)calloc((uInt)comprLen, 1);
+    uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
+    /* compr and uncompr are cleared to avoid reading uninitialized
+     * data and to ensure that uncompr compresses well.
+     */
+    if (compr == Z_NULL || uncompr == Z_NULL) {
+        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);
+
+    test_large_deflate(compr, comprLen, uncompr, uncomprLen);
+    test_large_inflate(compr, comprLen, uncompr, uncomprLen);
+
+    test_flush(compr, &comprLen);
+    test_sync(compr, comprLen, uncompr, uncomprLen);
+    comprLen = uncomprLen;
+
+    test_dict_deflate(compr, comprLen);
+    test_dict_inflate(compr, comprLen, uncompr, uncomprLen);
+
+    free(compr);
+    free(uncompr);
+
+    return 0;
+}
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libz/test/infcover.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/lib/libz/test/infcover.c	Wed Jul 25 16:23:00 2012 +0300
@@ -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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libz/test/minigzip.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/lib/libz/test/minigzip.c	Wed Jul 25 16:23:00 2012 +0300
@@ -0,0 +1,631 @@
+/* minigzip.c -- simulate gzip using the zlib compression library
+ * Copyright (C) 1995-2006, 2010, 2011 Jean-loup Gailly.
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/*
+ * minigzip is a minimal implementation of the gzip utility. This is
+ * only an example of using zlib and isn't meant to replace the
+ * full-featured gzip. No attempt is made to deal with file systems
+ * limiting names to 14 or 8+3 characters, etc... Error checking is
+ * very limited. So use minigzip only for testing; use gzip for the
+ * real thing. On MSDOS, use only on file names without extension
+ * or in pipe mode.
+ */
+
+/* @(#) $Id$ */
+
+#include "zlib.h"
+#include <stdio.h>
+
+#ifdef STDC
+#  include <string.h>
+#  include <stdlib.h>
+#endif
+
+#ifdef USE_MMAP
+#  include <sys/types.h>
+#  include <sys/mman.h>
+#  include <sys/stat.h>
+#endif
+
+#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
+#  include <fcntl.h>
+#  include <io.h>
+#  ifdef UNDER_CE
+#    include <stdlib.h>
+#  endif
+#  define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
+#else
+#  define SET_BINARY_MODE(file)
+#endif
+
+#ifdef VMS
+#  define unlink delete
+#  define GZ_SUFFIX "-gz"
+#endif
+#ifdef RISCOS
+#  define unlink remove
+#  define GZ_SUFFIX "-gz"
+#  define fileno(file) file->__file
+#endif
+#if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
+#  include <unix.h> /* for fileno */
+#endif
+
+#if !defined(Z_HAVE_UNISTD_H) && !defined(_LARGEFILE64_SOURCE)
+#ifndef WIN32 /* unlink already in stdio.h for WIN32 */
+  extern int unlink OF((const char *));
+#endif
+#endif
+
+#if defined(UNDER_CE)
+#  include <windows.h>
+#  define perror(s) pwinerror(s)
+
+/* Map the Windows error number in ERROR to a locale-dependent error
+   message string and return a pointer to it.  Typically, the values
+   for ERROR come from GetLastError.
+
+   The string pointed to shall not be modified by the application,
+   but may be overwritten by a subsequent call to strwinerror
+
+   The strwinerror function does not change the current setting
+   of GetLastError.  */
+
+static char *strwinerror (error)
+     DWORD error;
+{
+    static char buf[1024];
+
+    wchar_t *msgbuf;
+    DWORD lasterr = GetLastError();
+    DWORD chars = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
+        | FORMAT_MESSAGE_ALLOCATE_BUFFER,
+        NULL,
+        error,
+        0, /* Default language */
+        (LPVOID)&msgbuf,
+        0,
+        NULL);
+    if (chars != 0) {
+        /* If there is an \r\n appended, zap it.  */
+        if (chars >= 2
+            && msgbuf[chars - 2] == '\r' && msgbuf[chars - 1] == '\n') {
+            chars -= 2;
+            msgbuf[chars] = 0;
+        }
+
+        if (chars > sizeof (buf) - 1) {
+            chars = sizeof (buf) - 1;
+            msgbuf[chars] = 0;
+        }
+
+        wcstombs(buf, msgbuf, chars + 1);
+        LocalFree(msgbuf);
+    }
+    else {
+        sprintf(buf, "unknown win32 error (%ld)", error);
+    }
+
+    SetLastError(lasterr);
+    return buf;
+}
+
+static void pwinerror (s)
+    const char *s;
+{
+    if (s && *s)
+        fprintf(stderr, "%s: %s\n", s, strwinerror(GetLastError ()));
+    else
+        fprintf(stderr, "%s\n", strwinerror(GetLastError ()));
+}
+
+#endif /* UNDER_CE */
+
+#ifndef GZ_SUFFIX
+#  define GZ_SUFFIX ".gz"
+#endif
+#define SUFFIX_LEN (sizeof(GZ_SUFFIX)-1)
+
+#define BUFLEN      16384
+#define MAX_NAME_LEN 1024
+
+#ifdef MAXSEG_64K
+#  define local static
+   /* Needed for systems with limitation on stack size. */
+#else
+#  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));
+void gz_compress      OF((FILE   *in, gzFile out));
+#ifdef USE_MMAP
+int  gz_compress_mmap OF((FILE   *in, gzFile out));
+#endif
+void gz_uncompress    OF((gzFile in, FILE   *out));
+void file_compress    OF((char  *file, char *mode));
+void file_uncompress  OF((char  *file));
+int  main             OF((int argc, char *argv[]));
+
+/* ===========================================================================
+ * Display error message and exit
+ */
+void error(msg)
+    const char *msg;
+{
+    fprintf(stderr, "%s: %s\n", prog, msg);
+    exit(1);
+}
+
+/* ===========================================================================
+ * Compress input to output then close both files.
+ */
+
+void gz_compress(in, out)
+    FILE   *in;
+    gzFile out;
+{
+    local char buf[BUFLEN];
+    int len;
+    int err;
+
+#ifdef USE_MMAP
+    /* Try first compressing with mmap. If mmap fails (minigzip used in a
+     * pipe), use the normal fread loop.
+     */
+    if (gz_compress_mmap(in, out) == Z_OK) return;
+#endif
+    for (;;) {
+        len = (int)fread(buf, 1, sizeof(buf), in);
+        if (ferror(in)) {
+            perror("fread");
+            exit(1);
+        }
+        if (len == 0) break;
+
+        if (gzwrite(out, buf, (unsigned)len) != len) error(gzerror(out, &err));
+    }
+    fclose(in);
+    if (gzclose(out) != Z_OK) error("failed gzclose");
+}
+
+#ifdef USE_MMAP /* MMAP version, Miguel Albrecht <malbrech at eso.org> */
+
+/* Try compressing the input file at once using mmap. Return Z_OK if
+ * if success, Z_ERRNO otherwise.
+ */
+int gz_compress_mmap(in, out)
+    FILE   *in;
+    gzFile out;
+{
+    int len;
+    int err;
+    int ifd = fileno(in);
+    caddr_t buf;    /* mmap'ed buffer for the entire input file */
+    off_t buf_len;  /* length of the input file */
+    struct stat sb;
+
+    /* Determine the size of the file, needed for mmap: */
+    if (fstat(ifd, &sb) < 0) return Z_ERRNO;
+    buf_len = sb.st_size;
+    if (buf_len <= 0) return Z_ERRNO;
+
+    /* Now do the actual mmap: */
+    buf = mmap((caddr_t) 0, buf_len, PROT_READ, MAP_SHARED, ifd, (off_t)0);
+    if (buf == (caddr_t)(-1)) return Z_ERRNO;
+
+    /* Compress the whole file at once: */
+    len = gzwrite(out, (char *)buf, (unsigned)buf_len);
+
+    if (len != (int)buf_len) error(gzerror(out, &err));
+
+    munmap(buf, buf_len);
+    fclose(in);
+    if (gzclose(out) != Z_OK) error("failed gzclose");
+    return Z_OK;
+}
+#endif /* USE_MMAP */
+
+/* ===========================================================================
+ * Uncompress input to output then close both files.
+ */
+void gz_uncompress(in, out)
+    gzFile in;
+    FILE   *out;
+{
+    local char buf[BUFLEN];
+    int len;
+    int err;
+
+    for (;;) {
+        len = gzread(in, buf, sizeof(buf));
+        if (len < 0) error (gzerror(in, &err));
+        if (len == 0) break;
+
+        if ((int)fwrite(buf, 1, (unsigned)len, out) != len) {
+            error("failed fwrite");
+        }
+    }
+    if (fclose(out)) error("failed fclose");
+
+    if (gzclose(in) != Z_OK) error("failed gzclose");
+}
+
+
+/* ===========================================================================
+ * Compress the given file: create a corresponding .gz file and remove the
+ * original.
+ */
+void file_compress(file, mode)
+    char  *file;
+    char  *mode;
+{
+    local char outfile[MAX_NAME_LEN];
+    FILE  *in;
+    gzFile out;
+
+    if (strlen(file) + strlen(GZ_SUFFIX) >= sizeof(outfile)) {
+        fprintf(stderr, "%s: filename too long\n", prog);
+        exit(1);
+    }
+
+    strcpy(outfile, file);
+    strcat(outfile, GZ_SUFFIX);
+
+    in = fopen(file, "rb");
+    if (in == NULL) {
+        perror(file);
+        exit(1);
+    }
+    out = gzopen(outfile, mode);
+    if (out == NULL) {
+        fprintf(stderr, "%s: can't gzopen %s\n", prog, outfile);
+        exit(1);
+    }
+    gz_compress(in, out);
+
+    unlink(file);
+}
+
+
+/* ===========================================================================
+ * Uncompress the given file and remove the original.
+ */
+void file_uncompress(file)
+    char  *file;
+{
+    local char buf[MAX_NAME_LEN];
+    char *infile, *outfile;
+    FILE  *out;
+    gzFile in;
+    size_t len = strlen(file);
+
+    if (len + strlen(GZ_SUFFIX) >= sizeof(buf)) {
+        fprintf(stderr, "%s: filename too long\n", prog);
+        exit(1);
+    }
+
+    strcpy(buf, file);
+
+    if (len > SUFFIX_LEN && strcmp(file+len-SUFFIX_LEN, GZ_SUFFIX) == 0) {
+        infile = file;
+        outfile = buf;
+        outfile[len-3] = '\0';
+    } else {
+        outfile = file;
+        infile = buf;
+        strcat(infile, GZ_SUFFIX);
+    }
+    in = gzopen(infile, "rb");
+    if (in == NULL) {
+        fprintf(stderr, "%s: can't gzopen %s\n", prog, infile);
+        exit(1);
+    }
+    out = fopen(outfile, "wb");
+    if (out == NULL) {
+        perror(file);
+        exit(1);
+    }
+
+    gz_uncompress(in, out);
+
+    unlink(infile);
+}
+
+
+/* ===========================================================================
+ * Usage:  minigzip [-c] [-d] [-f] [-h] [-r] [-1 to -9] [files...]
+ *   -c : write to standard output
+ *   -d : decompress
+ *   -f : compress with Z_FILTERED
+ *   -h : compress with Z_HUFFMAN_ONLY
+ *   -r : compress with Z_RLE
+ *   -1 to -9 : compression level
+ */
+
+int main(argc, argv)
+    int argc;
+    char *argv[];
+{
+    int copyout = 0;
+    int uncompr = 0;
+    gzFile file;
+    char *bname, outmode[20];
+
+    strcpy(outmode, "wb6 ");
+
+    prog = argv[0];
+    bname = strrchr(argv[0], '/');
+    if (bname)
+      bname++;
+    else
+      bname = argv[0];
+    argc--, argv++;
+
+    if (!strcmp(bname, "gunzip"))
+      uncompr = 1;
+    else if (!strcmp(bname, "zcat"))
+      copyout = uncompr = 1;
+
+    while (argc > 0) {
+      if (strcmp(*argv, "-c") == 0)
+        copyout = 1;
+      else if (strcmp(*argv, "-d") == 0)
+        uncompr = 1;
+      else if (strcmp(*argv, "-f") == 0)
+        outmode[3] = 'f';
+      else if (strcmp(*argv, "-h") == 0)
+        outmode[3] = 'h';
+      else if (strcmp(*argv, "-r") == 0)
+        outmode[3] = 'R';
+      else if ((*argv)[0] == '-' && (*argv)[1] >= '1' && (*argv)[1] <= '9' &&
+               (*argv)[2] == 0)
+        outmode[2] = (*argv)[1];
+      else
+        break;
+      argc--, argv++;
+    }
+    if (outmode[3] == ' ')
+        outmode[3] = 0;
+    if (argc == 0) {
+        SET_BINARY_MODE(stdin);
+        SET_BINARY_MODE(stdout);
+        if (uncompr) {
+            file = gzdopen(fileno(stdin), "rb");
+            if (file == NULL) error("can't gzdopen stdin");
+            gz_uncompress(file, stdout);
+        } else {
+            file = gzdopen(fileno(stdout), outmode);
+            if (file == NULL) error("can't gzdopen stdout");
+            gz_compress(stdin, file);
+        }
+    } else {
+        if (copyout) {
+            SET_BINARY_MODE(stdout);
+        }
+        do {
+            if (uncompr) {
+                if (copyout) {
+                    file = gzopen(*argv, "rb");
+                    if (file == NULL)
+                        fprintf(stderr, "%s: can't gzopen %s\n", prog, *argv);
+                    else
+                        gz_uncompress(file, stdout);
+                } else {
+                    file_uncompress(*argv);
+                }
+            } else {
+                if (copyout) {
+                    FILE * in = fopen(*argv, "rb");
+
+                    if (in == NULL) {
+                        perror(*argv);
+                    } else {
+                        file = gzdopen(fileno(stdout), outmode);
+                        if (file == NULL) error("can't gzdopen stdout");
+
+                        gz_compress(in, file);
+                    }
+
+                } else {
+                    file_compress(*argv, outmode);
+                }
+            }
+        } while (argv++, --argc);
+    }
+    return 0;
+}
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libz/trees.c
--- a/head/lib/libz/trees.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libz/trees.c	Wed Jul 25 16:23:00 2012 +0300
@@ -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 @@
  * 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 @@
 
     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 @@
 }
 
 /* ===========================================================================
+ * 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 @@
     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 @@
     } while (lx < s->last_lit);
 
     send_code(s, END_BLOCK, ltree);
-    s->last_eob_len = ltree[END_BLOCK].Len;
 }
 
 /* ===========================================================================
@@ -1226,7 +1207,6 @@
     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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libz/zconf.h
--- a/head/lib/libz/zconf.h	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libz/zconf.h	Wed Jul 25 16:23:00 2012 +0300
@@ -1,9 +1,9 @@
 /* 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
  */
 
-/* @(#) $FreeBSD$ */
+/* @(#) $FreeBSD: head/lib/libz/zconf.h 237410 2012-06-21 21:47:08Z delphij $ */
 
 #ifndef ZCONF_H
 #define ZCONF_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 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 @@
  * 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 @@
 #  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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libz/zlib.3
--- a/head/lib/libz/zlib.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libz/zlib.3	Wed Jul 25 16:23:00 2012 +0300
@@ -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 @@
 .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 @@
 written by A.M. Kuchling (amk at 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 @@
 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 @@
 Send questions and/or comments to zlib at gzip.org,
 or (for the Windows DLL version) to Gilles Vollant (info at winimage.com).
 .SH AUTHORS
-Version 1.2.5
-Copyright (C) 1995-2010 Jean-loup Gailly (jloup at gzip.org)
+Version 1.2.7
+Copyright (C) 1995-2012 Jean-loup Gailly (jloup at gzip.org)
 and Mark Adler (madler at alumni.caltech.edu).
 .LP
 This software is provided "as-is,"
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libz/zlib.h
--- a/head/lib/libz/zlib.h	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libz/zlib.h	Wed Jul 25 16:23:00 2012 +0300
@@ -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 @@
 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 @@
 
     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 @@
   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 @@
   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 @@
                                              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 @@
      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,9 +702,29 @@
    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,
                                      int value));
@@ -703,8 +737,9 @@
    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 @@
    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 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 @@
      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 @@
      27-31: 0 (reserved)
  */
 
+#ifndef Z_SOLO
 
                         /* utility functions */
 
@@ -1149,10 +1190,11 @@
 
      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 @@
    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 @@
    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 @@
    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 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 @@
    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 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 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 @@
    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 @@
    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 @@
    file that is being written concurrently.
 */
 
+#endif /* !Z_SOLO */
 
                         /* checksum functions */
 
@@ -1492,16 +1575,17 @@
      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 @@
                                          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 @@
  * 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 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 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 @@
 /* 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libz/zopen.c
--- a/head/lib/libz/zopen.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libz/zopen.c	Wed Jul 25 16:23:00 2012 +0300
@@ -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 @@
     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 @@
 	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 -r d46effa10a19 -r 7449ca4973e7 head/lib/libz/zutil.c
--- a/head/lib/libz/zutil.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libz/zutil.c	Wed Jul 25 16:23:00 2012 +0300
@@ -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 @@
 #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 @@
 }
 #endif
 
+#ifndef Z_SOLO
 
 #ifdef SYS16BIT
 
@@ -316,3 +320,5 @@
 }
 
 #endif /* MY_ZCALLOC */
+
+#endif /* !Z_SOLO */
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/libz/zutil.h
--- a/head/lib/libz/zutil.h	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/libz/zutil.h	Wed Jul 25 16:23:00 2012 +0300
@@ -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 @@
 
 #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 @@
 
 #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 @@
 #  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 @@
 
          /* 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 @@
 #  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 -r d46effa10a19 -r 7449ca4973e7 head/lib/msun/Makefile
--- a/head/lib/msun/Makefile	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/msun/Makefile	Wed Jul 25 16:23:00 2012 +0300
@@ -1,5 +1,5 @@
 #  @(#)Makefile 5.1beta 93/09/24
-# $FreeBSD: head/lib/msun/Makefile 230192 2012-01-16 04:09:17Z das $
+# $FreeBSD: head/lib/msun/Makefile 238724 2012-07-23 19:23:49Z kargl $
 #
 #  ====================================================
 #  Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
@@ -94,7 +94,7 @@
 	e_hypotl.c e_remainderl.c e_sqrtl.c \
 	invtrig.c k_cosl.c k_sinl.c k_tanl.c \
 	s_atanl.c s_cbrtl.c s_ceill.c s_cosl.c s_cprojl.c \
-	s_csqrtl.c s_exp2l.c s_floorl.c s_fmal.c \
+	s_csqrtl.c s_exp2l.c s_expl.c s_floorl.c s_fmal.c \
 	s_frexpl.c s_logbl.c s_nanl.c s_nextafterl.c s_nexttoward.c \
 	s_remquol.c s_rintl.c s_scalbnl.c \
 	s_sinl.c s_tanl.c s_truncl.c w_cabsl.c
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/msun/Symbol.map
--- a/head/lib/msun/Symbol.map	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/msun/Symbol.map	Wed Jul 25 16:23:00 2012 +0300
@@ -1,5 +1,5 @@
 /*
- * $FreeBSD: head/lib/msun/Symbol.map 226458 2011-10-17 05:41:03Z das $
+ * $FreeBSD: head/lib/msun/Symbol.map 238722 2012-07-23 19:13:55Z kargl $
  */
 
 /* 7.0-CURRENT */
@@ -249,4 +249,5 @@
 	ctanf;
 	ctanh;
 	ctanhf;
+	expl;
 };
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/msun/ld128/s_expl.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/lib/msun/ld128/s_expl.c	Wed Jul 25 16:23:00 2012 +0300
@@ -0,0 +1,260 @@
+/*-
+ * Copyright (c) 2012 Steven G. Kargl
+ * 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 unmodified, 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 ``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 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: head/lib/msun/ld128/s_expl.c 238722 2012-07-23 19:13:55Z kargl $");
+
+#include <float.h>
+
+#include "math.h"
+#include "math_private.h"
+#include "fpmath.h"
+
+#define	BIAS	(LDBL_MAX_EXP - 1)
+#define	EXPMASK	(BIAS + LDBL_MAX_EXP)
+
+static volatile const long double twom10000 = 0x1p-10000L, tiny = 0x1p-10000L;
+
+static const long double
+huge = 0x1p10000L,
+o_threshold =  11356.523406294143949491931077970763428L,
+u_threshold = -11433.462743336297878837243843452621503L,
+L1 = 5.41521234812457272982212595914567508e-03L,
+L2 = -1.02536706388947310094527932552595546e-29L,
+INV_L = 1.84664965233787316142070359168242182e+02L;
+
+static const long double
+P2 = 5.00000000000000000000000000000000000e-1L,
+P3 = 1.66666666666666666666666666666666972e-1L,
+P4 = 4.16666666666666666666666666653708268e-2L,
+P5 = 8.33333333333333333333333315069867254e-3L,
+P6 = 1.38888888888888888888996596213795377e-3L,
+P7 = 1.98412698412698412718821436278644414e-4L,
+P8 = 2.48015873015869681884882576649543128e-5L,
+P9 = 2.75573192240103867817876199544468806e-6L,
+P10 = 2.75573236172670046201884000197885520e-7L,
+P11 = 2.50517544183909126492878226167697856e-8L;
+
+#define	NUM		128
+
+static const struct {
+	long double	hi;
+	long double	lo;
+} s[NUM] = {
+	0x1p0L, 0x0p0L,
+	0x1.0163da9fb33356d84a66aep0L, 0x3.36dcdfa4003ec04c360be2404078p-92L,
+	0x1.02c9a3e778060ee6f7cacap0L, 0x4.f7a29bde93d70a2cabc5cb89ba10p-92L,
+	0x1.04315e86e7f84bd738f9a2p0L, 0xd.a47e6ed040bb4bfc05af6455e9b8p-96L,
+	0x1.059b0d31585743ae7c548ep0L, 0xb.68ca417fe53e3495f7df4baf84a0p-92L,
+	0x1.0706b29ddf6ddc6dc403a8p0L, 0x1.d87b27ed07cb8b092ac75e311753p-88L,
+	0x1.0874518759bc808c35f25cp0L, 0x1.9427fa2b041b2d6829d8993a0d01p-88L,
+	0x1.09e3ecac6f3834521e060cp0L, 0x5.84d6b74ba2e023da730e7fccb758p-92L,
+	0x1.0b5586cf9890f6298b92b6p0L, 0x1.1842a98364291408b3ceb0a2a2bbp-88L,
+	0x1.0cc922b7247f7407b705b8p0L, 0x9.3dc5e8aac564e6fe2ef1d431fd98p-92L,
+	0x1.0e3ec32d3d1a2020742e4ep0L, 0x1.8af6a552ac4b358b1129e9f966a4p-88L,
+	0x1.0fb66affed31af232091dcp0L, 0x1.8a1426514e0b627bda694a400a27p-88L,
+	0x1.11301d0125b50a4ebbf1aep0L, 0xd.9318ceac5cc47ab166ee57427178p-92L,
+	0x1.12abdc06c31cbfb92bad32p0L, 0x4.d68e2f7270bdf7cedf94eb1cb818p-92L,
+	0x1.1429aaea92ddfb34101942p0L, 0x1.b2586d01844b389bea7aedd221d4p-88L,
+	0x1.15a98c8a58e512480d573cp0L, 0x1.d5613bf92a2b618ee31b376c2689p-88L,
+	0x1.172b83c7d517adcdf7c8c4p0L, 0x1.0eb14a792035509ff7d758693f24p-88L,
+	0x1.18af9388c8de9bbbf70b9ap0L, 0x3.c2505c97c0102e5f1211941d2840p-92L,
+	0x1.1a35beb6fcb753cb698f68p0L, 0x1.2d1c835a6c30724d5cfae31b84e5p-88L,
+	0x1.1bbe084045cd39ab1e72b4p0L, 0x4.27e35f9acb57e473915519a1b448p-92L,
+	0x1.1d4873168b9aa7805b8028p0L, 0x9.90f07a98b42206e46166cf051d70p-92L,
+	0x1.1ed5022fcd91cb8819ff60p0L, 0x1.121d1e504d36c47474c9b7de6067p-88L,
+	0x1.2063b88628cd63b8eeb028p0L, 0x1.50929d0fc487d21c2b84004264dep-88L,
+	0x1.21f49917ddc962552fd292p0L, 0x9.4bdb4b61ea62477caa1dce823ba0p-92L,
+	0x1.2387a6e75623866c1fadb0p0L, 0x1.c15cb593b0328566902df69e4de2p-88L,
+	0x1.251ce4fb2a63f3582ab7dep0L, 0x9.e94811a9c8afdcf796934bc652d0p-92L,
+	0x1.26b4565e27cdd257a67328p0L, 0x1.d3b249dce4e9186ddd5ff44e6b08p-92L,
+	0x1.284dfe1f5638096cf15cf0p0L, 0x3.ca0967fdaa2e52d7c8106f2e262cp-92L,
+	0x1.29e9df51fdee12c25d15f4p0L, 0x1.a24aa3bca890ac08d203fed80a07p-88L,
+	0x1.2b87fd0dad98ffddea4652p0L, 0x1.8fcab88442fdc3cb6de4519165edp-88L,
+	0x1.2d285a6e4030b40091d536p0L, 0xd.075384589c1cd1b3e4018a6b1348p-92L,
+	0x1.2ecafa93e2f5611ca0f45cp0L, 0x1.523833af611bdcda253c554cf278p-88L,
+	0x1.306fe0a31b7152de8d5a46p0L, 0x3.05c85edecbc27343629f502f1af2p-92L,
+	0x1.32170fc4cd8313539cf1c2p0L, 0x1.008f86dde3220ae17a005b6412bep-88L,
+	0x1.33c08b26416ff4c9c8610cp0L, 0x1.96696bf95d1593039539d94d662bp-88L,
+	0x1.356c55f929ff0c94623476p0L, 0x3.73af38d6d8d6f9506c9bbc93cbc0p-92L,
+	0x1.371a7373aa9caa7145502ep0L, 0x1.4547987e3e12516bf9c699be432fp-88L,
+	0x1.38cae6d05d86585a9cb0d8p0L, 0x1.bed0c853bd30a02790931eb2e8f0p-88L,
+	0x1.3a7db34e59ff6ea1bc9298p0L, 0x1.e0a1d336163fe2f852ceeb134067p-88L,
+	0x1.3c32dc313a8e484001f228p0L, 0xb.58f3775e06ab66353001fae9fca0p-92L,
+	0x1.3dea64c12342235b41223ep0L, 0x1.3d773fba2cb82b8244267c54443fp-92L,
+	0x1.3fa4504ac801ba0bf701aap0L, 0x4.1832fb8c1c8dbdff2c49909e6c60p-92L,
+	0x1.4160a21f72e29f84325b8ep0L, 0x1.3db61fb352f0540e6ba05634413ep-88L,
+	0x1.431f5d950a896dc7044394p0L, 0x1.0ccec81e24b0caff7581ef4127f7p-92L,
+	0x1.44e086061892d03136f408p0L, 0x1.df019fbd4f3b48709b78591d5cb5p-88L,
+	0x1.46a41ed1d005772512f458p0L, 0x1.229d97df404ff21f39c1b594d3a8p-88L,
+	0x1.486a2b5c13cd013c1a3b68p0L, 0x1.062f03c3dd75ce8757f780e6ec99p-88L,
+	0x1.4a32af0d7d3de672d8bcf4p0L, 0x6.f9586461db1d878b1d148bd3ccb8p-92L,
+	0x1.4bfdad5362a271d4397afep0L, 0xc.42e20e0363ba2e159c579f82e4b0p-92L,
+	0x1.4dcb299fddd0d63b36ef1ap0L, 0x9.e0cc484b25a5566d0bd5f58ad238p-92L,
+	0x1.4f9b2769d2ca6ad33d8b68p0L, 0x1.aa073ee55e028497a329a7333dbap-88L,
+	0x1.516daa2cf6641c112f52c8p0L, 0x4.d822190e718226177d7608d20038p-92L,
+	0x1.5342b569d4f81df0a83c48p0L, 0x1.d86a63f4e672a3e429805b049465p-88L,
+	0x1.551a4ca5d920ec52ec6202p0L, 0x4.34ca672645dc6c124d6619a87574p-92L,
+	0x1.56f4736b527da66ecb0046p0L, 0x1.64eb3c00f2f5ab3d801d7cc7272dp-88L,
+	0x1.58d12d497c7fd252bc2b72p0L, 0x1.43bcf2ec936a970d9cc266f0072fp-88L,
+	0x1.5ab07dd48542958c930150p0L, 0x1.91eb345d88d7c81280e069fbdb63p-88L,
+	0x1.5c9268a5946b701c4b1b80p0L, 0x1.6986a203d84e6a4a92f179e71889p-88L,
+	0x1.5e76f15ad21486e9be4c20p0L, 0x3.99766a06548a05829e853bdb2b52p-92L,
+	0x1.605e1b976dc08b076f592ap0L, 0x4.86e3b34ead1b4769df867b9c89ccp-92L,
+	0x1.6247eb03a5584b1f0fa06ep0L, 0x1.d2da42bb1ceaf9f732275b8aef30p-88L,
+	0x1.6434634ccc31fc76f8714cp0L, 0x4.ed9a4e41000307103a18cf7a6e08p-92L,
+	0x1.66238825522249127d9e28p0L, 0x1.b8f314a337f4dc0a3adf1787ff74p-88L,
+	0x1.68155d44ca973081c57226p0L, 0x1.b9f32706bfe4e627d809a85dcc66p-88L,
+	0x1.6a09e667f3bcc908b2fb12p0L, 0x1.66ea957d3e3adec17512775099dap-88L,
+	0x1.6c012750bdabeed76a9980p0L, 0xf.4f33fdeb8b0ecd831106f57b3d00p-96L,
+	0x1.6dfb23c651a2ef220e2cbep0L, 0x1.bbaa834b3f11577ceefbe6c1c411p-92L,
+	0x1.6ff7df9519483cf87e1b4ep0L, 0x1.3e213bff9b702d5aa477c12523cep-88L,
+	0x1.71f75e8ec5f73dd2370f2ep0L, 0xf.0acd6cb434b562d9e8a20adda648p-92L,
+	0x1.73f9a48a58173bd5c9a4e6p0L, 0x8.ab1182ae217f3a7681759553e840p-92L,
+	0x1.75feb564267c8bf6e9aa32p0L, 0x1.a48b27071805e61a17b954a2dad8p-88L,
+	0x1.780694fde5d3f619ae0280p0L, 0x8.58b2bb2bdcf86cd08e35fb04c0f0p-92L,
+	0x1.7a11473eb0186d7d51023ep0L, 0x1.6cda1f5ef42b66977960531e821bp-88L,
+	0x1.7c1ed0130c1327c4933444p0L, 0x1.937562b2dc933d44fc828efd4c9cp-88L,
+	0x1.7e2f336cf4e62105d02ba0p0L, 0x1.5797e170a1427f8fcdf5f3906108p-88L,
+	0x1.80427543e1a11b60de6764p0L, 0x9.a354ea706b8e4d8b718a672bf7c8p-92L,
+	0x1.82589994cce128acf88afap0L, 0xb.34a010f6ad65cbbac0f532d39be0p-92L,
+	0x1.8471a4623c7acce52f6b96p0L, 0x1.c64095370f51f48817914dd78665p-88L,
+	0x1.868d99b4492ec80e41d90ap0L, 0xc.251707484d73f136fb5779656b70p-92L,
+	0x1.88ac7d98a669966530bcdep0L, 0x1.2d4e9d61283ef385de170ab20f96p-88L,
+	0x1.8ace5422aa0db5ba7c55a0p0L, 0x1.92c9bb3e6ed61f2733304a346d8fp-88L,
+	0x1.8cf3216b5448bef2aa1cd0p0L, 0x1.61c55d84a9848f8c453b3ca8c946p-88L,
+	0x1.8f1ae991577362b982745cp0L, 0x7.2ed804efc9b4ae1458ae946099d4p-92L,
+	0x1.9145b0b91ffc588a61b468p0L, 0x1.f6b70e01c2a90229a4c4309ea719p-88L,
+	0x1.93737b0cdc5e4f4501c3f2p0L, 0x5.40a22d2fc4af581b63e8326efe9cp-92L,
+	0x1.95a44cbc8520ee9b483694p0L, 0x1.a0fc6f7c7d61b2b3a22a0eab2cadp-88L,
+	0x1.97d829fde4e4f8b9e920f8p0L, 0x1.1e8bd7edb9d7144b6f6818084cc7p-88L,
+	0x1.9a0f170ca07b9ba3109b8cp0L, 0x4.6737beb19e1eada6825d3c557428p-92L,
+	0x1.9c49182a3f0901c7c46b06p0L, 0x1.1f2be58ddade50c217186c90b457p-88L,
+	0x1.9e86319e323231824ca78ep0L, 0x6.4c6e010f92c082bbadfaf605cfd4p-92L,
+	0x1.a0c667b5de564b29ada8b8p0L, 0xc.ab349aa0422a8da7d4512edac548p-92L,
+	0x1.a309bec4a2d3358c171f76p0L, 0x1.0daad547fa22c26d168ea762d854p-88L,
+	0x1.a5503b23e255c8b424491cp0L, 0xa.f87bc8050a405381703ef7caff50p-92L,
+	0x1.a799e1330b3586f2dfb2b0p0L, 0x1.58f1a98796ce8908ae852236ca94p-88L,
+	0x1.a9e6b5579fdbf43eb243bcp0L, 0x1.ff4c4c58b571cf465caf07b4b9f5p-88L,
+	0x1.ac36bbfd3f379c0db966a2p0L, 0x1.1265fc73e480712d20f8597a8e7bp-88L,
+	0x1.ae89f995ad3ad5e8734d16p0L, 0x1.73205a7fbc3ae675ea440b162d6cp-88L,
+	0x1.b0e07298db66590842acdep0L, 0x1.c6f6ca0e5dcae2aafffa7a0554cbp-88L,
+	0x1.b33a2b84f15faf6bfd0e7ap0L, 0x1.d947c2575781dbb49b1237c87b6ep-88L,
+	0x1.b59728de559398e3881110p0L, 0x1.64873c7171fefc410416be0a6525p-88L,
+	0x1.b7f76f2fb5e46eaa7b081ap0L, 0xb.53c5354c8903c356e4b625aacc28p-92L,
+	0x1.ba5b030a10649840cb3c6ap0L, 0xf.5b47f297203757e1cc6eadc8bad0p-92L,
+	0x1.bcc1e904bc1d2247ba0f44p0L, 0x1.b3d08cd0b20287092bd59be4ad98p-88L,
+	0x1.bf2c25bd71e088408d7024p0L, 0x1.18e3449fa073b356766dfb568ff4p-88L,
+	0x1.c199bdd85529c2220cb12ap0L, 0x9.1ba6679444964a36661240043970p-96L,
+	0x1.c40ab5fffd07a6d14df820p0L, 0xf.1828a5366fd387a7bdd54cdf7300p-92L,
+	0x1.c67f12e57d14b4a2137fd2p0L, 0xf.2b301dd9e6b151a6d1f9d5d5f520p-96L,
+	0x1.c8f6d9406e7b511acbc488p0L, 0x5.c442ddb55820171f319d9e5076a8p-96L,
+	0x1.cb720dcef90691503cbd1ep0L, 0x9.49db761d9559ac0cb6dd3ed599e0p-92L,
+	0x1.cdf0b555dc3f9c44f8958ep0L, 0x1.ac51be515f8c58bdfb6f5740a3a4p-88L,
+	0x1.d072d4a07897b8d0f22f20p0L, 0x1.a158e18fbbfc625f09f4cca40874p-88L,
+	0x1.d2f87080d89f18ade12398p0L, 0x9.ea2025b4c56553f5cdee4c924728p-92L,
+	0x1.d5818dcfba48725da05aeap0L, 0x1.66e0dca9f589f559c0876ff23830p-88L,
+	0x1.d80e316c98397bb84f9d04p0L, 0x8.805f84bec614de269900ddf98d28p-92L,
+	0x1.da9e603db3285708c01a5ap0L, 0x1.6d4c97f6246f0ec614ec95c99392p-88L,
+	0x1.dd321f301b4604b695de3cp0L, 0x6.30a393215299e30d4fb73503c348p-96L,
+	0x1.dfc97337b9b5eb968cac38p0L, 0x1.ed291b7225a944efd5bb5524b927p-88L,
+	0x1.e264614f5a128a12761fa0p0L, 0x1.7ada6467e77f73bf65e04c95e29dp-88L,
+	0x1.e502ee78b3ff6273d13014p0L, 0x1.3991e8f49659e1693be17ae1d2f9p-88L,
+	0x1.e7a51fbc74c834b548b282p0L, 0x1.23786758a84f4956354634a416cep-88L,
+	0x1.ea4afa2a490d9858f73a18p0L, 0xf.5db301f86dea20610ceee13eb7b8p-92L,
+	0x1.ecf482d8e67f08db0312fap0L, 0x1.949cef462010bb4bc4ce72a900dfp-88L,
+	0x1.efa1bee615a27771fd21a8p0L, 0x1.2dac1f6dd5d229ff68e46f27e3dfp-88L,
+	0x1.f252b376bba974e8696fc2p0L, 0x1.6390d4c6ad5476b5162f40e1d9a9p-88L,
+	0x1.f50765b6e4540674f84b76p0L, 0x2.862baff99000dfc4352ba29b8908p-92L,
+	0x1.f7bfdad9cbe138913b4bfep0L, 0x7.2bd95c5ce7280fa4d2344a3f5618p-92L,
+	0x1.fa7c1819e90d82e90a7e74p0L, 0xb.263c1dc060c36f7650b4c0f233a8p-92L,
+	0x1.fd3c22b8f71f10975ba4b2p0L, 0x1.2bcf3a5e12d269d8ad7c1a4a8875p-88L
+};
+
+long double
+expl(long double x)
+{
+	union IEEEl2bits u, v;
+	long double fn, r, r1, r2, q, t, twopk, twopkp10000;
+	int k, n, n2;
+	uint32_t hx, ix;
+
+	/* Filter out exceptional cases. */
+	u.e = x;
+	hx = u.xbits.expsign;
+	ix = hx & EXPMASK;
+	if (ix >= BIAS + 13) {		/* |x| >= 8192 or x is NaN */
+		if (ix == BIAS + LDBL_MAX_EXP) {
+			if (u.xbits.manh != 0
+			    || u.xbits.manl != 0
+			    || (hx & 0x8000) == 0)
+				return (x + x);	/* x is NaN or +Inf */
+			else 
+				return (0.0);	/* x is -Inf */
+		}
+		if (x > o_threshold)
+			return (huge * huge);
+		if (x < u_threshold)
+			return (tiny * tiny);
+	} else if (ix <= BIAS - 115) {	/* |x| < 0x1p-33 */
+					/* includes pseudo-denormals */
+	    	if (huge + x > 1.0L)	/* trigger inexact iff x != 0 */
+			return (1.0L + x);
+	}
+
+	fn = x * INV_L + 0x1.8p112 - 0x1.8p112;
+	n  = (int)fn;
+	n2 = (unsigned)n % NUM;		/* Tang's j. */
+	k = (n - n2) / NUM;
+	r1 = x - fn * L1;
+	r2 = -fn * L2;
+
+	/* Prepare scale factors. */
+	v.xbits.manh = 0;
+	v.xbits.manl = 0;
+	if (k >= LDBL_MIN_EXP) {
+		v.xbits.expsign = BIAS + k;
+		twopk = v.e;
+	} else {
+		v.xbits.expsign = BIAS + k + 10000;
+		twopkp10000 = v.e;
+	}
+
+	r = r1 + r2;
+	q = r * r * (P2 + r * (P3 + r * (P4 + r * (P5 + r * (P6 + r * (P7 +
+	    r * (P8 + r * (P9 + r * (P10 + r * P11)))))))));
+	t = s[n2].lo + s[n2].hi;
+	t = s[n2].hi + (s[n2].lo + t * (r2 + q + r1));
+
+	/* Scale by 2**k. */
+	if (k >= LDBL_MIN_EXP) {
+		if (k == LDBL_MAX_EXP)
+			return (t * 2.0L * 0x1p16383L);
+		return (t * twopk);
+	} else {
+		return (t * twopkp10000 * twom10000);
+	}
+}
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/msun/ld80/s_expl.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/lib/msun/ld80/s_expl.c	Wed Jul 25 16:23:00 2012 +0300
@@ -0,0 +1,304 @@
+/*-
+ * Copyright (c) 2009-2012 Steven G. Kargl
+ * 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 unmodified, 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 ``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 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.
+ *
+ * Optimized by Bruce D. Evans.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/lib/msun/ld80/s_expl.c 238722 2012-07-23 19:13:55Z kargl $");
+
+/*
+ * Compute the exponential of x for Intel 80-bit format.  This is based on:
+ *
+ *   PTP Tang, "Table-driven implementation of the exponential function
+ *   in IEEE floating-point arithmetic," ACM Trans. Math. Soft., 15,
+ *   144-157 (1989).
+ *
+ * where the 32 table entries have been expanded to NUM (see below).
+ */
+
+#include <float.h>
+
+#ifdef __i386__
+#include <ieeefp.h>
+#endif
+
+#include "math.h"
+#define	FPSETPREC
+#ifdef NO_FPSETPREC
+#undef FPSETPREC
+#endif
+#include "math_private.h"
+#include "fpmath.h"
+
+#define	BIAS	(LDBL_MAX_EXP - 1)
+
+static const long double
+huge = 0x1p10000L,
+twom10000 = 0x1p-10000L;
+/* XXX Prevent gcc from erroneously constant folding this: */
+static volatile const long double tiny = 0x1p-10000L;
+
+static const union IEEEl2bits
+/* log(2**16384 - 0.5) rounded towards zero: */
+o_threshold = LD80C(0xb17217f7d1cf79ab, 13, 0,  11356.5234062941439488L),
+/* log(2**(-16381-64-1)) rounded towards zero: */
+u_threshold = LD80C(0xb21dfe7f09e2baa9, 13, 1, -11399.4985314888605581L);
+
+static const double __aligned(64)
+/*
+ * ln2/NUM = L1+L2 (hi+lo decomposition for multiplication).  L1 must have
+ * at least 22 (= log2(|LDBL_MIN_EXP-extras|) + log2(NUM)) lowest bits zero
+ * so that multiplication of it by n is exact.
+ */
+L1 =  5.4152123484527692e-3,		/*  0x162e42ff000000.0p-60 */
+L2 = -3.2819649005320973e-13,		/* -0x1718432a1b0e26.0p-94 */
+INV_L = 1.8466496523378731e+2,		/*  0x171547652b82fe.0p-45 */
+/*
+ * Domain [-0.002708, 0.002708], range ~[-5.7136e-24, 5.7110e-24]:
+ * |exp(x) - p(x)| < 2**-77.2
+ * (0.002708 is ln2/(2*NUM) rounded up a little).
+ */
+P2 =  0.5,
+P3 =  1.6666666666666119e-1,		/*  0x15555555555490.0p-55 */
+P4 =  4.1666666666665887e-2,		/*  0x155555555554e5.0p-57 */
+P5 =  8.3333354987869413e-3,		/*  0x1111115b789919.0p-59 */
+P6 =  1.3888891738560272e-3;		/*  0x16c16c651633ae.0p-62 */
+
+/*
+ * 2^(i/NUM) for i in [0,NUM] is represented by two values where the
+ * first 47 (?!) bits of the significand is stored in hi and the next 53
+ * bits are in lo.
+ */
+#define	NUM		128
+
+static const struct {
+	double	hi;
+	double	lo;
+} s[NUM] __aligned(16) = {
+	0x1p+0, 0x0p+0,
+	0x1.0163da9fb330p+0, 0x1.ab6c25335719bp-47,
+	0x1.02c9a3e77804p+0, 0x1.07737be56527cp-47,
+	0x1.04315e86e7f8p+0, 0x1.2f5ce3e688369p-50,
+	0x1.059b0d315854p+0, 0x1.a1d73e2a475b4p-47,
+	0x1.0706b29ddf6cp+0, 0x1.dc6dc403a9d88p-48,
+	0x1.0874518759bcp+0, 0x1.01186be4bb285p-49,
+	0x1.09e3ecac6f38p+0, 0x1.a290f03062c27p-51,
+	0x1.0b5586cf9890p+0, 0x1.ec5317256e308p-49,
+	0x1.0cc922b7247cp+0, 0x1.ba03db82dc49fp-47,
+	0x1.0e3ec32d3d18p+0, 0x1.10103a1727c58p-47,
+	0x1.0fb66affed30p+0, 0x1.af232091dd8a1p-48,
+	0x1.11301d0125b4p+0, 0x1.0a4ebbf1aed93p-48,
+	0x1.12abdc06c31cp+0, 0x1.7f72575a649adp-49,
+	0x1.1429aaea92dcp+0, 0x1.fb34101943b26p-48,
+	0x1.15a98c8a58e4p+0, 0x1.12480d573dd56p-48,
+	0x1.172b83c7d514p+0, 0x1.d6e6fbe462876p-47,
+	0x1.18af9388c8dcp+0, 0x1.4dddfb85cd1e1p-47,
+	0x1.1a35beb6fcb4p+0, 0x1.a9e5b4c7b4969p-47,
+	0x1.1bbe084045ccp+0, 0x1.39ab1e72b4428p-48,
+	0x1.1d4873168b98p+0, 0x1.53c02dc0144c8p-47,
+	0x1.1ed5022fcd90p+0, 0x1.cb8819ff61122p-48,
+	0x1.2063b88628ccp+0, 0x1.63b8eeb029509p-48,
+	0x1.21f49917ddc8p+0, 0x1.62552fd29294cp-48,
+	0x1.2387a6e75620p+0, 0x1.c3360fd6d8e0bp-47,
+	0x1.251ce4fb2a60p+0, 0x1.f9ac155bef4f5p-47,
+	0x1.26b4565e27ccp+0, 0x1.d257a673281d4p-48,
+	0x1.284dfe1f5638p+0, 0x1.2d9e2b9e07941p-53,
+	0x1.29e9df51fdecp+0, 0x1.09612e8afad12p-47,
+	0x1.2b87fd0dad98p+0, 0x1.ffbbd48ca71f9p-49,
+	0x1.2d285a6e4030p+0, 0x1.680123aa6da0fp-49,
+	0x1.2ecafa93e2f4p+0, 0x1.611ca0f45d524p-48,
+	0x1.306fe0a31b70p+0, 0x1.52de8d5a46306p-48,
+	0x1.32170fc4cd80p+0, 0x1.89a9ce78e1804p-47,
+	0x1.33c08b26416cp+0, 0x1.fa64e43086cb3p-47,
+	0x1.356c55f929fcp+0, 0x1.864a311a3b1bap-47,
+	0x1.371a7373aa9cp+0, 0x1.54e28aa05e8a9p-49,
+	0x1.38cae6d05d84p+0, 0x1.2c2d4e586cdf7p-47,
+	0x1.3a7db34e59fcp+0, 0x1.b750de494cf05p-47,
+	0x1.3c32dc313a8cp+0, 0x1.242000f9145acp-47,
+	0x1.3dea64c12340p+0, 0x1.11ada0911f09fp-47,
+	0x1.3fa4504ac800p+0, 0x1.ba0bf701aa418p-48,
+	0x1.4160a21f72e0p+0, 0x1.4fc2192dc79eep-47,
+	0x1.431f5d950a88p+0, 0x1.6dc704439410dp-48,
+	0x1.44e086061890p+0, 0x1.68189b7a04ef8p-47,
+	0x1.46a41ed1d004p+0, 0x1.772512f45922ap-48,
+	0x1.486a2b5c13ccp+0, 0x1.013c1a3b69063p-48,
+	0x1.4a32af0d7d3cp+0, 0x1.e672d8bcf46f9p-48,
+	0x1.4bfdad5362a0p+0, 0x1.38ea1cbd7f621p-47,
+	0x1.4dcb299fddd0p+0, 0x1.ac766dde353c2p-49,
+	0x1.4f9b2769d2c8p+0, 0x1.35699ec5b4d50p-47,
+	0x1.516daa2cf664p+0, 0x1.c112f52c84d82p-52,
+	0x1.5342b569d4f8p+0, 0x1.df0a83c49d86ap-52,
+	0x1.551a4ca5d920p+0, 0x1.d8a5d8c40486ap-49,
+	0x1.56f4736b527cp+0, 0x1.a66ecb004764fp-48,
+	0x1.58d12d497c7cp+0, 0x1.e9295e15b9a1ep-47,
+	0x1.5ab07dd48540p+0, 0x1.4ac64980a8c8fp-47,
+	0x1.5c9268a59468p+0, 0x1.b80e258dc0b4cp-47,
+	0x1.5e76f15ad214p+0, 0x1.0dd37c9840733p-49,
+	0x1.605e1b976dc0p+0, 0x1.160edeb25490ep-49,
+	0x1.6247eb03a558p+0, 0x1.2c7c3e81bf4b7p-50,
+	0x1.6434634ccc30p+0, 0x1.fc76f8714c4eep-48,
+	0x1.662388255220p+0, 0x1.24893ecf14dc8p-47,
+	0x1.68155d44ca94p+0, 0x1.9840e2b913dd0p-47,
+	0x1.6a09e667f3bcp+0, 0x1.921165f626cddp-49,
+	0x1.6c012750bda8p+0, 0x1.f76bb54cc007ap-47,
+	0x1.6dfb23c651a0p+0, 0x1.779107165f0dep-47,
+	0x1.6ff7df951948p+0, 0x1.e7c3f0da79f11p-51,
+	0x1.71f75e8ec5f4p+0, 0x1.9ee91b8797785p-47,
+	0x1.73f9a48a5814p+0, 0x1.9deae4d273456p-47,
+	0x1.75feb564267cp+0, 0x1.17edd35467491p-49,
+	0x1.780694fde5d0p+0, 0x1.fb0cd7014042cp-47,
+	0x1.7a11473eb018p+0, 0x1.b5f54408fdb37p-50,
+	0x1.7c1ed0130c10p+0, 0x1.93e2499a22c9cp-47,
+	0x1.7e2f336cf4e4p+0, 0x1.1082e815d0abdp-47,
+	0x1.80427543e1a0p+0, 0x1.1b60de67649a3p-48,
+	0x1.82589994cce0p+0, 0x1.28acf88afab35p-48,
+	0x1.8471a4623c78p+0, 0x1.667297b5cbe32p-47,
+	0x1.868d99b4492cp+0, 0x1.640720ec85613p-47,
+	0x1.88ac7d98a668p+0, 0x1.966530bcdf2d5p-48,
+	0x1.8ace5422aa0cp+0, 0x1.b5ba7c55a192dp-48,
+	0x1.8cf3216b5448p+0, 0x1.7de55439a2c39p-49,
+	0x1.8f1ae9915770p+0, 0x1.b15cc13a2e397p-47,
+	0x1.9145b0b91ffcp+0, 0x1.622986d1a7daep-50,
+	0x1.93737b0cdc5cp+0, 0x1.27a280e1f92a0p-47,
+	0x1.95a44cbc8520p+0, 0x1.dd36906d2b420p-49,
+	0x1.97d829fde4e4p+0, 0x1.f173d241f23d1p-49,
+	0x1.9a0f170ca078p+0, 0x1.cdd1884dc6234p-47,
+	0x1.9c49182a3f08p+0, 0x1.01c7c46b071f3p-48,
+	0x1.9e86319e3230p+0, 0x1.18c12653c7326p-47,
+	0x1.a0c667b5de54p+0, 0x1.2594d6d45c656p-47,
+	0x1.a309bec4a2d0p+0, 0x1.9ac60b8fbb86dp-47,
+	0x1.a5503b23e254p+0, 0x1.c8b424491caf8p-48,
+	0x1.a799e1330b34p+0, 0x1.86f2dfb2b158fp-48,
+	0x1.a9e6b5579fd8p+0, 0x1.fa1f5921deffap-47,
+	0x1.ac36bbfd3f34p+0, 0x1.ce06dcb351893p-47,
+	0x1.ae89f995ad38p+0, 0x1.6af439a68bb99p-47,
+	0x1.b0e07298db64p+0, 0x1.2c8421566fe38p-47,
+	0x1.b33a2b84f15cp+0, 0x1.d7b5fe873decap-47,
+	0x1.b59728de5590p+0, 0x1.cc71c40888b24p-47,
+	0x1.b7f76f2fb5e4p+0, 0x1.baa9ec206ad4fp-50,
+	0x1.ba5b030a1064p+0, 0x1.30819678d5eb7p-49,
+	0x1.bcc1e904bc1cp+0, 0x1.2247ba0f45b3dp-48,
+	0x1.bf2c25bd71e0p+0, 0x1.10811ae04a31cp-49,
+	0x1.c199bdd85528p+0, 0x1.c2220cb12a092p-48,
+	0x1.c40ab5fffd04p+0, 0x1.d368a6fc1078cp-47,
+	0x1.c67f12e57d14p+0, 0x1.694426ffa41e5p-49,
+	0x1.c8f6d9406e78p+0, 0x1.a88d65e24402ep-47,
+	0x1.cb720dcef904p+0, 0x1.48a81e5e8f4a5p-47,
+	0x1.cdf0b555dc3cp+0, 0x1.ce227c4ac7d63p-47,
+	0x1.d072d4a07894p+0, 0x1.dc68791790d0bp-47,
+	0x1.d2f87080d89cp+0, 0x1.8c56f091cc4f5p-47,
+	0x1.d5818dcfba48p+0, 0x1.c976816bad9b8p-50,
+	0x1.d80e316c9838p+0, 0x1.7bb84f9d04880p-48,
+	0x1.da9e603db328p+0, 0x1.5c2300696db53p-50,
+	0x1.dd321f301b44p+0, 0x1.025b4aef1e032p-47,
+	0x1.dfc97337b9b4p+0, 0x1.eb968cac39ed3p-48,
+	0x1.e264614f5a10p+0, 0x1.45093b0fd0bd7p-47,
+	0x1.e502ee78b3fcp+0, 0x1.b139e8980a9cdp-47,
+	0x1.e7a51fbc74c8p+0, 0x1.a5aa4594191bcp-51,
+	0x1.ea4afa2a490cp+0, 0x1.9858f73a18f5ep-48,
+	0x1.ecf482d8e67cp+0, 0x1.846d81897dca5p-47,
+	0x1.efa1bee615a0p+0, 0x1.3bb8fe90d496dp-47,
+	0x1.f252b376bba8p+0, 0x1.74e8696fc3639p-48,
+	0x1.f50765b6e454p+0, 0x1.9d3e12dd8a18bp-54,
+	0x1.f7bfdad9cbe0p+0, 0x1.38913b4bfe72cp-48,
+	0x1.fa7c1819e90cp+0, 0x1.82e90a7e74b26p-48,
+	0x1.fd3c22b8f71cp+0, 0x1.884badd25995ep-47
+};
+
+long double
+expl(long double x)
+{
+	union IEEEl2bits u, v;
+	long double fn, r, r1, r2, q, t, t23, t45, twopk, twopkp10000, z;
+	int k, n, n2;
+	uint16_t hx, ix;
+
+	/* Filter out exceptional cases. */
+	u.e = x;
+	hx = u.xbits.expsign;
+	ix = hx & 0x7fff;
+	if (ix >= BIAS + 13) {		/* |x| >= 8192 or x is NaN */
+		if (ix == BIAS + LDBL_MAX_EXP) {
+			if (hx & 0x8000 && u.xbits.man == 1ULL << 63)
+				return (0.0L);	/* x is -Inf */
+			return (x + x); /* x is +Inf, NaN or unsupported */
+		}
+		if (x > o_threshold.e)
+			return (huge * huge);
+		if (x < u_threshold.e)
+			return (tiny * tiny);
+	} else if (ix <= BIAS - 34) {	/* |x| < 0x1p-33 */
+					/* includes pseudo-denormals */
+	    	if (huge + x > 1.0L)	/* trigger inexact iff x != 0 */
+			return (1.0L + x);
+	}
+
+	ENTERI();
+
+	/* Reduce x to (k*ln2 + midpoint[n2] + r1 + r2). */
+	/* Use a specialized rint() to get fn.  Assume round-to-nearest. */
+	fn = x * INV_L + 0x1.8p63 - 0x1.8p63;
+	r = x - fn * L1 - fn * L2;	/* r = r1 + r2 done independently. */
+#if defined(HAVE_EFFICIENT_IRINTL)
+	n  = irintl(fn);
+#elif defined(HAVE_EFFICIENT_IRINT)
+	n  = irint(fn);
+#else
+	n  = (int)fn;
+#endif
+	n2 = (unsigned)n % NUM;		/* Tang's j. */
+	k = (n - n2) / NUM;
+	r1 = x - fn * L1;
+	r2 = -fn * L2;
+
+	/* Prepare scale factors. */
+	v.xbits.man = 1ULL << 63;
+	if (k >= LDBL_MIN_EXP) {
+		v.xbits.expsign = BIAS + k;
+		twopk = v.e;
+	} else {
+		v.xbits.expsign = BIAS + k + 10000;
+		twopkp10000 = v.e;
+	}
+
+	/* Evaluate expl(midpoint[n2] + r1 + r2) = s[n2] * expl(r1 + r2). */
+	/* Here q = q(r), not q(r1), since r1 is lopped like L1. */
+	t45 = r * P5 + P4;
+	z = r * r;
+	t23 = r * P3 + P2;
+	q = r2 + z * t23 + z * z * t45 + z * z * z * P6;
+	t = (long double)s[n2].lo + s[n2].hi;
+	t = s[n2].lo + t * (q + r1) + s[n2].hi;
+
+	/* Scale by 2**k. */
+	if (k >= LDBL_MIN_EXP) {
+		if (k == LDBL_MAX_EXP)
+			RETURNI(t * 2.0L * 0x1p16383L);
+		RETURNI(t * twopk);
+	} else {
+		RETURNI(t * twopkp10000 * twom10000);
+	}
+}
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/msun/man/cexp.3
--- a/head/lib/msun/man/cexp.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/msun/man/cexp.3	Wed Jul 25 16:23:00 2012 +0300
@@ -22,7 +22,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/msun/man/cexp.3 235286 2012-05-11 20:06:46Z gjb $
 .\"
 .Dd March 6, 2011
 .Dt CEXP 3
@@ -48,7 +48,7 @@
 .Fa z ,
 also known as
 .Em cis Ns ( Ns
-.Fa z Ns )
+.Fa z Ns ) .
 .Sh RETURN VALUES
 For real numbers
 .Fa x
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/msun/man/complex.3
--- a/head/lib/msun/man/complex.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/msun/man/complex.3	Wed Jul 25 16:23:00 2012 +0300
@@ -22,7 +22,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD: head/lib/msun/man/complex.3 226458 2011-10-17 05:41:03Z das $
+.\" $FreeBSD: head/lib/msun/man/complex.3 235286 2012-05-11 20:06:46Z gjb $
 .\"
 .Dd October 17, 2011
 .Dt COMPLEX 3
@@ -111,7 +111,7 @@
 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 -r d46effa10a19 -r 7449ca4973e7 head/lib/msun/man/exp.3
--- a/head/lib/msun/man/exp.3	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/msun/man/exp.3	Wed Jul 25 16:23:00 2012 +0300
@@ -26,15 +26,16 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     from: @(#)exp.3	6.12 (Berkeley) 7/31/91
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/msun/man/exp.3 238722 2012-07-23 19:13:55Z kargl $
 .\"
-.Dd January 17, 2008
+.Dd July 10, 2012
 .Dt EXP 3
 .Os
 .Sh NAME
 .Nm exp ,
 .Nm expf ,
-.\" The sorting error is intentional.  exp and expf should be adjacent.
+.Nm expl ,
+.\" The sorting error is intentional.  exp, expf, and expl should be adjacent.
 .Nm exp2 ,
 .Nm exp2f ,
 .Nm exp2l ,
@@ -51,6 +52,8 @@
 .Fn exp "double x"
 .Ft float
 .Fn expf "float x"
+.Ft long double
+.Fn expl "long double x"
 .Ft double
 .Fn exp2 "double x"
 .Ft float
@@ -67,9 +70,10 @@
 .Fn powf "float x" "float y"
 .Sh DESCRIPTION
 The
-.Fn exp
-and the
-.Fn expf
+.Fn exp ,
+.Fn expf ,
+and
+.Fn expl
 functions compute the base
 .Ms e
 exponential value of the given argument
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/msun/src/e_exp.c
--- a/head/lib/msun/src/e_exp.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/msun/src/e_exp.c	Wed Jul 25 16:23:00 2012 +0300
@@ -11,7 +11,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/msun/src/e_exp.c 226596 2011-10-21 06:26:38Z das $");
+__FBSDID("$FreeBSD: head/lib/msun/src/e_exp.c 238722 2012-07-23 19:13:55Z kargl $");
 
 /* __ieee754_exp(x)
  * Returns the exponential of x.
@@ -158,3 +158,7 @@
 	    return y*twopk*twom1000;
 	}
 }
+
+#if (LDBL_MANT_DIG == 53)
+__weak_reference(exp, expl);
+#endif
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/msun/src/math.h
--- a/head/lib/msun/src/math.h	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/msun/src/math.h	Wed Jul 25 16:23:00 2012 +0300
@@ -11,7 +11,7 @@
 
 /*
  * from: @(#)fdlibm.h 5.1 93/09/24
- * $FreeBSD: head/lib/msun/src/math.h 227472 2011-11-12 19:55:48Z theraven $
+ * $FreeBSD: head/lib/msun/src/math.h 238722 2012-07-23 19:13:55Z kargl $
  */
 
 #ifndef _MATH_H_
@@ -395,35 +395,16 @@
  * 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 +416,9 @@
 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 +428,53 @@
 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	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_ */
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/msun/src/math_private.h
--- a/head/lib/msun/src/math_private.h	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/msun/src/math_private.h	Wed Jul 25 16:23:00 2012 +0300
@@ -11,7 +11,7 @@
 
 /*
  * from: @(#)fdlibm.h 5.1 93/09/24
- * $FreeBSD: head/lib/msun/src/math_private.h 226597 2011-10-21 06:27:56Z das $
+ * $FreeBSD: head/lib/msun/src/math_private.h 238722 2012-07-23 19:13:55Z kargl $
  */
 
 #ifndef _MATH_PRIVATE_H_
@@ -207,6 +207,13 @@
   (d) = se_u.e;							\
 } while (0)
 
+/* Long double constants are broken on i386.  This workaround is OK always. */
+#define	LD80C(m, ex, s, v) {					\
+	/* .e = v, */		/* overwritten */		\
+	.xbits.man = __CONCAT(m, ULL),				\
+	.xbits.expsign = (0x3fff + (ex)) | ((s) ? 0x8000 : 0),	\
+}
+
 #ifdef FLT_EVAL_METHOD
 /*
  * Attempt to get strict C99 semantics for assignment with non-C99 compilers.
@@ -225,8 +232,30 @@
 	}					\
 } while (0)
 #endif
+#endif /* FLT_EVAL_METHOD */
+
+/* Support switching the mode to FP_PE if necessary. */
+#if defined(__i386__) && !defined(NO_FPSETPREC)
+#define	ENTERI()				\
+	long double __retval;			\
+	fp_prec_t __oprec;			\
+						\
+	if ((__oprec = fpgetprec()) != FP_PE)	\
+		fpsetprec(FP_PE);
+#define	RETURNI(x) do {				\
+	__retval = (x);				\
+	if (__oprec != FP_PE)			\
+		fpsetprec(__oprec);		\
+	RETURNF(__retval);			\
+} while (0)
+#else
+#define	ENTERI(x)
+#define	RETURNI(x)	RETURNF(x)
 #endif
 
+/* Default return statement if hack*_t() is not used. */
+#define      RETURNF(v)      return (v)
+
 /*
  * Common routine to process the arguments to nan(), nanf(), and nanl().
  */
@@ -323,6 +352,18 @@
 #define	HAVE_EFFICIENT_IRINT
 #endif
 
+#if defined(__amd64__) || defined(__i386__)
+static __inline int
+irintl(long double x)
+{
+	int n;
+
+	asm("fistl %0" : "=m" (n) : "t" (x));
+	return (n);
+}
+#define	HAVE_EFFICIENT_IRINTL
+#endif
+
 #endif /* __GNUCLIKE_ASM */
 
 /*
diff -r d46effa10a19 -r 7449ca4973e7 head/lib/msun/src/s_fabsl.c
--- a/head/lib/msun/src/s_fabsl.c	Wed Jul 25 16:21:35 2012 +0300
+++ b/head/lib/msun/src/s_fabsl.c	Wed Jul 25 16:23:00 2012 +0300
@@ -1,5 +1,5 @@
 /*-
- * Copyright (c) 2003 Dag-Erling Coïdan Smørgrav
+ * Copyright (c) 2003 Dag-Erling Smørgrav
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -25,7 +25,7 @@
  * (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: head/lib/msun/src/s_fabsl.c 229784 2012-01-07 16:13:56Z uqs $
+ * $FreeBSD: head/lib/msun/src/s_fabsl.c 234685 2012-04-25 18:07:35Z des $
  */
 
 #include <math.h>



More information about the Zrouter-src-freebsd mailing list