summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorsjg <sjg@FreeBSD.org>2015-05-27 01:19:58 +0000
committersjg <sjg@FreeBSD.org>2015-05-27 01:19:58 +0000
commit65145fa4c81da358fcbc3b650156dab705dfa34e (patch)
tree55c065b6730aaac2afb6c29933ee6ec5fa4c4249 /lib
parent60ff4eb0dff94a04d75d0d52a3957aaaf5f8c693 (diff)
parente6b664c390af88d4a87208bc042ce503da664c3b (diff)
downloadFreeBSD-src-65145fa4c81da358fcbc3b650156dab705dfa34e.zip
FreeBSD-src-65145fa4c81da358fcbc3b650156dab705dfa34e.tar.gz
Merge sync of head
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile60
-rw-r--r--lib/atf/libatf-c++/Makefile5
-rw-r--r--lib/atf/libatf-c++/Makefile.depend7
-rw-r--r--lib/clang/Makefile28
-rw-r--r--lib/clang/clang.build.mk54
-rw-r--r--lib/clang/include/AArch64GenAsmMatcher.inc2
-rw-r--r--lib/clang/include/AArch64GenAsmWriter.inc2
-rw-r--r--lib/clang/include/AArch64GenAsmWriter1.inc2
-rw-r--r--lib/clang/include/AArch64GenCallingConv.inc2
-rw-r--r--lib/clang/include/AArch64GenDAGISel.inc2
-rw-r--r--lib/clang/include/AArch64GenDisassemblerTables.inc2
-rw-r--r--lib/clang/include/AArch64GenFastISel.inc2
-rw-r--r--lib/clang/include/AArch64GenInstrInfo.inc2
-rw-r--r--lib/clang/include/AArch64GenMCCodeEmitter.inc2
-rw-r--r--lib/clang/include/AArch64GenMCPseudoLowering.inc2
-rw-r--r--lib/clang/include/AArch64GenRegisterInfo.inc2
-rw-r--r--lib/clang/include/AArch64GenSubtargetInfo.inc2
-rw-r--r--lib/clang/include/Makefile15
-rw-r--r--lib/clang/include/MipsGenFastISel.inc2
-rw-r--r--lib/clang/include/PPCGenDisassemblerTables.inc2
-rw-r--r--lib/clang/include/clang/AST/AttrVisitor.inc2
-rw-r--r--lib/clang/include/clang/Basic/AttrHasAttributeImpl.inc2
-rw-r--r--lib/clang/include/clang/Basic/Version.inc10
-rw-r--r--lib/clang/include/clang/Config/config.h23
-rw-r--r--lib/clang/include/clang/Driver/CC1AsOptions.inc2
-rw-r--r--lib/clang/include/clang/Lex/AttrSpellings.inc2
-rw-r--r--lib/clang/include/clang/Parse/AttrIdentifierArg.inc2
-rw-r--r--lib/clang/include/clang/Parse/AttrLateParsed.inc2
-rw-r--r--lib/clang/include/clang/Parse/AttrParserStringSwitches.inc2
-rw-r--r--lib/clang/include/clang/Parse/AttrTypeArg.inc2
-rw-r--r--lib/clang/include/llvm/Config/AsmParsers.def1
-rw-r--r--lib/clang/include/llvm/Config/AsmPrinters.def1
-rw-r--r--lib/clang/include/llvm/Config/Disassemblers.def2
-rw-r--r--lib/clang/include/llvm/Config/Targets.def1
-rw-r--r--lib/clang/include/llvm/Config/config.h156
-rw-r--r--lib/clang/include/llvm/Config/llvm-config.h49
-rw-r--r--lib/clang/include/llvm/Support/DataTypes.h72
-rw-r--r--lib/clang/libclanganalysis/Makefile5
-rw-r--r--lib/clang/libclangarcmigrate/Makefile1
-rw-r--r--lib/clang/libclangast/Makefile3
-rw-r--r--lib/clang/libclangbasic/Makefile12
-rw-r--r--lib/clang/libclangcodegen/Makefile10
-rw-r--r--lib/clang/libclangdriver/Makefile10
-rw-r--r--lib/clang/libclangfrontend/Makefile7
-rw-r--r--lib/clang/libclangfrontendtool/Makefile7
-rw-r--r--lib/clang/libclanglex/Makefile2
-rw-r--r--lib/clang/libclangparse/Makefile7
-rw-r--r--lib/clang/libclangrewrite/Makefile (renamed from lib/clang/libclangrewritecore/Makefile)4
-rw-r--r--lib/clang/libclangrewrite/Makefile.depend (renamed from lib/clang/libclangrewritecore/Makefile.depend)4
-rw-r--r--lib/clang/libclangrewritefrontend/Makefile4
-rw-r--r--lib/clang/libclangsema/Makefile3
-rw-r--r--lib/clang/libclangstaticanalyzercheckers/Makefile3
-rw-r--r--lib/clang/libclangstaticanalyzerfrontend/Makefile6
-rw-r--r--lib/clang/liblldb/Makefile4
-rw-r--r--lib/clang/liblldbAPI/Makefile9
-rw-r--r--lib/clang/liblldbBreakpoint/Makefile4
-rw-r--r--lib/clang/liblldbCommands/Makefile4
-rw-r--r--lib/clang/liblldbCore/Makefile7
-rw-r--r--lib/clang/liblldbDataFormatters/Makefile9
-rw-r--r--lib/clang/liblldbExpression/Makefile1
-rw-r--r--lib/clang/liblldbHostCommon/Makefile16
-rw-r--r--lib/clang/liblldbHostFreeBSD/Makefile5
-rw-r--r--lib/clang/liblldbHostPOSIX/Makefile16
-rw-r--r--lib/clang/liblldbInterpreter/Makefile6
-rw-r--r--lib/clang/liblldbPluginABISysV_ppc/Makefile15
-rw-r--r--lib/clang/liblldbPluginABISysV_ppc64/Makefile15
-rw-r--r--lib/clang/liblldbPluginInstructionARM64/Makefile10
-rw-r--r--lib/clang/liblldbPluginInstrumentationRuntimeAddressSanitizer/Makefile17
-rw-r--r--lib/clang/liblldbPluginJITLoaderGDB/Makefile15
-rw-r--r--lib/clang/liblldbPluginMemoryHistoryASan/Makefile15
-rw-r--r--lib/clang/liblldbPluginObjectFileJIT/Makefile17
-rw-r--r--lib/clang/liblldbPluginPlatformFreeBSD/Makefile4
-rw-r--r--lib/clang/liblldbPluginPlatformGDB/Makefile4
-rw-r--r--lib/clang/liblldbPluginProcessElfCore/Makefile1
-rw-r--r--lib/clang/liblldbPluginProcessGDBRemote/Makefile4
-rw-r--r--lib/clang/liblldbPluginProcessPOSIX/Makefile15
-rw-r--r--lib/clang/liblldbPluginProcessUtility/Makefile18
-rw-r--r--lib/clang/liblldbPluginSymbolFileDWARF/Makefile4
-rw-r--r--lib/clang/liblldbSymbol/Makefile1
-rw-r--r--lib/clang/liblldbTarget/Makefile16
-rw-r--r--lib/clang/liblldbUtility/Makefile8
-rw-r--r--lib/clang/libllvmaarch64asmparser/Makefile16
-rw-r--r--lib/clang/libllvmaarch64asmparser/Makefile.depend23
-rw-r--r--lib/clang/libllvmaarch64codegen/Makefile46
-rw-r--r--lib/clang/libllvmaarch64desc/Makefile24
-rw-r--r--lib/clang/libllvmaarch64desc/Makefile.depend47
-rw-r--r--lib/clang/libllvmaarch64disassembler/Makefile20
-rw-r--r--lib/clang/libllvmaarch64disassembler/Makefile.depend23
-rw-r--r--lib/clang/libllvmaarch64info/Makefile15
-rw-r--r--lib/clang/libllvmaarch64info/Makefile.depend (renamed from lib/clang/libllvmjit/Makefile.depend)3
-rw-r--r--lib/clang/libllvmaarch64instprinter/Makefile17
-rw-r--r--lib/clang/libllvmaarch64instprinter/Makefile.depend25
-rw-r--r--lib/clang/libllvmaarch64utils/Makefile15
-rw-r--r--lib/clang/libllvmaarch64utils/Makefile.depend21
-rw-r--r--lib/clang/libllvmanalysis/Makefile13
-rw-r--r--lib/clang/libllvmarmcodegen/Makefile3
-rw-r--r--lib/clang/libllvmarmdesc/Makefile6
-rw-r--r--lib/clang/libllvmasmprinter/Makefile11
-rw-r--r--lib/clang/libllvmcodegen/Makefile15
-rw-r--r--lib/clang/libllvmcore/Makefile12
-rw-r--r--lib/clang/libllvmdebuginfo/Makefile7
-rw-r--r--lib/clang/libllvmexecutionengine/Makefile2
-rw-r--r--lib/clang/libllvminstrumentation/Makefile3
-rw-r--r--lib/clang/libllvmipa/Makefile1
-rw-r--r--lib/clang/libllvmjit/Makefile12
-rw-r--r--lib/clang/libllvmmc/Makefile23
-rw-r--r--lib/clang/libllvmmcdisassembler/Makefile5
-rw-r--r--lib/clang/libllvmmipscodegen/Makefile7
-rw-r--r--lib/clang/libllvmmipsdesc/Makefile9
-rw-r--r--lib/clang/libllvmobjcarcopts/Makefile3
-rw-r--r--lib/clang/libllvmobject/Makefile4
-rw-r--r--lib/clang/libllvmpowerpccodegen/Makefile4
-rw-r--r--lib/clang/libllvmpowerpcdisassembler/Makefile16
-rw-r--r--lib/clang/libllvmpowerpcdisassembler/Makefile.depend23
-rw-r--r--lib/clang/libllvmprofiledata/Makefile18
-rw-r--r--lib/clang/libllvmprofiledata/Makefile.depend (renamed from lib/libmandoc/Makefile.depend)0
-rw-r--r--lib/clang/libllvmruntimedyld/Makefile3
-rw-r--r--lib/clang/libllvmscalaropts/Makefile8
-rw-r--r--lib/clang/libllvmselectiondag/Makefile1
-rw-r--r--lib/clang/libllvmsparccodegen/Makefile2
-rw-r--r--lib/clang/libllvmsupport/Makefile25
-rw-r--r--lib/clang/libllvmtablegen/Makefile1
-rw-r--r--lib/clang/libllvmtarget/Makefile4
-rw-r--r--lib/clang/libllvmtransformutils/Makefile7
-rw-r--r--lib/clang/libllvmx86asmparser/Makefile3
-rw-r--r--lib/clang/libllvmx86codegen/Makefile4
-rw-r--r--lib/clang/libllvmx86desc/Makefile3
-rw-r--r--lib/clang/libllvmx86disassembler/Makefile5
-rw-r--r--lib/csu/Makefile5
-rw-r--r--lib/csu/aarch64/Makefile44
-rw-r--r--lib/csu/aarch64/crt1.c (renamed from lib/libc/powerpc/gen/getcontextx.c)89
-rw-r--r--lib/csu/aarch64/crti.S48
-rw-r--r--lib/csu/aarch64/crtn.S44
-rw-r--r--lib/csu/i386/Makefile (renamed from lib/csu/i386-elf/Makefile)4
-rw-r--r--lib/csu/i386/Makefile.depend (renamed from lib/csu/i386-elf/Makefile.depend)0
-rw-r--r--lib/csu/i386/crt1_c.c (renamed from lib/csu/i386-elf/crt1_c.c)0
-rw-r--r--lib/csu/i386/crt1_s.S (renamed from lib/csu/i386-elf/crt1_s.S)0
-rw-r--r--lib/csu/i386/crti.S (renamed from lib/csu/i386-elf/crti.S)0
-rw-r--r--lib/csu/i386/crtn.S (renamed from lib/csu/i386-elf/crtn.S)0
-rw-r--r--lib/csu/powerpc64/Makefile7
-rw-r--r--lib/libarchive/Makefile22
-rw-r--r--lib/libarchive/config_freebsd.h7
-rw-r--r--lib/libarchive/test/Makefile3
-rw-r--r--lib/libblocksruntime/Makefile2
-rw-r--r--lib/libbluetooth/bluetooth.c2
-rw-r--r--lib/libbluetooth/dev.c1
-rw-r--r--lib/libbluetooth/hci.c1
-rw-r--r--lib/libbsnmp/libbsnmp/Makefile4
-rw-r--r--lib/libc++/Makefile16
-rw-r--r--lib/libc++/Makefile.depend1
-rw-r--r--lib/libc/Makefile17
-rw-r--r--lib/libc/Makefile.amd646
-rw-r--r--lib/libc/Makefile.i3866
-rw-r--r--lib/libc/aarch64/Makefile.inc9
-rw-r--r--lib/libc/aarch64/SYS.h63
-rw-r--r--lib/libc/aarch64/Symbol.map30
-rw-r--r--lib/libc/aarch64/_fpmath.h58
-rw-r--r--lib/libc/aarch64/arith.h19
-rw-r--r--lib/libc/aarch64/gd_qnan.h21
-rw-r--r--lib/libc/aarch64/gen/Makefile.inc10
-rw-r--r--lib/libc/aarch64/gen/_set_tp.c (renamed from lib/libc/posix1e/acl_size.c)21
-rw-r--r--lib/libc/aarch64/gen/_setjmp.S105
-rw-r--r--lib/libc/aarch64/gen/fabs.S33
-rw-r--r--lib/libc/aarch64/gen/flt_rounds.c (renamed from lib/libc/mips/sys/__vdso_gettc.c)27
-rw-r--r--lib/libc/aarch64/gen/setjmp.S123
-rw-r--r--lib/libc/aarch64/gen/sigsetjmp.S53
-rw-r--r--lib/libc/aarch64/sys/Makefile.inc25
-rw-r--r--lib/libc/aarch64/sys/brk.S93
-rw-r--r--lib/libc/aarch64/sys/cerror.S41
-rw-r--r--lib/libc/aarch64/sys/pipe.S52
-rw-r--r--lib/libc/aarch64/sys/sbrk.S79
-rw-r--r--lib/libc/aarch64/sys/shmat.S (renamed from lib/libc/powerpc/sys/__vdso_gettc.c)29
-rw-r--r--lib/libc/aarch64/sys/sigreturn.S35
-rw-r--r--lib/libc/aarch64/sys/syscall.S35
-rw-r--r--lib/libc/aarch64/sys/vfork.S42
-rw-r--r--lib/libc/amd64/sys/Makefile.inc3
-rw-r--r--lib/libc/arm/SYS.h2
-rw-r--r--lib/libc/arm/aeabi/Makefile.inc2
-rw-r--r--lib/libc/arm/aeabi/aeabi_vfp_double.S8
-rw-r--r--lib/libc/arm/aeabi/aeabi_vfp_float.S8
-rw-r--r--lib/libc/arm/gen/Makefile.inc5
-rw-r--r--lib/libc/arm/gen/_setjmp.S17
-rw-r--r--lib/libc/arm/gen/setjmp.S17
-rw-r--r--lib/libc/arm/string/ffs.S4
-rw-r--r--lib/libc/arm/string/memcmp.S4
-rw-r--r--lib/libc/arm/string/memcpy_arm.S37
-rw-r--r--lib/libc/arm/string/memcpy_xscale.S38
-rw-r--r--lib/libc/arm/string/memmove.S62
-rw-r--r--lib/libc/arm/string/memset.S102
-rw-r--r--lib/libc/arm/string/strlen.S14
-rw-r--r--lib/libc/arm/sys/Makefile.inc5
-rw-r--r--lib/libc/arm/sys/brk.S18
-rw-r--r--lib/libc/arm/sys/sbrk.S17
-rw-r--r--lib/libc/compat-43/creat.c13
-rw-r--r--lib/libc/db/hash/hash.c7
-rw-r--r--lib/libc/db/man/dbm.36
-rw-r--r--lib/libc/gen/Makefile.inc1
-rw-r--r--lib/libc/gen/Symbol.map3
-rw-r--r--lib/libc/gen/__pthread_mutex_init_calloc_cb_stub.c45
-rw-r--r--lib/libc/gen/_once_stub.c2
-rw-r--r--lib/libc/gen/_spinlock_stub.c41
-rw-r--r--lib/libc/gen/cap_rights_get.32
-rw-r--r--lib/libc/gen/directory.325
-rw-r--r--lib/libc/gen/disklabel.c23
-rw-r--r--lib/libc/gen/dlfcn.c12
-rw-r--r--lib/libc/gen/dlopen.34
-rw-r--r--lib/libc/gen/fstab.c2
-rw-r--r--lib/libc/gen/ftok.34
-rw-r--r--lib/libc/gen/fts.c11
-rw-r--r--lib/libc/gen/ftw.310
-rw-r--r--lib/libc/gen/getcap.35
-rw-r--r--lib/libc/gen/getgrent.c8
-rw-r--r--lib/libc/gen/getpwent.c10
-rw-r--r--lib/libc/gen/getutxent.32
-rw-r--r--lib/libc/gen/nice.336
-rw-r--r--lib/libc/gen/nice.c16
-rw-r--r--lib/libc/gen/nlist.c3
-rw-r--r--lib/libc/gen/pause.c9
-rw-r--r--lib/libc/gen/posix_spawn.312
-rw-r--r--lib/libc/gen/posix_spawn_file_actions_addopen.32
-rw-r--r--lib/libc/gen/posix_spawn_file_actions_init.32
-rw-r--r--lib/libc/gen/posix_spawnattr_getflags.32
-rw-r--r--lib/libc/gen/posix_spawnattr_getpgroup.32
-rw-r--r--lib/libc/gen/posix_spawnattr_getschedparam.32
-rw-r--r--lib/libc/gen/posix_spawnattr_getschedpolicy.32
-rw-r--r--lib/libc/gen/posix_spawnattr_getsigdefault.32
-rw-r--r--lib/libc/gen/posix_spawnattr_getsigmask.32
-rw-r--r--lib/libc/gen/posix_spawnattr_init.32
-rw-r--r--lib/libc/gen/raise.c8
-rw-r--r--lib/libc/gen/readdir.c6
-rw-r--r--lib/libc/gen/rewinddir.c1
-rw-r--r--lib/libc/gen/scandir.36
-rw-r--r--lib/libc/gen/sem_new.c6
-rw-r--r--lib/libc/gen/sem_post.35
-rw-r--r--lib/libc/gen/setmode.317
-rw-r--r--lib/libc/gen/setmode.c92
-rw-r--r--lib/libc/gen/setproctitle.c73
-rw-r--r--lib/libc/gen/sleep.38
-rw-r--r--lib/libc/gen/sleep.c8
-rw-r--r--lib/libc/gen/stringlist.c2
-rw-r--r--lib/libc/gen/syslog.c37
-rw-r--r--lib/libc/gen/telldir.c37
-rw-r--r--lib/libc/gen/telldir.h1
-rw-r--r--lib/libc/gen/termios.c18
-rw-r--r--lib/libc/gen/tls.c5
-rw-r--r--lib/libc/gen/trivial-getcontextx.c (renamed from lib/libc/arm/gen/getcontextx.c)0
-rw-r--r--lib/libc/gen/ttyname.c4
-rw-r--r--lib/libc/gen/ulimit.c12
-rw-r--r--lib/libc/gen/usleep.c5
-rw-r--r--lib/libc/gen/wait.c6
-rw-r--r--lib/libc/gen/wait3.c13
-rw-r--r--lib/libc/gen/waitid.c5
-rw-r--r--lib/libc/gen/waitpid.c6
-rw-r--r--lib/libc/gen/wordexp.c5
-rw-r--r--lib/libc/i386/sys/Makefile.inc3
-rw-r--r--lib/libc/iconv/__iconv.c2
-rw-r--r--lib/libc/iconv/bsd_iconv.c4
-rw-r--r--lib/libc/iconv/citrus_iconv.c8
-rw-r--r--lib/libc/iconv/citrus_iconv.h2
-rw-r--r--lib/libc/iconv/citrus_iconv_local.h4
-rw-r--r--lib/libc/iconv/citrus_none.c4
-rw-r--r--lib/libc/iconv/citrus_prop.c4
-rw-r--r--lib/libc/iconv/citrus_stdenc.h2
-rw-r--r--lib/libc/iconv/citrus_stdenc_local.h8
-rw-r--r--lib/libc/iconv/citrus_stdenc_template.h4
-rw-r--r--lib/libc/iconv/iconv-internal.h4
-rw-r--r--lib/libc/iconv/iconv.34
-rw-r--r--lib/libc/iconv/iconv.c2
-rw-r--r--lib/libc/iconv/iconv_compat.c4
-rw-r--r--lib/libc/iconv/iconvlist.34
-rw-r--r--lib/libc/include/compat.h9
-rw-r--r--lib/libc/include/libc_private.h163
-rw-r--r--lib/libc/locale/cXXrtomb_iconv.h3
-rw-r--r--lib/libc/locale/digittoint.32
-rw-r--r--lib/libc/locale/duplocale.32
-rw-r--r--lib/libc/locale/freelocale.32
-rw-r--r--lib/libc/locale/mbrtocXX_iconv.h3
-rw-r--r--lib/libc/locale/newlocale.32
-rw-r--r--lib/libc/locale/none.c2
-rw-r--r--lib/libc/locale/querylocale.32
-rw-r--r--lib/libc/locale/uselocale.32
-rw-r--r--lib/libc/locale/xlocale.32
-rw-r--r--lib/libc/mips/gen/Makefile.inc5
-rw-r--r--lib/libc/mips/gen/_setjmp.S83
-rw-r--r--lib/libc/mips/gen/getcontextx.c76
-rw-r--r--lib/libc/mips/gen/setjmp.S74
-rw-r--r--lib/libc/mips/gen/sigsetjmp.S2
-rw-r--r--lib/libc/mips/sys/Makefile.inc8
-rw-r--r--lib/libc/net/Symbol.map1
-rw-r--r--lib/libc/net/base64.c27
-rw-r--r--lib/libc/net/eui64.c1
-rw-r--r--lib/libc/net/getaddrinfo.34
-rw-r--r--lib/libc/net/getaddrinfo.c1
-rw-r--r--lib/libc/net/getifaddrs.322
-rw-r--r--lib/libc/net/ip6opt.c2
-rw-r--r--lib/libc/net/name6.c1
-rw-r--r--lib/libc/net/nsdispatch.c25
-rw-r--r--lib/libc/net/recv.c6
-rw-r--r--lib/libc/net/sctp_recvmsg.310
-rw-r--r--lib/libc/net/sctp_send.32
-rw-r--r--lib/libc/net/sctp_sys_calls.c10
-rw-r--r--lib/libc/net/send.c6
-rw-r--r--lib/libc/nls/catopen.32
-rw-r--r--lib/libc/nls/msgcat.c1
-rw-r--r--lib/libc/posix1e/acl_calc_mask.c1
-rw-r--r--lib/libc/posix1e/acl_set_flagset_np.32
-rw-r--r--lib/libc/posix1e/acl_strip.c14
-rw-r--r--lib/libc/powerpc/Makefile.inc2
-rw-r--r--lib/libc/powerpc/gen/Makefile.inc6
-rw-r--r--lib/libc/powerpc/gen/_set_tp.c3
-rw-r--r--lib/libc/powerpc/gen/_setjmp.S42
-rw-r--r--lib/libc/powerpc/gen/setjmp.S42
-rw-r--r--lib/libc/powerpc/gen/sigsetjmp.S42
-rw-r--r--lib/libc/powerpc/sys/Makefile.inc3
-rw-r--r--lib/libc/powerpc64/Makefile.inc2
-rw-r--r--lib/libc/powerpc64/gen/Makefile.inc5
-rw-r--r--lib/libc/powerpc64/gen/_set_tp.c3
-rw-r--r--lib/libc/powerpc64/gen/_setjmp.S36
-rw-r--r--lib/libc/powerpc64/gen/setjmp.S38
-rw-r--r--lib/libc/powerpc64/gen/sigsetjmp.S36
-rw-r--r--lib/libc/powerpc64/sys/Makefile.inc3
-rw-r--r--lib/libc/regex/engine.c4
-rw-r--r--lib/libc/regex/re_format.710
-rw-r--r--lib/libc/regex/regcomp.c29
-rw-r--r--lib/libc/regex/regex.36
-rw-r--r--lib/libc/rpc/clnt_dg.c3
-rw-r--r--lib/libc/rpc/crypt_client.c1
-rw-r--r--lib/libc/rpc/rpc.32
-rw-r--r--lib/libc/rpc/rpc_soc.c2
-rw-r--r--lib/libc/rpc/rpc_svc_reg.32
-rw-r--r--lib/libc/rpc/rpcbind.32
-rw-r--r--lib/libc/rpc/svc_vc.c2
-rw-r--r--lib/libc/sparc64/Makefile.inc2
-rw-r--r--lib/libc/sparc64/gen/Makefile.inc5
-rw-r--r--lib/libc/sparc64/gen/getcontextx.c76
-rw-r--r--lib/libc/sparc64/sys/Makefile.inc5
-rw-r--r--lib/libc/sparc64/sys/__vdso_gettc.c48
-rw-r--r--lib/libc/sparc64/sys/sigaction1.S (renamed from lib/libc/sparc64/sys/sigaction.S)5
-rw-r--r--lib/libc/stdio/fflush.c10
-rw-r--r--lib/libc/stdio/flags.c4
-rw-r--r--lib/libc/stdio/open_memstream.32
-rw-r--r--lib/libc/stdio/open_memstream.c2
-rw-r--r--lib/libc/stdio/open_wmemstream.c2
-rw-r--r--lib/libc/stdio/xprintf_float.c3
-rw-r--r--lib/libc/stdlib/Makefile.inc5
-rw-r--r--lib/libc/stdlib/Symbol.map2
-rw-r--r--lib/libc/stdlib/atexit.34
-rw-r--r--lib/libc/stdlib/exit.32
-rw-r--r--lib/libc/stdlib/jemalloc/Symbol.map1
-rw-r--r--lib/libc/stdlib/qsort.c53
-rw-r--r--lib/libc/stdlib/quick_exit.34
-rw-r--r--lib/libc/stdlib/random.35
-rw-r--r--lib/libc/stdlib/reallocarray.3142
-rw-r--r--lib/libc/stdlib/reallocarray.c42
-rw-r--r--lib/libc/stdlib/system.c15
-rw-r--r--lib/libc/stdlib/tdelete.c9
-rw-r--r--lib/libc/string/strlcat.c48
-rw-r--r--lib/libc/string/strlcpy.c37
-rw-r--r--lib/libc/string/strspn.32
-rw-r--r--lib/libc/sys/Makefile.inc67
-rw-r--r--lib/libc/sys/Symbol.map9
-rw-r--r--lib/libc/sys/__error.c25
-rw-r--r--lib/libc/sys/accept.c50
-rw-r--r--lib/libc/sys/accept4.c50
-rw-r--r--lib/libc/sys/access.22
-rw-r--r--lib/libc/sys/aio_suspend.c51
-rw-r--r--lib/libc/sys/cap_ioctls_limit.26
-rw-r--r--lib/libc/sys/close.c48
-rw-r--r--lib/libc/sys/closefrom.22
-rw-r--r--lib/libc/sys/connect.c50
-rw-r--r--lib/libc/sys/cpuset.23
-rw-r--r--lib/libc/sys/fcntl.c53
-rw-r--r--lib/libc/sys/fork.27
-rw-r--r--lib/libc/sys/fork.c48
-rw-r--r--lib/libc/sys/fsync.c47
-rw-r--r--lib/libc/sys/ftruncate.c55
-rw-r--r--lib/libc/sys/futimens.c97
-rw-r--r--lib/libc/sys/getdirentries.25
-rw-r--r--lib/libc/sys/getrlimit.22
-rw-r--r--lib/libc/sys/interposing_table.c89
-rw-r--r--lib/libc/sys/kevent.c53
-rw-r--r--lib/libc/sys/kqueue.2173
-rw-r--r--lib/libc/sys/lseek.c56
-rw-r--r--lib/libc/sys/mmap.220
-rw-r--r--lib/libc/sys/mmap.c56
-rw-r--r--lib/libc/sys/mount.29
-rw-r--r--lib/libc/sys/msync.c49
-rw-r--r--lib/libc/sys/nanosleep.c49
-rw-r--r--lib/libc/sys/open.26
-rw-r--r--lib/libc/sys/open.c59
-rw-r--r--lib/libc/sys/openat.c62
-rw-r--r--lib/libc/sys/poll.217
-rw-r--r--lib/libc/sys/poll.c49
-rw-r--r--lib/libc/sys/posix_openpt.24
-rw-r--r--lib/libc/sys/ppoll.c51
-rw-r--r--lib/libc/sys/pread.c57
-rw-r--r--lib/libc/sys/procctl.2304
-rw-r--r--lib/libc/sys/pselect.c51
-rw-r--r--lib/libc/sys/pwrite.c56
-rw-r--r--lib/libc/sys/read.c50
-rw-r--r--lib/libc/sys/readv.c50
-rw-r--r--lib/libc/sys/recvfrom.c53
-rw-r--r--lib/libc/sys/recvmsg.c50
-rw-r--r--lib/libc/sys/revoke.24
-rw-r--r--lib/libc/sys/sched_setscheduler.22
-rw-r--r--lib/libc/sys/select.c49
-rw-r--r--lib/libc/sys/sendmsg.c50
-rw-r--r--lib/libc/sys/sendto.c53
-rw-r--r--lib/libc/sys/setcontext.c52
-rw-r--r--lib/libc/sys/setresuid.27
-rw-r--r--lib/libc/sys/sigaction.c49
-rw-r--r--lib/libc/sys/sigprocmask.c49
-rw-r--r--lib/libc/sys/sigsuspend.c49
-rw-r--r--lib/libc/sys/sigtimedwait.c51
-rw-r--r--lib/libc/sys/sigwait.c14
-rw-r--r--lib/libc/sys/sigwaitinfo.22
-rw-r--r--lib/libc/sys/sigwaitinfo.c49
-rw-r--r--lib/libc/sys/socketpair.28
-rw-r--r--lib/libc/sys/swapcontext.c (renamed from lib/libc/gen/swapcontext.c)28
-rw-r--r--lib/libc/sys/trivial-vdso_tc.c (renamed from lib/libc/arm/sys/__vdso_gettc.c)0
-rw-r--r--lib/libc/sys/truncate.226
-rw-r--r--lib/libc/sys/truncate.c55
-rw-r--r--lib/libc/sys/utimensat.2292
-rw-r--r--lib/libc/sys/utimensat.c109
-rw-r--r--lib/libc/sys/vfork.26
-rw-r--r--lib/libc/sys/wait4.c49
-rw-r--r--lib/libc/sys/wait6.c52
-rw-r--r--lib/libc/sys/write.c50
-rw-r--r--lib/libc/sys/writev.c50
-rw-r--r--lib/libc/tests/c063/Makefile33
-rw-r--r--lib/libc/tests/db/Makefile1
-rw-r--r--lib/libc/tests/hash/Makefile8
-rw-r--r--lib/libc/tests/ssp/Makefile4
-rw-r--r--lib/libc/tests/sys/Makefile2
-rw-r--r--lib/libc/xdr/xdr_float.c3
-rw-r--r--lib/libcam/Makefile3
-rw-r--r--lib/libcapsicum/Makefile3
-rw-r--r--lib/libcapsicum/libcapsicum.318
-rw-r--r--lib/libcapsicum/libcapsicum.c14
-rw-r--r--lib/libcapsicum/libcapsicum.h4
-rw-r--r--lib/libcapsicum/libcapsicum_dns.c44
-rw-r--r--lib/libcapsicum/libcapsicum_grp.c35
-rw-r--r--lib/libcapsicum/libcapsicum_pwd.c22
-rw-r--r--lib/libcapsicum/libcapsicum_random.c2
-rw-r--r--lib/libcapsicum/libcapsicum_service.c2
-rw-r--r--lib/libcapsicum/libcapsicum_sysctl.c2
-rw-r--r--lib/libcasper/Makefile3
-rw-r--r--lib/libcasper/libcasper.c4
-rw-r--r--lib/libclang_rt/Makefile18
-rw-r--r--lib/libclang_rt/Makefile.inc26
-rw-r--r--lib/libclang_rt/asan/Makefile80
-rw-r--r--lib/libclang_rt/asan_cxx/Makefile11
-rw-r--r--lib/libclang_rt/profile/Makefile17
-rw-r--r--lib/libclang_rt/san/Makefile49
-rw-r--r--lib/libclang_rt/ubsan/Makefile17
-rw-r--r--lib/libclang_rt/ubsan_cxx/Makefile14
-rw-r--r--lib/libcom_err/Makefile2
-rw-r--r--lib/libcom_err/doc/Makefile7
-rw-r--r--lib/libcom_err/doc/com_err.texinfo615
-rw-r--r--lib/libcompat/4.3/rexec.c8
-rw-r--r--lib/libcompiler_rt/Makefile48
-rw-r--r--lib/libcrypt/tests/Makefile3
-rw-r--r--lib/libcuse/Makefile4
-rw-r--r--lib/libcxxrt/Makefile.depend.host13
-rw-r--r--lib/libdevctl/Makefile8
-rw-r--r--lib/libdevctl/devctl.3295
-rw-r--r--lib/libdevctl/devctl.c124
-rw-r--r--lib/libdevctl/devctl.h42
-rw-r--r--lib/libdevinfo/devinfo.h2
-rw-r--r--lib/libdevstat/Makefile3
-rw-r--r--lib/libdevstat/devstat.c24
-rw-r--r--lib/libdpv/Makefile3
-rw-r--r--lib/libdpv/Makefile.depend25
-rw-r--r--lib/libdpv/dpv.36
-rw-r--r--lib/libdwarf/Makefile16
-rw-r--r--lib/libedit/Makefile18
-rw-r--r--lib/libedit/Makefile.depend6
-rw-r--r--lib/libedit/TEST/rl1.c53
-rw-r--r--lib/libedit/TEST/tc1.c23
-rw-r--r--lib/libedit/TEST/wtc1.c281
-rw-r--r--lib/libedit/chared.c308
-rw-r--r--lib/libedit/chared.h53
-rw-r--r--lib/libedit/chartype.c360
-rw-r--r--lib/libedit/chartype.h27
-rw-r--r--lib/libedit/common.c280
-rw-r--r--lib/libedit/config.h290
-rw-r--r--lib/libedit/edit/readline/readline.h7
-rw-r--r--lib/libedit/editline.3162
-rw-r--r--lib/libedit/editrc.576
-rw-r--r--lib/libedit/el.c258
-rw-r--r--lib/libedit/el.h45
-rw-r--r--lib/libedit/eln.c401
-rw-r--r--lib/libedit/emacs.c158
-rw-r--r--lib/libedit/filecomplete.c305
-rw-r--r--lib/libedit/filecomplete.h9
-rw-r--r--lib/libedit/hist.c85
-rw-r--r--lib/libedit/hist.h30
-rw-r--r--lib/libedit/histedit.h150
-rw-r--r--lib/libedit/history.c459
-rw-r--r--lib/libedit/keymacro.c (renamed from lib/libedit/key.c)419
-rw-r--r--lib/libedit/keymacro.h (renamed from lib/libedit/key.h)60
-rw-r--r--lib/libedit/makelist34
-rw-r--r--lib/libedit/map.c226
-rw-r--r--lib/libedit/map.h19
-rw-r--r--lib/libedit/parse.c137
-rw-r--r--lib/libedit/parse.h11
-rw-r--r--lib/libedit/prompt.c59
-rw-r--r--lib/libedit/prompt.h13
-rw-r--r--lib/libedit/read.c235
-rw-r--r--lib/libedit/read.h5
-rw-r--r--lib/libedit/readline.c625
-rw-r--r--lib/libedit/refresh.c365
-rw-r--r--lib/libedit/refresh.h5
-rw-r--r--lib/libedit/search.c166
-rw-r--r--lib/libedit/search.h15
-rw-r--r--lib/libedit/sig.c14
-rw-r--r--lib/libedit/sig.h3
-rw-r--r--lib/libedit/sys.h99
-rw-r--r--lib/libedit/terminal.c (renamed from lib/libedit/term.c)1022
-rw-r--r--lib/libedit/terminal.h (renamed from lib/libedit/term.h)73
-rw-r--r--lib/libedit/tokenizer.c153
-rw-r--r--lib/libedit/tty.c379
-rw-r--r--lib/libedit/tty.h11
-rw-r--r--lib/libedit/vi.c349
-rw-r--r--lib/libelftc/Makefile30
-rw-r--r--lib/libelftc/elftc_version.c10
-rw-r--r--lib/libevent/Makefile1
-rw-r--r--lib/libexecinfo/Makefile3
-rw-r--r--lib/libexpat/Makefile2
-rw-r--r--lib/libfetch/Makefile6
-rw-r--r--lib/libfetch/common.c4
-rw-r--r--lib/libfetch/fetch.38
-rw-r--r--lib/libfigpar/Makefile.depend20
-rw-r--r--lib/libgeom/Makefile3
-rw-r--r--lib/libgeom/geom_xml2tree.c16
-rw-r--r--lib/libgpio/Makefile36
-rw-r--r--lib/libgpio/Makefile.depend20
-rw-r--r--lib/libgpio/gpio.3198
-rw-r--r--lib/libgpio/gpio.c278
-rw-r--r--lib/libgpio/libgpio.h110
-rw-r--r--lib/libgssapi/gss_acquire_cred.34
-rw-r--r--lib/libgssapi/gss_add_cred.34
-rw-r--r--lib/libgssapi/gss_add_oid_set_member.34
-rw-r--r--lib/libgssapi/gss_create_empty_oid_set.34
-rw-r--r--lib/libgssapi/gss_delete_sec_context.34
-rw-r--r--lib/libgssapi/gss_get_mic.34
-rw-r--r--lib/libgssapi/gss_import_sec_context.34
-rw-r--r--lib/libgssapi/gss_inquire_context.38
-rw-r--r--lib/libgssapi/gss_process_context_token.34
-rw-r--r--lib/libgssapi/gss_test_oid_set_member.32
-rw-r--r--lib/libgssapi/gss_unwrap.34
-rw-r--r--lib/libgssapi/gss_wrap.34
-rw-r--r--lib/libiconv/Makefile25
-rw-r--r--lib/libiconv_modules/BIG5/citrus_big5.c4
-rw-r--r--lib/libiconv_modules/DECHanyu/citrus_dechanyu.c4
-rw-r--r--lib/libiconv_modules/EUC/citrus_euc.c4
-rw-r--r--lib/libiconv_modules/EUCTW/citrus_euctw.c4
-rw-r--r--lib/libiconv_modules/GBK2K/citrus_gbk2k.c4
-rw-r--r--lib/libiconv_modules/HZ/citrus_hz.c4
-rw-r--r--lib/libiconv_modules/ISO2022/citrus_iso2022.c6
-rw-r--r--lib/libiconv_modules/JOHAB/citrus_johab.c4
-rw-r--r--lib/libiconv_modules/MSKanji/citrus_mskanji.c4
-rw-r--r--lib/libiconv_modules/UES/citrus_ues.c4
-rw-r--r--lib/libiconv_modules/UTF1632/citrus_utf1632.c4
-rw-r--r--lib/libiconv_modules/UTF7/citrus_utf7.c6
-rw-r--r--lib/libiconv_modules/UTF8/citrus_utf8.c4
-rw-r--r--lib/libiconv_modules/VIQR/citrus_viqr.c4
-rw-r--r--lib/libiconv_modules/ZW/citrus_zw.c4
-rw-r--r--lib/libiconv_modules/iconv_none/citrus_iconv_none.c2
-rw-r--r--lib/libiconv_modules/iconv_std/citrus_iconv_std.c6
-rw-r--r--lib/libjail/jail.c4
-rw-r--r--lib/libjail/jail_getid.c10
-rw-r--r--lib/libkiconv/xlat16_iconv.c19
-rw-r--r--lib/libkvm/kvm_aarch64.c (renamed from lib/libc/powerpc64/sys/__vdso_gettc.c)40
-rw-r--r--lib/libldns/Makefile3
-rw-r--r--lib/liblzma/Makefile42
-rw-r--r--lib/liblzma/Makefile.depend2
-rw-r--r--lib/liblzma/Symbol.map20
-rw-r--r--lib/liblzma/Versions.def4
-rw-r--r--lib/liblzma/config.h429
-rw-r--r--lib/libmagic/Makefile3
-rw-r--r--lib/libmagic/config.h37
-rw-r--r--lib/libmandoc/Makefile20
-rw-r--r--lib/libmd/Makefile8
-rw-r--r--lib/libmd/Makefile.depend.host36
-rw-r--r--lib/libmd/md4.h28
-rw-r--r--lib/libmd/md4c.c15
-rw-r--r--lib/libmd/md5.h37
-rw-r--r--lib/libmd/md5c.c19
-rw-r--r--lib/libmd/mdXhl.c17
-rw-r--r--lib/libmd/ripemd.h35
-rw-r--r--lib/libmd/rmd160c.c19
-rw-r--r--lib/libmd/sha.h68
-rw-r--r--lib/libmd/sha1c.c30
-rw-r--r--lib/libmd/sha256.h32
-rw-r--r--lib/libmd/sha256c.c15
-rw-r--r--lib/libmd/sha512.h32
-rw-r--r--lib/libmd/sha512c.c15
-rw-r--r--lib/libmd/shadriver.c3
-rw-r--r--lib/libmemstat/Makefile3
-rw-r--r--lib/libmp/Makefile3
-rw-r--r--lib/libmp/tests/Makefile3
-rw-r--r--lib/libmt/Makefile12
-rw-r--r--lib/libmt/Makefile.depend22
-rw-r--r--lib/libmt/mt.3454
-rw-r--r--lib/libmt/mtlib.c773
-rw-r--r--lib/libmt/mtlib.h122
-rw-r--r--lib/libnetgraph/debug.c29
-rw-r--r--lib/libnv/Makefile184
-rw-r--r--lib/libnv/dnv.h106
-rw-r--r--lib/libnv/dnvlist.c252
-rw-r--r--lib/libnv/nv.397
-rw-r--r--lib/libnv/nv.h275
-rw-r--r--lib/libnv/nv_impl.h134
-rw-r--r--lib/libnv/nvlist.c1848
-rw-r--r--lib/libnv/nvlist_impl.h47
-rw-r--r--lib/libnv/nvpair.c1282
-rw-r--r--lib/libnv/nvpair_impl.h92
-rw-r--r--lib/libnv/tests/Makefile9
-rw-r--r--lib/libnv/tests/dnv_tests.cc567
-rw-r--r--lib/libnv/tests/nv_tests.cc1275
-rw-r--r--lib/libnv/tests/nvlist_send_recv_test.c23
-rw-r--r--lib/libopie/Makefile3
-rw-r--r--lib/libpam/libpam/tests/Makefile3
-rw-r--r--lib/libpam/modules/Makefile.inc3
-rw-r--r--lib/libpam/modules/modules.inc2
-rw-r--r--lib/libpam/modules/pam_guest/pam_guest.82
-rw-r--r--lib/libpam/modules/pam_krb5/Makefile3
-rw-r--r--lib/libpam/modules/pam_ksu/Makefile3
-rw-r--r--lib/libpam/modules/pam_nologin/Makefile3
-rw-r--r--lib/libpam/modules/pam_opie/Makefile3
-rw-r--r--lib/libpam/modules/pam_opieaccess/Makefile3
-rw-r--r--lib/libpam/modules/pam_passwdqc/Makefile3
-rw-r--r--lib/libpam/modules/pam_radius/Makefile3
-rw-r--r--lib/libpam/modules/pam_radius/pam_radius.c30
-rw-r--r--lib/libpam/modules/pam_ssh/Makefile4
-rw-r--r--lib/libpam/modules/pam_tacplus/Makefile3
-rw-r--r--lib/libpam/modules/pam_unix/Makefile6
-rw-r--r--lib/libpcap/Makefile3
-rw-r--r--lib/libpcap/config.h24
-rw-r--r--lib/libpjdlog/Makefile3
-rw-r--r--lib/libpmc/libpmc.c206
-rw-r--r--lib/libpmc/pmc.31
-rw-r--r--lib/libpmc/pmc.corei7.38
-rw-r--r--lib/libpmc/pmc.corei7uc.38
-rw-r--r--lib/libpmc/pmc.haswell.3153
-rw-r--r--lib/libpmc/pmc.haswellxeon.3956
-rw-r--r--lib/libpmc/pmc.ivybridge.3141
-rw-r--r--lib/libpmc/pmc.ivybridgexeon.3141
-rw-r--r--lib/libpmc/pmc.sandybridge.3100
-rw-r--r--lib/libpmc/pmc.sandybridgexeon.3112
-rw-r--r--lib/libpmc/pmc.soft.38
-rw-r--r--lib/libpmc/pmc.ucf.38
-rw-r--r--lib/libpmc/pmc.westmere.38
-rw-r--r--lib/libpmc/pmc.westmereuc.38
-rw-r--r--lib/libpmc/pmc.xscale.32
-rw-r--r--lib/libpmc/pmc_capabilities.32
-rw-r--r--lib/libproc/Makefile12
-rw-r--r--lib/libproc/Makefile.depend1
-rw-r--r--lib/libproc/proc_bkpt.c3
-rw-r--r--lib/libproc/proc_regs.c8
-rw-r--r--lib/libproc/proc_sym.c42
-rw-r--r--lib/libproc/tests/proc_test.c40
-rw-r--r--lib/libprocstat/Makefile33
-rw-r--r--lib/libprocstat/libprocstat.353
-rw-r--r--lib/libprocstat/udf.c1
-rw-r--r--lib/libradius/Makefile10
-rw-r--r--lib/librpcsec_gss/Makefile3
-rw-r--r--lib/librpcsec_gss/Makefile.depend1
-rw-r--r--lib/librpcsec_gss/rpc_gss_get_error.32
-rw-r--r--lib/librpcsec_gss/rpc_gss_get_mech_info.32
-rw-r--r--lib/librpcsec_gss/rpc_gss_get_mechanisms.32
-rw-r--r--lib/librpcsec_gss/rpc_gss_get_principal_name.34
-rw-r--r--lib/librpcsec_gss/rpc_gss_get_versions.32
-rw-r--r--lib/librpcsec_gss/rpc_gss_getcred.32
-rw-r--r--lib/librpcsec_gss/rpc_gss_is_installed.32
-rw-r--r--lib/librpcsec_gss/rpc_gss_max_data_length.32
-rw-r--r--lib/librpcsec_gss/rpc_gss_mech_to_oid.32
-rw-r--r--lib/librpcsec_gss/rpc_gss_oid_to_mech.32
-rw-r--r--lib/librpcsec_gss/rpc_gss_qop_to_num.32
-rw-r--r--lib/librpcsec_gss/rpc_gss_seccreate.36
-rw-r--r--lib/librpcsec_gss/rpc_gss_set_callback.34
-rw-r--r--lib/librpcsec_gss/rpc_gss_set_defaults.32
-rw-r--r--lib/librpcsec_gss/rpc_gss_set_svc_name.34
-rw-r--r--lib/librpcsec_gss/rpc_gss_svc_max_data_length.32
-rw-r--r--lib/librpcsec_gss/rpcsec_gss.38
-rw-r--r--lib/librt/Makefile7
-rw-r--r--lib/librt/Makefile.amd646
-rw-r--r--lib/librt/Makefile.i3866
-rw-r--r--lib/librt/tests/Makefile3
-rw-r--r--lib/librtld_db/librtld_db.34
-rw-r--r--lib/libsdp/search.c1
-rw-r--r--lib/libsdp/service.c1
-rw-r--r--lib/libsdp/session.c5
-rw-r--r--lib/libsdp/util.c1
-rw-r--r--lib/libsmb/Makefile3
-rw-r--r--lib/libsqlite3/Makefile39
-rw-r--r--lib/libsqlite3/Makefile.depend21
-rw-r--r--lib/libstand/Makefile45
-rw-r--r--lib/libstand/cd9660.c15
-rw-r--r--lib/libstand/dosfs.c3
-rw-r--r--lib/libstand/ext2fs.c12
-rw-r--r--lib/libstand/libstand.32
-rw-r--r--lib/libstand/nandfs.c2
-rw-r--r--lib/libstand/nfs.c4
-rw-r--r--lib/libstand/powerpc/_setjmp.S4
-rw-r--r--lib/libstand/powerpc/syncicache.c103
-rw-r--r--lib/libstand/printf.c4
-rw-r--r--lib/libstand/read.c2
-rw-r--r--lib/libstand/stand.h3
-rw-r--r--lib/libstand/tftp.c4
-rw-r--r--lib/libstand/twiddle.c21
-rw-r--r--lib/libstand/ufs.c14
-rw-r--r--lib/libstand/write.c2
-rw-r--r--lib/libstdthreads/Makefile3
-rw-r--r--lib/libstdthreads/Makefile.depend1
-rw-r--r--lib/libstdthreads/mtx.c2
-rw-r--r--lib/libstdthreads/thrd.c3
-rw-r--r--lib/libtacplus/Makefile3
-rw-r--r--lib/libthr/Makefile9
-rw-r--r--lib/libthr/Makefile.amd646
-rw-r--r--lib/libthr/Makefile.i3866
-rw-r--r--lib/libthr/arch/aarch64/Makefile.inc2
-rw-r--r--lib/libthr/arch/aarch64/include/pthread_md.h (renamed from lib/libc/powerpc64/gen/getcontextx.c)78
-rw-r--r--lib/libthr/arch/amd64/Makefile.inc2
-rw-r--r--lib/libthr/arch/amd64/amd64/pthread_md.c55
-rw-r--r--lib/libthr/arch/amd64/include/pthread_md.h3
-rw-r--r--lib/libthr/arch/arm/Makefile.inc3
-rw-r--r--lib/libthr/arch/arm/arm/pthread_md.c53
-rw-r--r--lib/libthr/arch/arm/include/pthread_md.h6
-rw-r--r--lib/libthr/arch/i386/Makefile.inc2
-rw-r--r--lib/libthr/arch/i386/i386/pthread_md.c57
-rw-r--r--lib/libthr/arch/i386/include/pthread_md.h6
-rw-r--r--lib/libthr/arch/mips/Makefile.inc3
-rw-r--r--lib/libthr/arch/mips/include/pthread_md.h6
-rw-r--r--lib/libthr/arch/mips/mips/pthread_md.c59
-rw-r--r--lib/libthr/arch/powerpc/Makefile.inc3
-rw-r--r--lib/libthr/arch/powerpc/include/pthread_md.h17
-rw-r--r--lib/libthr/arch/powerpc/powerpc/pthread_md.c54
-rw-r--r--lib/libthr/arch/sparc64/Makefile.inc2
-rw-r--r--lib/libthr/arch/sparc64/include/pthread_md.h6
-rw-r--r--lib/libthr/libthr.342
-rw-r--r--lib/libthr/pthread.map96
-rw-r--r--lib/libthr/sys/thr_error.c3
-rw-r--r--lib/libthr/tests/Makefile2
-rw-r--r--lib/libthr/thread/Makefile.inc1
-rw-r--r--lib/libthr/thread/thr_barrier.c5
-rw-r--r--lib/libthr/thread/thr_clean.c2
-rw-r--r--lib/libthr/thread/thr_create.c8
-rw-r--r--lib/libthr/thread/thr_ctrdtr.c (renamed from lib/libthr/arch/sparc64/sparc64/pthread_md.c)2
-rw-r--r--lib/libthr/thread/thr_fork.c6
-rw-r--r--lib/libthr/thread/thr_init.c10
-rw-r--r--lib/libthr/thread/thr_mutex.c7
-rw-r--r--lib/libthr/thread/thr_printf.c1
-rw-r--r--lib/libthr/thread/thr_private.h29
-rw-r--r--lib/libthr/thread/thr_sig.c180
-rw-r--r--lib/libthr/thread/thr_spec.c201
-rw-r--r--lib/libthr/thread/thr_spinlock.c10
-rw-r--r--lib/libthr/thread/thr_syscalls.c558
-rw-r--r--lib/libthread_db/arch/aarch64/libpthread_md.c96
-rw-r--r--lib/libthread_db/arch/i386/libpthread_md.c2
-rw-r--r--lib/libucl/Makefile9
-rw-r--r--lib/libufs/Makefile1
-rw-r--r--lib/libulog/Makefile3
-rw-r--r--lib/libunbound/Makefile11
-rw-r--r--lib/libusb/Makefile3
-rw-r--r--lib/libusb/libusb.34
-rw-r--r--lib/libusb/libusb.h2
-rw-r--r--lib/libusb/libusb20.32
-rw-r--r--lib/libusb/libusb20_desc.h6
-rw-r--r--lib/libutil/gr_util.c25
-rw-r--r--lib/libutil/quotafile.34
-rw-r--r--lib/libutil/tests/Makefile3
-rw-r--r--lib/libvmmapi/Makefile2
-rw-r--r--lib/libvmmapi/vmmapi.c131
-rw-r--r--lib/libvmmapi/vmmapi.h32
-rw-r--r--lib/libxo/Makefile48
-rw-r--r--lib/msun/Makefile4
-rw-r--r--lib/msun/Makefile.amd646
-rw-r--r--lib/msun/Makefile.i3866
-rw-r--r--lib/msun/aarch64/Makefile.inc4
-rw-r--r--lib/msun/aarch64/fenv.c56
-rw-r--r--lib/msun/aarch64/fenv.h246
-rw-r--r--lib/msun/ld128/k_expl.h2
-rw-r--r--lib/msun/ld80/k_expl.h2
-rw-r--r--lib/msun/man/cexp.32
-rw-r--r--lib/msun/man/complex.32
-rw-r--r--lib/msun/man/csqrt.32
-rw-r--r--lib/msun/man/j0.345
-rw-r--r--lib/msun/man/lgamma.33
-rw-r--r--lib/msun/man/nextafter.34
-rw-r--r--lib/msun/man/sin.32
-rw-r--r--lib/msun/src/catrig.c64
-rw-r--r--lib/msun/src/catrigf.c64
-rw-r--r--lib/msun/src/e_j0.c30
-rw-r--r--lib/msun/src/e_j0f.c45
-rw-r--r--lib/msun/src/e_j1.c28
-rw-r--r--lib/msun/src/e_j1f.c43
-rw-r--r--lib/msun/src/e_jn.c10
-rw-r--r--lib/msun/src/e_jnf.c11
-rw-r--r--lib/msun/src/k_exp.c2
-rw-r--r--lib/msun/src/k_expf.c2
-rw-r--r--lib/msun/src/math_private.h18
-rw-r--r--lib/msun/src/s_ccosh.c28
-rw-r--r--lib/msun/src/s_ccoshf.c28
-rw-r--r--lib/msun/src/s_cexp.c12
-rw-r--r--lib/msun/src/s_cexpf.c12
-rw-r--r--lib/msun/src/s_conj.c2
-rw-r--r--lib/msun/src/s_conjf.c2
-rw-r--r--lib/msun/src/s_conjl.c2
-rw-r--r--lib/msun/src/s_cproj.c2
-rw-r--r--lib/msun/src/s_cprojf.c2
-rw-r--r--lib/msun/src/s_cprojl.c2
-rw-r--r--lib/msun/src/s_csinh.c30
-rw-r--r--lib/msun/src/s_csinhf.c30
-rw-r--r--lib/msun/src/s_csqrt.c14
-rw-r--r--lib/msun/src/s_csqrtf.c14
-rw-r--r--lib/msun/src/s_csqrtl.c14
-rw-r--r--lib/msun/src/s_ctanh.c14
-rw-r--r--lib/msun/src/s_ctanhf.c14
-rw-r--r--lib/msun/src/s_scalbln.c40
-rw-r--r--lib/msun/tests/Makefile12
-rw-r--r--lib/ncurses/Makefile7
-rw-r--r--lib/ncurses/form/Makefile3
-rw-r--r--lib/ncurses/form/Makefile.depend1
-rw-r--r--lib/ncurses/formw/Makefile.depend1
-rw-r--r--lib/ncurses/menu/Makefile3
-rw-r--r--lib/ncurses/menu/Makefile.depend1
-rw-r--r--lib/ncurses/menuw/Makefile.depend1
-rw-r--r--lib/ncurses/panel/Makefile3
-rw-r--r--lib/ncurses/panel/Makefile.depend1
-rw-r--r--lib/ncurses/panelw/Makefile.depend1
832 files changed, 21496 insertions, 12341 deletions
diff --git a/lib/Makefile b/lib/Makefile
index 8ca673a..bee05ab 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -8,11 +8,12 @@
# and the main list to avoid needing a SUBDIR_DEPEND line on every library
# naming just these few items.
-SUBDIR_ORDERED= ${_csu} \
+SUBDIR_ORDERED= csu \
.WAIT \
libc \
libc_nonshared \
libcompiler_rt \
+ ${_libclang_rt} \
${_libcplusplus} \
${_libcxxrt} \
libelf \
@@ -40,18 +41,20 @@ SUBDIR= ${SUBDIR_ORDERED} \
${_libcom_err} \
libcompat \
libcrypt \
+ libdevctl \
libdevinfo \
libdevstat \
libdpv \
libdwarf \
libedit \
+ ${_libelftc} \
${_libevent} \
libexecinfo \
libexpat \
libfetch \
libfigpar \
libgeom \
- ${_libgpib} \
+ ${_libgpio} \
${_libgssapi} \
${_librpcsec_gss} \
${_libiconv_modules} \
@@ -61,12 +64,12 @@ SUBDIR= ${SUBDIR_ORDERED} \
libkvm \
${_libldns} \
liblzma \
- libmagic \
- libmandoc \
+ ${_libmagic} \
libmemstat \
libmd \
${_libmilter} \
${_libmp} \
+ libmt \
${_libnandfs} \
libnetbsd \
${_libnetgraph} \
@@ -80,7 +83,7 @@ SUBDIR= ${SUBDIR_ORDERED} \
${_libpmc} \
${_libproc} \
libprocstat \
- libradius \
+ ${_libradius} \
librpcsvc \
librt \
${_librtld_db} \
@@ -90,6 +93,7 @@ SUBDIR= ${SUBDIR_ORDERED} \
${_libsmb} \
${_libsmdb} \
${_libsmutil} \
+ libsqlite3 \
libstand \
libstdbuf \
libstdthreads \
@@ -139,7 +143,7 @@ SUBDIR_DEPEND_liblibrpcsec_gss= libgssapi
SUBDIR_DEPEND_libmagic= libz
SUBDIR_DEPEND_libmemstat= libkvm
SUBDIR_DEPEND_libopie= libmd
-SUBDIR_DEPEND_libpam= libcrypt libopie libradius librpcsvc libtacplus libutil ${_libypclnt} ${_libcom_err}
+SUBDIR_DEPEND_libpam= libcrypt libopie ${_libradius} librpcsvc libtacplus libutil ${_libypclnt} ${_libcom_err}
SUBDIR_DEPEND_libpjdlog= libutil
SUBDIR_DEPEND_libprocstat= libkvm libutil
SUBDIR_DEPEND_libradius= libmd
@@ -149,16 +153,7 @@ SUBDIR_DEPEND_libstdc++= msun
SUBDIR_DEPEND_libtacplus= libmd
SUBDIR_DEPEND_libulog= libmd
SUBDIR_DEPEND_libunbound= ${_libldns}
-
-.if exists(${.CURDIR}/csu/${MACHINE_ARCH}-elf)
-_csu=csu/${MACHINE_ARCH}-elf
-.elif exists(${.CURDIR}/csu/${MACHINE_ARCH})
-_csu=csu/${MACHINE_ARCH}
-.elif exists(${.CURDIR}/csu/${MACHINE_CPUARCH}/Makefile)
-_csu=csu/${MACHINE_CPUARCH}
-.else
-_csu=csu
-.endif
+SUBDIR_DEPEND_liblzma= ${_libthr}
# NB: keep these sorted by MK_* knobs
@@ -188,8 +183,16 @@ _clang= clang
_cuse= libcuse
.endif
-.if ${MK_GPIB} != "no"
-_libgpib= libgpib
+.if ${MK_ELFTOOLCHAIN_TOOLS} != "no"
+_libelftc= libelftc
+.endif
+
+.if ${MK_FILE} != "no"
+_libmagic= libmagic
+.endif
+
+.if ${MK_GPIO} != "no"
+_libgpio= libgpio
.endif
.if ${MK_GSSAPI} != "no"
@@ -209,6 +212,15 @@ _libcom_err= libcom_err
_libldns= libldns
.endif
+# The libraries under libclang_rt can only be built by clang, and only make
+# sense to build when clang is enabled at all. Furthermore, they can only be
+# built for certain architectures.
+.if ${MK_CLANG} != "no" && ${COMPILER_TYPE} == "clang" && \
+ (${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64" || \
+ (${MACHINE_CPUARCH} == "arm" && ${MACHINE_ARCH} != "armeb"))
+_libclang_rt= libclang_rt
+.endif
+
.if ${MK_LIBCPLUSPLUS} != "no"
_libcxxrt= libcxxrt
_libcplusplus= libc++
@@ -242,8 +254,10 @@ _librtld_db= librtld_db
.endif
.if ${MACHINE_CPUARCH} == "amd64"
+.if ${MK_BHYVE} != "no"
_libvmmapi= libvmmapi
.endif
+.endif
.if ${MACHINE_CPUARCH} == "mips"
_libproc= libproc
@@ -260,6 +274,12 @@ _libsmb= libsmb
_libsmb= libsmb
.endif
+.if ${MACHINE_CPUARCH} == "arm"
+_libsmb= libsmb
+_libproc= libproc
+_librtld_db= librtld_db
+.endif
+
.if ${MK_OPENSSL} != "no"
_libmp= libmp
.endif
@@ -268,6 +288,10 @@ _libmp= libmp
_libpmc= libpmc
.endif
+.if ${MK_RADIUS_SUPPORT} != "no"
+_libradius= libradius
+.endif
+
.if ${MK_SENDMAIL} != "no"
_libmilter= libmilter
_libsm= libsm
diff --git a/lib/atf/libatf-c++/Makefile b/lib/atf/libatf-c++/Makefile
index 352a8f4..13f3fe4 100644
--- a/lib/atf/libatf-c++/Makefile
+++ b/lib/atf/libatf-c++/Makefile
@@ -28,13 +28,12 @@
.include <src.opts.mk>
.include <bsd.init.mk>
-LIB= atf-c++
+LIB_CXX= atf-c++
PRIVATELIB= true
SHLIB_MAJOR= 2
# libatf-c++ depends on the C version of the ATF library to build.
-DPADD= ${LIBATF_C}
-LDADD= -latf-c
+LIBADD+= atf_c
LDFLAGS+= -L${.OBJDIR}/../libatf-c
diff --git a/lib/atf/libatf-c++/Makefile.depend b/lib/atf/libatf-c++/Makefile.depend
index c93850e..5f89eee 100644
--- a/lib/atf/libatf-c++/Makefile.depend
+++ b/lib/atf/libatf-c++/Makefile.depend
@@ -3,10 +3,17 @@
DEP_RELDIR := ${_PARSEDIR:S,${SRCTOP}/,,}
DIRDEPS = \
+ gnu/lib/csu \
+ gnu/lib/libgcc \
include \
include/xlocale \
+ lib/${CSU_DIR} \
lib/atf/libatf-c \
+ lib/libc \
lib/libc++ \
+ lib/libcompiler_rt \
+ lib/libcxxrt \
+ lib/msun \
usr.bin/xinstall.host \
diff --git a/lib/clang/Makefile b/lib/clang/Makefile
index 328aa78..a7513c3 100644
--- a/lib/clang/Makefile
+++ b/lib/clang/Makefile
@@ -11,11 +11,6 @@ _libclangstaticanalyzer= \
_libclangarcmigrate= \
libclangarcmigrate
.endif # MK_CLANG_FULL
-.if ${MK_CLANG_FULL} != "no" || ${MK_LLDB} != "no"
-_libclangrewriter= \
- libclangrewritecore \
- libclangrewritefrontend
-.endif # (MK_CLANG_FULL || MK_LLDB)
SUBDIR= libclanganalysis \
${_libclangarcmigrate} \
@@ -28,7 +23,8 @@ SUBDIR= libclanganalysis \
libclangfrontendtool \
libclanglex \
libclangparse \
- ${_libclangrewriter} \
+ libclangrewritefrontend \
+ libclangrewrite \
libclangsema \
libclangserialization \
${_libclangstaticanalyzer} \
@@ -47,10 +43,12 @@ SUBDIR= libclanganalysis \
libllvmirreader \
libllvmlinker \
libllvmmc \
+ libllvmmcdisassembler \
libllvmmcparser \
libllvmobjcarcopts \
libllvmobject \
libllvmoption \
+ libllvmprofiledata \
libllvmscalaropts \
libllvmselectiondag \
libllvmsupport \
@@ -59,6 +57,13 @@ SUBDIR= libclanganalysis \
libllvmtransformutils \
libllvmvectorize \
\
+ libllvmaarch64asmparser \
+ libllvmaarch64codegen \
+ libllvmaarch64desc \
+ libllvmaarch64disassembler \
+ libllvmaarch64info \
+ libllvmaarch64instprinter \
+ libllvmaarch64utils \
libllvmarmasmparser \
libllvmarmcodegen \
libllvmarmdesc \
@@ -74,6 +79,7 @@ SUBDIR= libclanganalysis \
libllvmpowerpcasmparser \
libllvmpowerpccodegen \
libllvmpowerpcdesc \
+ libllvmpowerpcdisassembler \
libllvmpowerpcinfo \
libllvmpowerpcinstprinter \
libllvmsparcasmparser \
@@ -96,8 +102,6 @@ SUBDIR+=libllvmdebuginfo
.if ${MK_CLANG_EXTRAS} != "no" || ${MK_LLDB} != "no"
SUBDIR+=libllvmexecutionengine \
libllvminterpreter \
- libllvmjit \
- libllvmmcdisassembler \
libllvmmcjit \
libllvmruntimedyld
.endif # MK_CLANG_EXTRAS | LLDB
@@ -113,19 +117,27 @@ SUBDIR+=liblldb \
liblldbExpression \
liblldbHostCommon \
liblldbHostFreeBSD \
+ liblldbHostPOSIX \
liblldbInterpreter \
liblldbSymbol \
liblldbTarget \
liblldbUtility \
\
+ liblldbPluginABISysV_ppc \
+ liblldbPluginABISysV_ppc64 \
liblldbPluginABISysV_x86_64 \
liblldbPluginCXXItaniumABI \
liblldbPluginDisassemblerLLVM \
liblldbPluginDynamicLoaderStatic \
liblldbPluginDynamicLoaderPosixDYLD \
liblldbPluginInstructionARM \
+ liblldbPluginInstructionARM64 \
+ liblldbPluginInstrumentationRuntimeAddressSanitizer \
+ liblldbPluginJITLoaderGDB \
+ liblldbPluginMemoryHistoryASan \
liblldbPluginObjectContainerBSDArchive \
liblldbPluginObjectFileELF \
+ liblldbPluginObjectFileJIT \
liblldbPluginPlatformFreeBSD \
liblldbPluginPlatformGDB \
liblldbPluginProcessElfCore \
diff --git a/lib/clang/clang.build.mk b/lib/clang/clang.build.mk
index 0f68178..c4ce724 100644
--- a/lib/clang/clang.build.mk
+++ b/lib/clang/clang.build.mk
@@ -12,7 +12,6 @@ CFLAGS+= -I${LLVM_SRCS}/include -I${CLANG_SRCS}/include \
.if ${MK_CLANG_FULL} != "no"
CFLAGS+= -DCLANG_ENABLE_ARCMT \
- -DCLANG_ENABLE_REWRITER \
-DCLANG_ENABLE_STATIC_ANALYZER
.endif # MK_CLANG_FULL
@@ -30,22 +29,29 @@ TARGET_ABI= gnueabi
TARGET_ABI= unknown
.endif
-TARGET_TRIPLE?= ${TARGET_ARCH:C/amd64/x86_64/:C/armv6hf/armv6/}-${TARGET_ABI}-freebsd11.0
-BUILD_TRIPLE?= ${BUILD_ARCH:C/amd64/x86_64/:C/armv6hf/armv6/}-unknown-freebsd11.0
+TARGET_TRIPLE?= ${TARGET_ARCH:C/amd64/x86_64/:C/armv6hf/armv6/:C/arm64/aarch64/}-${TARGET_ABI}-freebsd11.0
+BUILD_TRIPLE?= ${BUILD_ARCH:C/amd64/x86_64/:C/armv6hf/armv6/:C/arm64/aarch64/}-unknown-freebsd11.0
CFLAGS+= -DLLVM_DEFAULT_TARGET_TRIPLE=\"${TARGET_TRIPLE}\" \
-DLLVM_HOST_TRIPLE=\"${BUILD_TRIPLE}\" \
-DDEFAULT_SYSROOT=\"${TOOLS_PREFIX}\"
-CXXFLAGS+= -fno-exceptions -fno-rtti
+CXXFLAGS+= -std=c++11 -fno-exceptions -fno-rtti
+CXXFLAGS.clang+= -stdlib=libc++
.PATH: ${LLVM_SRCS}/${SRCDIR}
-.if ${MACHINE} == "host" && defined(EARLY_BUILD)
+#.info ${MACHINE BOOTSTRAPPING_TOOLS LEGACY_TOOLS:L:@v@$v=${$v}@}
+.if empty(TOOLSDIR) || !exists(${TOOLSDIR}/usr/bin/clang-tblgen)
+.if ${MACHINE} == "host" && defined(BOOTSTRAPPING_TOOLS)
.if !empty(LEGACY_TOOLS) && exists(${LEGACY_TOOLS}/usr/bin/tblgen)
TOOLSDIR= ${LEGACY_TOOLS}
.endif
.endif
-.if ${MK_STAGING} == "yes"
-TOOLSDIR?= ${STAGE_HOST_OBJTOP}
+.if ${MK_STAGING} == "yes" && exists(${STAGE_HOST_OBJTOP:Uno}/usr/bin/tblgen)
+TOOLSDIR= ${STAGE_HOST_OBJTOP}
+.endif
+.if exists(${LEGACY_TOOLS:Uno}/usr/bin/tblgen)
+TOOLSDIR= ${LEGACY_TOOLS}
+.endif
.endif
TOOLSDIR?=
.if !empty(TOOLSDIR) && exists(${TOOLSDIR}/usr/bin/clang-tblgen)
@@ -54,13 +60,14 @@ CLANG_TBLGEN= ${TOOLSDIR}/usr/bin/clang-tblgen
.endif
TBLGEN?= tblgen
CLANG_TBLGEN?= clang-tblgen
+#.info ${TOOLSDIR TBLGEN CLANG_TBLGEN:L:@v@$v=${$v}@}
Intrinsics.inc.h: ${LLVM_SRCS}/include/llvm/IR/Intrinsics.td
${TBLGEN} -gen-intrinsic \
-I ${LLVM_SRCS}/include -d ${.TARGET:C/\.h$/.d/} -o ${.TARGET} \
${LLVM_SRCS}/include/llvm/IR/Intrinsics.td
.for arch in \
- ARM/ARM Mips/Mips PowerPC/PPC Sparc/Sparc X86/X86
+ AArch64/AArch64 ARM/ARM Mips/Mips PowerPC/PPC Sparc/Sparc X86/X86
. for hdr in \
AsmMatcher/-gen-asm-matcher \
AsmWriter1/-gen-asm-writer,-asmwriternum=1 \
@@ -71,7 +78,7 @@ Intrinsics.inc.h: ${LLVM_SRCS}/include/llvm/IR/Intrinsics.td
DisassemblerTables/-gen-disassembler \
FastISel/-gen-fast-isel \
InstrInfo/-gen-instr-info \
- MCCodeEmitter/-gen-emitter,-mc-emitter \
+ MCCodeEmitter/-gen-emitter \
MCPseudoLowering/-gen-pseudo-lowering \
RegisterInfo/-gen-register-info \
SubtargetInfo/-gen-subtarget
@@ -93,8 +100,8 @@ AttrDump.inc.h: ${CLANG_SRCS}/include/clang/Basic/Attr.td
-I ${CLANG_SRCS}/include -d ${.TARGET:C/\.h$/.d/} -o ${.TARGET} \
${CLANG_SRCS}/include/clang/Basic/Attr.td
-AttrIdentifierArg.inc.h: ${CLANG_SRCS}/include/clang/Basic/Attr.td
- ${CLANG_TBLGEN} -gen-clang-attr-identifier-arg-list \
+AttrHasAttributeImpl.inc.h: ${CLANG_SRCS}/include/clang/Basic/Attr.td
+ ${CLANG_TBLGEN} -gen-clang-attr-has-attribute-impl \
-I ${CLANG_SRCS}/include -d ${.TARGET:C/\.h$/.d/} -o ${.TARGET} \
${CLANG_SRCS}/include/clang/Basic/Attr.td
@@ -103,11 +110,6 @@ AttrImpl.inc.h: ${CLANG_SRCS}/include/clang/Basic/Attr.td
-I ${CLANG_SRCS}/include -d ${.TARGET:C/\.h$/.d/} -o ${.TARGET} \
${CLANG_SRCS}/include/clang/Basic/Attr.td
-AttrLateParsed.inc.h: ${CLANG_SRCS}/include/clang/Basic/Attr.td
- ${CLANG_TBLGEN} -gen-clang-attr-late-parsed-list \
- -I ${CLANG_SRCS}/include -d ${.TARGET:C/\.h$/.d/} -o ${.TARGET} \
- ${CLANG_SRCS}/include/clang/Basic/Attr.td
-
AttrList.inc.h: ${CLANG_SRCS}/include/clang/Basic/Attr.td
${CLANG_TBLGEN} -gen-clang-attr-list \
-I ${CLANG_SRCS}/include -d ${.TARGET:C/\.h$/.d/} -o ${.TARGET} \
@@ -128,6 +130,11 @@ AttrParsedAttrList.inc.h: ${CLANG_SRCS}/include/clang/Basic/Attr.td
-I ${CLANG_SRCS}/include -d ${.TARGET:C/\.h$/.d/} -o ${.TARGET} \
${CLANG_SRCS}/include/clang/Basic/Attr.td
+AttrParserStringSwitches.inc.h: ${CLANG_SRCS}/include/clang/Basic/Attr.td
+ ${CLANG_TBLGEN} -gen-clang-attr-parser-string-switches \
+ -I ${CLANG_SRCS}/include -d ${.TARGET:C/\.h$/.d/} -o ${.TARGET} \
+ ${CLANG_SRCS}/include/clang/Basic/Attr.td
+
AttrPCHRead.inc.h: ${CLANG_SRCS}/include/clang/Basic/Attr.td
${CLANG_TBLGEN} -gen-clang-attr-pch-read \
-I ${CLANG_SRCS}/include -d ${.TARGET:C/\.h$/.d/} -o ${.TARGET} \
@@ -138,11 +145,6 @@ AttrPCHWrite.inc.h: ${CLANG_SRCS}/include/clang/Basic/Attr.td
-I ${CLANG_SRCS}/include -d ${.TARGET:C/\.h$/.d/} -o ${.TARGET} \
${CLANG_SRCS}/include/clang/Basic/Attr.td
-AttrSpellings.inc.h: ${CLANG_SRCS}/include/clang/Basic/Attr.td
- ${CLANG_TBLGEN} -gen-clang-attr-spelling-list \
- -I ${CLANG_SRCS}/include -d ${.TARGET:C/\.h$/.d/} -o ${.TARGET} \
- ${CLANG_SRCS}/include/clang/Basic/Attr.td
-
AttrSpellingListIndex.inc.h: ${CLANG_SRCS}/include/clang/Basic/Attr.td
${CLANG_TBLGEN} -gen-clang-attr-spelling-index \
-I ${CLANG_SRCS}/include -d ${.TARGET:C/\.h$/.d/} -o ${.TARGET} \
@@ -153,8 +155,8 @@ AttrTemplateInstantiate.inc.h: ${CLANG_SRCS}/include/clang/Basic/Attr.td
-I ${CLANG_SRCS}/include -d ${.TARGET:C/\.h$/.d/} -o ${.TARGET} \
${CLANG_SRCS}/include/clang/Basic/Attr.td
-AttrTypeArg.inc.h: ${CLANG_SRCS}/include/clang/Basic/Attr.td
- ${CLANG_TBLGEN} -gen-clang-attr-type-arg-list \
+AttrVisitor.inc.h: ${CLANG_SRCS}/include/clang/Basic/Attr.td
+ ${CLANG_TBLGEN} -gen-clang-attr-ast-visitor \
-I ${CLANG_SRCS}/include -d ${.TARGET:C/\.h$/.d/} -o ${.TARGET} \
${CLANG_SRCS}/include/clang/Basic/Attr.td
@@ -233,12 +235,6 @@ Options.inc.h: ${CLANG_SRCS}/include/clang/Driver/Options.td
-d ${.TARGET:C/\.h$/.d/} -o ${.TARGET} \
${CLANG_SRCS}/include/clang/Driver/Options.td
-CC1AsOptions.inc.h: ${CLANG_SRCS}/include/clang/Driver/CC1AsOptions.td
- ${TBLGEN} -gen-opt-parser-defs \
- -I ${LLVM_SRCS}/include -I ${CLANG_SRCS}/include/clang/Driver \
- -d ${.TARGET:C/\.h$/.d/} -o ${.TARGET} \
- ${CLANG_SRCS}/include/clang/Driver/CC1AsOptions.td
-
Checkers.inc.h: ${CLANG_SRCS}/lib/StaticAnalyzer/Checkers/Checkers.td
${CLANG_TBLGEN} -gen-clang-sa-checkers \
-I ${CLANG_SRCS}/include -d ${.TARGET:C/\.h$/.d/} -o ${.TARGET} \
diff --git a/lib/clang/include/AArch64GenAsmMatcher.inc b/lib/clang/include/AArch64GenAsmMatcher.inc
new file mode 100644
index 0000000..0b1e0a9
--- /dev/null
+++ b/lib/clang/include/AArch64GenAsmMatcher.inc
@@ -0,0 +1,2 @@
+/* $FreeBSD$ */
+#include "AArch64GenAsmMatcher.inc.h"
diff --git a/lib/clang/include/AArch64GenAsmWriter.inc b/lib/clang/include/AArch64GenAsmWriter.inc
new file mode 100644
index 0000000..20b130b
--- /dev/null
+++ b/lib/clang/include/AArch64GenAsmWriter.inc
@@ -0,0 +1,2 @@
+/* $FreeBSD$ */
+#include "AArch64GenAsmWriter.inc.h"
diff --git a/lib/clang/include/AArch64GenAsmWriter1.inc b/lib/clang/include/AArch64GenAsmWriter1.inc
new file mode 100644
index 0000000..caf7812
--- /dev/null
+++ b/lib/clang/include/AArch64GenAsmWriter1.inc
@@ -0,0 +1,2 @@
+/* $FreeBSD$ */
+#include "AArch64GenAsmWriter1.inc.h"
diff --git a/lib/clang/include/AArch64GenCallingConv.inc b/lib/clang/include/AArch64GenCallingConv.inc
new file mode 100644
index 0000000..75bfa38
--- /dev/null
+++ b/lib/clang/include/AArch64GenCallingConv.inc
@@ -0,0 +1,2 @@
+/* $FreeBSD$ */
+#include "AArch64GenCallingConv.inc.h"
diff --git a/lib/clang/include/AArch64GenDAGISel.inc b/lib/clang/include/AArch64GenDAGISel.inc
new file mode 100644
index 0000000..39bb084
--- /dev/null
+++ b/lib/clang/include/AArch64GenDAGISel.inc
@@ -0,0 +1,2 @@
+/* $FreeBSD$ */
+#include "AArch64GenDAGISel.inc.h"
diff --git a/lib/clang/include/AArch64GenDisassemblerTables.inc b/lib/clang/include/AArch64GenDisassemblerTables.inc
new file mode 100644
index 0000000..3b26336
--- /dev/null
+++ b/lib/clang/include/AArch64GenDisassemblerTables.inc
@@ -0,0 +1,2 @@
+/* $FreeBSD$ */
+#include "AArch64GenDisassemblerTables.inc.h"
diff --git a/lib/clang/include/AArch64GenFastISel.inc b/lib/clang/include/AArch64GenFastISel.inc
new file mode 100644
index 0000000..ebc2ad2
--- /dev/null
+++ b/lib/clang/include/AArch64GenFastISel.inc
@@ -0,0 +1,2 @@
+/* $FreeBSD$ */
+#include "AArch64GenFastISel.inc.h"
diff --git a/lib/clang/include/AArch64GenInstrInfo.inc b/lib/clang/include/AArch64GenInstrInfo.inc
new file mode 100644
index 0000000..12e60a9
--- /dev/null
+++ b/lib/clang/include/AArch64GenInstrInfo.inc
@@ -0,0 +1,2 @@
+/* $FreeBSD$ */
+#include "AArch64GenInstrInfo.inc.h"
diff --git a/lib/clang/include/AArch64GenMCCodeEmitter.inc b/lib/clang/include/AArch64GenMCCodeEmitter.inc
new file mode 100644
index 0000000..e3515f5
--- /dev/null
+++ b/lib/clang/include/AArch64GenMCCodeEmitter.inc
@@ -0,0 +1,2 @@
+/* $FreeBSD$ */
+#include "AArch64GenMCCodeEmitter.inc.h"
diff --git a/lib/clang/include/AArch64GenMCPseudoLowering.inc b/lib/clang/include/AArch64GenMCPseudoLowering.inc
new file mode 100644
index 0000000..93f3f3a
--- /dev/null
+++ b/lib/clang/include/AArch64GenMCPseudoLowering.inc
@@ -0,0 +1,2 @@
+/* $FreeBSD$ */
+#include "AArch64GenMCPseudoLowering.inc.h"
diff --git a/lib/clang/include/AArch64GenRegisterInfo.inc b/lib/clang/include/AArch64GenRegisterInfo.inc
new file mode 100644
index 0000000..a6a9647
--- /dev/null
+++ b/lib/clang/include/AArch64GenRegisterInfo.inc
@@ -0,0 +1,2 @@
+/* $FreeBSD$ */
+#include "AArch64GenRegisterInfo.inc.h"
diff --git a/lib/clang/include/AArch64GenSubtargetInfo.inc b/lib/clang/include/AArch64GenSubtargetInfo.inc
new file mode 100644
index 0000000..8674332
--- /dev/null
+++ b/lib/clang/include/AArch64GenSubtargetInfo.inc
@@ -0,0 +1,2 @@
+/* $FreeBSD$ */
+#include "AArch64GenSubtargetInfo.inc.h"
diff --git a/lib/clang/include/Makefile b/lib/clang/include/Makefile
index 1ffd3e1..0e6ac6e 100644
--- a/lib/clang/include/Makefile
+++ b/lib/clang/include/Makefile
@@ -8,13 +8,21 @@ LLVM_SRCS= ${.CURDIR}/../../../contrib/llvm
.PATH: ${LLVM_SRCS}/tools/clang/lib/Headers
-INCSDIR=${INCLUDEDIR}/clang/3.4.1
+INCSDIR=${LIBDIR}/clang/3.6.0/include
-INCS= __wmmintrin_aes.h \
+INCS= __stddef_max_align_t.h \
+ __wmmintrin_aes.h \
__wmmintrin_pclmul.h \
+ adxintrin.h \
altivec.h \
ammintrin.h \
+ arm_acle.h \
avx2intrin.h \
+ avx512bwintrin.h \
+ avx512erintrin.h \
+ avx512fintrin.h \
+ avx512vlbwintrin.h \
+ avx512vlintrin.h \
avxintrin.h \
bmi2intrin.h \
bmiintrin.h \
@@ -23,12 +31,13 @@ INCS= __wmmintrin_aes.h \
f16cintrin.h \
fma4intrin.h \
fmaintrin.h \
+ ia32intrin.h \
immintrin.h \
lzcntintrin.h \
mm3dnow.h \
mm_malloc.h \
mmintrin.h \
- module.map \
+ module.modulemap \
nmmintrin.h \
pmmintrin.h \
popcntintrin.h \
diff --git a/lib/clang/include/MipsGenFastISel.inc b/lib/clang/include/MipsGenFastISel.inc
new file mode 100644
index 0000000..a2aaacf
--- /dev/null
+++ b/lib/clang/include/MipsGenFastISel.inc
@@ -0,0 +1,2 @@
+/* $FreeBSD$ */
+#include "MipsGenFastISel.inc.h"
diff --git a/lib/clang/include/PPCGenDisassemblerTables.inc b/lib/clang/include/PPCGenDisassemblerTables.inc
new file mode 100644
index 0000000..c581dbe
--- /dev/null
+++ b/lib/clang/include/PPCGenDisassemblerTables.inc
@@ -0,0 +1,2 @@
+/* $FreeBSD$ */
+#include "PPCGenDisassemblerTables.inc.h"
diff --git a/lib/clang/include/clang/AST/AttrVisitor.inc b/lib/clang/include/clang/AST/AttrVisitor.inc
new file mode 100644
index 0000000..8f8bdb0
--- /dev/null
+++ b/lib/clang/include/clang/AST/AttrVisitor.inc
@@ -0,0 +1,2 @@
+/* $FreeBSD$ */
+#include "AttrVisitor.inc.h"
diff --git a/lib/clang/include/clang/Basic/AttrHasAttributeImpl.inc b/lib/clang/include/clang/Basic/AttrHasAttributeImpl.inc
new file mode 100644
index 0000000..0e996d2
--- /dev/null
+++ b/lib/clang/include/clang/Basic/AttrHasAttributeImpl.inc
@@ -0,0 +1,2 @@
+/* $FreeBSD$ */
+#include "AttrHasAttributeImpl.inc.h"
diff --git a/lib/clang/include/clang/Basic/Version.inc b/lib/clang/include/clang/Basic/Version.inc
index d2fcc04..c6d4a8e 100644
--- a/lib/clang/include/clang/Basic/Version.inc
+++ b/lib/clang/include/clang/Basic/Version.inc
@@ -1,11 +1,11 @@
/* $FreeBSD$ */
-#define CLANG_VERSION 3.4.1
+#define CLANG_VERSION 3.6.0
#define CLANG_VERSION_MAJOR 3
-#define CLANG_VERSION_MINOR 4
-#define CLANG_VERSION_PATCHLEVEL 1
+#define CLANG_VERSION_MINOR 6
+#define CLANG_VERSION_PATCHLEVEL 0
#define CLANG_VENDOR "FreeBSD "
-#define CLANG_VENDOR_SUFFIX " 20140512"
+#define CLANG_VENDOR_SUFFIX " 20150225"
-#define SVN_REVISION "208032"
+#define SVN_REVISION "230434"
diff --git a/lib/clang/include/clang/Config/config.h b/lib/clang/include/clang/Config/config.h
index 5c35829..9c4512d 100644
--- a/lib/clang/include/clang/Config/config.h
+++ b/lib/clang/include/clang/Config/config.h
@@ -1,26 +1,39 @@
/* $FreeBSD$ */
/* tools/clang/include/clang/Config/config.h. Generated from config.h.in by configure. */
-/* include/clang/Config/config.h.in. */
+/* This generated file is for internal use. Do not include it from headers. */
-#ifndef CONFIG_H
+#ifdef CONFIG_H
+#error config.h can only be included once
+#else
#define CONFIG_H
/* Bug report URL. */
#define BUG_REPORT_URL "https://bugs.freebsd.org/submit/"
+/* Multilib suffix for libdir. */
+#define CLANG_LIBDIR_SUFFIX ""
+
/* 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 ""
+/* Define if we have libxml2 */
+/* #undef CLANG_HAVE_LIBXML */
+
+#define PACKAGE_STRING "LLVM 3.6.0"
+
+/* The LLVM product name and version */
+#define BACKEND_PACKAGE_STRING PACKAGE_STRING
+
+/* Linker version detected at compile time. */
+/* #undef HOST_LINK_VERSION */
+
#endif
diff --git a/lib/clang/include/clang/Driver/CC1AsOptions.inc b/lib/clang/include/clang/Driver/CC1AsOptions.inc
deleted file mode 100644
index 3d76958..0000000
--- a/lib/clang/include/clang/Driver/CC1AsOptions.inc
+++ /dev/null
@@ -1,2 +0,0 @@
-/* $FreeBSD$ */
-#include "CC1AsOptions.inc.h"
diff --git a/lib/clang/include/clang/Lex/AttrSpellings.inc b/lib/clang/include/clang/Lex/AttrSpellings.inc
deleted file mode 100644
index 8859ae3..0000000
--- a/lib/clang/include/clang/Lex/AttrSpellings.inc
+++ /dev/null
@@ -1,2 +0,0 @@
-/* $FreeBSD$ */
-#include "AttrSpellings.inc.h"
diff --git a/lib/clang/include/clang/Parse/AttrIdentifierArg.inc b/lib/clang/include/clang/Parse/AttrIdentifierArg.inc
deleted file mode 100644
index 2969a50..0000000
--- a/lib/clang/include/clang/Parse/AttrIdentifierArg.inc
+++ /dev/null
@@ -1,2 +0,0 @@
-/* $FreeBSD$ */
-#include "AttrIdentifierArg.inc.h"
diff --git a/lib/clang/include/clang/Parse/AttrLateParsed.inc b/lib/clang/include/clang/Parse/AttrLateParsed.inc
deleted file mode 100644
index 1282d9e..0000000
--- a/lib/clang/include/clang/Parse/AttrLateParsed.inc
+++ /dev/null
@@ -1,2 +0,0 @@
-/* $FreeBSD$ */
-#include "AttrLateParsed.inc.h"
diff --git a/lib/clang/include/clang/Parse/AttrParserStringSwitches.inc b/lib/clang/include/clang/Parse/AttrParserStringSwitches.inc
new file mode 100644
index 0000000..ef8642c
--- /dev/null
+++ b/lib/clang/include/clang/Parse/AttrParserStringSwitches.inc
@@ -0,0 +1,2 @@
+/* $FreeBSD$ */
+#include "AttrParserStringSwitches.inc.h"
diff --git a/lib/clang/include/clang/Parse/AttrTypeArg.inc b/lib/clang/include/clang/Parse/AttrTypeArg.inc
deleted file mode 100644
index 8eb4699..0000000
--- a/lib/clang/include/clang/Parse/AttrTypeArg.inc
+++ /dev/null
@@ -1,2 +0,0 @@
-/* $FreeBSD$ */
-#include "AttrTypeArg.inc.h"
diff --git a/lib/clang/include/llvm/Config/AsmParsers.def b/lib/clang/include/llvm/Config/AsmParsers.def
index e0165f0..3be6e38 100644
--- a/lib/clang/include/llvm/Config/AsmParsers.def
+++ b/lib/clang/include/llvm/Config/AsmParsers.def
@@ -1,5 +1,6 @@
/* $FreeBSD$ */
+LLVM_ASM_PARSER(AArch64)
LLVM_ASM_PARSER(ARM)
LLVM_ASM_PARSER(Mips)
LLVM_ASM_PARSER(PowerPC)
diff --git a/lib/clang/include/llvm/Config/AsmPrinters.def b/lib/clang/include/llvm/Config/AsmPrinters.def
index 97ca952..9ed0217 100644
--- a/lib/clang/include/llvm/Config/AsmPrinters.def
+++ b/lib/clang/include/llvm/Config/AsmPrinters.def
@@ -1,5 +1,6 @@
/* $FreeBSD$ */
+LLVM_ASM_PRINTER(AArch64)
LLVM_ASM_PRINTER(ARM)
LLVM_ASM_PRINTER(Mips)
LLVM_ASM_PRINTER(PowerPC)
diff --git a/lib/clang/include/llvm/Config/Disassemblers.def b/lib/clang/include/llvm/Config/Disassemblers.def
index 25406a4..44fc7ef 100644
--- a/lib/clang/include/llvm/Config/Disassemblers.def
+++ b/lib/clang/include/llvm/Config/Disassemblers.def
@@ -1,7 +1,9 @@
/* $FreeBSD$ */
+LLVM_DISASSEMBLER(AArch64)
LLVM_DISASSEMBLER(ARM)
LLVM_DISASSEMBLER(Mips)
+LLVM_DISASSEMBLER(PowerPC)
LLVM_DISASSEMBLER(Sparc)
LLVM_DISASSEMBLER(X86)
diff --git a/lib/clang/include/llvm/Config/Targets.def b/lib/clang/include/llvm/Config/Targets.def
index e51e06a..96b60d9 100644
--- a/lib/clang/include/llvm/Config/Targets.def
+++ b/lib/clang/include/llvm/Config/Targets.def
@@ -1,5 +1,6 @@
/* $FreeBSD$ */
+LLVM_TARGET(AArch64)
LLVM_TARGET(ARM)
LLVM_TARGET(Mips)
LLVM_TARGET(PowerPC)
diff --git a/lib/clang/include/llvm/Config/config.h b/lib/clang/include/llvm/Config/config.h
index ce32c50..3fc38be 100644
--- a/lib/clang/include/llvm/Config/config.h
+++ b/lib/clang/include/llvm/Config/config.h
@@ -14,6 +14,9 @@
/* Define if we have libxml2 */
/* #undef CLANG_HAVE_LIBXML */
+/* Multilib suffix for libdir. */
+/* #undef CLANG_LIBDIR_SUFFIX */
+
/* Relative directory for resource files */
#define CLANG_RESOURCE_DIR ""
@@ -38,39 +41,12 @@
/* Directory where gcc is installed. */
#define GCC_INSTALL_PREFIX ""
-/* Define to 1 if you have the `arc4random' function. */
-#define HAVE_ARC4RANDOM 1
-
-/* Define to 1 if you have the `argz_append' function. */
-/* #undef HAVE_ARGZ_APPEND */
-
-/* Define to 1 if you have the `argz_create_sep' function. */
-/* #undef HAVE_ARGZ_CREATE_SEP */
-
-/* Define to 1 if you have the <argz.h> header file. */
-/* #undef HAVE_ARGZ_H */
-
-/* Define to 1 if you have the `argz_insert' function. */
-/* #undef HAVE_ARGZ_INSERT */
-
-/* Define to 1 if you have the `argz_next' function. */
-/* #undef HAVE_ARGZ_NEXT */
-
-/* Define to 1 if you have the `argz_stringify' function. */
-/* #undef HAVE_ARGZ_STRINGIFY */
-
/* Define to 1 if you have the `backtrace' function. */
/* #undef HAVE_BACKTRACE */
/* Define to 1 if you have the `ceilf' function. */
#define HAVE_CEILF 1
-/* Define if the neat program is available */
-/* #undef HAVE_CIRCO */
-
-/* Define to 1 if you have the `closedir' function. */
-#define HAVE_CLOSEDIR 1
-
/* Define to 1 if you have the <CrashReporterClient.h> header file. */
/* #undef HAVE_CRASHREPORTERCLIENT_H */
@@ -80,6 +56,10 @@
/* Define to 1 if you have the <cxxabi.h> header file. */
#define HAVE_CXXABI_H 1
+/* Define to 1 if you have the declaration of `arc4random', and to 0 if you
+ don't. */
+#define HAVE_DECL_ARC4RANDOM 1
+
/* Define to 1 if you have the declaration of `FE_ALL_EXCEPT', and to 0 if you
don't. */
#define HAVE_DECL_FE_ALL_EXCEPT 1
@@ -96,12 +76,6 @@
*/
#define HAVE_DIRENT_H 1
-/* Define if you have the GNU dld library. */
-/* #undef HAVE_DLD */
-
-/* Define to 1 if you have the `dlerror' function. */
-#define HAVE_DLERROR 1
-
/* Define to 1 if you have the <dlfcn.h> header file. */
#define HAVE_DLFCN_H 1
@@ -111,20 +85,13 @@
/* Define if the dot program is available */
/* #undef HAVE_DOT */
-/* Define if the dotty program is available */
-/* #undef HAVE_DOTTY */
-
-/* Define if you have the _dyld_func_lookup function. */
-/* #undef HAVE_DYLD */
-
/* Define to 1 if you have the <errno.h> header file. */
#define HAVE_ERRNO_H 1
-/* Define to 1 if the system has the type `error_t'. */
-/* #undef HAVE_ERROR_T */
-
/* Define to 1 if you have the <execinfo.h> header file. */
-/* #undef HAVE_EXECINFO_H */
+#if __FreeBSD_version >= 1000052
+#define HAVE_EXECINFO_H 1
+#endif
/* Define to 1 if you have the `exp' function. */
#define HAVE_EXP 1
@@ -135,9 +102,6 @@
/* Define to 1 if you have the <fcntl.h> header file. */
#define HAVE_FCNTL_H 1
-/* Define if the neat program is available */
-/* #undef HAVE_FDP */
-
/* Define to 1 if you have the <fenv.h> header file. */
#define HAVE_FENV_H 1
@@ -160,7 +124,9 @@
#define HAVE_FMODF 1
/* Define to 1 if you have the `futimens' function. */
-/* #undef HAVE_FUTIMENS */
+#if __FreeBSD_version >= 1100056
+#define HAVE_FUTIMENS 1
+#endif
/* Define to 1 if you have the `futimes' function. */
#define HAVE_FUTIMES 1
@@ -180,12 +146,6 @@
/* Define to 1 if you have the `gettimeofday' function. */
#define HAVE_GETTIMEOFDAY 1
-/* Define if the Graphviz program is available */
-/* #undef HAVE_GRAPHVIZ */
-
-/* Define if the gv program is available */
-/* #undef HAVE_GV */
-
/* Define to 1 if the system has the type `int64_t'. */
#define HAVE_INT64_T 1
@@ -207,8 +167,8 @@
/* Set to 1 if the isnan function is found in <math.h> */
#define HAVE_ISNAN_IN_MATH_H 1
-/* Define if you have the libdl library or equivalent. */
-#define HAVE_LIBDL 1
+/* Define if libedit is available on this platform. */
+#define HAVE_LIBEDIT 1
/* Define to 1 if you have the `imagehlp' library (-limagehlp). */
/* #undef HAVE_LIBIMAGEHLP */
@@ -225,9 +185,6 @@
/* Define to 1 if you have the `shell32' library (-lshell32). */
/* #undef HAVE_LIBSHELL32 */
-/* Define to 1 if you have the `udis86' library (-ludis86). */
-/* #undef HAVE_LIBUDIS86 */
-
/* Define to 1 if you have the `z' library (-lz). */
#define HAVE_LIBZ 1
@@ -258,9 +215,6 @@
/* Define to 1 if you have the <mach/mach.h> header file. */
/* #undef HAVE_MACH_MACH_H */
-/* Define to 1 if you have the <mach-o/dyld.h> header file. */
-/* #undef HAVE_MACH_O_DYLD_H */
-
/* Define if mallinfo() is available on this platform. */
/* #undef HAVE_MALLINFO */
@@ -301,12 +255,6 @@
/* Define to 1 if you have the `nearbyintf' function. */
#define HAVE_NEARBYINTF 1
-/* Define if the neat program is available */
-/* #undef HAVE_NEATO */
-
-/* Define to 1 if you have the `opendir' function. */
-#define HAVE_OPENDIR 1
-
/* Define to 1 if you have the `posix_spawn' function. */
/* #undef HAVE_POSIX_SPAWN */
@@ -316,9 +264,6 @@
/* Define to 1 if you have the `pread' function. */
#define HAVE_PREAD 1
-/* Define if libtool can extract symbol lists from object files. */
-#define HAVE_PRELOADED_SYMBOLS 1
-
/* Define to have the %a format string */
#define HAVE_PRINTF_A 1
@@ -337,9 +282,6 @@
/* Define to 1 if srand48/lrand48/drand48 exist in <stdlib.h> */
#define HAVE_RAND48 1
-/* Define to 1 if you have the `readdir' function. */
-#define HAVE_READDIR 1
-
/* Define to 1 if you have the `realpath' function. */
#define HAVE_REALPATH 1
@@ -367,9 +309,6 @@
/* Define to 1 if you have the `setrlimit' function. */
#define HAVE_SETRLIMIT 1
-/* Define if you have the shl_load function. */
-/* #undef HAVE_SHL_LOAD */
-
/* Define to 1 if you have the `siglongjmp' function. */
#define HAVE_SIGLONGJMP 1
@@ -456,9 +395,6 @@
/* Define to 1 if you have the <termios.h> header file. */
#define HAVE_TERMIOS_H 1
-/* Define if the neat program is available */
-/* #undef HAVE_TWOPI */
-
/* Define to 1 if the system has the type `uint64_t'. */
#define HAVE_UINT64_T 1
@@ -477,9 +413,6 @@
/* Define to 1 if you have the `writev' function. */
#define HAVE_WRITEV 1
-/* Define if the xdot program is available */
-/* #undef HAVE_XDOT */
-
/* Define to 1 if you have the <zlib.h> header file. */
#define HAVE_ZLIB_H 1
@@ -603,33 +536,9 @@
/* Define if this is Win32ish platform */
/* #undef LLVM_ON_WIN32 */
-/* Define to path to circo program if found or 'echo circo' otherwise */
-/* #undef LLVM_PATH_CIRCO */
-
/* Define to path to dot program if found or 'echo dot' otherwise */
/* #undef LLVM_PATH_DOT */
-/* Define to path to dotty program if found or 'echo dotty' otherwise */
-/* #undef LLVM_PATH_DOTTY */
-
-/* Define to path to fdp program if found or 'echo fdp' otherwise */
-/* #undef LLVM_PATH_FDP */
-
-/* Define to path to Graphviz program if found or 'echo Graphviz' otherwise */
-/* #undef LLVM_PATH_GRAPHVIZ */
-
-/* Define to path to gv program if found or 'echo gv' otherwise */
-/* #undef LLVM_PATH_GV */
-
-/* Define to path to neato program if found or 'echo neato' otherwise */
-/* #undef LLVM_PATH_NEATO */
-
-/* Define to path to twopi program if found or 'echo twopi' otherwise */
-/* #undef LLVM_PATH_TWOPI */
-
-/* Define to path to xdot program if found or 'echo xdot' otherwise */
-/* #undef LLVM_PATH_XDOT */
-
/* Installation prefix directory */
#define LLVM_PREFIX "/usr"
@@ -643,45 +552,35 @@
#define LLVM_VERSION_MAJOR 3
/* Minor version of the LLVM API */
-#define LLVM_VERSION_MINOR 4
+#define LLVM_VERSION_MINOR 6
/* Patch version of the LLVM API */
-#define LLVM_VERSION_PATCH 1
-
-/* Define if the OS needs help to load dependent libraries for dlopen(). */
-#define LTDL_DLOPEN_DEPLIBS 1
+#define LLVM_VERSION_PATCH 0
-/* Define to the sub-directory in which libtool stores uninstalled libraries.
- */
-#define LTDL_OBJDIR ".libs/"
+/* LLVM version string */
+#define LLVM_VERSION_STRING "3.6.0"
-/* Define to the extension used for shared libraries, say, ".so". */
+/* The shared library extension */
#define LTDL_SHLIB_EXT ".so"
-/* Define to the system default library search path. */
-#define LTDL_SYSSEARCHPATH "/lib:/usr/lib"
-
/* Define if /dev/zero should be used when mapping RWX memory, or undefine if
its not necessary */
/* #undef NEED_DEV_ZERO_FOR_MMAP */
-/* Define if dlsym() requires a leading underscore in symbol names. */
-/* #undef NEED_USCORE */
-
/* Define to the address where bug reports for this package should be sent. */
-#define PACKAGE_BUGREPORT "http://llvm.org/bugs/"
+#define PACKAGE_BUGREPORT "https://bugs.freebsd.org/submit/"
/* Define to the full name of this package. */
#define PACKAGE_NAME "LLVM"
/* Define to the full name and version of this package. */
-#define PACKAGE_STRING "LLVM 3.4.1"
+#define PACKAGE_STRING "LLVM 3.6.0"
/* 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.4.1"
+#define PACKAGE_VERSION "3.6.0"
/* Define as the return type of signal handlers (`int' or `void'). */
#define RETSIGTYPE void
@@ -698,18 +597,9 @@
/* Define to 1 if your <sys/time.h> declares `struct tm'. */
/* #undef TM_IN_SYS_TIME */
-/* Define if use udis86 library */
-#define USE_UDIS86 0
-
/* Type of 1st arg on ELM Callback */
/* #undef WIN32_ELMCB_PCSTR */
-/* Define to empty if `const' does not conform to ANSI C. */
-/* #undef const */
-
-/* Define to a type to use for `error_t' if it is not otherwise available. */
-#define error_t int
-
/* Define to `int' if <sys/types.h> does not define. */
/* #undef pid_t */
diff --git a/lib/clang/include/llvm/Config/llvm-config.h b/lib/clang/include/llvm/Config/llvm-config.h
index 1717863..ba95263 100644
--- a/lib/clang/include/llvm/Config/llvm-config.h
+++ b/lib/clang/include/llvm/Config/llvm-config.h
@@ -1,6 +1,6 @@
/* $FreeBSD$ */
/* include/llvm/Config/llvm-config.h. Generated from llvm-config.h.in by configure. */
-/*===-- llvm/config/llvm-config.h - llvm configure variable -------*- C -*-===*/
+/*===------- llvm/Config/llvm-config.h - llvm configuration -------*- C -*-===*/
/* */
/* The LLVM Compiler Infrastructure */
/* */
@@ -9,14 +9,12 @@
/* */
/*===----------------------------------------------------------------------===*/
-/* This file enumerates all of the llvm variables from configure so that
- they can be in exported headers and won't override package specific
- directives. This is a C file so we can include it in the llvm-c headers. */
+/* This file enumerates variables from the LLVM configuration so that they
+ can be in exported headers and won't override package specific directives.
+ This is a C header that can be included in the llvm-c headers. */
-/* To avoid multiple inclusions of these variables when we include the exported
- headers and config.h, conditionally include these. */
-/* TODO: This is a bit of a hack. */
-#ifndef CONFIG_H
+#ifndef LLVM_CONFIG_H
+#define LLVM_CONFIG_H
/* Installation directory for binary executables */
/* #undef LLVM_BINDIR */
@@ -81,33 +79,6 @@
/* Define if this is Win32ish platform */
/* #undef LLVM_ON_WIN32 */
-/* Define to path to circo program if found or 'echo circo' otherwise */
-/* #undef LLVM_PATH_CIRCO */
-
-/* Define to path to dot program if found or 'echo dot' otherwise */
-/* #undef LLVM_PATH_DOT */
-
-/* Define to path to dotty program if found or 'echo dotty' otherwise */
-/* #undef LLVM_PATH_DOTTY */
-
-/* Define to path to fdp program if found or 'echo fdp' otherwise */
-/* #undef LLVM_PATH_FDP */
-
-/* Define to path to Graphviz program if found or 'echo Graphviz' otherwise */
-/* #undef LLVM_PATH_GRAPHVIZ */
-
-/* Define to path to gv program if found or 'echo gv' otherwise */
-/* #undef LLVM_PATH_GV */
-
-/* Define to path to neato program if found or 'echo neato' otherwise */
-/* #undef LLVM_PATH_NEATO */
-
-/* Define to path to twopi program if found or 'echo twopi' otherwise */
-/* #undef LLVM_PATH_TWOPI */
-
-/* Define to path to xdot.py program if found or 'echo xdot.py' otherwise */
-/* #undef LLVM_PATH_XDOT_PY */
-
/* Installation prefix directory */
#define LLVM_PREFIX "/usr"
@@ -121,6 +92,12 @@
#define LLVM_VERSION_MAJOR 3
/* Minor version of the LLVM API */
-#define LLVM_VERSION_MINOR 4
+#define LLVM_VERSION_MINOR 6
+
+/* Patch version of the LLVM API */
+#define LLVM_VERSION_PATCH 0
+
+/* LLVM version string */
+#define LLVM_VERSION_STRING "3.6.0"
#endif
diff --git a/lib/clang/include/llvm/Support/DataTypes.h b/lib/clang/include/llvm/Support/DataTypes.h
index d0fdb7c..6f95bc4 100644
--- a/lib/clang/include/llvm/Support/DataTypes.h
+++ b/lib/clang/include/llvm/Support/DataTypes.h
@@ -1,6 +1,6 @@
/* $FreeBSD$ */
/* include/llvm/Support/DataTypes.h. Generated from DataTypes.h.in by configure. */
-/*===-- include/System/DataTypes.h - Define fixed size types -----*- C -*-===*\
+/*===-- include/Support/DataTypes.h - Define fixed size types -----*- C -*-===*\
|* *|
|* The LLVM Compiler Infrastructure *|
|* *|
@@ -23,10 +23,11 @@
/* Please leave this file C-compatible. */
+/* Please keep this file in sync with DataTypes.h.cmake */
+
#ifndef SUPPORT_DATATYPES_H
#define SUPPORT_DATATYPES_H
-#define HAVE_SYS_TYPES_H 1
#define HAVE_INTTYPES_H 1
#define HAVE_STDINT_H 1
#define HAVE_UINT64_T 1
@@ -38,31 +39,33 @@
#include <math.h>
#endif
+#ifdef HAVE_INTTYPES_H
+#include <inttypes.h>
+#endif
+
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#else
+#error "Compiler must provide an implementation of stdint.h"
+#endif
+
+#ifndef _MSC_VER
+
/* Note that this header's correct operation depends on __STDC_LIMIT_MACROS
being defined. We would define it here, but in order to prevent Bad Things
happening when system headers or C++ STL headers include stdint.h before we
define it here, we define it on the g++ command line (in Makefile.rules). */
#if !defined(__STDC_LIMIT_MACROS)
-# error "Must #define __STDC_LIMIT_MACROS before #including System/DataTypes.h"
+# error "Must #define __STDC_LIMIT_MACROS before #including Support/DataTypes.h"
#endif
#if !defined(__STDC_CONSTANT_MACROS)
# error "Must #define __STDC_CONSTANT_MACROS before " \
- "#including System/DataTypes.h"
+ "#including Support/DataTypes.h"
#endif
/* Note that <inttypes.h> includes <stdint.h>, if this is a C99 system. */
-#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
-#endif
-
-#ifdef HAVE_INTTYPES_H
-#include <inttypes.h>
-#endif
-
-#ifdef HAVE_STDINT_H
-#include <stdint.h>
-#endif
#ifdef _AIX
#include "llvm/Support/AIXDataTypesFix.h"
@@ -77,18 +80,33 @@ typedef u_int64_t uint64_t;
#endif
#endif
-#ifdef _OpenBSD_
-#define INT8_MAX 127
-#define INT8_MIN -128
-#define UINT8_MAX 255
-#define INT16_MAX 32767
-#define INT16_MIN -32768
-#define UINT16_MAX 65535
-#define INT32_MAX 2147483647
-#define INT32_MIN -2147483648
-#define UINT32_MAX 4294967295U
+#else /* _MSC_VER */
+#include <stdlib.h>
+#include <stddef.h>
+#include <sys/types.h>
+#ifdef __cplusplus
+#include <cmath>
+#else
+#include <math.h>
#endif
+#if defined(_WIN64)
+typedef signed __int64 ssize_t;
+#else
+typedef signed int ssize_t;
+#endif /* _WIN64 */
+
+#ifndef HAVE_INTTYPES_H
+#define PRId64 "I64d"
+#define PRIi64 "I64i"
+#define PRIo64 "I64o"
+#define PRIu64 "I64u"
+#define PRIx64 "I64x"
+#define PRIX64 "I64X"
+#endif /* HAVE_INTTYPES_H */
+
+#endif /* _MSC_VER */
+
/* Set defaults for constants which we cannot find. */
#if !defined(INT64_MAX)
# define INT64_MAX 9223372036854775807LL
@@ -100,12 +118,6 @@ typedef u_int64_t uint64_t;
# define UINT64_MAX 0xffffffffffffffffULL
#endif
-#if __GNUC__ > 3
-#define END_WITH_NULL __attribute__((sentinel))
-#else
-#define END_WITH_NULL
-#endif
-
#ifndef HUGE_VALF
#define HUGE_VALF (float)HUGE_VAL
#endif
diff --git a/lib/clang/libclanganalysis/Makefile b/lib/clang/libclanganalysis/Makefile
index f71b689..6a34dca 100644
--- a/lib/clang/libclanganalysis/Makefile
+++ b/lib/clang/libclanganalysis/Makefile
@@ -12,6 +12,7 @@ SRCS= AnalysisDeclContext.cpp \
CFGStmtMap.cpp \
CallGraph.cpp \
CocoaConventions.cpp \
+ CodeInjector.cpp \
Consumed.cpp \
Dominators.cpp \
FormatString.cpp \
@@ -24,9 +25,13 @@ SRCS= AnalysisDeclContext.cpp \
ReachableCode.cpp \
ScanfFormatString.cpp \
ThreadSafety.cpp \
+ ThreadSafetyCommon.cpp \
+ ThreadSafetyLogical.cpp \
+ ThreadSafetyTIL.cpp \
UninitializedValues.cpp
TGHDRS= AttrList \
+ AttrVisitor \
Attrs \
CommentCommandList \
CommentNodes \
diff --git a/lib/clang/libclangarcmigrate/Makefile b/lib/clang/libclangarcmigrate/Makefile
index 1604a50..a6b06c4 100644
--- a/lib/clang/libclangarcmigrate/Makefile
+++ b/lib/clang/libclangarcmigrate/Makefile
@@ -28,6 +28,7 @@ SRCS= ARCMT.cpp \
TGHDRS= AttrList \
AttrParsedAttrList \
+ AttrVisitor \
Attrs \
CommentCommandList \
CommentNodes \
diff --git a/lib/clang/libclangast/Makefile b/lib/clang/libclangast/Makefile
index 71cd684..a3f00aa 100644
--- a/lib/clang/libclangast/Makefile
+++ b/lib/clang/libclangast/Makefile
@@ -39,7 +39,6 @@ SRCS= APValue.cpp \
ItaniumCXXABI.cpp \
ItaniumMangle.cpp \
Mangle.cpp \
- MangleNumberingContext.cpp \
MicrosoftCXXABI.cpp \
MicrosoftMangle.cpp \
NSAPI.cpp \
@@ -65,6 +64,7 @@ SRCS= APValue.cpp \
TGHDRS= AttrDump \
AttrImpl \
AttrList \
+ AttrVisitor \
Attrs \
CommentCommandInfo \
CommentCommandList \
@@ -76,6 +76,7 @@ TGHDRS= AttrDump \
DiagnosticASTKinds \
DiagnosticCommentKinds \
DiagnosticCommonKinds \
+ DiagnosticFrontendKinds \
DiagnosticSemaKinds \
StmtNodes
diff --git a/lib/clang/libclangbasic/Makefile b/lib/clang/libclangbasic/Makefile
index 16bae4c..6a5791c 100644
--- a/lib/clang/libclangbasic/Makefile
+++ b/lib/clang/libclangbasic/Makefile
@@ -5,7 +5,8 @@
LIB= clangbasic
SRCDIR= tools/clang/lib/Basic
-SRCS= Builtins.cpp \
+SRCS= Attributes.cpp \
+ Builtins.cpp \
CharInfo.cpp \
Diagnostic.cpp \
DiagnosticIDs.cpp \
@@ -17,15 +18,20 @@ SRCS= Builtins.cpp \
ObjCRuntime.cpp \
OpenMPKinds.cpp \
OperatorPrecedence.cpp \
+ SanitizerBlacklist.cpp \
+ Sanitizers.cpp \
SourceLocation.cpp \
SourceManager.cpp \
TargetInfo.cpp \
Targets.cpp \
TokenKinds.cpp \
Version.cpp \
- VersionTuple.cpp
+ VersionTuple.cpp \
+ VirtualFileSystem.cpp \
+ Warnings.cpp
-TGHDRS= DiagnosticAnalysisKinds \
+TGHDRS= AttrHasAttributeImpl \
+ DiagnosticAnalysisKinds \
DiagnosticASTKinds \
DiagnosticCommentKinds \
DiagnosticCommonKinds \
diff --git a/lib/clang/libclangcodegen/Makefile b/lib/clang/libclangcodegen/Makefile
index 3b45f6b..521a430 100644
--- a/lib/clang/libclangcodegen/Makefile
+++ b/lib/clang/libclangcodegen/Makefile
@@ -26,29 +26,35 @@ SRCS= BackendUtil.cpp \
CGExprComplex.cpp \
CGExprConstant.cpp \
CGExprScalar.cpp \
+ CGLoopInfo.cpp \
CGObjC.cpp \
CGObjCGNU.cpp \
CGObjCMac.cpp \
CGObjCRuntime.cpp \
CGOpenCLRuntime.cpp \
- CGRTTI.cpp \
+ CGOpenMPRuntime.cpp \
CGRecordLayoutBuilder.cpp \
CGStmt.cpp \
+ CGStmtOpenMP.cpp \
CGVTT.cpp \
CGVTables.cpp \
CodeGenABITypes.cpp \
CodeGenAction.cpp \
CodeGenFunction.cpp \
CodeGenModule.cpp \
+ CodeGenPGO.cpp \
CodeGenTBAA.cpp \
CodeGenTypes.cpp \
+ CoverageMappingGen.cpp \
ItaniumCXXABI.cpp \
MicrosoftCXXABI.cpp \
- MicrosoftVBTables.cpp \
ModuleBuilder.cpp \
+ SanitizerMetadata.cpp \
TargetInfo.cpp
TGHDRS= AttrList \
+ AttrParsedAttrList \
+ AttrVisitor \
Attrs \
CommentCommandList \
CommentNodes \
diff --git a/lib/clang/libclangdriver/Makefile b/lib/clang/libclangdriver/Makefile
index 91a8f61..aa51384 100644
--- a/lib/clang/libclangdriver/Makefile
+++ b/lib/clang/libclangdriver/Makefile
@@ -6,22 +6,22 @@ LIB= clangdriver
SRCDIR= tools/clang/lib/Driver
SRCS= Action.cpp \
- CC1AsOptions.cpp \
Compilation.cpp \
+ CrossWindowsToolChain.cpp \
Driver.cpp \
DriverOptions.cpp \
Job.cpp \
+ MSVCToolChain.cpp \
+ Multilib.cpp \
Phases.cpp \
SanitizerArgs.cpp \
Tool.cpp \
ToolChain.cpp \
ToolChains.cpp \
Tools.cpp \
- Types.cpp \
- WindowsToolChain.cpp
+ Types.cpp
-TGHDRS= CC1AsOptions \
- DiagnosticCommonKinds \
+TGHDRS= DiagnosticCommonKinds \
DiagnosticDriverKinds \
DiagnosticSemaKinds \
Options
diff --git a/lib/clang/libclangfrontend/Makefile b/lib/clang/libclangfrontend/Makefile
index 4ea3556..95b8fc8 100644
--- a/lib/clang/libclangfrontend/Makefile
+++ b/lib/clang/libclangfrontend/Makefile
@@ -11,6 +11,7 @@ SRCS= ASTConsumers.cpp \
CacheTokens.cpp \
ChainedDiagnosticConsumer.cpp \
ChainedIncludesSource.cpp \
+ CodeGenOptions.cpp \
CompilerInstance.cpp \
CompilerInvocation.cpp \
CreateInvocationFromCommandLine.cpp \
@@ -26,17 +27,19 @@ SRCS= ASTConsumers.cpp \
LangStandards.cpp \
LayoutOverrideSource.cpp \
LogDiagnosticPrinter.cpp \
+ ModuleDependencyCollector.cpp \
MultiplexConsumer.cpp \
PrintPreprocessedOutput.cpp \
SerializedDiagnosticPrinter.cpp \
+ SerializedDiagnosticReader.cpp \
TextDiagnostic.cpp \
TextDiagnosticBuffer.cpp \
TextDiagnosticPrinter.cpp \
- VerifyDiagnosticConsumer.cpp \
- Warnings.cpp
+ VerifyDiagnosticConsumer.cpp
TGHDRS= AttrList \
AttrParsedAttrList \
+ AttrVisitor \
Attrs \
CommentCommandList \
CommentNodes \
diff --git a/lib/clang/libclangfrontendtool/Makefile b/lib/clang/libclangfrontendtool/Makefile
index f20aa35..0d71d55 100644
--- a/lib/clang/libclangfrontendtool/Makefile
+++ b/lib/clang/libclangfrontendtool/Makefile
@@ -7,8 +7,11 @@ LIB= clangfrontendtool
SRCDIR= tools/clang/lib/FrontendTool
SRCS= ExecuteCompilerInvocation.cpp
-TGHDRS= DiagnosticCommonKinds \
+TGHDRS= CommentCommandList \
+ DeclNodes \
+ DiagnosticCommonKinds \
DiagnosticFrontendKinds \
- Options
+ Options \
+ StmtNodes
.include "../clang.lib.mk"
diff --git a/lib/clang/libclanglex/Makefile b/lib/clang/libclanglex/Makefile
index 3a2873f..90b1fca 100644
--- a/lib/clang/libclanglex/Makefile
+++ b/lib/clang/libclanglex/Makefile
@@ -28,7 +28,7 @@ SRCS= HeaderMap.cpp \
TokenConcatenation.cpp \
TokenLexer.cpp
-TGHDRS= AttrSpellings \
+TGHDRS= AttrSpellingListIndex \
DiagnosticCommonKinds \
DiagnosticLexKinds
diff --git a/lib/clang/libclangparse/Makefile b/lib/clang/libclangparse/Makefile
index b204d87..e690d66 100644
--- a/lib/clang/libclangparse/Makefile
+++ b/lib/clang/libclangparse/Makefile
@@ -16,15 +16,14 @@ SRCS= ParseAST.cpp \
ParseOpenMP.cpp \
ParsePragma.cpp \
ParseStmt.cpp \
+ ParseStmtAsm.cpp \
ParseTemplate.cpp \
ParseTentative.cpp \
Parser.cpp
-TGHDRS= AttrIdentifierArg \
- AttrLateParsed \
- AttrList \
+TGHDRS= AttrList \
AttrParsedAttrList \
- AttrTypeArg \
+ AttrParserStringSwitches \
Attrs \
CommentCommandList \
CommentNodes \
diff --git a/lib/clang/libclangrewritecore/Makefile b/lib/clang/libclangrewrite/Makefile
index 80115ee..ec770c3 100644
--- a/lib/clang/libclangrewritecore/Makefile
+++ b/lib/clang/libclangrewrite/Makefile
@@ -2,9 +2,9 @@
.include <bsd.own.mk>
-LIB= clangrewritecore
+LIB= clangrewrite
-SRCDIR= tools/clang/lib/Rewrite/Core
+SRCDIR= tools/clang/lib/Rewrite
SRCS= DeltaTree.cpp \
HTMLRewrite.cpp \
RewriteRope.cpp \
diff --git a/lib/clang/libclangrewritecore/Makefile.depend b/lib/clang/libclangrewrite/Makefile.depend
index a211b19..ef170d1 100644
--- a/lib/clang/libclangrewritecore/Makefile.depend
+++ b/lib/clang/libclangrewrite/Makefile.depend
@@ -16,10 +16,6 @@ DIRDEPS = \
# local dependencies - needed for -jN in clean tree
HTMLRewrite.o: DiagnosticCommonKinds.inc.h
HTMLRewrite.po: DiagnosticCommonKinds.inc.h
-Rewriter.o: DeclNodes.inc.h
Rewriter.o: DiagnosticCommonKinds.inc.h
-Rewriter.o: StmtNodes.inc.h
-Rewriter.po: DeclNodes.inc.h
Rewriter.po: DiagnosticCommonKinds.inc.h
-Rewriter.po: StmtNodes.inc.h
.endif
diff --git a/lib/clang/libclangrewritefrontend/Makefile b/lib/clang/libclangrewritefrontend/Makefile
index 8c41669..2f614fb 100644
--- a/lib/clang/libclangrewritefrontend/Makefile
+++ b/lib/clang/libclangrewritefrontend/Makefile
@@ -4,14 +4,12 @@
LIB= clangrewritefrontend
-SRCDIR= tools/clang/lib/Rewrite/Frontend
+SRCDIR= tools/clang/lib/Frontend/Rewrite
SRCS= FixItRewriter.cpp \
FrontendActions.cpp \
HTMLPrint.cpp \
InclusionRewriter.cpp \
RewriteMacros.cpp \
- RewriteModernObjC.cpp \
- RewriteObjC.cpp \
RewriteTest.cpp
TGHDRS= AttrList \
diff --git a/lib/clang/libclangsema/Makefile b/lib/clang/libclangsema/Makefile
index 9157b46..08c120a 100644
--- a/lib/clang/libclangsema/Makefile
+++ b/lib/clang/libclangsema/Makefile
@@ -18,6 +18,7 @@ SRCS= AnalysisBasedWarnings.cpp \
Sema.cpp \
SemaAccess.cpp \
SemaAttr.cpp \
+ SemaCUDA.cpp \
SemaCXXScopeSpec.cpp \
SemaCast.cpp \
SemaChecking.cpp \
@@ -49,7 +50,6 @@ SRCS= AnalysisBasedWarnings.cpp \
SemaTemplateInstantiateDecl.cpp \
SemaTemplateVariadic.cpp \
SemaType.cpp \
- TargetAttributesSema.cpp \
TypeLocBuilder.cpp
TGHDRS= AttrList \
@@ -58,6 +58,7 @@ TGHDRS= AttrList \
AttrParsedAttrList \
AttrSpellingListIndex \
AttrTemplateInstantiate \
+ AttrVisitor \
Attrs \
CommentCommandList \
CommentNodes \
diff --git a/lib/clang/libclangstaticanalyzercheckers/Makefile b/lib/clang/libclangstaticanalyzercheckers/Makefile
index db27182..5fb1035 100644
--- a/lib/clang/libclangstaticanalyzercheckers/Makefile
+++ b/lib/clang/libclangstaticanalyzercheckers/Makefile
@@ -33,7 +33,6 @@ SRCS= AllocationDiagnostics.cpp \
ExprInspectionChecker.cpp \
FixedAddressChecker.cpp \
GenericTaintChecker.cpp \
- IdempotentOperationChecker.cpp \
IdenticalExprChecker.cpp \
IvarInvalidationChecker.cpp \
LLVMConventionsChecker.cpp \
@@ -62,6 +61,7 @@ SRCS= AllocationDiagnostics.cpp \
StackAddrEscapeChecker.cpp \
StreamChecker.cpp \
TaintTesterChecker.cpp \
+ TestAfterDivZeroChecker.cpp \
TraversalChecker.cpp \
UndefBranchChecker.cpp \
UndefCapturedBlockVarChecker.cpp \
@@ -74,6 +74,7 @@ SRCS= AllocationDiagnostics.cpp \
VirtualCallChecker.cpp
TGHDRS= AttrList \
+ AttrVisitor \
Attrs \
Checkers \
CommentCommandList \
diff --git a/lib/clang/libclangstaticanalyzerfrontend/Makefile b/lib/clang/libclangstaticanalyzerfrontend/Makefile
index de7b326..3975509 100644
--- a/lib/clang/libclangstaticanalyzerfrontend/Makefile
+++ b/lib/clang/libclangstaticanalyzerfrontend/Makefile
@@ -7,9 +7,13 @@ LIB= clangstaticanalyzerfrontend
SRCDIR= tools/clang/lib/StaticAnalyzer/Frontend
SRCS= AnalysisConsumer.cpp \
CheckerRegistration.cpp \
- FrontendActions.cpp
+ ModelConsumer.cpp \
+ FrontendActions.cpp \
+ ModelInjector.cpp
TGHDRS= AttrList \
+ AttrParsedAttrList \
+ AttrVisitor \
Attrs \
Checkers \
CommentCommandList \
diff --git a/lib/clang/liblldb/Makefile b/lib/clang/liblldb/Makefile
index cba14e7..1306cdf 100644
--- a/lib/clang/liblldb/Makefile
+++ b/lib/clang/liblldb/Makefile
@@ -10,7 +10,9 @@ SRCDIR= tools/lldb/source
SRCS= lldb.cpp \
lldb-log.cpp
-TGHDRS= DiagnosticCommonKinds \
+TGHDRS= AttrList \
+ Attrs \
+ DiagnosticCommonKinds \
DeclNodes \
StmtNodes \
CommentCommandList
diff --git a/lib/clang/liblldbAPI/Makefile b/lib/clang/liblldbAPI/Makefile
index d041d09..44addca 100644
--- a/lib/clang/liblldbAPI/Makefile
+++ b/lib/clang/liblldbAPI/Makefile
@@ -19,6 +19,7 @@ SRCS= SBAddress.cpp \
SBDeclaration.cpp \
SBError.cpp \
SBEvent.cpp \
+ SBExecutionContext.cpp \
SBExpressionOptions.cpp \
SBFileSpec.cpp \
SBFileSpecList.cpp \
@@ -43,19 +44,25 @@ SRCS= SBAddress.cpp \
SBSymbolContext.cpp \
SBSymbolContextList.cpp \
SBTarget.cpp \
+ SBThreadCollection.cpp \
+ SBThreadPlan.cpp \
SBThread.cpp \
SBType.cpp \
SBTypeCategory.cpp \
+ SBTypeEnumMember.cpp \
SBTypeFilter.cpp \
SBTypeFormat.cpp \
SBTypeNameSpecifier.cpp \
SBTypeSummary.cpp \
SBTypeSynthetic.cpp \
+ SBUnixSignals.cpp \
SBValue.cpp \
SBValueList.cpp \
SBWatchpoint.cpp
-TGHDRS= DiagnosticCommonKinds \
+TGHDRS= AttrList \
+ Attrs \
+ DiagnosticCommonKinds \
DeclNodes \
StmtNodes \
CommentCommandList
diff --git a/lib/clang/liblldbBreakpoint/Makefile b/lib/clang/liblldbBreakpoint/Makefile
index 396b0aa..b6885d8 100644
--- a/lib/clang/liblldbBreakpoint/Makefile
+++ b/lib/clang/liblldbBreakpoint/Makefile
@@ -27,7 +27,9 @@ SRCS= Breakpoint.cpp \
WatchpointList.cpp \
WatchpointOptions.cpp
-TGHDRS= DiagnosticCommonKinds \
+TGHDRS= AttrList \
+ Attrs \
+ DiagnosticCommonKinds \
DeclNodes \
StmtNodes \
CommentCommandList
diff --git a/lib/clang/liblldbCommands/Makefile b/lib/clang/liblldbCommands/Makefile
index f7baf83..833c8a8 100644
--- a/lib/clang/liblldbCommands/Makefile
+++ b/lib/clang/liblldbCommands/Makefile
@@ -34,7 +34,9 @@ SRCS= CommandCompletions.cpp \
CommandObjectWatchpoint.cpp \
CommandObjectWatchpointCommand.cpp
-TGHDRS= DiagnosticCommonKinds \
+TGHDRS= AttrList \
+ Attrs \
+ DiagnosticCommonKinds \
DeclNodes \
StmtNodes \
CommentCommandList
diff --git a/lib/clang/liblldbCore/Makefile b/lib/clang/liblldbCore/Makefile
index e0335f4..7d9e86b 100644
--- a/lib/clang/liblldbCore/Makefile
+++ b/lib/clang/liblldbCore/Makefile
@@ -15,7 +15,6 @@ SRCS= Address.cpp \
Broadcaster.cpp \
Communication.cpp \
Connection.cpp \
- ConnectionFileDescriptor.cpp \
ConnectionMachPort.cpp \
ConnectionSharedMemory.cpp \
ConstString.cpp \
@@ -29,6 +28,7 @@ SRCS= Address.cpp \
EmulateInstruction.cpp \
Error.cpp \
Event.cpp \
+ FastDemangle.cpp \
FileLineResolver.cpp \
FileSpecList.cpp \
History.cpp \
@@ -56,6 +56,7 @@ SRCS= Address.cpp \
StreamGDBRemote.cpp \
StreamString.cpp \
StringList.cpp \
+ StructuredData.cpp \
Timer.cpp \
UserID.cpp \
UserSettingsController.cpp \
@@ -75,7 +76,9 @@ SRCS= Address.cpp \
ValueObjectVariable.cpp \
VMRange.cpp
-TGHDRS= DiagnosticCommonKinds \
+TGHDRS= AttrList \
+ Attrs \
+ DiagnosticCommonKinds \
DeclNodes \
StmtNodes \
CommentCommandList
diff --git a/lib/clang/liblldbDataFormatters/Makefile b/lib/clang/liblldbDataFormatters/Makefile
index b224215..df34f00 100644
--- a/lib/clang/liblldbDataFormatters/Makefile
+++ b/lib/clang/liblldbDataFormatters/Makefile
@@ -13,21 +13,28 @@ SRCS= CF.cpp \
FormatClasses.cpp \
FormatManager.cpp \
LibCxx.cpp \
+ LibCxxInitializerList.cpp \
LibCxxList.cpp \
LibCxxMap.cpp \
LibCxxUnorderedMap.cpp \
+ LibCxxVector.cpp \
LibStdcpp.cpp \
NSArray.cpp \
NSDictionary.cpp \
+ NSIndexPath.cpp \
NSSet.cpp \
+ StringPrinter.cpp \
TypeCategory.cpp \
TypeCategoryMap.cpp \
TypeFormat.cpp \
TypeSummary.cpp \
TypeSynthetic.cpp \
+ TypeValidator.cpp \
ValueObjectPrinter.cpp
-TGHDRS= DiagnosticCommonKinds \
+TGHDRS= AttrList \
+ Attrs \
+ DiagnosticCommonKinds \
DeclNodes \
StmtNodes \
CommentCommandList
diff --git a/lib/clang/liblldbExpression/Makefile b/lib/clang/liblldbExpression/Makefile
index 120add5..d2d822b 100644
--- a/lib/clang/liblldbExpression/Makefile
+++ b/lib/clang/liblldbExpression/Makefile
@@ -13,6 +13,7 @@ SRCS= ASTDumper.cpp \
ClangExpressionParser.cpp \
ClangExpressionVariable.cpp \
ClangFunction.cpp \
+ ClangModulesDeclVendor.cpp \
ClangPersistentVariables.cpp \
ClangUserExpression.cpp \
ClangUtilityFunction.cpp \
diff --git a/lib/clang/liblldbHostCommon/Makefile b/lib/clang/liblldbHostCommon/Makefile
index f2022bb..af3c053 100644
--- a/lib/clang/liblldbHostCommon/Makefile
+++ b/lib/clang/liblldbHostCommon/Makefile
@@ -6,20 +6,32 @@ LIB= lldbHostCommon
SRCDIR= tools/lldb/source/Host/common
SRCS= Condition.cpp \
- DynamicLibrary.cpp \
Editline.cpp \
File.cpp \
FileSpec.cpp \
Host.cpp \
+ HostInfoBase.cpp \
+ HostNativeThreadBase.cpp \
+ HostProcess.cpp \
+ HostThread.cpp \
+ IOObject.cpp \
+ MonitoringProcessLauncher.cpp \
Mutex.cpp \
OptionParser.cpp \
+ PipeBase.cpp \
ProcessRunLock.cpp \
+ Socket.cpp \
SocketAddress.cpp \
+ SoftwareBreakpoint.cpp \
Symbols.cpp \
Terminal.cpp \
+ ThisThread.cpp \
+ ThreadLauncher.cpp \
TimeValue.cpp
-TGHDRS= DiagnosticCommonKinds \
+TGHDRS= AttrList \
+ Attrs \
+ DiagnosticCommonKinds \
DeclNodes \
StmtNodes \
CommentCommandList
diff --git a/lib/clang/liblldbHostFreeBSD/Makefile b/lib/clang/liblldbHostFreeBSD/Makefile
index e07f8ed..6ebc9b4 100644
--- a/lib/clang/liblldbHostFreeBSD/Makefile
+++ b/lib/clang/liblldbHostFreeBSD/Makefile
@@ -5,7 +5,10 @@
LIB= lldbHostFreeBSD
SRCDIR= tools/lldb/source/Host/freebsd
-SRCS= Host.cpp
+SRCS= Host.cpp \
+ HostInfoFreeBSD.cpp \
+ HostThreadFreeBSD.cpp \
+ ThisThread.cpp
TGHDRS= DiagnosticCommonKinds \
DeclNodes \
diff --git a/lib/clang/liblldbHostPOSIX/Makefile b/lib/clang/liblldbHostPOSIX/Makefile
new file mode 100644
index 0000000..6fe660a
--- /dev/null
+++ b/lib/clang/liblldbHostPOSIX/Makefile
@@ -0,0 +1,16 @@
+# $FreeBSD$
+
+.include <bsd.own.mk>
+
+LIB= lldbHostPOSIX
+
+SRCDIR= tools/lldb/source/Host/posix
+SRCS= ConnectionFileDescriptorPosix.cpp \
+ FileSystem.cpp \
+ HostInfoPosix.cpp \
+ HostProcessPosix.cpp \
+ HostThreadPosix.cpp \
+ PipePosix.cpp \
+ ProcessLauncherPosix.cpp
+
+.include "../lldb.lib.mk"
diff --git a/lib/clang/liblldbInterpreter/Makefile b/lib/clang/liblldbInterpreter/Makefile
index c560adf..f707d9b 100644
--- a/lib/clang/liblldbInterpreter/Makefile
+++ b/lib/clang/liblldbInterpreter/Makefile
@@ -11,6 +11,7 @@ SRCS= Args.cpp \
CommandObject.cpp \
CommandObjectRegexCommand.cpp \
CommandObjectScript.cpp \
+ CommandOptionValidators.cpp \
CommandReturnObject.cpp \
OptionGroupArchitecture.cpp \
OptionGroupBoolean.cpp \
@@ -27,6 +28,7 @@ SRCS= Args.cpp \
OptionValueArgs.cpp \
OptionValueArray.cpp \
OptionValueBoolean.cpp \
+ OptionValueChar.cpp \
OptionValueDictionary.cpp \
OptionValueEnumeration.cpp \
OptionValueFileSpec.cpp \
@@ -48,7 +50,9 @@ SRCS= Args.cpp \
ScriptInterpreterNone.cpp \
ScriptInterpreterPython.cpp
-TGHDRS= DiagnosticCommonKinds \
+TGHDRS= AttrList \
+ Attrs \
+ DiagnosticCommonKinds \
DeclNodes \
StmtNodes \
CommentCommandList
diff --git a/lib/clang/liblldbPluginABISysV_ppc/Makefile b/lib/clang/liblldbPluginABISysV_ppc/Makefile
new file mode 100644
index 0000000..4cbbc02
--- /dev/null
+++ b/lib/clang/liblldbPluginABISysV_ppc/Makefile
@@ -0,0 +1,15 @@
+# $FreeBSD$
+
+.include <bsd.own.mk>
+
+LIB= lldbPluginABISysV_ppc
+
+SRCDIR= tools/lldb/source/Plugins/ABI/SysV-ppc
+SRCS= ABISysV_ppc.cpp
+
+TGHDRS= DiagnosticCommonKinds \
+ DeclNodes \
+ StmtNodes \
+ CommentCommandList
+
+.include "../lldb.lib.mk"
diff --git a/lib/clang/liblldbPluginABISysV_ppc64/Makefile b/lib/clang/liblldbPluginABISysV_ppc64/Makefile
new file mode 100644
index 0000000..fe72ab5
--- /dev/null
+++ b/lib/clang/liblldbPluginABISysV_ppc64/Makefile
@@ -0,0 +1,15 @@
+# $FreeBSD$
+
+.include <bsd.own.mk>
+
+LIB= lldbPluginABISysV_ppc64
+
+SRCDIR= tools/lldb/source/Plugins/ABI/SysV-ppc64
+SRCS= ABISysV_ppc64.cpp
+
+TGHDRS= DiagnosticCommonKinds \
+ DeclNodes \
+ StmtNodes \
+ CommentCommandList
+
+.include "../lldb.lib.mk"
diff --git a/lib/clang/liblldbPluginInstructionARM64/Makefile b/lib/clang/liblldbPluginInstructionARM64/Makefile
new file mode 100644
index 0000000..92d976e
--- /dev/null
+++ b/lib/clang/liblldbPluginInstructionARM64/Makefile
@@ -0,0 +1,10 @@
+# $FreeBSD$
+
+.include <bsd.own.mk>
+
+LIB= lldbPluginInstructionARM64
+
+SRCDIR= tools/lldb/source/Plugins/Instruction/ARM64
+SRCS= EmulateInstructionARM64.cpp
+
+.include "../lldb.lib.mk"
diff --git a/lib/clang/liblldbPluginInstrumentationRuntimeAddressSanitizer/Makefile b/lib/clang/liblldbPluginInstrumentationRuntimeAddressSanitizer/Makefile
new file mode 100644
index 0000000..bb02244
--- /dev/null
+++ b/lib/clang/liblldbPluginInstrumentationRuntimeAddressSanitizer/Makefile
@@ -0,0 +1,17 @@
+# $FreeBSD$
+
+.include <bsd.own.mk>
+
+LIB= lldbPluginInstrumentationRuntimeAddressSanitizer
+
+SRCDIR= tools/lldb/source/Plugins/InstrumentationRuntime/AddressSanitizer
+SRCS= AddressSanitizerRuntime.cpp
+
+TGHDRS= AttrList \
+ Attrs \
+ DiagnosticCommonKinds \
+ DeclNodes \
+ StmtNodes \
+ CommentCommandList
+
+.include "../lldb.lib.mk"
diff --git a/lib/clang/liblldbPluginJITLoaderGDB/Makefile b/lib/clang/liblldbPluginJITLoaderGDB/Makefile
new file mode 100644
index 0000000..80e84df
--- /dev/null
+++ b/lib/clang/liblldbPluginJITLoaderGDB/Makefile
@@ -0,0 +1,15 @@
+# $FreeBSD$
+
+.include <bsd.own.mk>
+
+LIB= lldbPluginJITLoaderGDB
+
+SRCDIR= tools/lldb/source/Plugins/JITLoader/GDB
+SRCS= JITLoaderGDB.cpp
+
+TGHDRS= DiagnosticCommonKinds \
+ DeclNodes \
+ StmtNodes \
+ CommentCommandList
+
+.include "../lldb.lib.mk"
diff --git a/lib/clang/liblldbPluginMemoryHistoryASan/Makefile b/lib/clang/liblldbPluginMemoryHistoryASan/Makefile
new file mode 100644
index 0000000..ac57d6a
--- /dev/null
+++ b/lib/clang/liblldbPluginMemoryHistoryASan/Makefile
@@ -0,0 +1,15 @@
+# $FreeBSD$
+
+.include <bsd.own.mk>
+
+LIB= lldbPluginMemoryHistoryASan
+
+SRCDIR= tools/lldb/source/Plugins/MemoryHistory/asan
+SRCS= MemoryHistoryASan.cpp
+
+TGHDRS= DiagnosticCommonKinds \
+ DeclNodes \
+ StmtNodes \
+ CommentCommandList
+
+.include "../lldb.lib.mk"
diff --git a/lib/clang/liblldbPluginObjectFileJIT/Makefile b/lib/clang/liblldbPluginObjectFileJIT/Makefile
new file mode 100644
index 0000000..2640350
--- /dev/null
+++ b/lib/clang/liblldbPluginObjectFileJIT/Makefile
@@ -0,0 +1,17 @@
+# $FreeBSD$
+
+.include <bsd.own.mk>
+
+LIB= lldbPluginObjectFileJIT
+
+SRCDIR= tools/lldb/source/Plugins/ObjectFile/JIT
+SRCS= ObjectFileJIT.cpp
+
+TGHDRS= AttrList \
+ Attrs \
+ DiagnosticCommonKinds \
+ DeclNodes \
+ StmtNodes \
+ CommentCommandList
+
+.include "../lldb.lib.mk"
diff --git a/lib/clang/liblldbPluginPlatformFreeBSD/Makefile b/lib/clang/liblldbPluginPlatformFreeBSD/Makefile
index 9be7af3..c2eee8a 100644
--- a/lib/clang/liblldbPluginPlatformFreeBSD/Makefile
+++ b/lib/clang/liblldbPluginPlatformFreeBSD/Makefile
@@ -7,7 +7,9 @@ LIB= lldbPluginPlatformFreeBSD
SRCDIR= tools/lldb/source/Plugins/Platform/FreeBSD
SRCS= PlatformFreeBSD.cpp
-TGHDRS= DiagnosticCommonKinds \
+TGHDRS= AttrList \
+ Attrs \
+ DiagnosticCommonKinds \
DeclNodes \
StmtNodes \
CommentCommandList
diff --git a/lib/clang/liblldbPluginPlatformGDB/Makefile b/lib/clang/liblldbPluginPlatformGDB/Makefile
index 1d8a994..714a311 100644
--- a/lib/clang/liblldbPluginPlatformGDB/Makefile
+++ b/lib/clang/liblldbPluginPlatformGDB/Makefile
@@ -7,7 +7,9 @@ LIB= lldbPluginPlatformGDB
SRCDIR= tools/lldb/source/Plugins/Platform/gdb-server
SRCS= PlatformRemoteGDBServer.cpp
-TGHDRS= DiagnosticCommonKinds \
+TGHDRS= AttrList \
+ Attrs \
+ DiagnosticCommonKinds \
DeclNodes \
StmtNodes \
CommentCommandList
diff --git a/lib/clang/liblldbPluginProcessElfCore/Makefile b/lib/clang/liblldbPluginProcessElfCore/Makefile
index 30198b5..66852dd 100644
--- a/lib/clang/liblldbPluginProcessElfCore/Makefile
+++ b/lib/clang/liblldbPluginProcessElfCore/Makefile
@@ -11,6 +11,7 @@ SRCDIR= tools/lldb/source/Plugins/Process/elf-core
SRCS= ProcessElfCore.cpp \
ThreadElfCore.cpp \
RegisterContextPOSIXCore_mips64.cpp \
+ RegisterContextPOSIXCore_powerpc.cpp \
RegisterContextPOSIXCore_x86_64.cpp
TGHDRS= DiagnosticCommonKinds \
diff --git a/lib/clang/liblldbPluginProcessGDBRemote/Makefile b/lib/clang/liblldbPluginProcessGDBRemote/Makefile
index c76fe8a..5bbb40f 100644
--- a/lib/clang/liblldbPluginProcessGDBRemote/Makefile
+++ b/lib/clang/liblldbPluginProcessGDBRemote/Makefile
@@ -13,7 +13,9 @@ SRCS= GDBRemoteCommunication.cpp \
ProcessGDBRemoteLog.cpp \
ThreadGDBRemote.cpp
-TGHDRS= DiagnosticCommonKinds \
+TGHDRS= AttrList \
+ Attrs \
+ DiagnosticCommonKinds \
DeclNodes \
StmtNodes \
CommentCommandList
diff --git a/lib/clang/liblldbPluginProcessPOSIX/Makefile b/lib/clang/liblldbPluginProcessPOSIX/Makefile
index f681fd3..ddd902a 100644
--- a/lib/clang/liblldbPluginProcessPOSIX/Makefile
+++ b/lib/clang/liblldbPluginProcessPOSIX/Makefile
@@ -15,17 +15,14 @@ SRCS= POSIXStopInfo.cpp \
ProcessMessage.cpp \
ProcessPOSIX.cpp \
ProcessPOSIXLog.cpp \
- RegisterContextFreeBSD_i386.cpp \
- RegisterContextFreeBSD_mips64.cpp \
- RegisterContextFreeBSD_x86_64.cpp \
- RegisterContextLinux_i386.cpp \
- RegisterContextLinux_x86_64.cpp \
+ RegisterContextPOSIXProcessMonitor_arm64.cpp \
RegisterContextPOSIXProcessMonitor_mips64.cpp \
- RegisterContextPOSIXProcessMonitor_x86.cpp \
- RegisterContextPOSIX_mips64.cpp \
- RegisterContextPOSIX_x86.cpp
+ RegisterContextPOSIXProcessMonitor_powerpc.cpp \
+ RegisterContextPOSIXProcessMonitor_x86.cpp
-TGHDRS= DiagnosticCommonKinds \
+TGHDRS= AttrList \
+ Attrs \
+ DiagnosticCommonKinds \
DeclNodes \
StmtNodes \
CommentCommandList
diff --git a/lib/clang/liblldbPluginProcessUtility/Makefile b/lib/clang/liblldbPluginProcessUtility/Makefile
index 1459254..d43396f 100644
--- a/lib/clang/liblldbPluginProcessUtility/Makefile
+++ b/lib/clang/liblldbPluginProcessUtility/Makefile
@@ -6,27 +6,43 @@ LIB= lldbPluginProcessUtility
SRCDIR= tools/lldb/source/Plugins/Process/Utility
SRCS= DynamicRegisterInfo.cpp \
+ FreeBSDSignals.cpp \
HistoryThread.cpp \
HistoryUnwind.cpp \
InferiorCallPOSIX.cpp \
+ LinuxSignals.cpp \
RegisterContextDarwin_arm.cpp \
+ RegisterContextDarwin_arm64.cpp \
RegisterContextDarwin_i386.cpp \
RegisterContextDarwin_x86_64.cpp \
RegisterContextDummy.cpp \
+ RegisterContextFreeBSD_i386.cpp \
+ RegisterContextFreeBSD_mips64.cpp \
+ RegisterContextFreeBSD_powerpc.cpp \
+ RegisterContextFreeBSD_x86_64.cpp \
RegisterContextHistory.cpp \
+ RegisterContextLinux_arm64.cpp \
+ RegisterContextLinux_i386.cpp \
+ RegisterContextLinux_x86_64.cpp \
RegisterContextLLDB.cpp \
RegisterContextMach_arm.cpp \
RegisterContextMach_i386.cpp \
RegisterContextMach_x86_64.cpp \
RegisterContextMacOSXFrameBackchain.cpp \
RegisterContextMemory.cpp \
+ RegisterContextPOSIX_arm64.cpp \
+ RegisterContextPOSIX_mips64.cpp \
+ RegisterContextPOSIX_powerpc.cpp \
+ RegisterContextPOSIX_x86.cpp \
RegisterContextThreadMemory.cpp \
StopInfoMachException.cpp \
ThreadMemory.cpp \
UnwindLLDB.cpp \
UnwindMacOSXFrameBackchain.cpp
-TGHDRS= DiagnosticCommonKinds \
+TGHDRS= AttrList \
+ Attrs \
+ DiagnosticCommonKinds \
DeclNodes \
StmtNodes \
CommentCommandList
diff --git a/lib/clang/liblldbPluginSymbolFileDWARF/Makefile b/lib/clang/liblldbPluginSymbolFileDWARF/Makefile
index ac23199..5b8dbfd 100644
--- a/lib/clang/liblldbPluginSymbolFileDWARF/Makefile
+++ b/lib/clang/liblldbPluginSymbolFileDWARF/Makefile
@@ -31,7 +31,9 @@ SRCS= DWARFAbbreviationDeclaration.cpp \
SymbolFileDWARFDebugMap.cpp \
UniqueDWARFASTType.cpp
-TGHDRS= DiagnosticCommonKinds \
+TGHDRS= AttrList \
+ Attrs \
+ DiagnosticCommonKinds \
DeclNodes \
StmtNodes \
CommentCommandList \
diff --git a/lib/clang/liblldbSymbol/Makefile b/lib/clang/liblldbSymbol/Makefile
index ed22ec3..82c11ff 100644
--- a/lib/clang/liblldbSymbol/Makefile
+++ b/lib/clang/liblldbSymbol/Makefile
@@ -12,6 +12,7 @@ SRCS= Block.cpp \
ClangExternalASTSourceCallbacks.cpp \
ClangExternalASTSourceCommon.cpp \
ClangNamespaceDecl.cpp \
+ CompactUnwindInfo.cpp \
CompileUnit.cpp \
Declaration.cpp \
DWARFCallFrameInfo.cpp \
diff --git a/lib/clang/liblldbTarget/Makefile b/lib/clang/liblldbTarget/Makefile
index 2e0226d..95ced8d 100644
--- a/lib/clang/liblldbTarget/Makefile
+++ b/lib/clang/liblldbTarget/Makefile
@@ -10,13 +10,23 @@ SRCDIR= tools/lldb/source/Target
SRCS= ABI.cpp \
CPPLanguageRuntime.cpp \
ExecutionContext.cpp \
+ FileAction.cpp \
+ InstrumentationRuntime.cpp \
+ InstrumentationRuntimeStopInfo.cpp \
+ JITLoader.cpp \
+ JITLoaderList.cpp \
LanguageRuntime.cpp \
Memory.cpp \
+ MemoryHistory.cpp \
+ NativeRegisterContext.cpp \
+ NativeRegisterContextRegisterInfo.cpp \
ObjCLanguageRuntime.cpp \
OperatingSystem.cpp \
PathMappingList.cpp \
Platform.cpp \
Process.cpp \
+ ProcessInfo.cpp \
+ ProcessLaunchInfo.cpp \
Queue.cpp \
QueueItem.cpp \
QueueList.cpp \
@@ -31,11 +41,13 @@ SRCS= ABI.cpp \
Target.cpp \
TargetList.cpp \
Thread.cpp \
+ ThreadCollection.cpp \
ThreadList.cpp \
ThreadPlan.cpp \
ThreadPlanBase.cpp \
ThreadPlanCallFunction.cpp \
ThreadPlanCallUserExpression.cpp \
+ ThreadPlanPython.cpp \
ThreadPlanRunToAddress.cpp \
ThreadPlanShouldStopHere.cpp \
ThreadPlanStepInRange.cpp \
@@ -51,7 +63,9 @@ SRCS= ABI.cpp \
UnixSignals.cpp \
UnwindAssembly.cpp
-TGHDRS= DiagnosticCommonKinds \
+TGHDRS= AttrList \
+ Attrs \
+ DiagnosticCommonKinds \
DeclNodes \
StmtNodes \
CommentCommandList
diff --git a/lib/clang/liblldbUtility/Makefile b/lib/clang/liblldbUtility/Makefile
index e5723b2..13ed72d 100644
--- a/lib/clang/liblldbUtility/Makefile
+++ b/lib/clang/liblldbUtility/Makefile
@@ -5,13 +5,17 @@
LIB= lldbUtility
SRCDIR= tools/lldb/source/Utility
-SRCS= ARM_DWARF_Registers.cpp \
+SRCS= ARM64_DWARF_Registers.cpp \
+ ARM_DWARF_Registers.cpp \
KQueue.cpp \
PseudoTerminal.cpp \
Range.cpp \
+ RegisterNumber.cpp \
SharingPtr.cpp \
StringExtractor.cpp \
StringExtractorGDBRemote.cpp \
- TimeSpecTimeout.cpp
+ StringLexer.cpp \
+ TimeSpecTimeout.cpp \
+ UriParser.cpp
.include "../lldb.lib.mk"
diff --git a/lib/clang/libllvmaarch64asmparser/Makefile b/lib/clang/libllvmaarch64asmparser/Makefile
new file mode 100644
index 0000000..d93fb9a
--- /dev/null
+++ b/lib/clang/libllvmaarch64asmparser/Makefile
@@ -0,0 +1,16 @@
+# $FreeBSD$
+
+.include <bsd.own.mk>
+
+LIB= llvmaarch64asmparser
+
+SRCDIR= lib/Target/AArch64/AsmParser
+INCDIR= lib/Target/AArch64
+SRCS= AArch64AsmParser.cpp
+
+TGHDRS= AArch64GenAsmMatcher \
+ AArch64GenInstrInfo \
+ AArch64GenRegisterInfo \
+ AArch64GenSubtargetInfo
+
+.include "../clang.lib.mk"
diff --git a/lib/clang/libllvmaarch64asmparser/Makefile.depend b/lib/clang/libllvmaarch64asmparser/Makefile.depend
new file mode 100644
index 0000000..39ddb0e
--- /dev/null
+++ b/lib/clang/libllvmaarch64asmparser/Makefile.depend
@@ -0,0 +1,23 @@
+# Autogenerated - do NOT edit!
+
+DEP_RELDIR := ${_PARSEDIR:S,${SRCTOP}/,,}
+
+DIRDEPS = \
+ include \
+ include/xlocale \
+ usr.bin/clang/tblgen.host \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+AArch64AsmParser.o: AArch64GenAsmMatcher.inc.h
+AArch64AsmParser.o: AArch64GenInstrInfo.inc.h
+AArch64AsmParser.o: AArch64GenRegisterInfo.inc.h
+AArch64AsmParser.o: AArch64GenSubtargetInfo.inc.h
+AArch64AsmParser.po: AArch64GenAsmMatcher.inc.h
+AArch64AsmParser.po: AArch64GenInstrInfo.inc.h
+AArch64AsmParser.po: AArch64GenRegisterInfo.inc.h
+AArch64AsmParser.po: AArch64GenSubtargetInfo.inc.h
+.endif
diff --git a/lib/clang/libllvmaarch64codegen/Makefile b/lib/clang/libllvmaarch64codegen/Makefile
new file mode 100644
index 0000000..db0023f
--- /dev/null
+++ b/lib/clang/libllvmaarch64codegen/Makefile
@@ -0,0 +1,46 @@
+# $FreeBSD$
+
+.include <bsd.own.mk>
+
+LIB= llvmaarch64codegen
+
+SRCDIR= lib/Target/AArch64
+SRCS= AArch64A53Fix835769.cpp \
+ AArch64A57FPLoadBalancing.cpp \
+ AArch64AddressTypePromotion.cpp \
+ AArch64AdvSIMDScalarPass.cpp \
+ AArch64AsmPrinter.cpp \
+ AArch64BranchRelaxation.cpp \
+ AArch64CleanupLocalDynamicTLSPass.cpp \
+ AArch64CollectLOH.cpp \
+ AArch64ConditionOptimizer.cpp \
+ AArch64ConditionalCompares.cpp \
+ AArch64DeadRegisterDefinitionsPass.cpp \
+ AArch64ExpandPseudoInsts.cpp \
+ AArch64FastISel.cpp \
+ AArch64FrameLowering.cpp \
+ AArch64ISelDAGToDAG.cpp \
+ AArch64ISelLowering.cpp \
+ AArch64InstrInfo.cpp \
+ AArch64LoadStoreOptimizer.cpp \
+ AArch64MCInstLower.cpp \
+ AArch64PBQPRegAlloc.cpp \
+ AArch64PromoteConstant.cpp \
+ AArch64RegisterInfo.cpp \
+ AArch64SelectionDAGInfo.cpp \
+ AArch64StorePairSuppress.cpp \
+ AArch64Subtarget.cpp \
+ AArch64TargetMachine.cpp \
+ AArch64TargetObjectFile.cpp \
+ AArch64TargetTransformInfo.cpp
+
+TGHDRS= AArch64GenCallingConv \
+ AArch64GenDAGISel \
+ AArch64GenFastISel \
+ AArch64GenInstrInfo \
+ AArch64GenMCPseudoLowering \
+ AArch64GenRegisterInfo \
+ AArch64GenSubtargetInfo \
+ Intrinsics
+
+.include "../clang.lib.mk"
diff --git a/lib/clang/libllvmaarch64desc/Makefile b/lib/clang/libllvmaarch64desc/Makefile
new file mode 100644
index 0000000..041fbf2
--- /dev/null
+++ b/lib/clang/libllvmaarch64desc/Makefile
@@ -0,0 +1,24 @@
+# $FreeBSD$
+
+.include <bsd.own.mk>
+
+LIB= llvmaarch64desc
+
+SRCDIR= lib/Target/AArch64/MCTargetDesc
+SRCS= AArch64AsmBackend.cpp \
+ AArch64ELFObjectWriter.cpp \
+ AArch64ELFStreamer.cpp \
+ AArch64MCAsmInfo.cpp \
+ AArch64MCCodeEmitter.cpp \
+ AArch64MCExpr.cpp \
+ AArch64MCTargetDesc.cpp \
+ AArch64MachObjectWriter.cpp \
+ AArch64TargetStreamer.cpp
+CFLAGS+= -I${LLVM_SRCS}/${SRCDIR}/..
+
+TGHDRS= AArch64GenInstrInfo \
+ AArch64GenMCCodeEmitter \
+ AArch64GenRegisterInfo \
+ AArch64GenSubtargetInfo
+
+.include "../clang.lib.mk"
diff --git a/lib/clang/libllvmaarch64desc/Makefile.depend b/lib/clang/libllvmaarch64desc/Makefile.depend
new file mode 100644
index 0000000..f1a450c
--- /dev/null
+++ b/lib/clang/libllvmaarch64desc/Makefile.depend
@@ -0,0 +1,47 @@
+# Autogenerated - do NOT edit!
+
+DEP_RELDIR := ${_PARSEDIR:S,${SRCTOP}/,,}
+
+DIRDEPS = \
+ include \
+ include/xlocale \
+ usr.bin/clang/tblgen.host \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+AArch64AsmBackend.o: AArch64GenInstrInfo.inc.h
+AArch64AsmBackend.o: AArch64GenRegisterInfo.inc.h
+AArch64AsmBackend.o: AArch64GenSubtargetInfo.inc.h
+AArch64AsmBackend.po: AArch64GenInstrInfo.inc.h
+AArch64AsmBackend.po: AArch64GenRegisterInfo.inc.h
+AArch64AsmBackend.po: AArch64GenSubtargetInfo.inc.h
+AArch64ELFObjectWriter.o: AArch64GenInstrInfo.inc.h
+AArch64ELFObjectWriter.o: AArch64GenRegisterInfo.inc.h
+AArch64ELFObjectWriter.o: AArch64GenSubtargetInfo.inc.h
+AArch64ELFObjectWriter.po: AArch64GenInstrInfo.inc.h
+AArch64ELFObjectWriter.po: AArch64GenRegisterInfo.inc.h
+AArch64ELFObjectWriter.po: AArch64GenSubtargetInfo.inc.h
+AArch64MCCodeEmitter.o: AArch64GenInstrInfo.inc.h
+AArch64MCCodeEmitter.o: AArch64GenMCCodeEmitter.inc.h
+AArch64MCCodeEmitter.o: AArch64GenRegisterInfo.inc.h
+AArch64MCCodeEmitter.o: AArch64GenSubtargetInfo.inc.h
+AArch64MCCodeEmitter.po: AArch64GenInstrInfo.inc.h
+AArch64MCCodeEmitter.po: AArch64GenMCCodeEmitter.inc.h
+AArch64MCCodeEmitter.po: AArch64GenRegisterInfo.inc.h
+AArch64MCCodeEmitter.po: AArch64GenSubtargetInfo.inc.h
+AArch64MCTargetDesc.o: AArch64GenInstrInfo.inc.h
+AArch64MCTargetDesc.o: AArch64GenRegisterInfo.inc.h
+AArch64MCTargetDesc.o: AArch64GenSubtargetInfo.inc.h
+AArch64MCTargetDesc.po: AArch64GenInstrInfo.inc.h
+AArch64MCTargetDesc.po: AArch64GenRegisterInfo.inc.h
+AArch64MCTargetDesc.po: AArch64GenSubtargetInfo.inc.h
+AArch64MachObjectWriter.o: AArch64GenInstrInfo.inc.h
+AArch64MachObjectWriter.o: AArch64GenRegisterInfo.inc.h
+AArch64MachObjectWriter.o: AArch64GenSubtargetInfo.inc.h
+AArch64MachObjectWriter.po: AArch64GenInstrInfo.inc.h
+AArch64MachObjectWriter.po: AArch64GenRegisterInfo.inc.h
+AArch64MachObjectWriter.po: AArch64GenSubtargetInfo.inc.h
+.endif
diff --git a/lib/clang/libllvmaarch64disassembler/Makefile b/lib/clang/libllvmaarch64disassembler/Makefile
new file mode 100644
index 0000000..0cf9658
--- /dev/null
+++ b/lib/clang/libllvmaarch64disassembler/Makefile
@@ -0,0 +1,20 @@
+# $FreeBSD$
+
+.include <src.opts.mk>
+
+LIB= llvmaarch64disassembler
+
+SRCDIR= lib/Target/AArch64/Disassembler
+INCDIR= lib/Target/AArch64
+SRCS= AArch64Disassembler.cpp
+
+.if ${MK_CLANG_EXTRAS} != "no" || ${MK_LLDB} != "no"
+SRCS+= AArch64ExternalSymbolizer.cpp
+.endif
+
+TGHDRS= AArch64GenDisassemblerTables \
+ AArch64GenInstrInfo \
+ AArch64GenRegisterInfo \
+ AArch64GenSubtargetInfo
+
+.include "../clang.lib.mk"
diff --git a/lib/clang/libllvmaarch64disassembler/Makefile.depend b/lib/clang/libllvmaarch64disassembler/Makefile.depend
new file mode 100644
index 0000000..ef36bba
--- /dev/null
+++ b/lib/clang/libllvmaarch64disassembler/Makefile.depend
@@ -0,0 +1,23 @@
+# Autogenerated - do NOT edit!
+
+DEP_RELDIR := ${_PARSEDIR:S,${SRCTOP}/,,}
+
+DIRDEPS = \
+ include \
+ include/xlocale \
+ usr.bin/clang/tblgen.host \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+AArch64Disassembler.o: AArch64GenDisassemblerTables.inc.h
+AArch64Disassembler.o: AArch64GenInstrInfo.inc.h
+AArch64Disassembler.o: AArch64GenRegisterInfo.inc.h
+AArch64Disassembler.o: AArch64GenSubtargetInfo.inc.h
+AArch64Disassembler.po: AArch64GenDisassemblerTables.inc.h
+AArch64Disassembler.po: AArch64GenInstrInfo.inc.h
+AArch64Disassembler.po: AArch64GenRegisterInfo.inc.h
+AArch64Disassembler.po: AArch64GenSubtargetInfo.inc.h
+.endif
diff --git a/lib/clang/libllvmaarch64info/Makefile b/lib/clang/libllvmaarch64info/Makefile
new file mode 100644
index 0000000..c62a6e1
--- /dev/null
+++ b/lib/clang/libllvmaarch64info/Makefile
@@ -0,0 +1,15 @@
+# $FreeBSD$
+
+.include <bsd.own.mk>
+
+LIB= llvmaarch64info
+
+SRCDIR= lib/Target/AArch64/TargetInfo
+INCDIR= lib/Target/AArch64
+SRCS= AArch64TargetInfo.cpp
+
+TGHDRS= AArch64GenInstrInfo \
+ AArch64GenRegisterInfo \
+ AArch64GenSubtargetInfo
+
+.include "../clang.lib.mk"
diff --git a/lib/clang/libllvmjit/Makefile.depend b/lib/clang/libllvmaarch64info/Makefile.depend
index 4d8f064..2be5570 100644
--- a/lib/clang/libllvmjit/Makefile.depend
+++ b/lib/clang/libllvmaarch64info/Makefile.depend
@@ -5,8 +5,7 @@ DEP_RELDIR := ${_PARSEDIR:S,${SRCTOP}/,,}
DIRDEPS = \
include \
include/xlocale \
- lib/libc++ \
- lib/msun \
+ usr.bin/clang/tblgen.host \
.include <dirdeps.mk>
diff --git a/lib/clang/libllvmaarch64instprinter/Makefile b/lib/clang/libllvmaarch64instprinter/Makefile
new file mode 100644
index 0000000..c037dc8
--- /dev/null
+++ b/lib/clang/libllvmaarch64instprinter/Makefile
@@ -0,0 +1,17 @@
+# $FreeBSD$
+
+.include <bsd.own.mk>
+
+LIB= llvmaarch64instprinter
+
+SRCDIR= lib/Target/AArch64/InstPrinter
+INCDIR= lib/Target/AArch64
+SRCS= AArch64InstPrinter.cpp
+
+TGHDRS= AArch64GenAsmWriter \
+ AArch64GenAsmWriter1 \
+ AArch64GenInstrInfo \
+ AArch64GenRegisterInfo \
+ AArch64GenSubtargetInfo
+
+.include "../clang.lib.mk"
diff --git a/lib/clang/libllvmaarch64instprinter/Makefile.depend b/lib/clang/libllvmaarch64instprinter/Makefile.depend
new file mode 100644
index 0000000..c2fc2109
--- /dev/null
+++ b/lib/clang/libllvmaarch64instprinter/Makefile.depend
@@ -0,0 +1,25 @@
+# Autogenerated - do NOT edit!
+
+DEP_RELDIR := ${_PARSEDIR:S,${SRCTOP}/,,}
+
+DIRDEPS = \
+ include \
+ include/xlocale \
+ usr.bin/clang/tblgen.host \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+AArch64InstPrinter.o: AArch64GenAsmWriter.inc.h
+AArch64InstPrinter.o: AArch64GenAsmWriter1.inc.h
+AArch64InstPrinter.o: AArch64GenInstrInfo.inc.h
+AArch64InstPrinter.o: AArch64GenRegisterInfo.inc.h
+AArch64InstPrinter.o: AArch64GenSubtargetInfo.inc.h
+AArch64InstPrinter.po: AArch64GenAsmWriter.inc.h
+AArch64InstPrinter.po: AArch64GenAsmWriter1.inc.h
+AArch64InstPrinter.po: AArch64GenInstrInfo.inc.h
+AArch64InstPrinter.po: AArch64GenRegisterInfo.inc.h
+AArch64InstPrinter.po: AArch64GenSubtargetInfo.inc.h
+.endif
diff --git a/lib/clang/libllvmaarch64utils/Makefile b/lib/clang/libllvmaarch64utils/Makefile
new file mode 100644
index 0000000..d945927
--- /dev/null
+++ b/lib/clang/libllvmaarch64utils/Makefile
@@ -0,0 +1,15 @@
+# $FreeBSD$
+
+.include <bsd.own.mk>
+
+LIB= llvmaarch64utils
+
+SRCDIR= lib/Target/AArch64/Utils
+INCDIR= lib/Target/AArch64
+SRCS= AArch64BaseInfo.cpp
+
+TGHDRS= AArch64GenInstrInfo \
+ AArch64GenRegisterInfo \
+ AArch64GenSubtargetInfo
+
+.include "../clang.lib.mk"
diff --git a/lib/clang/libllvmaarch64utils/Makefile.depend b/lib/clang/libllvmaarch64utils/Makefile.depend
new file mode 100644
index 0000000..59e0fe9
--- /dev/null
+++ b/lib/clang/libllvmaarch64utils/Makefile.depend
@@ -0,0 +1,21 @@
+# Autogenerated - do NOT edit!
+
+DEP_RELDIR := ${_PARSEDIR:S,${SRCTOP}/,,}
+
+DIRDEPS = \
+ include \
+ include/xlocale \
+ usr.bin/clang/tblgen.host \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+AArch64BaseInfo.o: AArch64GenInstrInfo.inc.h
+AArch64BaseInfo.o: AArch64GenRegisterInfo.inc.h
+AArch64BaseInfo.o: AArch64GenSubtargetInfo.inc.h
+AArch64BaseInfo.po: AArch64GenInstrInfo.inc.h
+AArch64BaseInfo.po: AArch64GenRegisterInfo.inc.h
+AArch64BaseInfo.po: AArch64GenSubtargetInfo.inc.h
+.endif
diff --git a/lib/clang/libllvmanalysis/Makefile b/lib/clang/libllvmanalysis/Makefile
index ea2a718..7c81c5b 100644
--- a/lib/clang/libllvmanalysis/Makefile
+++ b/lib/clang/libllvmanalysis/Makefile
@@ -11,10 +11,15 @@ SRCS= AliasAnalysis.cpp \
AliasDebugger.cpp \
AliasSetTracker.cpp \
Analysis.cpp \
+ AssumptionCache.cpp \
BasicAliasAnalysis.cpp \
+ BlockFrequencyInfo.cpp \
+ BlockFrequencyInfoImpl.cpp \
BranchProbabilityInfo.cpp \
CFG.cpp \
CFGPrinter.cpp \
+ CFLAliasAnalysis.cpp \
+ CGSCCPassManager.cpp \
CaptureTracking.cpp \
CodeMetrics.cpp \
ConstantFolding.cpp \
@@ -23,11 +28,14 @@ SRCS= AliasAnalysis.cpp \
DependenceAnalysis.cpp \
DomPrinter.cpp \
DominanceFrontier.cpp \
+ FunctionTargetTransformInfo.cpp \
IVUsers.cpp \
InstCount.cpp \
InstructionSimplify.cpp \
Interval.cpp \
IntervalPartition.cpp \
+ JumpInstrTableInfo.cpp \
+ LazyCallGraph.cpp \
LazyValueInfo.cpp \
LibCallAliasAnalysis.cpp \
LibCallSemantics.cpp \
@@ -50,16 +58,13 @@ SRCS= AliasAnalysis.cpp \
ScalarEvolutionAliasAnalysis.cpp \
ScalarEvolutionExpander.cpp \
ScalarEvolutionNormalization.cpp \
+ ScopedNoAliasAA.cpp \
SparsePropagation.cpp \
TargetTransformInfo.cpp \
Trace.cpp \
TypeBasedAliasAnalysis.cpp \
ValueTracking.cpp
-.if ${MK_CLANG_EXTRAS} != "no"
-SRCS+= BlockFrequencyInfo.cpp
-.endif
-
TGHDRS= Intrinsics
.include "../clang.lib.mk"
diff --git a/lib/clang/libllvmarmcodegen/Makefile b/lib/clang/libllvmarmcodegen/Makefile
index db57418..dc951e3 100644
--- a/lib/clang/libllvmarmcodegen/Makefile
+++ b/lib/clang/libllvmarmcodegen/Makefile
@@ -9,7 +9,6 @@ SRCS= A15SDOptimizer.cpp \
ARMAsmPrinter.cpp \
ARMBaseInstrInfo.cpp \
ARMBaseRegisterInfo.cpp \
- ARMCodeEmitter.cpp \
ARMConstantIslandPass.cpp \
ARMConstantPoolValue.cpp \
ARMExpandPseudoInsts.cpp \
@@ -19,11 +18,11 @@ SRCS= A15SDOptimizer.cpp \
ARMISelDAGToDAG.cpp \
ARMISelLowering.cpp \
ARMInstrInfo.cpp \
- ARMJITInfo.cpp \
ARMLoadStoreOptimizer.cpp \
ARMMCInstLower.cpp \
ARMMachineFunctionInfo.cpp \
ARMRegisterInfo.cpp \
+ ARMOptimizeBarriersPass.cpp \
ARMSelectionDAGInfo.cpp \
ARMSubtarget.cpp \
ARMTargetMachine.cpp \
diff --git a/lib/clang/libllvmarmdesc/Makefile b/lib/clang/libllvmarmdesc/Makefile
index 73999ad..42c3f5c 100644
--- a/lib/clang/libllvmarmdesc/Makefile
+++ b/lib/clang/libllvmarmdesc/Makefile
@@ -7,6 +7,7 @@ LIB= llvmarmdesc
SRCDIR= lib/Target/ARM/MCTargetDesc
SRCS= ARMAsmBackend.cpp \
ARMELFObjectWriter.cpp \
+ ARMELFObjectWriter.cpp \
ARMELFStreamer.cpp \
ARMMCAsmInfo.cpp \
ARMMCCodeEmitter.cpp \
@@ -14,7 +15,10 @@ SRCS= ARMAsmBackend.cpp \
ARMMCTargetDesc.cpp \
ARMMachORelocationInfo.cpp \
ARMMachObjectWriter.cpp \
- ARMUnwindOpAsm.cpp
+ ARMTargetStreamer.cpp \
+ ARMUnwindOpAsm.cpp \
+ ARMWinCOFFObjectWriter.cpp \
+ ARMWinCOFFStreamer.cpp
CFLAGS+= -I${LLVM_SRCS}/${SRCDIR}/..
TGHDRS= ARMGenInstrInfo \
diff --git a/lib/clang/libllvmasmprinter/Makefile b/lib/clang/libllvmasmprinter/Makefile
index afb0ecf..4ff6f22 100644
--- a/lib/clang/libllvmasmprinter/Makefile
+++ b/lib/clang/libllvmasmprinter/Makefile
@@ -6,19 +6,26 @@ LIB= llvmasmprinter
SRCDIR= lib/CodeGen/AsmPrinter
SRCS= ARMException.cpp \
+ AddressPool.cpp \
AsmPrinter.cpp \
AsmPrinterDwarf.cpp \
AsmPrinterInlineAsm.cpp \
DIE.cpp \
DIEHash.cpp \
+ DbgValueHistoryCalculator.cpp \
DwarfAccelTable.cpp \
DwarfCFIException.cpp \
DwarfCompileUnit.cpp \
DwarfDebug.cpp \
- DwarfException.cpp \
+ DwarfExpression.cpp \
+ DwarfFile.cpp \
+ DwarfStringPool.cpp \
+ DwarfUnit.cpp \
+ EHStreamer.cpp \
ErlangGCPrinter.cpp \
OcamlGCPrinter.cpp \
- Win64Exception.cpp
+ Win64Exception.cpp \
+ WinCodeViewLineTables.cpp
TGHDRS= Intrinsics
diff --git a/lib/clang/libllvmcodegen/Makefile b/lib/clang/libllvmcodegen/Makefile
index e43f39d..d5d8e43 100644
--- a/lib/clang/libllvmcodegen/Makefile
+++ b/lib/clang/libllvmcodegen/Makefile
@@ -8,11 +8,13 @@ SRCDIR= lib/CodeGen
SRCS= AggressiveAntiDepBreaker.cpp \
AllocationOrder.cpp \
Analysis.cpp \
+ AtomicExpandPass.cpp \
BasicTargetTransformInfo.cpp \
BranchFolding.cpp \
CalcSpillWeights.cpp \
CallingConvLower.cpp \
CodeGen.cpp \
+ CodeGenPrepare.cpp \
CriticalAntiDepBreaker.cpp \
DFAPacketizer.cpp \
DeadMachineInstructionElim.cpp \
@@ -23,14 +25,16 @@ SRCS= AggressiveAntiDepBreaker.cpp \
ExecutionDepsFix.cpp \
ExpandISelPseudos.cpp \
ExpandPostRAPseudos.cpp \
+ ForwardControlFlowIntegrity.cpp \
GCMetadata.cpp \
GCMetadataPrinter.cpp \
GCStrategy.cpp \
+ GlobalMerge.cpp \
IfConversion.cpp \
InlineSpiller.cpp \
InterferenceCache.cpp \
IntrinsicLowering.cpp \
- JITCodeEmitter.cpp \
+ JumpInstrTables.cpp \
LLVMTargetMachine.cpp \
LatencyPriorityQueue.cpp \
LexicalScopes.cpp \
@@ -38,10 +42,10 @@ SRCS= AggressiveAntiDepBreaker.cpp \
LiveInterval.cpp \
LiveIntervalAnalysis.cpp \
LiveIntervalUnion.cpp \
+ LivePhysRegs.cpp \
LiveRangeCalc.cpp \
LiveRangeEdit.cpp \
LiveRegMatrix.cpp \
- LiveRegUnits.cpp \
LiveStackAnalysis.cpp \
LiveVariables.cpp \
LocalStackSlotAllocation.cpp \
@@ -50,8 +54,9 @@ SRCS= AggressiveAntiDepBreaker.cpp \
MachineBlockPlacement.cpp \
MachineBranchProbabilityInfo.cpp \
MachineCSE.cpp \
- MachineCodeEmitter.cpp \
+ MachineCombiner.cpp \
MachineCopyPropagation.cpp \
+ MachineDominanceFrontier.cpp \
MachineDominators.cpp \
MachineFunction.cpp \
MachineFunctionAnalysis.cpp \
@@ -65,6 +70,7 @@ SRCS= AggressiveAntiDepBreaker.cpp \
MachineModuleInfoImpls.cpp \
MachinePassRegistry.cpp \
MachinePostDominators.cpp \
+ MachineRegionInfo.cpp \
MachineRegisterInfo.cpp \
MachineSSAUpdater.cpp \
MachineScheduler.cpp \
@@ -98,12 +104,13 @@ SRCS= AggressiveAntiDepBreaker.cpp \
SjLjEHPrepare.cpp \
SlotIndexes.cpp \
SpillPlacement.cpp \
- Spiller.cpp \
SplitKit.cpp \
StackColoring.cpp \
+ StackMapLivenessAnalysis.cpp \
StackMaps.cpp \
StackProtector.cpp \
StackSlotColoring.cpp \
+ StatepointExampleGC.cpp \
TailDuplication.cpp \
TargetFrameLoweringImpl.cpp \
TargetInstrInfo.cpp \
diff --git a/lib/clang/libllvmcore/Makefile b/lib/clang/libllvmcore/Makefile
index 137b1c3..921d0be 100644
--- a/lib/clang/libllvmcore/Makefile
+++ b/lib/clang/libllvmcore/Makefile
@@ -9,36 +9,44 @@ SRCS= AsmWriter.cpp \
Attributes.cpp \
AutoUpgrade.cpp \
BasicBlock.cpp \
+ Comdat.cpp \
ConstantFold.cpp \
+ ConstantRange.cpp \
Constants.cpp \
Core.cpp \
DIBuilder.cpp \
DataLayout.cpp \
DebugInfo.cpp \
DebugLoc.cpp \
+ DiagnosticInfo.cpp \
+ DiagnosticPrinter.cpp \
Dominators.cpp \
Function.cpp \
GCOV.cpp \
GVMaterializer.cpp \
Globals.cpp \
IRBuilder.cpp \
+ IRPrintingPasses.cpp \
InlineAsm.cpp \
Instruction.cpp \
Instructions.cpp \
IntrinsicInst.cpp \
LLVMContext.cpp \
LLVMContextImpl.cpp \
- LeakDetector.cpp \
LegacyPassManager.cpp \
+ MDBuilder.cpp \
+ Mangler.cpp \
Metadata.cpp \
+ MetadataTracking.cpp \
Module.cpp \
Pass.cpp \
PassManager.cpp \
PassRegistry.cpp \
- PrintModulePass.cpp \
+ Statepoint.cpp \
Type.cpp \
TypeFinder.cpp \
Use.cpp \
+ UseListOrder.cpp \
User.cpp \
Value.cpp \
ValueSymbolTable.cpp \
diff --git a/lib/clang/libllvmdebuginfo/Makefile b/lib/clang/libllvmdebuginfo/Makefile
index c8039dc..3cee40e 100644
--- a/lib/clang/libllvmdebuginfo/Makefile
+++ b/lib/clang/libllvmdebuginfo/Makefile
@@ -1,6 +1,6 @@
# $FreeBSD$
-.include <bsd.own.mk>
+.include <src.opts.mk>
LIB= llvmdebuginfo
@@ -21,4 +21,9 @@ SRCS= DIContext.cpp \
DWARFTypeUnit.cpp \
DWARFUnit.cpp
+.if ${MK_CLANG_EXTRAS} != "no"
+SRCS+= DWARFAcceleratorTable.cpp \
+ SyntaxHighlighting.cpp
+.endif
+
.include "../clang.lib.mk"
diff --git a/lib/clang/libllvmexecutionengine/Makefile b/lib/clang/libllvmexecutionengine/Makefile
index 382dd88..5a7e6c3 100644
--- a/lib/clang/libllvmexecutionengine/Makefile
+++ b/lib/clang/libllvmexecutionengine/Makefile
@@ -7,7 +7,7 @@ LIB= llvmexecutionengine
SRCDIR= lib/ExecutionEngine
SRCS= ExecutionEngine.cpp \
ExecutionEngineBindings.cpp \
- RTDyldMemoryManager.cpp \
+ GDBRegistrationListener.cpp \
TargetSelect.cpp
.include "../clang.lib.mk"
diff --git a/lib/clang/libllvminstrumentation/Makefile b/lib/clang/libllvminstrumentation/Makefile
index faba349..963b638 100644
--- a/lib/clang/libllvminstrumentation/Makefile
+++ b/lib/clang/libllvminstrumentation/Makefile
@@ -8,10 +8,11 @@ SRCDIR= lib/Transforms/Instrumentation
SRCS= AddressSanitizer.cpp \
BoundsChecking.cpp \
DataFlowSanitizer.cpp \
- DebugIR.cpp \
GCOVProfiling.cpp \
MemorySanitizer.cpp \
Instrumentation.cpp \
+ InstrProfiling.cpp \
+ SanitizerCoverage.cpp \
ThreadSanitizer.cpp
TGHDRS= Intrinsics
diff --git a/lib/clang/libllvmipa/Makefile b/lib/clang/libllvmipa/Makefile
index c866ca0..3380cf3 100644
--- a/lib/clang/libllvmipa/Makefile
+++ b/lib/clang/libllvmipa/Makefile
@@ -8,7 +8,6 @@ SRCDIR= lib/Analysis/IPA
SRCS= CallGraph.cpp \
CallGraphSCCPass.cpp \
CallPrinter.cpp \
- FindUsedTypes.cpp \
GlobalsModRef.cpp \
InlineCost.cpp
diff --git a/lib/clang/libllvmjit/Makefile b/lib/clang/libllvmjit/Makefile
deleted file mode 100644
index a04eeb6..0000000
--- a/lib/clang/libllvmjit/Makefile
+++ /dev/null
@@ -1,12 +0,0 @@
-# $FreeBSD$
-
-.include <bsd.own.mk>
-
-LIB= llvmjit
-
-SRCDIR= lib/ExecutionEngine/JIT
-SRCS= JIT.cpp \
- JITEmitter.cpp \
- JITMemoryManager.cpp
-
-.include "../clang.lib.mk"
diff --git a/lib/clang/libllvmmc/Makefile b/lib/clang/libllvmmc/Makefile
index 84ba618..f4582c2 100644
--- a/lib/clang/libllvmmc/Makefile
+++ b/lib/clang/libllvmmc/Makefile
@@ -5,7 +5,8 @@
LIB= llvmmc
SRCDIR= lib/MC
-SRCS= ELFObjectWriter.cpp \
+SRCS= ConstantPools.cpp \
+ ELFObjectWriter.cpp \
MCAsmBackend.cpp \
MCAsmInfo.cpp \
MCAsmInfoCOFF.cpp \
@@ -13,7 +14,6 @@ SRCS= ELFObjectWriter.cpp \
MCAsmInfoELF.cpp \
MCAsmStreamer.cpp \
MCAssembler.cpp \
- MCAtom.cpp \
MCCodeEmitter.cpp \
MCCodeGenInfo.cpp \
MCContext.cpp \
@@ -22,25 +22,18 @@ SRCS= ELFObjectWriter.cpp \
MCELFObjectTargetWriter.cpp \
MCELFStreamer.cpp \
MCExpr.cpp \
- MCExternalSymbolizer.cpp \
- MCFunction.cpp \
MCInst.cpp \
MCInstPrinter.cpp \
MCInstrAnalysis.cpp \
MCLabel.cpp \
+ MCLinkerOptimizationHint.cpp \
MCMachOStreamer.cpp \
MCMachObjectTargetWriter.cpp \
- MCModule.cpp \
- MCModuleYAML.cpp \
MCNullStreamer.cpp \
- MCObjectDisassembler.cpp \
MCObjectFileInfo.cpp \
MCObjectStreamer.cpp \
- MCObjectSymbolizer.cpp \
MCObjectWriter.cpp \
- MCPureStreamer.cpp \
MCRegisterInfo.cpp \
- MCRelocationInfo.cpp \
MCSection.cpp \
MCSectionCOFF.cpp \
MCSectionELF.cpp \
@@ -49,15 +42,15 @@ SRCS= ELFObjectWriter.cpp \
MCSubtargetInfo.cpp \
MCSymbol.cpp \
MCSymbolizer.cpp \
+ MCTargetOptions.cpp \
MCValue.cpp \
MCWin64EH.cpp \
+ MCWinEH.cpp \
MachObjectWriter.cpp \
+ StringTableBuilder.cpp \
SubtargetFeature.cpp \
WinCOFFObjectWriter.cpp \
- WinCOFFStreamer.cpp
-
-.if ${MK_CLANG_EXTRAS} != "no" || ${MK_LLDB} != "no"
-SRCS+= MCDisassembler.cpp
-.endif
+ WinCOFFStreamer.cpp \
+ YAML.cpp
.include "../clang.lib.mk"
diff --git a/lib/clang/libllvmmcdisassembler/Makefile b/lib/clang/libllvmmcdisassembler/Makefile
index cfcf919..2f8a940 100644
--- a/lib/clang/libllvmmcdisassembler/Makefile
+++ b/lib/clang/libllvmmcdisassembler/Makefile
@@ -5,6 +5,9 @@
LIB= llvmmcdisassembler
SRCDIR= lib/MC/MCDisassembler
-SRCS= Disassembler.cpp
+SRCS= Disassembler.cpp \
+ MCDisassembler.cpp \
+ MCExternalSymbolizer.cpp \
+ MCRelocationInfo.cpp
.include "../clang.lib.mk"
diff --git a/lib/clang/libllvmmipscodegen/Makefile b/lib/clang/libllvmmipscodegen/Makefile
index 9ba7099..4495f50 100644
--- a/lib/clang/libllvmmipscodegen/Makefile
+++ b/lib/clang/libllvmmipscodegen/Makefile
@@ -7,24 +7,26 @@ LIB= llvmmipscodegen
SRCDIR= lib/Target/Mips
SRCS= Mips16FrameLowering.cpp \
Mips16HardFloat.cpp \
+ Mips16HardFloatInfo.cpp \
Mips16ISelDAGToDAG.cpp \
Mips16ISelLowering.cpp \
Mips16InstrInfo.cpp \
Mips16RegisterInfo.cpp \
MipsAnalyzeImmediate.cpp \
MipsAsmPrinter.cpp \
- MipsCodeEmitter.cpp \
+ MipsCCState.cpp \
MipsConstantIslandPass.cpp \
MipsDelaySlotFiller.cpp \
+ MipsFastISel.cpp \
MipsFrameLowering.cpp \
MipsISelDAGToDAG.cpp \
MipsISelLowering.cpp \
MipsInstrInfo.cpp \
- MipsJITInfo.cpp \
MipsLongBranch.cpp \
MipsMCInstLower.cpp \
MipsMachineFunction.cpp \
MipsModuleISelDAGToDAG.cpp \
+ MipsOptimizePICCall.cpp \
MipsOs16.cpp \
MipsRegisterInfo.cpp \
MipsSEFrameLowering.cpp \
@@ -42,6 +44,7 @@ TGHDRS= Intrinsics \
MipsGenCallingConv \
MipsGenCodeEmitter \
MipsGenDAGISel \
+ MipsGenFastISel \
MipsGenInstrInfo \
MipsGenMCPseudoLowering \
MipsGenRegisterInfo \
diff --git a/lib/clang/libllvmmipsdesc/Makefile b/lib/clang/libllvmmipsdesc/Makefile
index 07cbbfa..f22ff80 100644
--- a/lib/clang/libllvmmipsdesc/Makefile
+++ b/lib/clang/libllvmmipsdesc/Makefile
@@ -5,12 +5,17 @@
LIB= llvmmipsdesc
SRCDIR= lib/Target/Mips/MCTargetDesc
-SRCS= MipsAsmBackend.cpp \
+SRCS= MipsABIFlagsSection.cpp \
+ MipsABIInfo.cpp \
+ MipsAsmBackend.cpp \
MipsELFObjectWriter.cpp \
+ MipsELFStreamer.cpp \
MipsMCAsmInfo.cpp \
MipsMCCodeEmitter.cpp \
+ MipsMCExpr.cpp \
MipsMCTargetDesc.cpp \
- MipsReginfo.cpp \
+ MipsNaClELFStreamer.cpp \
+ MipsOptionRecord.cpp \
MipsTargetStreamer.cpp
CFLAGS+= -I${LLVM_SRCS}/${SRCDIR}/..
diff --git a/lib/clang/libllvmobjcarcopts/Makefile b/lib/clang/libllvmobjcarcopts/Makefile
index 5c47aa8..ee3ca83 100644
--- a/lib/clang/libllvmobjcarcopts/Makefile
+++ b/lib/clang/libllvmobjcarcopts/Makefile
@@ -13,7 +13,8 @@ SRCS= ObjCARC.cpp \
ObjCARCUtil.cpp \
ObjCARCContract.cpp \
DependencyAnalysis.cpp \
- ProvenanceAnalysis.cpp
+ ProvenanceAnalysis.cpp \
+ ProvenanceAnalysisEvaluator.cpp
TGHDRS= Intrinsics
diff --git a/lib/clang/libllvmobject/Makefile b/lib/clang/libllvmobject/Makefile
index 7e48093..804fff8 100644
--- a/lib/clang/libllvmobject/Makefile
+++ b/lib/clang/libllvmobject/Makefile
@@ -13,10 +13,12 @@ SRCS= Archive.cpp \
ELFObjectFile.cpp \
ELFYAML.cpp \
Error.cpp \
+ IRObjectFile.cpp \
MachOObjectFile.cpp \
MachOUniversal.cpp \
Object.cpp \
ObjectFile.cpp \
- YAML.cpp
+ RecordStreamer.cpp \
+ SymbolicFile.cpp
.include "../clang.lib.mk"
diff --git a/lib/clang/libllvmpowerpccodegen/Makefile b/lib/clang/libllvmpowerpccodegen/Makefile
index 9fd268b..211bc22 100644
--- a/lib/clang/libllvmpowerpccodegen/Makefile
+++ b/lib/clang/libllvmpowerpccodegen/Makefile
@@ -8,14 +8,12 @@ SRCDIR= lib/Target/PowerPC
SRCS= PPCAsmPrinter.cpp \
PPCBranchSelector.cpp \
PPCCTRLoops.cpp \
- PPCCodeEmitter.cpp \
- PPCFastISel.cpp \
+ PPCFastISel.cpp \
PPCFrameLowering.cpp \
PPCHazardRecognizers.cpp \
PPCISelDAGToDAG.cpp \
PPCISelLowering.cpp \
PPCInstrInfo.cpp \
- PPCJITInfo.cpp \
PPCMCInstLower.cpp \
PPCMachineFunctionInfo.cpp \
PPCRegisterInfo.cpp \
diff --git a/lib/clang/libllvmpowerpcdisassembler/Makefile b/lib/clang/libllvmpowerpcdisassembler/Makefile
new file mode 100644
index 0000000..58735e4
--- /dev/null
+++ b/lib/clang/libllvmpowerpcdisassembler/Makefile
@@ -0,0 +1,16 @@
+# $FreeBSD$
+
+.include <bsd.own.mk>
+
+LIB= llvmpowerpcdisassembler
+
+SRCDIR= lib/Target/PowerPC/Disassembler
+INCDIR= lib/Target/PowerPC
+SRCS= PPCDisassembler.cpp
+
+TGHDRS= PPCGenDisassemblerTables \
+ PPCGenInstrInfo \
+ PPCGenRegisterInfo \
+ PPCGenSubtargetInfo
+
+.include "../clang.lib.mk"
diff --git a/lib/clang/libllvmpowerpcdisassembler/Makefile.depend b/lib/clang/libllvmpowerpcdisassembler/Makefile.depend
new file mode 100644
index 0000000..bf2f722
--- /dev/null
+++ b/lib/clang/libllvmpowerpcdisassembler/Makefile.depend
@@ -0,0 +1,23 @@
+# Autogenerated - do NOT edit!
+
+DEP_RELDIR := ${_PARSEDIR:S,${SRCTOP}/,,}
+
+DIRDEPS = \
+ include \
+ include/xlocale \
+ usr.bin/clang/tblgen.host \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+PPCDisassembler.o: PPCGenDisassemblerTables.inc.h
+PPCDisassembler.o: PPCGenInstrInfo.inc.h
+PPCDisassembler.o: PPCGenRegisterInfo.inc.h
+PPCDisassembler.o: PPCGenSubtargetInfo.inc.h
+PPCDisassembler.po: PPCGenDisassemblerTables.inc.h
+PPCDisassembler.po: PPCGenInstrInfo.inc.h
+PPCDisassembler.po: PPCGenRegisterInfo.inc.h
+PPCDisassembler.po: PPCGenSubtargetInfo.inc.h
+.endif
diff --git a/lib/clang/libllvmprofiledata/Makefile b/lib/clang/libllvmprofiledata/Makefile
new file mode 100644
index 0000000..332bf1c
--- /dev/null
+++ b/lib/clang/libllvmprofiledata/Makefile
@@ -0,0 +1,18 @@
+# $FreeBSD$
+
+.include <bsd.own.mk>
+
+LIB= llvmprofiledata
+
+SRCDIR= lib/ProfileData
+SRCS= CoverageMapping.cpp \
+ CoverageMappingReader.cpp \
+ CoverageMappingWriter.cpp \
+ InstrProf.cpp \
+ InstrProfReader.cpp \
+ InstrProfWriter.cpp \
+ SampleProf.cpp \
+ SampleProfReader.cpp \
+ SampleProfWriter.cpp
+
+.include "../clang.lib.mk"
diff --git a/lib/libmandoc/Makefile.depend b/lib/clang/libllvmprofiledata/Makefile.depend
index 639d45d..639d45d 100644
--- a/lib/libmandoc/Makefile.depend
+++ b/lib/clang/libllvmprofiledata/Makefile.depend
diff --git a/lib/clang/libllvmruntimedyld/Makefile b/lib/clang/libllvmruntimedyld/Makefile
index 02ca4bd..75eb843 100644
--- a/lib/clang/libllvmruntimedyld/Makefile
+++ b/lib/clang/libllvmruntimedyld/Makefile
@@ -5,8 +5,9 @@
LIB= llvmruntimedyld
SRCDIR= lib/ExecutionEngine/RuntimeDyld
-SRCS= GDBRegistrar.cpp \
+SRCS= RTDyldMemoryManager.cpp \
RuntimeDyld.cpp \
+ RuntimeDyldChecker.cpp \
RuntimeDyldELF.cpp \
RuntimeDyldMachO.cpp
diff --git a/lib/clang/libllvmscalaropts/Makefile b/lib/clang/libllvmscalaropts/Makefile
index 8da4bf0..bb8dc96 100644
--- a/lib/clang/libllvmscalaropts/Makefile
+++ b/lib/clang/libllvmscalaropts/Makefile
@@ -6,7 +6,8 @@ LIB= llvmscalaropts
SRCDIR= lib/Transforms/Scalar
SRCS= ADCE.cpp \
- CodeGenPrepare.cpp \
+ AlignmentFromAssumptions.cpp \
+ ConstantHoisting.cpp \
ConstantProp.cpp \
CorrelatedValuePropagation.cpp \
DCE.cpp \
@@ -14,10 +15,10 @@ SRCS= ADCE.cpp \
EarlyCSE.cpp \
FlattenCFGPass.cpp \
GVN.cpp \
- GlobalMerge.cpp \
IndVarSimplify.cpp \
JumpThreading.cpp \
LICM.cpp \
+ LoadCombine.cpp \
LoopDeletion.cpp \
LoopIdiomRecognize.cpp \
LoopRerollPass.cpp \
@@ -27,6 +28,7 @@ SRCS= ADCE.cpp \
LoopUnswitch.cpp \
LowerAtomic.cpp \
MemCpyOptimizer.cpp \
+ MergedLoadStoreMotion.cpp \
PartiallyInlineLibCalls.cpp \
Reassociate.cpp \
Reg2Mem.cpp \
@@ -34,6 +36,8 @@ SRCS= ADCE.cpp \
SROA.cpp \
SampleProfile.cpp \
ScalarReplAggregates.cpp \
+ Scalarizer.cpp \
+ SeparateConstOffsetFromGEP.cpp \
SimplifyCFGPass.cpp \
Sink.cpp \
StructurizeCFG.cpp \
diff --git a/lib/clang/libllvmselectiondag/Makefile b/lib/clang/libllvmselectiondag/Makefile
index 7543102..b73a1c5 100644
--- a/lib/clang/libllvmselectiondag/Makefile
+++ b/lib/clang/libllvmselectiondag/Makefile
@@ -26,6 +26,7 @@ SRCS= DAGCombiner.cpp \
SelectionDAGDumper.cpp \
SelectionDAGISel.cpp \
SelectionDAGPrinter.cpp \
+ StatepointLowering.cpp \
TargetLowering.cpp \
TargetSelectionDAGInfo.cpp
diff --git a/lib/clang/libllvmsparccodegen/Makefile b/lib/clang/libllvmsparccodegen/Makefile
index 36cf0a6..29bbae1 100644
--- a/lib/clang/libllvmsparccodegen/Makefile
+++ b/lib/clang/libllvmsparccodegen/Makefile
@@ -7,12 +7,10 @@ LIB= llvmsparccodegen
SRCDIR= lib/Target/Sparc
SRCS= DelaySlotFiller.cpp \
SparcAsmPrinter.cpp \
- SparcCodeEmitter.cpp \
SparcFrameLowering.cpp \
SparcISelDAGToDAG.cpp \
SparcISelLowering.cpp \
SparcInstrInfo.cpp \
- SparcJITInfo.cpp \
SparcMCInstLower.cpp \
SparcMachineFunctionInfo.cpp \
SparcRegisterInfo.cpp \
diff --git a/lib/clang/libllvmsupport/Makefile b/lib/clang/libllvmsupport/Makefile
index b7cfe6a..f325b15 100644
--- a/lib/clang/libllvmsupport/Makefile
+++ b/lib/clang/libllvmsupport/Makefile
@@ -8,12 +8,14 @@ SRCDIR= lib/Support
SRCS= APFloat.cpp \
APInt.cpp \
APSInt.cpp \
+ ARMBuildAttrs.cpp \
+ ARMWinEH.cpp \
Allocator.cpp \
Atomic.cpp \
BlockFrequency.cpp \
BranchProbability.cpp \
CommandLine.cpp \
- ConstantRange.cpp \
+ Compression.cpp \
ConvertUTF.c \
ConvertUTFWrapper.cpp \
CrashRecoveryContext.cpp \
@@ -31,39 +33,44 @@ SRCS= APFloat.cpp \
GraphWriter.cpp \
Hashing.cpp \
Host.cpp \
- IncludeFile.cpp \
IntEqClasses.cpp \
IntervalMap.cpp \
IntrusiveRefCntPtr.cpp \
IsInf.cpp \
IsNAN.cpp \
+ LEB128.cpp \
+ LineIterator.cpp \
Locale.cpp \
LockFileManager.cpp \
MD5.cpp \
ManagedStatic.cpp \
+ MathExtras.cpp \
Memory.cpp \
MemoryBuffer.cpp \
MemoryObject.cpp \
Mutex.cpp \
+ Options.cpp \
Path.cpp \
PluginLoader.cpp \
PrettyStackTrace.cpp \
Process.cpp \
Program.cpp \
RWMutex.cpp \
+ RandomNumberGenerator.cpp \
Regex.cpp \
+ ScaledNumber.cpp \
SearchForAddressOfSpecialSymbol.cpp \
Signals.cpp \
SmallPtrSet.cpp \
SmallVector.cpp \
SourceMgr.cpp \
+ SpecialCaseList.cpp \
Statistic.cpp \
- StreamableMemoryObject.cpp \
+ StreamingMemoryObject.cpp \
StringExtras.cpp \
StringMap.cpp \
StringPool.cpp \
StringRef.cpp \
- StringRefMemoryObject.cpp \
TargetRegistry.cpp \
ThreadLocal.cpp \
Threading.cpp \
@@ -84,16 +91,10 @@ SRCS= APFloat.cpp \
regerror.c \
regexec.c \
regfree.c \
- regstrlcpy.c \
- system_error.cpp
-
-.if ${MK_CLANG_EXTRAS} != "no" || ${MK_LLDB} != "no"
-SRCS+= Disassembler.cpp
-.endif
+ regstrlcpy.c
.if ${MK_CLANG_EXTRAS} != "no"
-SRCS+= Compression.cpp \
- DataStream.cpp \
+SRCS+= DataStream.cpp \
FileUtilities.cpp \
SystemUtils.cpp
.endif
diff --git a/lib/clang/libllvmtablegen/Makefile b/lib/clang/libllvmtablegen/Makefile
index 9a764b3..fb0c5b8 100644
--- a/lib/clang/libllvmtablegen/Makefile
+++ b/lib/clang/libllvmtablegen/Makefile
@@ -8,6 +8,7 @@ SRCDIR= lib/TableGen
SRCS= Error.cpp \
Main.cpp \
Record.cpp \
+ SetTheory.cpp \
StringMatcher.cpp \
TableGenBackend.cpp \
TGLexer.cpp \
diff --git a/lib/clang/libllvmtarget/Makefile b/lib/clang/libllvmtarget/Makefile
index b85fbec..3f9619b 100644
--- a/lib/clang/libllvmtarget/Makefile
+++ b/lib/clang/libllvmtarget/Makefile
@@ -5,10 +5,8 @@
LIB= llvmtarget
SRCDIR= lib/Target
-SRCS= Mangler.cpp \
- Target.cpp \
+SRCS= Target.cpp \
TargetIntrinsicInfo.cpp \
- TargetJITInfo.cpp \
TargetLibraryInfo.cpp \
TargetLoweringObjectFile.cpp \
TargetMachine.cpp \
diff --git a/lib/clang/libllvmtransformutils/Makefile b/lib/clang/libllvmtransformutils/Makefile
index cfad040..a3cf212 100644
--- a/lib/clang/libllvmtransformutils/Makefile
+++ b/lib/clang/libllvmtransformutils/Makefile
@@ -5,7 +5,9 @@
LIB= llvmtransformutils
SRCDIR= lib/Transforms/Utils
-SRCS= BasicBlockUtils.cpp \
+SRCS= ASanStackFrameLayout.cpp \
+ AddDiscriminators.cpp \
+ BasicBlockUtils.cpp \
BreakCriticalEdges.cpp \
BuildLibCalls.cpp \
BypassSlowDivision.cpp \
@@ -13,6 +15,7 @@ SRCS= BasicBlockUtils.cpp \
CloneModule.cpp \
CmpInstAnalysis.cpp \
CodeExtractor.cpp \
+ CtorUtils.cpp \
DemoteRegToStack.cpp \
FlattenCFG.cpp \
GlobalStatus.cpp \
@@ -36,7 +39,7 @@ SRCS= BasicBlockUtils.cpp \
SimplifyIndVar.cpp \
SimplifyInstructions.cpp \
SimplifyLibCalls.cpp \
- SpecialCaseList.cpp \
+ SymbolRewriter.cpp \
UnifyFunctionExitNodes.cpp \
ValueMapper.cpp
diff --git a/lib/clang/libllvmx86asmparser/Makefile b/lib/clang/libllvmx86asmparser/Makefile
index 0d32f9c..f972065 100644
--- a/lib/clang/libllvmx86asmparser/Makefile
+++ b/lib/clang/libllvmx86asmparser/Makefile
@@ -6,7 +6,8 @@ LIB= llvmx86asmparser
SRCDIR= lib/Target/X86/AsmParser
INCDIR= lib/Target/X86
-SRCS= X86AsmParser.cpp
+SRCS= X86AsmInstrumentation.cpp \
+ X86AsmParser.cpp
TGHDRS= X86GenAsmMatcher \
X86GenInstrInfo \
diff --git a/lib/clang/libllvmx86codegen/Makefile b/lib/clang/libllvmx86codegen/Makefile
index ed7ab8e..b030b1f 100644
--- a/lib/clang/libllvmx86codegen/Makefile
+++ b/lib/clang/libllvmx86codegen/Makefile
@@ -6,8 +6,7 @@ LIB= llvmx86codegen
SRCDIR= lib/Target/X86
SRCS= X86AsmPrinter.cpp \
- X86COFFMachineModuleInfo.cpp \
- X86CodeEmitter.cpp \
+ X86CallFrameOptimization.cpp \
X86FastISel.cpp \
X86FixupLEAs.cpp \
X86FloatingPoint.cpp \
@@ -15,7 +14,6 @@ SRCS= X86AsmPrinter.cpp \
X86ISelDAGToDAG.cpp \
X86ISelLowering.cpp \
X86InstrInfo.cpp \
- X86JITInfo.cpp \
X86MCInstLower.cpp \
X86MachineFunctionInfo.cpp \
X86PadShortFunction.cpp \
diff --git a/lib/clang/libllvmx86desc/Makefile b/lib/clang/libllvmx86desc/Makefile
index 6401649..1ca2839 100644
--- a/lib/clang/libllvmx86desc/Makefile
+++ b/lib/clang/libllvmx86desc/Makefile
@@ -13,7 +13,8 @@ SRCS= X86AsmBackend.cpp \
X86MCTargetDesc.cpp \
X86MachORelocationInfo.cpp \
X86MachObjectWriter.cpp \
- X86WinCOFFObjectWriter.cpp
+ X86WinCOFFObjectWriter.cpp \
+ X86WinCOFFStreamer.cpp
CFLAGS+= -I${LLVM_SRCS}/${SRCDIR}/..
TGHDRS= X86GenInstrInfo \
diff --git a/lib/clang/libllvmx86disassembler/Makefile b/lib/clang/libllvmx86disassembler/Makefile
index e5489a0..23ec976 100644
--- a/lib/clang/libllvmx86disassembler/Makefile
+++ b/lib/clang/libllvmx86disassembler/Makefile
@@ -9,11 +9,12 @@ INCDIR= lib/Target/X86
SRCS= X86Disassembler.cpp
.if ${MK_CLANG_EXTRAS} != "no" || ${MK_LLDB} != "no"
-SRCS+= X86DisassemblerDecoder.c
+SRCS+= X86DisassemblerDecoder.cpp
.endif
TGHDRS= X86GenDisassemblerTables \
X86GenInstrInfo \
- X86GenRegisterInfo
+ X86GenRegisterInfo \
+ X86GenSubtargetInfo
.include "../clang.lib.mk"
diff --git a/lib/csu/Makefile b/lib/csu/Makefile
index 320a5a4..5f1cddc 100644
--- a/lib/csu/Makefile
+++ b/lib/csu/Makefile
@@ -1,8 +1,7 @@
# $FreeBSD$
-ARCH= ${MACHINE_ARCH:S/i386/i386-elf/}
-.if exists(${.CURDIR}/${ARCH})
-SUBDIR+= ${ARCH}
+.if exists(${.CURDIR}/${MACHINE_ARCH})
+SUBDIR+= ${MACHINE_ARCH}
.else
SUBDIR+= ${MACHINE_CPUARCH}
.endif
diff --git a/lib/csu/aarch64/Makefile b/lib/csu/aarch64/Makefile
new file mode 100644
index 0000000..bf4c7b1
--- /dev/null
+++ b/lib/csu/aarch64/Makefile
@@ -0,0 +1,44 @@
+# $FreeBSD$
+
+.PATH: ${.CURDIR}/../common
+
+SRCS= crt1.c crti.S crtn.S
+OBJS= ${SRCS:N*.h:R:S/$/.o/g}
+OBJS+= Scrt1.o gcrt1.o
+CFLAGS+= -I${.CURDIR}/../common \
+ -I${.CURDIR}/../../libc/include
+
+all: ${OBJS}
+
+CLEANFILES= ${OBJS}
+CLEANFILES+= crt1.s gcrt1.s Scrt1.s
+
+# See the comment in lib/csu/common/crtbrand.c for the reason crt1.c is not
+# directly compiled to .o files.
+
+crt1.s: crt1.c
+ ${CC} ${CFLAGS} -S -o ${.TARGET} ${.CURDIR}/crt1.c
+ sed ${SED_FIX_NOTE} ${.TARGET}
+
+crt1.o: crt1.s
+ ${CC} ${ACFLAGS} -c -o ${.TARGET} crt1.s
+
+gcrt1.s: crt1.c
+ ${CC} ${CFLAGS} -DGCRT -S -o ${.TARGET} ${.CURDIR}/crt1.c
+ sed ${SED_FIX_NOTE} ${.TARGET}
+
+gcrt1.o: gcrt1.s
+ ${CC} ${ACFLAGS} -c -o ${.TARGET} gcrt1.s
+
+Scrt1.s: crt1.c
+ ${CC} ${CFLAGS} -fPIC -DPIC -S -o ${.TARGET} ${.CURDIR}/crt1.c
+ sed ${SED_FIX_NOTE} ${.TARGET}
+
+Scrt1.o: Scrt1.s
+ ${CC} ${ACFLAGS} -c -o ${.TARGET} Scrt1.s
+
+realinstall:
+ ${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
+ ${OBJS} ${DESTDIR}${LIBDIR}
+
+.include <bsd.lib.mk>
diff --git a/lib/libc/powerpc/gen/getcontextx.c b/lib/csu/aarch64/crt1.c
index 54f8513..6518e8d 100644
--- a/lib/libc/powerpc/gen/getcontextx.c
+++ b/lib/csu/aarch64/crt1.c
@@ -1,11 +1,16 @@
-/*
- * Copyright (c) 2011 Konstantin Belousov <kib@FreeBSD.org>
+/* LINTLIBRARY */
+/*-
+ * Copyright 1996-1998 John D. Polstra.
+ * Copyright 2014 Andrew Turner.
+ * Copyright 2014-2015 The FreeBSD Foundation.
* All rights reserved.
*
+ * Portions of this software were developed by Andrew Turner
+ * under sponsorship from the FreeBSD Foundation.
+ *
* 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
@@ -27,50 +32,58 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
-#include <sys/types.h>
-#include <sys/ucontext.h>
-#include <errno.h>
+#ifndef lint
+#ifndef __GNUC__
+#error "GCC is needed to compile this file"
+#endif
+#endif /* lint */
+
#include <stdlib.h>
-int
-__getcontextx_size(void)
-{
+#include "libc_private.h"
+#include "crtbrand.c"
+#include "ignore_init.c"
- return (sizeof(ucontext_t));
-}
+#ifdef GCRT
+extern void _mcleanup(void);
+extern void monstartup(void *, void *);
+extern int eprol;
+extern int etext;
+#endif
-int
-__fillcontextx2(char *ctx)
-{
+void __start(int, char **, char **, void (*)(void));
+
+/* The entry function. */
+__asm(" .text \n"
+" .align 0 \n"
+" .globl _start \n"
+" _start: \n"
+" mov x3, x2 \n" /* cleanup */
+" ldr x0, [sp] \n" /* Load argc */
+" add x1, sp, #8 \n" /* load argv */
+" add x2, x1, x0, lsl #3 \n" /* env is after argv */
+" add x2, x2, #8 \n" /* argv is null terminated */
+" b __start ");
- return (0);
-}
-int
-__fillcontextx(char *ctx)
+/* The entry function. */
+void
+__start(int argc, char *argv[], char *env[], void (*cleanup)(void))
{
- ucontext_t *ucp;
- ucp = (ucontext_t *)ctx;
- return (getcontext(ucp));
-}
+ handle_argv(argc, argv, env);
-__weak_reference(__getcontextx, getcontextx);
+ if (&_DYNAMIC != NULL)
+ atexit(cleanup);
+ else
+ _init_tls();
-ucontext_t *
-__getcontextx(void)
-{
- char *ctx;
- int error;
+#ifdef GCRT
+ atexit(_mcleanup);
+ monstartup(&eprol, &etext);
+__asm__("eprol:");
+#endif
- ctx = malloc(__getcontextx_size());
- if (ctx == NULL)
- return (NULL);
- if (__fillcontextx(ctx) == -1) {
- error = errno;
- free(ctx);
- errno = error;
- return (NULL);
- }
- return ((ucontext_t *)ctx);
+ handle_static_init(argc, argv, env);
+ exit(main(argc, argv, env));
}
diff --git a/lib/csu/aarch64/crti.S b/lib/csu/aarch64/crti.S
new file mode 100644
index 0000000..13e3b74
--- /dev/null
+++ b/lib/csu/aarch64/crti.S
@@ -0,0 +1,48 @@
+/*-
+ * Copyright 2001 David E. O'Brien
+ * Copyright 2014 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Andrew Turner
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * 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 ``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 <machine/asm.h>
+__FBSDID("$FreeBSD$");
+
+ .section .init,"ax",@progbits
+ .align 4
+ .globl _init
+ .type _init,@function
+_init:
+ sub sp, sp, #16
+ str lr, [sp]
+
+ .section .fini,"ax",@progbits
+ .align 4
+ .globl _fini
+ .type _fini,@function
+_fini:
+ sub sp, sp, #16
+ str lr, [sp]
+
diff --git a/lib/csu/aarch64/crtn.S b/lib/csu/aarch64/crtn.S
new file mode 100644
index 0000000..ebb59b7
--- /dev/null
+++ b/lib/csu/aarch64/crtn.S
@@ -0,0 +1,44 @@
+/*-
+ * Copyright 2001 David E. O'Brien
+ * Copyright 2014 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Andrew Turner
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * 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 ``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 <machine/asm.h>
+__FBSDID("$FreeBSD$");
+
+ .section .init,"ax",@progbits
+ ldr lr, [sp]
+ add sp, sp, #16
+ ret
+
+
+ .section .fini,"ax",@progbits
+ ldr lr, [sp]
+ add sp, sp, #16
+ ret
+
+ .section .note.GNU-stack,"",%progbits
diff --git a/lib/csu/i386-elf/Makefile b/lib/csu/i386/Makefile
index 57f4f05..d5ca479 100644
--- a/lib/csu/i386-elf/Makefile
+++ b/lib/csu/i386/Makefile
@@ -35,7 +35,7 @@ crt1_c.o: crt1_c.s
crt1.o: crt1_c.o crt1_s.o
${LD} ${_LDFLAGS} -o crt1.o -r crt1_s.o crt1_c.o
- objcopy --localize-symbol _start1 crt1.o
+ ${OBJCOPY} --localize-symbol _start1 crt1.o
Scrt1_c.s: crt1_c.c
${CC} ${CFLAGS} -fPIC -DPIC -S -o ${.TARGET} ${.CURDIR}/crt1_c.c
@@ -46,7 +46,7 @@ Scrt1_c.o: Scrt1_c.s
Scrt1.o: Scrt1_c.o crt1_s.o
${LD} ${_LDFLAGS} -o Scrt1.o -r crt1_s.o Scrt1_c.o
- objcopy --localize-symbol _start1 Scrt1.o
+ ${OBJCOPY} --localize-symbol _start1 Scrt1.o
realinstall:
${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
diff --git a/lib/csu/i386-elf/Makefile.depend b/lib/csu/i386/Makefile.depend
index 7d982eb..7d982eb 100644
--- a/lib/csu/i386-elf/Makefile.depend
+++ b/lib/csu/i386/Makefile.depend
diff --git a/lib/csu/i386-elf/crt1_c.c b/lib/csu/i386/crt1_c.c
index 65de04c..65de04c 100644
--- a/lib/csu/i386-elf/crt1_c.c
+++ b/lib/csu/i386/crt1_c.c
diff --git a/lib/csu/i386-elf/crt1_s.S b/lib/csu/i386/crt1_s.S
index 17ac0e3..17ac0e3 100644
--- a/lib/csu/i386-elf/crt1_s.S
+++ b/lib/csu/i386/crt1_s.S
diff --git a/lib/csu/i386-elf/crti.S b/lib/csu/i386/crti.S
index 77e4e77..77e4e77 100644
--- a/lib/csu/i386-elf/crti.S
+++ b/lib/csu/i386/crti.S
diff --git a/lib/csu/i386-elf/crtn.S b/lib/csu/i386/crtn.S
index 0264e22..0264e22 100644
--- a/lib/csu/i386-elf/crtn.S
+++ b/lib/csu/i386/crtn.S
diff --git a/lib/csu/powerpc64/Makefile b/lib/csu/powerpc64/Makefile
index 123391e..1c93355 100644
--- a/lib/csu/powerpc64/Makefile
+++ b/lib/csu/powerpc64/Makefile
@@ -9,6 +9,13 @@ CFLAGS+= -I${.CURDIR}/../common \
-I${.CURDIR}/../../libc/include \
-mlongcall
+# XXX: See the log for r232932 as to why the above -mlongcall is needed. Since
+# clang doesn't support -mlongcall, and testing shows a clang linked with a
+# clang-built csu segfaults, this must currently be compiled with gcc. Once
+# clang supports -mlongcall, or we get a fixed ld, this can be revisited.
+CC:= gcc
+COMPILER_TYPE:= gcc
+
all: ${OBJS}
CLEANFILES= ${OBJS}
diff --git a/lib/libarchive/Makefile b/lib/libarchive/Makefile
index b7e9d7f..9dfad77 100644
--- a/lib/libarchive/Makefile
+++ b/lib/libarchive/Makefile
@@ -4,19 +4,9 @@
LIBARCHIVEDIR= ${.CURDIR}/../../contrib/libarchive
LIB= archive
-DPADD= ${LIBZ}
-LDADD= -lz
-DPADD+= ${LIBBZ2}
-LDADD+= -lbz2
-CFLAGS+= -DHAVE_BZLIB_H=1
-
-DPADD+= ${LIBLZMA}
-LDADD+= -llzma
-CFLAGS+= -DHAVE_LIBLZMA=1 -DHAVE_LZMA_H=1
-
-DPADD+= ${LIBBSDXML}
-LDADD+= -lbsdxml
+LIBADD= z bz2 lzma bsdxml
+CFLAGS+= -DHAVE_BZLIB_H=1 -DHAVE_LIBLZMA=1 -DHAVE_LZMA_H=1
# FreeBSD SHLIB_MAJOR value is managed as part of the FreeBSD system.
# It has no real relation to the libarchive version number.
@@ -27,17 +17,15 @@ CFLAGS+= -I${.OBJDIR}
.if ${MK_OPENSSL} != "no"
CFLAGS+= -DWITH_OPENSSL
-DPADD+= ${LIBCRYPTO}
-LDADD+= -lcrypto
+LIBADD+= crypto
.else
-DPADD+= ${LIBMD}
-LDADD+= -lmd
+LIBADD+= md
.endif
.if ${MK_ICONV} != "no"
# TODO: This can be changed back to CFLAGS once iconv works correctly
# with statically linked binaries.
-SHARED_CFLAGS+= -DHAVE_ICONV=1 -DHAVE_ICONV_H=1 -DICONV_CONST=const
+SHARED_CFLAGS+= -DHAVE_ICONV=1 -DHAVE_ICONV_H=1 -DICONV_CONST=
.endif
.if ${MACHINE_ARCH:Marm*} != "" || ${MACHINE_ARCH:Mmips*} != "" || \
diff --git a/lib/libarchive/config_freebsd.h b/lib/libarchive/config_freebsd.h
index 0df3f91..fbf429f 100644
--- a/lib/libarchive/config_freebsd.h
+++ b/lib/libarchive/config_freebsd.h
@@ -25,6 +25,8 @@
* $FreeBSD$
*/
+#include <osreldate.h>
+
/* FreeBSD 5.0 and later have ACL and extattr support. */
#if __FreeBSD__ > 4
#define HAVE_ACL_CREATE_ENTRY 1
@@ -220,6 +222,11 @@
#define HAVE_ZLIB_H 1
#define TIME_WITH_SYS_TIME 1
+#if __FreeBSD_version >= 1100056
+#define HAVE_FUTIMENS 1
+#define HAVE_UTIMENSAT 1
+#endif
+
/* FreeBSD 4 and earlier lack intmax_t/uintmax_t */
#if __FreeBSD__ < 5
#define intmax_t int64_t
diff --git a/lib/libarchive/test/Makefile b/lib/libarchive/test/Makefile
index 16a485a..80d6dd4 100644
--- a/lib/libarchive/test/Makefile
+++ b/lib/libarchive/test/Makefile
@@ -6,9 +6,8 @@ MAN=
PROG=libarchive_test
INTERNALPROG=yes # Don't install this; it's just for testing
-DPADD=${LIBBZ2} ${LIBZ} ${LIBMD} ${LIBCRYPTO} ${LIBBSDXML}
LDADD= -L ${.OBJDIR}/.. -larchive
-LDADD+= -lz -lbz2 -llzma -lmd -lcrypto -lbsdxml
+LIBADD= z bz2 lzma md crypto bsdxml
CFLAGS+= -g
CFLAGS+= -I${.CURDIR}/.. -I${.OBJDIR}
CFLAGS+= -I${LIBARCHIVEDIR}/libarchive -I${LIBARCHIVEDIR}/test_utils
diff --git a/lib/libblocksruntime/Makefile b/lib/libblocksruntime/Makefile
index 01a78fe..f9539331 100644
--- a/lib/libblocksruntime/Makefile
+++ b/lib/libblocksruntime/Makefile
@@ -5,7 +5,7 @@ SHLIB_MAJOR=0
CFLAGS+=-I${.CURDIR}
WARNS?= 2
-.PATH: ${.CURDIR}/../../contrib/compiler-rt/BlocksRuntime
+.PATH: ${.CURDIR}/../../contrib/compiler-rt/lib/BlocksRuntime
INCS= Block.h Block_private.h
SRCS= data.c runtime.c
diff --git a/lib/libbluetooth/bluetooth.c b/lib/libbluetooth/bluetooth.c
index 23b7df0..bbcf007 100644
--- a/lib/libbluetooth/bluetooth.c
+++ b/lib/libbluetooth/bluetooth.c
@@ -30,7 +30,7 @@
* $Id: bluetooth.c,v 1.3 2003/05/20 23:04:30 max Exp $
* $FreeBSD$
*/
-
+#define L2CAP_SOCKET_CHECKED
#include <bluetooth.h>
#include <stdio.h>
#include <stdlib.h>
diff --git a/lib/libbluetooth/dev.c b/lib/libbluetooth/dev.c
index 1f9e745..a6295dd 100644
--- a/lib/libbluetooth/dev.c
+++ b/lib/libbluetooth/dev.c
@@ -30,6 +30,7 @@
* $FreeBSD$
*/
+#define L2CAP_SOCKET_CHECKED
#include <bluetooth.h>
#include <stdio.h>
#include <string.h>
diff --git a/lib/libbluetooth/hci.c b/lib/libbluetooth/hci.c
index 1ae6ff9..651c0dd 100644
--- a/lib/libbluetooth/hci.c
+++ b/lib/libbluetooth/hci.c
@@ -31,6 +31,7 @@
*/
#include <assert.h>
+#define L2CAP_SOCKET_CHECKED
#include <bluetooth.h>
#include <inttypes.h>
#include <stdio.h>
diff --git a/lib/libbsnmp/libbsnmp/Makefile b/lib/libbsnmp/libbsnmp/Makefile
index 0b9087d..ef6e35b 100644
--- a/lib/libbsnmp/libbsnmp/Makefile
+++ b/lib/libbsnmp/libbsnmp/Makefile
@@ -9,14 +9,14 @@ CONTRIB= ${.CURDIR}/../../../contrib/bsnmp/lib
LIB= bsnmp
SHLIB_MAJOR= 6
+LD_FATAL_WARNINGS= no
CFLAGS+= -I${CONTRIB} -DHAVE_ERR_H -DHAVE_GETADDRINFO -DHAVE_STRLCPY
CFLAGS+= -DHAVE_STDINT_H -DHAVE_INTTYPES_H -DQUADFMT='"llu"' -DQUADXFMT='"llx"'
.if ${MK_OPENSSL} != "no"
CFLAGS+= -DHAVE_LIBCRYPTO
-DPADD+= ${LIBCRYPTO}
-LDADD+= -lcrypto
+LIBADD= crypto
.endif
SRCS= asn1.c snmp.c snmpagent.c snmpclient.c snmpcrypto.c support.c
diff --git a/lib/libc++/Makefile b/lib/libc++/Makefile
index e55cf55..469ee47 100644
--- a/lib/libc++/Makefile
+++ b/lib/libc++/Makefile
@@ -62,8 +62,7 @@ CFLAGS+= -I${HDRDIR} -I${LIBCXXRTDIR} -nostdlib -DLIBCXXRT
CXXFLAGS+= -std=c++11
.endif
-DPADD= ${LIBCXXRT}
-LDADD= -lcxxrt
+LIBADD+= cxxrt
LDFLAGS+= --verbose
INCSGROUPS= STD EXP EXT
@@ -76,6 +75,7 @@ STD_HEADERS= __bit_reference\
__hash_table\
__locale\
__mutex_base\
+ __refstring\
__split_buffer\
__sso_allocator\
__std_stream\
@@ -177,8 +177,12 @@ STD+= ${LIBCXXRTDIR}/${hdr}
.endfor
STDDIR= ${CXXINCLUDEDIR}
-EXP_HEADERS= dynarray\
- optional
+EXP_HEADERS= __config\
+ dynarray\
+ optional\
+ string_view\
+ type_traits\
+ utility
.for hdr in ${EXP_HEADERS}
EXP+= ${HDRDIR}/experimental/${hdr}
@@ -204,4 +208,8 @@ afterinstall:
${.OBJDIR}/libstdc++.a
.endif
+# avoid cyclic dependency
+CFLAGS+= -I${LIBCXXRTDIR}
+GENDIRDEPS_FILTER= N*/libcxxrt
+
.include <bsd.lib.mk>
diff --git a/lib/libc++/Makefile.depend b/lib/libc++/Makefile.depend
index e391c40..83e9e6a 100644
--- a/lib/libc++/Makefile.depend
+++ b/lib/libc++/Makefile.depend
@@ -10,7 +10,6 @@ DIRDEPS = \
lib/${CSU_DIR} \
lib/libc \
lib/libcompiler_rt \
- lib/libcxxrt \
lib/msun \
diff --git a/lib/libc/Makefile b/lib/libc/Makefile
index 5653220..b6d3f9f 100644
--- a/lib/libc/Makefile
+++ b/lib/libc/Makefile
@@ -44,13 +44,11 @@ CFLAGS+=${CANCELPOINTS_CFLAGS}
#
# Link with static libcompiler_rt.a.
#
-DPADD+= ${LIBCOMPILER_RT}
LDFLAGS+= -nodefaultlibs
-LDADD+= -lcompiler_rt
+LIBADD+= compiler_rt
.if ${MK_SSP} != "no"
-DPADD+= ${LIBSSP_NONSHARED}
-LDADD+= -lssp_nonshared
+LIBADD+= ssp_nonshared
.endif
# Extras that live in either libc.a or libc_nonshared.a
@@ -81,7 +79,8 @@ NOASM=
.include "${LIBC_SRCTOP}/net/Makefile.inc"
.include "${LIBC_SRCTOP}/nls/Makefile.inc"
.include "${LIBC_SRCTOP}/posix1e/Makefile.inc"
-.if ${LIBC_ARCH} != "amd64" && \
+.if ${LIBC_ARCH} != "aarch64" && \
+ ${LIBC_ARCH} != "amd64" && \
${LIBC_ARCH} != "powerpc64" && \
${LIBC_ARCH} != "sparc64" && \
${MACHINE_ARCH:Mmipsn32*} == "" && \
@@ -151,14 +150,16 @@ KSRCS= bcmp.c ffs.c ffsl.c fls.c flsl.c mcount.c strcat.c strchr.c \
libkern: libkern.gen libkern.${LIBC_ARCH}
libkern.gen: ${KQSRCS} ${KSRCS}
- cp -fp ${LIBC_SRCTOP}/quad/quad.h ${.ALLSRC} ${DESTDIR}/sys/libkern
+ ${CP} ${LIBC_SRCTOP}/quad/quad.h ${.ALLSRC} ${DESTDIR}/sys/libkern
libkern.${LIBC_ARCH}:: ${KMSRCS}
.if defined(KMSRCS) && !empty(KMSRCS)
- cp -fp ${.ALLSRC} ${DESTDIR}/sys/libkern/${LIBC_ARCH}
+ ${CP} ${.ALLSRC} ${DESTDIR}/sys/libkern/${LIBC_ARCH}
.endif
-.include <bsd.arch.inc.mk>
+.if ${MK_TESTS} != "no"
+SUBDIR+= tests
+.endif
.include <bsd.lib.mk>
diff --git a/lib/libc/Makefile.amd64 b/lib/libc/Makefile.amd64
deleted file mode 100644
index dd0f5b0..0000000
--- a/lib/libc/Makefile.amd64
+++ /dev/null
@@ -1,6 +0,0 @@
-# $FreeBSD$
-
-.if ${MK_TESTS} != "no"
-SUBDIR+= tests
-.endif
-
diff --git a/lib/libc/Makefile.i386 b/lib/libc/Makefile.i386
deleted file mode 100644
index dd0f5b0..0000000
--- a/lib/libc/Makefile.i386
+++ /dev/null
@@ -1,6 +0,0 @@
-# $FreeBSD$
-
-.if ${MK_TESTS} != "no"
-SUBDIR+= tests
-.endif
-
diff --git a/lib/libc/aarch64/Makefile.inc b/lib/libc/aarch64/Makefile.inc
new file mode 100644
index 0000000..5f17200
--- /dev/null
+++ b/lib/libc/aarch64/Makefile.inc
@@ -0,0 +1,9 @@
+# $FreeBSD$
+#
+# Machine dependent definitions for the arm 64-bit architecture.
+#
+
+# Long double is quad precision
+GDTOASRCS+=strtorQ.c
+MDSRCS+=machdep_ldisQ.c
+SYM_MAPS+=${LIBC_SRCTOP}/aarch64/Symbol.map
diff --git a/lib/libc/aarch64/SYS.h b/lib/libc/aarch64/SYS.h
new file mode 100644
index 0000000..e0be59d
--- /dev/null
+++ b/lib/libc/aarch64/SYS.h
@@ -0,0 +1,63 @@
+/*-
+ * Copyright (c) 2014 Andrew Turner
+ * Copyright (c) 2015 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Andrew Turner under
+ * sponsorship from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/syscall.h>
+#include <machine/asm.h>
+
+#define _SYSCALL(name) \
+ mov x8, SYS_ ## name; \
+ svc 0
+
+#define SYSCALL(name) \
+ENTRY(__sys_##name); \
+ WEAK_REFERENCE(__sys_##name, name); \
+ WEAK_REFERENCE(__sys_##name, _##name); \
+ _SYSCALL(name); \
+ ret; \
+END(__sys_##name)
+
+#define PSEUDO(name) \
+ENTRY(__sys_##name); \
+ WEAK_REFERENCE(__sys_##name, _##name); \
+ _SYSCALL(name); \
+ b.cs cerror; \
+ ret; \
+END(__sys_##name)
+
+#define RSYSCALL(name) \
+ENTRY(__sys_##name); \
+ WEAK_REFERENCE(__sys_##name, name); \
+ WEAK_REFERENCE(__sys_##name, _##name); \
+ _SYSCALL(name); \
+ b.cs cerror; \
+ ret; \
+END(__sys_##name)
diff --git a/lib/libc/aarch64/Symbol.map b/lib/libc/aarch64/Symbol.map
new file mode 100644
index 0000000..a0b33da
--- /dev/null
+++ b/lib/libc/aarch64/Symbol.map
@@ -0,0 +1,30 @@
+/*
+ * $FreeBSD$
+ */
+
+/*
+ * This only needs to contain symbols that are not listed in
+ * symbol maps from other parts of libc (i.e., not found in
+ * stdlib/Symbol.map, string/Symbol.map, sys/Symbol.map, ...).
+ */
+FBSD_1.0 {
+ /* PSEUDO syscalls */
+ _exit;
+
+ _setjmp;
+ _longjmp;
+ fabs;
+ setjmp;
+ longjmp;
+ sigsetjmp;
+ siglongjmp;
+ vfork;
+ brk;
+ sbrk;
+};
+
+FBSDprivate_1.0 {
+ _set_tp;
+ curbrk;
+ minbrk;
+};
diff --git a/lib/libc/aarch64/_fpmath.h b/lib/libc/aarch64/_fpmath.h
new file mode 100644
index 0000000..71d0a71
--- /dev/null
+++ b/lib/libc/aarch64/_fpmath.h
@@ -0,0 +1,58 @@
+/*-
+ * Copyright (c) 2002, 2003 David Schultz <das@FreeBSD.ORG>
+ * Copyright (2) 2014 The FreeBSD Foundation
+ * 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$
+ */
+
+union IEEEl2bits {
+ long double e;
+ struct {
+ unsigned long manl :64;
+ unsigned long manh :48;
+ unsigned int exp :15;
+ unsigned int sign :1;
+ } bits;
+ /* TODO andrew: Check the packing here */
+ struct {
+ unsigned long manl :64;
+ unsigned long manh :48;
+ unsigned int expsign :16;
+ } xbits;
+};
+
+#define LDBL_NBIT 0
+#define LDBL_IMPLICIT_NBIT
+#define mask_nbit_l(u) ((void)0)
+
+#define LDBL_MANH_SIZE 48
+#define LDBL_MANL_SIZE 64
+
+#define LDBL_TO_ARRAY32(u, a) do { \
+ (a)[0] = (uint32_t)(u).bits.manl; \
+ (a)[1] = (uint32_t)((u).bits.manl >> 32); \
+ (a)[2] = (uint32_t)(u).bits.manh; \
+ (a)[3] = (uint32_t)((u).bits.manh >> 32); \
+} while(0)
diff --git a/lib/libc/aarch64/arith.h b/lib/libc/aarch64/arith.h
new file mode 100644
index 0000000..ecb1a33
--- /dev/null
+++ b/lib/libc/aarch64/arith.h
@@ -0,0 +1,19 @@
+/*
+ * MD header for contrib/gdtoa
+ *
+ * $FreeBSD$
+ */
+
+/*
+ * NOTE: The definitions in this file must be correct or strtod(3) and
+ * floating point formats in printf(3) will break! The file can be
+ * generated by running contrib/gdtoa/arithchk.c on the target
+ * architecture. See contrib/gdtoa/gdtoaimp.h for details.
+ */
+
+#define IEEE_8087
+#define Arith_Kind_ASL 1
+#define Long int
+#define Intcast (int)(long)
+#define Double_Align
+#define X64_bit_pointers
diff --git a/lib/libc/aarch64/gd_qnan.h b/lib/libc/aarch64/gd_qnan.h
new file mode 100644
index 0000000..27e8d58
--- /dev/null
+++ b/lib/libc/aarch64/gd_qnan.h
@@ -0,0 +1,21 @@
+/*
+ * MD header for contrib/gdtoa
+ *
+ * This file can be generated by compiling and running contrib/gdtoa/qnan.c
+ * on the target architecture after arith.h has been generated.
+ *
+ * $FreeBSD$
+ */
+
+#define f_QNAN 0x7fc00000
+#define d_QNAN0 0x0
+#define d_QNAN1 0x7ff80000
+#define ld_QNAN0 0x0
+#define ld_QNAN1 0x0
+#define ld_QNAN2 0x0
+#define ld_QNAN3 0x7fff8000
+#define ldus_QNAN0 0x0
+#define ldus_QNAN1 0x0
+#define ldus_QNAN2 0x0
+#define ldus_QNAN3 0x0
+#define ldus_QNAN4 0x0
diff --git a/lib/libc/aarch64/gen/Makefile.inc b/lib/libc/aarch64/gen/Makefile.inc
new file mode 100644
index 0000000..c4f7c80
--- /dev/null
+++ b/lib/libc/aarch64/gen/Makefile.inc
@@ -0,0 +1,10 @@
+# $FreeBSD$
+
+SRCS+= fabs.S \
+ flt_rounds.c \
+ ldexp.c \
+ _setjmp.S \
+ _set_tp.c \
+ setjmp.S \
+ sigsetjmp.S \
+ trivial-getcontextx.c
diff --git a/lib/libc/posix1e/acl_size.c b/lib/libc/aarch64/gen/_set_tp.c
index 27ad651..a587b2e 100644
--- a/lib/libc/posix1e/acl_size.c
+++ b/lib/libc/aarch64/gen/_set_tp.c
@@ -1,5 +1,5 @@
-/*
- * Copyright (c) 2001-2002 Chris D. Faulhaber
+/*-
+ * Copyright (c) 2014 Andrew Turner
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -14,7 +14,7 @@
* 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 AUTHOR OR CONTRIBUTORS BE LIABLE
+ * 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)
@@ -27,17 +27,16 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
+#include <string.h>
#include <sys/types.h>
-#include "namespace.h"
-#include <sys/acl.h>
-#include "un-namespace.h"
-#include <errno.h>
+#include <machine/sysarch.h>
-ssize_t
-acl_size(acl_t acl)
+#include <stdlib.h>
+
+void
+_set_tp(void *tp)
{
- errno = ENOSYS;
- return (-1);
+ asm volatile("msr tpidr_el0, %0" : : "r"(tp));
}
diff --git a/lib/libc/aarch64/gen/_setjmp.S b/lib/libc/aarch64/gen/_setjmp.S
new file mode 100644
index 0000000..504423b
--- /dev/null
+++ b/lib/libc/aarch64/gen/_setjmp.S
@@ -0,0 +1,105 @@
+/*-
+ * Copyright (c) 2014 Andrew Turner
+ * Copyright (c) 2014 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Andrew Turner
+ * under sponsorship from the FreeBSD Foundation
+ *
+ * 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$");
+
+#include <machine/setjmp.h>
+
+ENTRY(_setjmp)
+ /* Store the magic value and stack pointer */
+ ldr x8, .Lmagic
+ mov x9, sp
+ stp x8, x9, [x0], #16
+
+ /* Store the general purpose registers and lr */
+ stp x19, x20, [x0], #16
+ stp x21, x22, [x0], #16
+ stp x23, x24, [x0], #16
+ stp x25, x26, [x0], #16
+ stp x27, x28, [x0], #16
+ stp x29, lr, [x0], #16
+
+#ifndef _STANDALONE
+ /* Store the vfp registers */
+ stp d8, d9, [x0], #16
+ stp d10, d11, [x0], #16
+ stp d12, d13, [x0], #16
+ stp d14, d15, [x0]
+#endif
+
+ /* Return value */
+ mov x0, #0
+ ret
+.Lmagic:
+ .align 3
+ .quad _JB_MAGIC__SETJMP
+END(_setjmp)
+
+ENTRY(_longjmp)
+ /* Check the magic value */
+ ldr x8, [x0], #8
+ ldr x9, .Lmagic
+ cmp x8, x9
+ b.ne botch
+
+ /* Restore the stack pointer */
+ ldr x8, [x0], #8
+ mov sp, x8
+
+ /* Restore the general purpose registers and lr */
+ ldp x19, x20, [x0], #16
+ ldp x21, x22, [x0], #16
+ ldp x23, x24, [x0], #16
+ ldp x25, x26, [x0], #16
+ ldp x27, x28, [x0], #16
+ ldp x29, lr, [x0], #16
+
+#ifndef _STANDALONE
+ /* Restore the vfp registers */
+ ldp d8, d9, [x0], #16
+ ldp d10, d11, [x0], #16
+ ldp d12, d13, [x0], #16
+ ldp d14, d15, [x0]
+#endif
+
+ /* Load the return value */
+ mov x0, x1
+ ret
+
+botch:
+#ifdef _STANDALONE
+ b botch
+#else
+ bl _C_LABEL(longjmperror)
+ bl _C_LABEL(abort)
+#endif
+END(_longjmp)
diff --git a/lib/libc/aarch64/gen/fabs.S b/lib/libc/aarch64/gen/fabs.S
new file mode 100644
index 0000000..2f5fd06
--- /dev/null
+++ b/lib/libc/aarch64/gen/fabs.S
@@ -0,0 +1,33 @@
+/*-
+ * Copyright (c) 2015 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <machine/asm.h>
+__FBSDID("$FreeBSD$");
+
+ENTRY(fabs)
+ fabs d0, d0
+ ret
+END(fabs)
diff --git a/lib/libc/mips/sys/__vdso_gettc.c b/lib/libc/aarch64/gen/flt_rounds.c
index b99bbc4..6f8eeeb 100644
--- a/lib/libc/mips/sys/__vdso_gettc.c
+++ b/lib/libc/aarch64/gen/flt_rounds.c
@@ -1,5 +1,6 @@
/*-
- * Copyright (c) 2013 Konstantin Belousov <kib@FreeBSD.org>
+ * Copyright (c) 2012 Ian Lepore <freebsd@damnhippie.dyndns.org>
+ * All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -27,22 +28,22 @@
__FBSDID("$FreeBSD$");
#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/vdso.h>
-#include <errno.h>
-#pragma weak __vdso_gettc
-u_int
-__vdso_gettc(const struct vdso_timehands *th)
-{
+#include <fenv.h>
+#include <float.h>
- return (0);
-}
+static int map[] = {
+ 1, /* round to nearest */
+ 2, /* round to positive infinity */
+ 3, /* round to negative infinity */
+ 0 /* round to zero */
+};
-#pragma weak __vdso_gettimekeep
int
-__vdso_gettimekeep(struct vdso_timekeep **tk)
+__flt_rounds(void)
{
+ uint64_t fpcr;
- return (ENOSYS);
+ asm volatile("mrs %0, fpcr" : "=r" (fpcr));
+ return map[(fpcr >> 22) & 3];
}
diff --git a/lib/libc/aarch64/gen/setjmp.S b/lib/libc/aarch64/gen/setjmp.S
new file mode 100644
index 0000000..80a9484
--- /dev/null
+++ b/lib/libc/aarch64/gen/setjmp.S
@@ -0,0 +1,123 @@
+/*-
+ * Copyright (c) 2014 Andrew Turner
+ * Copyright (c) 2014 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Andrew Turner
+ * under sponsorship from the FreeBSD Foundation
+ *
+ * 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$");
+
+#include <machine/setjmp.h>
+
+ENTRY(setjmp)
+ sub sp, sp, #16
+ stp x0, lr, [sp]
+
+ /* Store the signal mask */
+ add x2, x0, #(_JB_SIGMASK * 8) /* oset */
+ mov x1, #0 /* set */
+ mov x0, #1 /* SIG_BLOCK */
+ bl sigprocmask
+
+ ldp x0, lr, [sp]
+ add sp, sp, #16
+
+ /* Store the magic value and stack pointer */
+ ldr x8, .Lmagic
+ mov x9, sp
+ stp x8, x9, [x0], #16
+
+ /* Store the general purpose registers and lr */
+ stp x19, x20, [x0], #16
+ stp x21, x22, [x0], #16
+ stp x23, x24, [x0], #16
+ stp x25, x26, [x0], #16
+ stp x27, x28, [x0], #16
+ stp x29, lr, [x0], #16
+
+ /* Store the vfp registers */
+ stp d8, d9, [x0], #16
+ stp d10, d11, [x0], #16
+ stp d12, d13, [x0], #16
+ stp d14, d15, [x0]
+
+ /* Return value */
+ mov x0, #0
+ ret
+.Lmagic:
+ .align 3
+ .quad _JB_MAGIC_SETJMP
+END(setjmp)
+
+ENTRY(longjmp)
+ sub sp, sp, #32
+ stp x0, lr, [sp]
+ str x1, [sp, #16]
+
+ /* Restore the signal mask */
+ mov x1, #0 /* oset */
+ add x1, x0, #(_JB_SIGMASK * 8) /* set */
+ mov x0, #3 /* SIG_BLOCK */
+ bl sigprocmask
+
+ ldr x1, [sp, #16]
+ ldp x0, lr, [sp]
+ add sp, sp, #32
+
+ /* Check the magic value */
+ ldr x8, [x0], #8
+ ldr x9, .Lmagic
+ cmp x8, x9
+ b.ne botch
+
+ /* Restore the stack pointer */
+ ldr x8, [x0], #8
+ mov sp, x8
+
+ /* Restore the general purpose registers and lr */
+ ldp x19, x20, [x0], #16
+ ldp x21, x22, [x0], #16
+ ldp x23, x24, [x0], #16
+ ldp x25, x26, [x0], #16
+ ldp x27, x28, [x0], #16
+ ldp x29, lr, [x0], #16
+
+ /* Restore the vfp registers */
+ ldp d8, d9, [x0], #16
+ ldp d10, d11, [x0], #16
+ ldp d12, d13, [x0], #16
+ ldp d14, d15, [x0]
+
+ /* Load the return value */
+ mov x0, x1
+ ret
+
+botch:
+ bl _C_LABEL(longjmperror)
+ bl _C_LABEL(abort)
+END(longjmp)
diff --git a/lib/libc/aarch64/gen/sigsetjmp.S b/lib/libc/aarch64/gen/sigsetjmp.S
new file mode 100644
index 0000000..8a13c9f
--- /dev/null
+++ b/lib/libc/aarch64/gen/sigsetjmp.S
@@ -0,0 +1,53 @@
+/*-
+ * Copyright (c) 2014 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Andrew Turner under
+ * sponsorship from the FreeBSD Foundation.
+ *
+ * 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$");
+
+#include <machine/setjmp.h>
+
+ENTRY(sigsetjmp)
+ cmp x1, #0
+ b.eq _C_LABEL(_setjmp)
+ b _C_LABEL(setjmp)
+END(sigsetjmp)
+
+ENTRY(siglongjmp)
+ /* Load the _setjmp magic */
+ ldr x2, .Lmagic
+ ldr x3, [x0]
+
+ /* Check the magic */
+ cmp x2, x3
+ b.eq _C_LABEL(_longjmp)
+ b _C_LABEL(longjmp)
+.Lmagic:
+ .align 3
+ .quad _JB_MAGIC__SETJMP
+END(siglongjmp)
diff --git a/lib/libc/aarch64/sys/Makefile.inc b/lib/libc/aarch64/sys/Makefile.inc
new file mode 100644
index 0000000..cb56f73
--- /dev/null
+++ b/lib/libc/aarch64/sys/Makefile.inc
@@ -0,0 +1,25 @@
+# $FreeBSD$
+
+SRCS+= trivial-vdso_tc.c
+
+#MDASM= ptrace.S
+MDASM= brk.S \
+ cerror.S \
+ pipe.S \
+ sbrk.S \
+ shmat.S \
+ sigreturn.S \
+ syscall.S \
+ vfork.S
+
+# Don't generate default code for these syscalls:
+NOASM= break.o \
+ exit.o \
+ getlogin.o \
+ openbsd_poll.o \
+ sstk.o \
+ vfork.o \
+ yield.o
+
+PSEUDO= _exit.o \
+ _getlogin.o
diff --git a/lib/libc/aarch64/sys/brk.S b/lib/libc/aarch64/sys/brk.S
new file mode 100644
index 0000000..09167b6
--- /dev/null
+++ b/lib/libc/aarch64/sys/brk.S
@@ -0,0 +1,93 @@
+/*-
+ * Copyright (c) 2014 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Andrew Turner under
+ * sponsorship from the FreeBSD Foundation.
+ *
+ * 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$");
+
+#include "SYS.h"
+
+ .data
+ .align 3
+ .globl _C_LABEL(minbrk)
+ .type _C_LABEL(minbrk),#object
+_C_LABEL(minbrk):
+ .quad _C_LABEL(_end)
+
+ .text
+/*
+ * int brk(const void *addr);
+ */
+ENTRY(_brk)
+ WEAK_REFERENCE(_brk, brk)
+
+ /* Load the address of minbrk */
+#ifdef __PIC__
+ adrp x2, :got:minbrk
+ ldr x3, [x2, #:got_lo12:minbrk]
+#else
+ ldr x3, .Lminbrk
+#endif
+
+ /* Get the minimum allowable brk address */
+ ldr x2, [x3]
+
+ /* Validate the address */
+ cmp x0, x2
+ b.ge 1f
+ /* Invalid, set it to the minimum */
+ mov x0, x2
+
+ /* Backup the new address */
+1: mov x4, x0
+
+ /* Update for this value, will overwrite x0 and x1 */
+ _SYSCALL(break)
+ b.cs cerror
+
+#ifdef __PIC__
+ adrp x2, :got:curbrk
+ ldr x3, [x2, #:got_lo12:curbrk]
+#else
+ ldr x3, .Lcurbrk
+#endif
+
+ /* Store the new curbrk value */
+ str x4, [x3]
+
+ /* Return success */
+ mov x0, #0
+ ret
+
+#ifndef __PIC__
+.Lcurbrk:
+ .quad _C_LABEL(curbrk)
+.Lminbrk:
+ .quad _C_LABEL(minbrk)
+#endif
+END(_brk)
diff --git a/lib/libc/aarch64/sys/cerror.S b/lib/libc/aarch64/sys/cerror.S
new file mode 100644
index 0000000..26c61bc
--- /dev/null
+++ b/lib/libc/aarch64/sys/cerror.S
@@ -0,0 +1,41 @@
+/*-
+ * Copyright (c) 2014 Andrew Turner
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include <machine/asm.h>
+__FBSDID("$FreeBSD$");
+
+ENTRY(cerror)
+ sub sp, sp, #16
+ stp x0, lr, [sp]
+ bl _C_LABEL(__error)
+ ldp x1, lr, [sp]
+ str x1, [x0]
+ movn x0, #0
+ movn x1, #0
+ add sp, sp, #16
+ ret
+END(cerror)
diff --git a/lib/libc/aarch64/sys/pipe.S b/lib/libc/aarch64/sys/pipe.S
new file mode 100644
index 0000000..6b1cf24
--- /dev/null
+++ b/lib/libc/aarch64/sys/pipe.S
@@ -0,0 +1,52 @@
+/*-
+ * Copyright (c) 2014 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Andrew Turner under
+ * sponsorship from the FreeBSD Foundation.
+ *
+ * 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$");
+
+#include "SYS.h"
+
+ENTRY(__sys_pipe)
+ WEAK_REFERENCE(__sys_pipe, pipe)
+
+ /* Backup the pointer passed to us */
+ mov x2, x0
+
+ /* Make the syscall */
+ _SYSCALL(pipe)
+ b.cs cerror
+
+ /* Store the result */
+ str w0, [x2, #0]
+ str w1, [x2, #4]
+
+ /* Return */
+ mov x0, #0
+ ret
+END(__sys_pipe)
diff --git a/lib/libc/aarch64/sys/sbrk.S b/lib/libc/aarch64/sys/sbrk.S
new file mode 100644
index 0000000..db9d7e1
--- /dev/null
+++ b/lib/libc/aarch64/sys/sbrk.S
@@ -0,0 +1,79 @@
+/*-
+ * Copyright (c) 2014 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Andrew Turner under
+ * sponsorship from the FreeBSD Foundation.
+ *
+ * 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$");
+
+#include "SYS.h"
+
+ .data
+ .align 3
+ .global _C_LABEL(curbrk)
+ .type _C_LABEL(curbrk),#object
+_C_LABEL(curbrk):
+ .quad _C_LABEL(_end)
+
+ .text
+/*
+ * void *sbrk(intptr_t incr);
+ */
+ENTRY(_sbrk)
+ WEAK_REFERENCE(_sbrk, sbrk)
+
+ /* Load the address of curbrk */
+#ifdef __PIC__
+ adrp x2, :got:curbrk
+ ldr x3, [x2, #:got_lo12:curbrk]
+#else
+ ldr x3, .Lcurbrk
+#endif
+
+ /* Get the current brk address */
+ ldr x2, [x3]
+
+ /* Calculate the new value */
+ add x0, x2, x0
+ mov x4, x0
+
+ /* Update for this value, will overwrite x0 and x1 */
+ _SYSCALL(break)
+ b.cs cerror
+
+ /* Load the old value to return */
+ ldr x0, [x3]
+
+ /* Store the new curbrk value */
+ str x4, [x3]
+
+ ret
+#ifndef __PIC__
+.Lcurbrk:
+ .quad _C_LABEL(curbrk)
+#endif
+END(_sbrk)
diff --git a/lib/libc/powerpc/sys/__vdso_gettc.c b/lib/libc/aarch64/sys/shmat.S
index b99bbc4..c0fb34f 100644
--- a/lib/libc/powerpc/sys/__vdso_gettc.c
+++ b/lib/libc/aarch64/sys/shmat.S
@@ -1,5 +1,9 @@
/*-
- * Copyright (c) 2013 Konstantin Belousov <kib@FreeBSD.org>
+ * Copyright (c) 2014 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Andrew Turner under
+ * sponsorship from the FreeBSD Foundation.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -23,26 +27,9 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
+#include <machine/asm.h>
__FBSDID("$FreeBSD$");
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/vdso.h>
-#include <errno.h>
-
-#pragma weak __vdso_gettc
-u_int
-__vdso_gettc(const struct vdso_timehands *th)
-{
-
- return (0);
-}
-
-#pragma weak __vdso_gettimekeep
-int
-__vdso_gettimekeep(struct vdso_timekeep **tk)
-{
+#include "SYS.h"
- return (ENOSYS);
-}
+RSYSCALL(shmat)
diff --git a/lib/libc/aarch64/sys/sigreturn.S b/lib/libc/aarch64/sys/sigreturn.S
new file mode 100644
index 0000000..21ec1e4
--- /dev/null
+++ b/lib/libc/aarch64/sys/sigreturn.S
@@ -0,0 +1,35 @@
+/*-
+ * Copyright (c) 2014 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Andrew Turner under
+ * sponsorship from the FreeBSD Foundation.
+ *
+ * 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$");
+
+#include "SYS.h"
+
+RSYSCALL(sigreturn)
diff --git a/lib/libc/aarch64/sys/syscall.S b/lib/libc/aarch64/sys/syscall.S
new file mode 100644
index 0000000..6314835
--- /dev/null
+++ b/lib/libc/aarch64/sys/syscall.S
@@ -0,0 +1,35 @@
+/*-
+ * Copyright (c) 2014 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Andrew Turner under
+ * sponsorship from the FreeBSD Foundation.
+ *
+ * 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$");
+
+#include "SYS.h"
+
+RSYSCALL(syscall)
diff --git a/lib/libc/aarch64/sys/vfork.S b/lib/libc/aarch64/sys/vfork.S
new file mode 100644
index 0000000..daecd1f
--- /dev/null
+++ b/lib/libc/aarch64/sys/vfork.S
@@ -0,0 +1,42 @@
+/*-
+ * Copyright (c) 2014 Andrew Turner
+ * 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$");
+#include "SYS.h"
+
+ENTRY(__sys_vfork)
+ WEAK_REFERENCE(__sys_vfork, vfork)
+ WEAK_REFERENCE(__sys_vfork, _vfork)
+ mov x2, lr
+ _SYSCALL(vfork)
+ b.cs cerror
+ sub x1, x1, #1
+ and x0, x0, x1
+ mov lr, x2
+ ret
+END(__sys_vfork)
diff --git a/lib/libc/amd64/sys/Makefile.inc b/lib/libc/amd64/sys/Makefile.inc
index 8e0d614..46ea955 100644
--- a/lib/libc/amd64/sys/Makefile.inc
+++ b/lib/libc/amd64/sys/Makefile.inc
@@ -11,6 +11,3 @@ MDASM= vfork.S brk.S cerror.S exect.S getcontext.S pipe.S ptrace.S \
NOASM= break.o exit.o getlogin.o openbsd_poll.o sstk.o vfork.o yield.o
PSEUDO= _getlogin.o _exit.o
-.if ${MK_SYSCALL_COMPAT} != "no"
-PSEUDO+= _pread.o _pwrite.o _lseek.o _mmap.o _ftruncate.o _truncate.o
-.endif
diff --git a/lib/libc/arm/SYS.h b/lib/libc/arm/SYS.h
index ed1a045..3254c45 100644
--- a/lib/libc/arm/SYS.h
+++ b/lib/libc/arm/SYS.h
@@ -62,6 +62,7 @@
#define _SYSCALL(x) \
_SYSCALL_NOERROR(x); \
+ it cs; \
bcs PIC_SYM(CERROR, PLT)
#define SYSCALL(x) \
@@ -72,6 +73,7 @@
.weak _C_LABEL(__CONCAT(_,x)); \
.set _C_LABEL(__CONCAT(_,x)),_C_LABEL(__CONCAT(__sys_,x)); \
SYSTRAP(x); \
+ it cs; \
bcs PIC_SYM(CERROR, PLT); \
RET
diff --git a/lib/libc/arm/aeabi/Makefile.inc b/lib/libc/arm/aeabi/Makefile.inc
index b204a53..fa0ec8e 100644
--- a/lib/libc/arm/aeabi/Makefile.inc
+++ b/lib/libc/arm/aeabi/Makefile.inc
@@ -20,7 +20,7 @@ SRCS+= aeabi_vfp_double.S \
# libc. This causes issues when other parts of libc call these functions.
# We work around this by including these functions in libc but mark them as
# hidden so users of libc will not pick up these versions.
-.PATH: ${LIBC_SRCTOP}/../../contrib/compiler-rt/lib/arm
+.PATH: ${LIBC_SRCTOP}/../../contrib/compiler-rt/lib/builtins/arm
SRCS+= aeabi_memcmp.S \
aeabi_memcpy.S \
diff --git a/lib/libc/arm/aeabi/aeabi_vfp_double.S b/lib/libc/arm/aeabi/aeabi_vfp_double.S
index 62100d2..aae49f8 100644
--- a/lib/libc/arm/aeabi/aeabi_vfp_double.S
+++ b/lib/libc/arm/aeabi/aeabi_vfp_double.S
@@ -66,6 +66,7 @@ AEABI_ENTRY(dcmpeq)
LOAD_DREG(d1, r2, r3)
vcmp.f64 d0, d1
vmrs APSR_nzcv, fpscr
+ ite ne
movne r0, #0
moveq r0, #1
RET
@@ -77,8 +78,9 @@ AEABI_ENTRY(dcmplt)
LOAD_DREG(d1, r2, r3)
vcmp.f64 d0, d1
vmrs APSR_nzcv, fpscr
+ ite cs
movcs r0, #0
- movlt r0, #1
+ movcc r0, #1
RET
AEABI_END(dcmplt)
@@ -88,6 +90,7 @@ AEABI_ENTRY(dcmple)
LOAD_DREG(d1, r2, r3)
vcmp.f64 d0, d1
vmrs APSR_nzcv, fpscr
+ ite hi
movhi r0, #0
movls r0, #1
RET
@@ -99,6 +102,7 @@ AEABI_ENTRY(dcmpge)
LOAD_DREG(d1, r2, r3)
vcmp.f64 d0, d1
vmrs APSR_nzcv, fpscr
+ ite lt
movlt r0, #0
movge r0, #1
RET
@@ -110,6 +114,7 @@ AEABI_ENTRY(dcmpgt)
LOAD_DREG(d1, r2, r3)
vcmp.f64 d0, d1
vmrs APSR_nzcv, fpscr
+ ite le
movle r0, #0
movgt r0, #1
RET
@@ -121,6 +126,7 @@ AEABI_ENTRY(dcmpun)
LOAD_DREG(d1, r2, r3)
vcmp.f64 d0, d1
vmrs APSR_nzcv, fpscr
+ ite vc
movvc r0, #0
movvs r0, #1
RET
diff --git a/lib/libc/arm/aeabi/aeabi_vfp_float.S b/lib/libc/arm/aeabi/aeabi_vfp_float.S
index c9a9a7e..7de8daf 100644
--- a/lib/libc/arm/aeabi/aeabi_vfp_float.S
+++ b/lib/libc/arm/aeabi/aeabi_vfp_float.S
@@ -62,6 +62,7 @@ AEABI_ENTRY(fcmpeq)
LOAD_SREGS(s0, s1, r0, r1)
vcmp.f32 s0, s1
vmrs APSR_nzcv, fpscr
+ ite ne
movne r0, #0
moveq r0, #1
RET
@@ -72,8 +73,9 @@ AEABI_ENTRY(fcmplt)
LOAD_SREGS(s0, s1, r0, r1)
vcmp.f32 s0, s1
vmrs APSR_nzcv, fpscr
+ ite cs
movcs r0, #0
- movlt r0, #1
+ movcc r0, #1
RET
AEABI_END(fcmplt)
@@ -82,6 +84,7 @@ AEABI_ENTRY(fcmple)
LOAD_SREGS(s0, s1, r0, r1)
vcmp.f32 s0, s1
vmrs APSR_nzcv, fpscr
+ ite hi
movhi r0, #0
movls r0, #1
RET
@@ -92,6 +95,7 @@ AEABI_ENTRY(fcmpge)
LOAD_SREGS(s0, s1, r0, r1)
vcmp.f32 s0, s1
vmrs APSR_nzcv, fpscr
+ ite lt
movlt r0, #0
movge r0, #1
RET
@@ -102,6 +106,7 @@ AEABI_ENTRY(fcmpgt)
LOAD_SREGS(s0, s1, r0, r1)
vcmp.f32 s0, s1
vmrs APSR_nzcv, fpscr
+ ite le
movle r0, #0
movgt r0, #1
RET
@@ -112,6 +117,7 @@ AEABI_ENTRY(fcmpun)
LOAD_SREGS(s0, s1, r0, r1)
vcmp.f32 s0, s1
vmrs APSR_nzcv, fpscr
+ ite vc
movvc r0, #0
movvs r0, #1
RET
diff --git a/lib/libc/arm/gen/Makefile.inc b/lib/libc/arm/gen/Makefile.inc
index 8efde09..c0f5392 100644
--- a/lib/libc/arm/gen/Makefile.inc
+++ b/lib/libc/arm/gen/Makefile.inc
@@ -2,9 +2,10 @@
# $FreeBSD$
SRCS+= _ctx_start.S _setjmp.S _set_tp.c alloca.S fabs.c \
- getcontextx.c infinity.c ldexp.c makecontext.c \
+ infinity.c ldexp.c makecontext.c \
__aeabi_read_tp.S setjmp.S signalcontext.c sigsetjmp.S flt_rounds.c \
- arm_initfini.c
+ arm_initfini.c \
+ trivial-getcontextx.c
.if ${MACHINE_ARCH} == "armv6hf"
SRCS+= fpgetmask_vfp.c fpgetround_vfp.c fpgetsticky_vfp.c fpsetmask_vfp.c \
diff --git a/lib/libc/arm/gen/_setjmp.S b/lib/libc/arm/gen/_setjmp.S
index 387f8a9..3de9d99 100644
--- a/lib/libc/arm/gen/_setjmp.S
+++ b/lib/libc/arm/gen/_setjmp.S
@@ -85,7 +85,13 @@ ENTRY(_setjmp)
add r0, r0, #(_JB_REG_R4 * 4)
/* Store integer registers */
+#ifndef __thumb__
stmia r0, {r4-r14}
+#else
+ stmia r0, {r4-r12}
+ str r13, [r0, #((_JB_REG_R13 - _JB_REG_R4) * 4)]
+ str r14, [r0, #((_JB_REG_R14 - _JB_REG_R4) * 4)]
+#endif
mov r0, #0x00000000
RET
@@ -120,15 +126,24 @@ ENTRY(_longjmp)
add r0, r0, #(_JB_REG_R4 * 4)
/* Restore integer registers */
+#ifndef __thumb__
ldmia r0, {r4-r14}
+#else
+ ldmia r0, {r4-r12}
+ ldr r13, [r0, #((_JB_REG_R13 - _JB_REG_R4) * 4)]
+ ldr r14, [r0, #((_JB_REG_R14 - _JB_REG_R4) * 4)]
+#endif
/* Validate sp and r14 */
teq sp, #0
+ it ne
teqne r14, #0
+ it eq
beq botch
/* Set return value */
movs r0, r1
+ it eq
moveq r0, #0x00000001
RET
@@ -137,7 +152,7 @@ botch:
#if !defined(_STANDALONE)
bl PIC_SYM(_C_LABEL(longjmperror), PLT)
bl PIC_SYM(_C_LABEL(abort), PLT)
- b . - 8 /* Cannot get here */
+1: b 1b /* Cannot get here */
#else
b .
#endif
diff --git a/lib/libc/arm/gen/setjmp.S b/lib/libc/arm/gen/setjmp.S
index ad4ba38..6269563 100644
--- a/lib/libc/arm/gen/setjmp.S
+++ b/lib/libc/arm/gen/setjmp.S
@@ -90,7 +90,13 @@ ENTRY(setjmp)
/* Store integer registers */
add r0, r0, #(_JB_REG_R4 * 4)
+#ifndef __thumb__
stmia r0, {r4-r14}
+#else
+ stmia r0, {r4-r12}
+ str r13, [r0, #((_JB_REG_R13 - _JB_REG_R4) * 4)]
+ str r14, [r0, #((_JB_REG_R14 - _JB_REG_R4) * 4)]
+#endif
mov r0, #0x00000000
RET
@@ -133,15 +139,24 @@ ENTRY(__longjmp)
add r0, r0, #(_JB_REG_R4 * 4)
/* Restore integer registers */
+#ifndef __thumb__
ldmia r0, {r4-r14}
+#else
+ ldmia r0, {r4-r12}
+ ldr r13, [r0, #((_JB_REG_R13 - _JB_REG_R4) * 4)]
+ ldr r14, [r0, #((_JB_REG_R14 - _JB_REG_R4) * 4)]
+#endif
/* Validate sp and r14 */
teq sp, #0
+ it ne
teqne r14, #0
+ it eq
beq .Lbotch
/* Set return value */
movs r0, r1
+ it eq
moveq r0, #0x00000001
RET
@@ -149,5 +164,5 @@ ENTRY(__longjmp)
.Lbotch:
bl PIC_SYM(_C_LABEL(longjmperror), PLT)
bl PIC_SYM(_C_LABEL(abort), PLT)
- b . - 8 /* Cannot get here */
+1: b 1b /* Cannot get here */
END(__longjmp)
diff --git a/lib/libc/arm/string/ffs.S b/lib/libc/arm/string/ffs.S
index d3684ed..4567f6c 100644
--- a/lib/libc/arm/string/ffs.S
+++ b/lib/libc/arm/string/ffs.S
@@ -32,6 +32,8 @@
__FBSDID("$FreeBSD$");
+.syntax unified
+
/*
* ffs - find first set bit, this algorithm isolates the first set
* bit, then multiplies the number by 0x0450fbaf which leaves the top
@@ -60,7 +62,7 @@ ENTRY(ffs)
rsbne r0, r0, r0, lsl #16 /* r0 = X * 0x0450fbaf */
/* now lookup in table indexed on top 6 bits of r0 */
- ldrneb r0, [ r2, r0, lsr #26 ]
+ ldrbne r0, [ r2, r0, lsr #26 ]
RET
.text;
diff --git a/lib/libc/arm/string/memcmp.S b/lib/libc/arm/string/memcmp.S
index 63a00ef..6fd8130 100644
--- a/lib/libc/arm/string/memcmp.S
+++ b/lib/libc/arm/string/memcmp.S
@@ -66,6 +66,8 @@
__FBSDID("$FreeBSD$");
+.syntax unified
+
ENTRY(memcmp)
mov ip, r0
#if defined(_KERNEL) && !defined(_STANDALONE)
@@ -76,7 +78,7 @@ ENTRY(memcmp)
/* Are both addresses aligned the same way? */
cmp r2, #0x00
- eornes r3, ip, r1
+ eorsne r3, ip, r1
RETeq /* len == 0, or same addresses! */
tst r3, #0x03
subne r2, r2, #0x01
diff --git a/lib/libc/arm/string/memcpy_arm.S b/lib/libc/arm/string/memcpy_arm.S
index eff1eb0..56fb703 100644
--- a/lib/libc/arm/string/memcpy_arm.S
+++ b/lib/libc/arm/string/memcpy_arm.S
@@ -31,6 +31,9 @@
#include <machine/asm.h>
__FBSDID("$FreeBSD$");
+
+.syntax unified
+
/*
* This is one fun bit of code ...
* Some easy listening music is suggested while trying to understand this
@@ -91,8 +94,8 @@ ENTRY(memcpy)
bge .Lmemcpy_loop32
cmn r2, #0x10
- ldmgeia r1!, {r3, r4, r12, lr} /* blat a remaining 16 bytes */
- stmgeia r0!, {r3, r4, r12, lr}
+ ldmiage r1!, {r3, r4, r12, lr} /* blat a remaining 16 bytes */
+ stmiage r0!, {r3, r4, r12, lr}
subge r2, r2, #0x10
ldmia sp!, {r4} /* return r4 */
@@ -101,9 +104,9 @@ ENTRY(memcpy)
/* blat 12 bytes at a time */
.Lmemcpy_loop12:
- ldmgeia r1!, {r3, r12, lr}
- stmgeia r0!, {r3, r12, lr}
- subges r2, r2, #0x0c
+ ldmiage r1!, {r3, r12, lr}
+ stmiage r0!, {r3, r12, lr}
+ subsge r2, r2, #0x0c
bge .Lmemcpy_loop12
.Lmemcpy_l12:
@@ -113,26 +116,26 @@ ENTRY(memcpy)
subs r2, r2, #4
ldrlt r3, [r1], #4
strlt r3, [r0], #4
- ldmgeia r1!, {r3, r12}
- stmgeia r0!, {r3, r12}
+ ldmiage r1!, {r3, r12}
+ stmiage r0!, {r3, r12}
subge r2, r2, #4
.Lmemcpy_l4:
/* less than 4 bytes to go */
adds r2, r2, #4
#ifdef __APCS_26_
- ldmeqia sp!, {r0, pc}^ /* done */
+ ldmiaeq sp!, {r0, pc}^ /* done */
#else
- ldmeqia sp!, {r0, pc} /* done */
+ ldmiaeq sp!, {r0, pc} /* done */
#endif
/* copy the crud byte at a time */
cmp r2, #2
ldrb r3, [r1], #1
strb r3, [r0], #1
- ldrgeb r3, [r1], #1
- strgeb r3, [r0], #1
- ldrgtb r3, [r1], #1
- strgtb r3, [r0], #1
+ ldrbge r3, [r1], #1
+ strbge r3, [r0], #1
+ ldrbgt r3, [r1], #1
+ strbgt r3, [r0], #1
ldmia sp!, {r0, pc}
/* erg - unaligned destination */
@@ -143,10 +146,10 @@ ENTRY(memcpy)
/* align destination with byte copies */
ldrb r3, [r1], #1
strb r3, [r0], #1
- ldrgeb r3, [r1], #1
- strgeb r3, [r0], #1
- ldrgtb r3, [r1], #1
- strgtb r3, [r0], #1
+ ldrbge r3, [r1], #1
+ strbge r3, [r0], #1
+ ldrbgt r3, [r1], #1
+ strbgt r3, [r0], #1
subs r2, r2, r12
blt .Lmemcpy_l4 /* less the 4 bytes */
diff --git a/lib/libc/arm/string/memcpy_xscale.S b/lib/libc/arm/string/memcpy_xscale.S
index 1f48cd9..a451de4 100644
--- a/lib/libc/arm/string/memcpy_xscale.S
+++ b/lib/libc/arm/string/memcpy_xscale.S
@@ -38,6 +38,8 @@
#include <machine/asm.h>
__FBSDID("$FreeBSD$");
+.syntax unified
+
/* LINTSTUB: Func: void *memcpy(void *dst, const void *src, size_t len) */
ENTRY(memcpy)
pld [r1]
@@ -52,12 +54,12 @@ ENTRY(memcpy)
ldrb ip, [r1], #0x01
sub r2, r2, #0x01
strb ip, [r3], #0x01
- ldrleb ip, [r1], #0x01
+ ldrble ip, [r1], #0x01
suble r2, r2, #0x01
- strleb ip, [r3], #0x01
- ldrltb ip, [r1], #0x01
+ strble ip, [r3], #0x01
+ ldrblt ip, [r1], #0x01
sublt r2, r2, #0x01
- strltb ip, [r3], #0x01
+ strblt ip, [r3], #0x01
/* Destination buffer is now word aligned */
.Lmemcpy_wordaligned:
@@ -134,7 +136,7 @@ ENTRY(memcpy)
.Lmemcpy_w_lessthan128:
adds r2, r2, #0x80 /* Adjust for extra sub */
- ldmeqfd sp!, {r4-r9}
+ ldmfdeq sp!, {r4-r9}
bxeq lr /* Return now if done */
subs r2, r2, #0x20
blt .Lmemcpy_w_lessthan32
@@ -159,7 +161,7 @@ ENTRY(memcpy)
.Lmemcpy_w_lessthan32:
adds r2, r2, #0x20 /* Adjust for extra sub */
- ldmeqfd sp!, {r4-r9}
+ ldmfdeq sp!, {r4-r9}
bxeq lr /* Return now if done */
and r4, r2, #0x18
@@ -195,11 +197,11 @@ ENTRY(memcpy)
addlt r2, r2, #0x04
ldrb ip, [r1], #0x01
cmp r2, #0x02
- ldrgeb r2, [r1], #0x01
+ ldrbge r2, [r1], #0x01
strb ip, [r3], #0x01
- ldrgtb ip, [r1]
- strgeb r2, [r3], #0x01
- strgtb ip, [r3]
+ ldrbgt ip, [r1]
+ strbge r2, [r3], #0x01
+ strbgt ip, [r3]
bx lr
@@ -253,7 +255,7 @@ ENTRY(memcpy)
bge .Lmemcpy_bad1_loop16
adds r2, r2, #0x10
- ldmeqfd sp!, {r4-r7}
+ ldmfdeq sp!, {r4-r7}
bxeq lr /* Return now if done */
subs r2, r2, #0x04
sublt r1, r1, #0x03
@@ -314,7 +316,7 @@ ENTRY(memcpy)
bge .Lmemcpy_bad2_loop16
adds r2, r2, #0x10
- ldmeqfd sp!, {r4-r7}
+ ldmfdeq sp!, {r4-r7}
bxeq lr /* Return now if done */
subs r2, r2, #0x04
sublt r1, r1, #0x02
@@ -375,7 +377,7 @@ ENTRY(memcpy)
bge .Lmemcpy_bad3_loop16
adds r2, r2, #0x10
- ldmeqfd sp!, {r4-r7}
+ ldmfdeq sp!, {r4-r7}
bxeq lr /* Return now if done */
subs r2, r2, #0x04
sublt r1, r1, #0x01
@@ -404,11 +406,11 @@ ENTRY(memcpy)
bxeq lr
ldrb ip, [r1], #0x01
cmp r2, #0x02
- ldrgeb r2, [r1], #0x01
+ ldrbge r2, [r1], #0x01
strb ip, [r3], #0x01
- ldrgtb ip, [r1]
- strgeb r2, [r3], #0x01
- strgtb ip, [r3]
+ ldrbgt ip, [r1]
+ strbge r2, [r3], #0x01
+ strbgt ip, [r3]
bx lr
@@ -440,7 +442,7 @@ ENTRY(memcpy)
ldrb ip, [r1], #0x01
1: subs r2, r2, #0x01
strb ip, [r3], #0x01
- ldrneb ip, [r1], #0x01
+ ldrbne ip, [r1], #0x01
bne 1b
bx lr
diff --git a/lib/libc/arm/string/memmove.S b/lib/libc/arm/string/memmove.S
index 75a2744..94e5474 100644
--- a/lib/libc/arm/string/memmove.S
+++ b/lib/libc/arm/string/memmove.S
@@ -32,6 +32,8 @@
#include <machine/asm.h>
__FBSDID("$FreeBSD$");
+.syntax unified
+
#ifndef _BCOPY
/* LINTSTUB: Func: void *memmove(void *, const void *, size_t) */
ENTRY(memmove)
@@ -86,8 +88,8 @@ ENTRY(bcopy)
bge .Lmemmove_floop32
cmn r2, #0x10
- ldmgeia r1!, {r3, r4, r12, lr} /* blat a remaining 16 bytes */
- stmgeia r0!, {r3, r4, r12, lr}
+ ldmiage r1!, {r3, r4, r12, lr} /* blat a remaining 16 bytes */
+ stmiage r0!, {r3, r4, r12, lr}
subge r2, r2, #0x10
ldmia sp!, {r4} /* return r4 */
@@ -96,9 +98,9 @@ ENTRY(bcopy)
/* blat 12 bytes at a time */
.Lmemmove_floop12:
- ldmgeia r1!, {r3, r12, lr}
- stmgeia r0!, {r3, r12, lr}
- subges r2, r2, #0x0c
+ ldmiage r1!, {r3, r12, lr}
+ stmiage r0!, {r3, r12, lr}
+ subsge r2, r2, #0x0c
bge .Lmemmove_floop12
.Lmemmove_fl12:
@@ -108,23 +110,23 @@ ENTRY(bcopy)
subs r2, r2, #4
ldrlt r3, [r1], #4
strlt r3, [r0], #4
- ldmgeia r1!, {r3, r12}
- stmgeia r0!, {r3, r12}
+ ldmiage r1!, {r3, r12}
+ stmiage r0!, {r3, r12}
subge r2, r2, #4
.Lmemmove_fl4:
/* less than 4 bytes to go */
adds r2, r2, #4
- ldmeqia sp!, {r0, pc} /* done */
+ ldmiaeq sp!, {r0, pc} /* done */
/* copy the crud byte at a time */
cmp r2, #2
ldrb r3, [r1], #1
strb r3, [r0], #1
- ldrgeb r3, [r1], #1
- strgeb r3, [r0], #1
- ldrgtb r3, [r1], #1
- strgtb r3, [r0], #1
+ ldrbge r3, [r1], #1
+ strbge r3, [r0], #1
+ ldrbgt r3, [r1], #1
+ strbgt r3, [r0], #1
ldmia sp!, {r0, pc}
/* erg - unaligned destination */
@@ -135,10 +137,10 @@ ENTRY(bcopy)
/* align destination with byte copies */
ldrb r3, [r1], #1
strb r3, [r0], #1
- ldrgeb r3, [r1], #1
- strgeb r3, [r0], #1
- ldrgtb r3, [r1], #1
- strgtb r3, [r0], #1
+ ldrbge r3, [r1], #1
+ strbge r3, [r0], #1
+ ldrbgt r3, [r1], #1
+ strbgt r3, [r0], #1
subs r2, r2, r12
blt .Lmemmove_fl4 /* less the 4 bytes */
@@ -353,12 +355,12 @@ ENTRY(bcopy)
.Lmemmove_bl32:
cmn r2, #0x10
- ldmgedb r1!, {r3, r4, r12, lr} /* blat a remaining 16 bytes */
- stmgedb r0!, {r3, r4, r12, lr}
+ ldmdbge r1!, {r3, r4, r12, lr} /* blat a remaining 16 bytes */
+ stmdbge r0!, {r3, r4, r12, lr}
subge r2, r2, #0x10
adds r2, r2, #0x14
- ldmgedb r1!, {r3, r12, lr} /* blat a remaining 12 bytes */
- stmgedb r0!, {r3, r12, lr}
+ ldmdbge r1!, {r3, r12, lr} /* blat a remaining 12 bytes */
+ stmdbge r0!, {r3, r12, lr}
subge r2, r2, #0x0c
ldmia sp!, {r4, lr}
@@ -368,8 +370,8 @@ ENTRY(bcopy)
subs r2, r2, #4
ldrlt r3, [r1, #-4]!
strlt r3, [r0, #-4]!
- ldmgedb r1!, {r3, r12}
- stmgedb r0!, {r3, r12}
+ ldmdbge r1!, {r3, r12}
+ stmdbge r0!, {r3, r12}
subge r2, r2, #4
.Lmemmove_bl4:
@@ -381,10 +383,10 @@ ENTRY(bcopy)
cmp r2, #2
ldrb r3, [r1, #-1]!
strb r3, [r0, #-1]!
- ldrgeb r3, [r1, #-1]!
- strgeb r3, [r0, #-1]!
- ldrgtb r3, [r1, #-1]!
- strgtb r3, [r0, #-1]!
+ ldrbge r3, [r1, #-1]!
+ strbge r3, [r0, #-1]!
+ ldrbgt r3, [r1, #-1]!
+ strbgt r3, [r0, #-1]!
RET
/* erg - unaligned destination */
@@ -394,10 +396,10 @@ ENTRY(bcopy)
/* align destination with byte copies */
ldrb r3, [r1, #-1]!
strb r3, [r0, #-1]!
- ldrgeb r3, [r1, #-1]!
- strgeb r3, [r0, #-1]!
- ldrgtb r3, [r1, #-1]!
- strgtb r3, [r0, #-1]!
+ ldrbge r3, [r1, #-1]!
+ strbge r3, [r0, #-1]!
+ ldrbgt r3, [r1, #-1]!
+ strbgt r3, [r0, #-1]!
subs r2, r2, r12
blt .Lmemmove_bl4 /* less than 4 bytes to go */
ands r12, r1, #3
diff --git a/lib/libc/arm/string/memset.S b/lib/libc/arm/string/memset.S
index 458f8f7..66af33e 100644
--- a/lib/libc/arm/string/memset.S
+++ b/lib/libc/arm/string/memset.S
@@ -69,6 +69,8 @@
#include <machine/asm.h>
__FBSDID("$FreeBSD$");
+.syntax unified
+
/*
* memset: Sets a block of memory to the specified value
*
@@ -125,39 +127,39 @@ ENTRY(memset)
.Lmemset_loop128:
subs r1, r1, #0x80
#ifdef _ARM_ARCH_5E
- strged r2, [ip], #0x08
- strged r2, [ip], #0x08
- strged r2, [ip], #0x08
- strged r2, [ip], #0x08
- strged r2, [ip], #0x08
- strged r2, [ip], #0x08
- strged r2, [ip], #0x08
- strged r2, [ip], #0x08
- strged r2, [ip], #0x08
- strged r2, [ip], #0x08
- strged r2, [ip], #0x08
- strged r2, [ip], #0x08
- strged r2, [ip], #0x08
- strged r2, [ip], #0x08
- strged r2, [ip], #0x08
- strged r2, [ip], #0x08
+ strdge r2, [ip], #0x08
+ strdge r2, [ip], #0x08
+ strdge r2, [ip], #0x08
+ strdge r2, [ip], #0x08
+ strdge r2, [ip], #0x08
+ strdge r2, [ip], #0x08
+ strdge r2, [ip], #0x08
+ strdge r2, [ip], #0x08
+ strdge r2, [ip], #0x08
+ strdge r2, [ip], #0x08
+ strdge r2, [ip], #0x08
+ strdge r2, [ip], #0x08
+ strdge r2, [ip], #0x08
+ strdge r2, [ip], #0x08
+ strdge r2, [ip], #0x08
+ strdge r2, [ip], #0x08
#else
- stmgeia ip!, {r2-r3}
- stmgeia ip!, {r2-r3}
- stmgeia ip!, {r2-r3}
- stmgeia ip!, {r2-r3}
- stmgeia ip!, {r2-r3}
- stmgeia ip!, {r2-r3}
- stmgeia ip!, {r2-r3}
- stmgeia ip!, {r2-r3}
- stmgeia ip!, {r2-r3}
- stmgeia ip!, {r2-r3}
- stmgeia ip!, {r2-r3}
- stmgeia ip!, {r2-r3}
- stmgeia ip!, {r2-r3}
- stmgeia ip!, {r2-r3}
- stmgeia ip!, {r2-r3}
- stmgeia ip!, {r2-r3}
+ stmiage ip!, {r2-r3}
+ stmiage ip!, {r2-r3}
+ stmiage ip!, {r2-r3}
+ stmiage ip!, {r2-r3}
+ stmiage ip!, {r2-r3}
+ stmiage ip!, {r2-r3}
+ stmiage ip!, {r2-r3}
+ stmiage ip!, {r2-r3}
+ stmiage ip!, {r2-r3}
+ stmiage ip!, {r2-r3}
+ stmiage ip!, {r2-r3}
+ stmiage ip!, {r2-r3}
+ stmiage ip!, {r2-r3}
+ stmiage ip!, {r2-r3}
+ stmiage ip!, {r2-r3}
+ stmiage ip!, {r2-r3}
#endif
bgt .Lmemset_loop128
RETeq /* Zero length so just exit */
@@ -168,15 +170,15 @@ ENTRY(memset)
.Lmemset_loop32:
subs r1, r1, #0x20
#ifdef _ARM_ARCH_5E
- strged r2, [ip], #0x08
- strged r2, [ip], #0x08
- strged r2, [ip], #0x08
- strged r2, [ip], #0x08
+ strdge r2, [ip], #0x08
+ strdge r2, [ip], #0x08
+ strdge r2, [ip], #0x08
+ strdge r2, [ip], #0x08
#else
- stmgeia ip!, {r2-r3}
- stmgeia ip!, {r2-r3}
- stmgeia ip!, {r2-r3}
- stmgeia ip!, {r2-r3}
+ stmiage ip!, {r2-r3}
+ stmiage ip!, {r2-r3}
+ stmiage ip!, {r2-r3}
+ stmiage ip!, {r2-r3}
#endif
bgt .Lmemset_loop32
RETeq /* Zero length so just exit */
@@ -185,11 +187,11 @@ ENTRY(memset)
/* Deal with 16 bytes or more */
#ifdef _ARM_ARCH_5E
- strged r2, [ip], #0x08
- strged r2, [ip], #0x08
+ strdge r2, [ip], #0x08
+ strdge r2, [ip], #0x08
#else
- stmgeia ip!, {r2-r3}
- stmgeia ip!, {r2-r3}
+ stmiage ip!, {r2-r3}
+ stmiage ip!, {r2-r3}
#endif
RETeq /* Zero length so just exit */
@@ -212,17 +214,17 @@ ENTRY(memset)
#endif
strb r3, [ip], #0x01 /* Set 1 byte */
- strgeb r3, [ip], #0x01 /* Set another byte */
- strgtb r3, [ip] /* and a third */
+ strbge r3, [ip], #0x01 /* Set another byte */
+ strbgt r3, [ip] /* and a third */
RET /* Exit */
.Lmemset_wordunaligned:
rsb r2, r2, #0x004
strb r3, [ip], #0x01 /* Set 1 byte */
cmp r2, #0x02
- strgeb r3, [ip], #0x01 /* Set another byte */
+ strbge r3, [ip], #0x01 /* Set another byte */
sub r1, r1, r2
- strgtb r3, [ip], #0x01 /* and a third */
+ strbgt r3, [ip], #0x01 /* and a third */
cmp r1, #0x04 /* More than 4 bytes left? */
bge .Lmemset_wordaligned /* Yup */
@@ -231,8 +233,8 @@ ENTRY(memset)
RETeq /* Zero length so exit */
strb r3, [ip], #0x01 /* Set 1 byte */
cmp r1, #0x02
- strgeb r3, [ip], #0x01 /* Set another byte */
- strgtb r3, [ip] /* and a third */
+ strbge r3, [ip], #0x01 /* Set another byte */
+ strbgt r3, [ip] /* and a third */
RET /* Exit */
#ifdef _BZERO
END(bzero)
diff --git a/lib/libc/arm/string/strlen.S b/lib/libc/arm/string/strlen.S
index 3d7726f..7447710 100644
--- a/lib/libc/arm/string/strlen.S
+++ b/lib/libc/arm/string/strlen.S
@@ -27,6 +27,8 @@
#include <machine/asm.h>
__FBSDID("$FreeBSD$");
+.syntax unified
+
ENTRY(strlen)
mov r1, #0
/* Check that the pointer is aligned on 32 bits. */
@@ -53,23 +55,23 @@ ENTRY(strlen)
addne r1, r1, #1
.Ldo_3:
#ifndef __ARMEB__
- andnes r3, r2, #0x0000ff00
+ andsne r3, r2, #0x0000ff00
#else
- andnes r3, r2, #0x00ff0000
+ andsne r3, r2, #0x00ff0000
#endif
addne r1, r1, #1
.Ldo_2:
#ifndef __ARMEB__
- andnes r3, r2, #0x00ff0000
+ andsne r3, r2, #0x00ff0000
#else
- andnes r3, r2, #0x0000ff00
+ andsne r3, r2, #0x0000ff00
#endif
addne r1, r1, #1
.Ldo_1:
#ifndef __ARMEB__
- andnes r3, r2, #0xff000000
+ andsne r3, r2, #0xff000000
#else
- andnes r3, r2, #0x000000ff
+ andsne r3, r2, #0x000000ff
#endif
addne r1, r1, #1
bne .Loop
diff --git a/lib/libc/arm/sys/Makefile.inc b/lib/libc/arm/sys/Makefile.inc
index 069aad3..60c2dc3 100644
--- a/lib/libc/arm/sys/Makefile.inc
+++ b/lib/libc/arm/sys/Makefile.inc
@@ -1,6 +1,6 @@
# $FreeBSD$
-SRCS+= __vdso_gettc.c
+SRCS+= trivial-vdso_tc.c
MDASM= Ovfork.S brk.S cerror.S pipe.S ptrace.S sbrk.S shmat.S sigreturn.S syscall.S
@@ -8,6 +8,3 @@ MDASM= Ovfork.S brk.S cerror.S pipe.S ptrace.S sbrk.S shmat.S sigreturn.S syscal
NOASM= break.o exit.o getlogin.o openbsd_poll.o sstk.o vfork.o yield.o
PSEUDO= _exit.o _getlogin.o
-.if ${MK_SYSCALL_COMPAT} != "no"
-PSEUDO+= _pread.o _pwrite.o _lseek.o _mmap.o _ftruncate.o _truncate.o
-.endif
diff --git a/lib/libc/arm/sys/brk.S b/lib/libc/arm/sys/brk.S
index f3d8d87..e5f8336 100644
--- a/lib/libc/arm/sys/brk.S
+++ b/lib/libc/arm/sys/brk.S
@@ -53,16 +53,10 @@ _C_LABEL(minbrk):
* Change the data segment size
*/
ENTRY(_brk)
-#ifdef PIC
/* Setup the GOT */
- ldr r3, .Lgot
- add r3, pc, r3
-.L1:
- ldr r1, .Lminbrk
- ldr r1, [r3, r1]
-#else
- ldr r1, .Lminbrk
-#endif
+ GOT_INIT(r3, .Lgot, .L1)
+ GOT_GET(r1, r3, .Lminbrk)
+
/* Get the minimum allowable brk address */
ldr r1, [r1]
@@ -71,6 +65,7 @@ ENTRY(_brk)
* if the address is below minbrk.
*/
cmp r0, r1
+ it lt
movlt r0, r1
mov r2, r0
SYSTRAP(break)
@@ -90,10 +85,7 @@ ENTRY(_brk)
RET
.align 2
-#ifdef PIC
-.Lgot:
- .word _GLOBAL_OFFSET_TABLE_ - (.L1+4)
-#endif
+ GOT_INITSYM(.Lgot, .L1)
.Lminbrk:
.word PIC_SYM(_C_LABEL(minbrk), GOT)
.Lcurbrk:
diff --git a/lib/libc/arm/sys/sbrk.S b/lib/libc/arm/sys/sbrk.S
index 7d22aa7..5cd9a03 100644
--- a/lib/libc/arm/sys/sbrk.S
+++ b/lib/libc/arm/sys/sbrk.S
@@ -52,16 +52,10 @@ CURBRK:
* Change the data segment size
*/
ENTRY(_sbrk)
-#ifdef PIC
/* Setup the GOT */
- ldr r3, .Lgot
- add r3, pc, r3
-.L1:
- ldr r2, .Lcurbrk
- ldr r2, [r3, r2]
-#else
- ldr r2, .Lcurbrk
-#endif
+ GOT_INIT(r3, .Lgot, .L1)
+ GOT_GET(r2, r3, .Lcurbrk)
+
/* Get the current brk address */
ldr r1, [r2]
@@ -80,10 +74,7 @@ ENTRY(_sbrk)
RET
.align 0
-#ifdef PIC
-.Lgot:
- .word _GLOBAL_OFFSET_TABLE_ - (.L1+4)
-#endif
+ GOT_INITSYM(.Lgot, .L1)
.Lcurbrk:
.word PIC_SYM(CURBRK, GOT)
END(_sbrk)
diff --git a/lib/libc/compat-43/creat.c b/lib/libc/compat-43/creat.c
index fc3be06..4545482 100644
--- a/lib/libc/compat-43/creat.c
+++ b/lib/libc/compat-43/creat.c
@@ -36,11 +36,18 @@ __FBSDID("$FreeBSD$");
#include "namespace.h"
#include <fcntl.h>
#include "un-namespace.h"
+#include "libc_private.h"
+__weak_reference(__creat, creat);
+__weak_reference(__creat, _creat);
+
+#pragma weak creat
int
__creat(const char *path, mode_t mode)
{
- return(_open(path, O_WRONLY|O_CREAT|O_TRUNC, mode));
+
+ return (((int (*)(int, const char *, int, ...))
+ __libc_interposing[INTERPOS_openat])(AT_FDCWD, path, O_WRONLY |
+ O_CREAT | O_TRUNC, mode));
}
-__weak_reference(__creat, creat);
-__weak_reference(__creat, _creat);
+
diff --git a/lib/libc/db/hash/hash.c b/lib/libc/db/hash/hash.c
index af80929..e6da5fe 100644
--- a/lib/libc/db/hash/hash.c
+++ b/lib/libc/db/hash/hash.c
@@ -808,7 +808,7 @@ __expand_table(HTAB *hashp)
hashp->DSIZE = dirsize << 1;
}
if ((hashp->dir[new_segnum] =
- (SEGMENT)calloc(hashp->SGSIZE, sizeof(SEGMENT))) == NULL)
+ calloc(hashp->SGSIZE, sizeof(SEGMENT))) == NULL)
return (-1);
hashp->exsegs++;
hashp->nsegs++;
@@ -877,7 +877,7 @@ alloc_segs(HTAB *hashp, int nsegs)
int save_errno;
if ((hashp->dir =
- (SEGMENT *)calloc(hashp->DSIZE, sizeof(SEGMENT *))) == NULL) {
+ calloc(hashp->DSIZE, sizeof(SEGMENT *))) == NULL) {
save_errno = errno;
(void)hdestroy(hashp);
errno = save_errno;
@@ -887,8 +887,7 @@ alloc_segs(HTAB *hashp, int nsegs)
if (nsegs == 0)
return (0);
/* Allocate segments */
- if ((store = (SEGMENT)calloc(nsegs << hashp->SSHIFT,
- sizeof(SEGMENT))) == NULL) {
+ if ((store = calloc(nsegs << hashp->SSHIFT, sizeof(SEGMENT))) == NULL) {
save_errno = errno;
(void)hdestroy(hashp);
errno = save_errno;
diff --git a/lib/libc/db/man/dbm.3 b/lib/libc/db/man/dbm.3
index fabce8a..eedf804 100644
--- a/lib/libc/db/man/dbm.3
+++ b/lib/libc/db/man/dbm.3
@@ -15,7 +15,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd April 16, 2006
+.Dd February 19, 2015
.Dt DBM 3
.Os
.Sh NAME
@@ -174,9 +174,7 @@ deletes the entry for
The
.Fn dbm_delete
function
-normally returns zero but returns 1 if there was no entry with
-.Fa key
-in the database or returns -1 and sets
+normally returns zero or returns -1 and sets
.Va errno
if there were any errors.
.Pp
diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc
index f64caf0..2232b79 100644
--- a/lib/libc/gen/Makefile.inc
+++ b/lib/libc/gen/Makefile.inc
@@ -5,6 +5,7 @@
.PATH: ${LIBC_SRCTOP}/${LIBC_ARCH}/gen ${LIBC_SRCTOP}/gen
SRCS+= __getosreldate.c \
+ __pthread_mutex_init_calloc_cb_stub.c \
__xuname.c \
_once_stub.c \
_pthread_stubs.c \
diff --git a/lib/libc/gen/Symbol.map b/lib/libc/gen/Symbol.map
index 77413d6..ee4d619 100644
--- a/lib/libc/gen/Symbol.map
+++ b/lib/libc/gen/Symbol.map
@@ -487,6 +487,7 @@ FBSDprivate_1.0 {
_rtld_atfork_post;
_rtld_error; /* for private use */
_rtld_get_stack_prot;
+ _rtld_is_dlopened;
_rtld_thread_init; /* for private use */
__elf_phdr_match_addr;
_err;
@@ -532,6 +533,8 @@ FBSDprivate_1.0 {
_libc_sem_post_compat;
_libc_sem_getvalue_compat;
+ __libc_tcdrain;
+
__elf_aux_vector;
__pthread_map_stacks_exec;
__fillcontextx;
diff --git a/lib/libc/gen/__pthread_mutex_init_calloc_cb_stub.c b/lib/libc/gen/__pthread_mutex_init_calloc_cb_stub.c
new file mode 100644
index 0000000..1c566ec
--- /dev/null
+++ b/lib/libc/gen/__pthread_mutex_init_calloc_cb_stub.c
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2014 The FreeBSD Foundation.
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Konstantin Belousov
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * 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(s), this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified other than the possible
+ * addition of one or more copyright notices.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <pthread.h>
+#include "libc_private.h"
+
+int
+_pthread_mutex_init_calloc_cb_stub(pthread_mutex_t *mutex,
+ void *(calloc_cb)(size_t, size_t))
+{
+
+ return (0);
+}
diff --git a/lib/libc/gen/_once_stub.c b/lib/libc/gen/_once_stub.c
index d2acc29..c45565a 100644
--- a/lib/libc/gen/_once_stub.c
+++ b/lib/libc/gen/_once_stub.c
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2009 Advanced Computing Technologies LLC
+ * Copyright (c) 2009 Hudson River Trading LLC
* Written by: John H. Baldwin <jhb@FreeBSD.org>
* All rights reserved.
*
diff --git a/lib/libc/gen/_spinlock_stub.c b/lib/libc/gen/_spinlock_stub.c
index 47bbfeb..3decf8a 100644
--- a/lib/libc/gen/_spinlock_stub.c
+++ b/lib/libc/gen/_spinlock_stub.c
@@ -33,51 +33,48 @@ __FBSDID("$FreeBSD$");
#include <stdio.h>
#include "spinlock.h"
+#include "libc_private.h"
long _atomic_lock_stub(volatile long *);
void _spinlock_stub(spinlock_t *);
void _spinunlock_stub(spinlock_t *);
void _spinlock_debug_stub(spinlock_t *, char *, int);
-/*
- * Declare weak definitions in case the application is not linked
- * with libpthread.
- */
__weak_reference(_atomic_lock_stub, _atomic_lock);
-__weak_reference(_spinlock_stub, _spinlock);
-__weak_reference(_spinunlock_stub, _spinunlock);
-__weak_reference(_spinlock_debug_stub, _spinlock_debug);
-/*
- * This function is a stub for the _atomic_lock function in libpthread.
- */
long
_atomic_lock_stub(volatile long *lck __unused)
{
return (0L);
}
+__weak_reference(_spinlock, _spinlock_debug);
+#pragma weak _spinlock
+void
+_spinlock(spinlock_t *lck)
+{
-/*
- * This function is a stub for the spinlock function in libpthread.
- */
+ ((void (*)(spinlock_t *lck))__libc_interposing[INTERPOS_spinlock])
+ (lck);
+
+}
+
+#pragma weak _spinunlock
void
-_spinlock_stub(spinlock_t *lck __unused)
+_spinunlock(spinlock_t *lck)
{
+
+ ((void (*)(spinlock_t *lck))__libc_interposing[INTERPOS_spinunlock])
+ (lck);
+
}
-/*
- * This function is a stub for the spinunlock function in libpthread.
- */
void
-_spinunlock_stub(spinlock_t *lck __unused)
+__libc_spinlock_stub(spinlock_t *lck __unused)
{
}
-/*
- * This function is a stub for the debug spinlock function in libpthread.
- */
void
-_spinlock_debug_stub(spinlock_t *lck __unused, char *fname __unused, int lineno __unused)
+__libc_spinunlock_stub(spinlock_t *lck __unused)
{
}
diff --git a/lib/libc/gen/cap_rights_get.3 b/lib/libc/gen/cap_rights_get.3
index f74d1f7a..a665465 100644
--- a/lib/libc/gen/cap_rights_get.3
+++ b/lib/libc/gen/cap_rights_get.3
@@ -100,10 +100,10 @@ argument points at an invalid address.
.El
.Sh SEE ALSO
.Xr cap_rights_limit 2 ,
-.Xr cap_rights_init 3 ,
.Xr errno 2 ,
.Xr open 2 ,
.Xr assert 3 ,
+.Xr cap_rights_init 3 ,
.Xr err 3 ,
.Xr memcmp 3 ,
.Xr memset 3 ,
diff --git a/lib/libc/gen/directory.3 b/lib/libc/gen/directory.3
index 1e864f8..f0d0f4b 100644
--- a/lib/libc/gen/directory.3
+++ b/lib/libc/gen/directory.3
@@ -28,7 +28,7 @@
.\" @(#)directory.3 8.1 (Berkeley) 6/4/93
.\" $FreeBSD$
.\"
-.Dd July 28, 2014
+.Dd May 6, 2015
.Dt DIRECTORY 3
.Os
.Sh NAME
@@ -263,8 +263,25 @@ function appeared in
function appeared in
.Fx 10.0 .
.Sh BUGS
-The invalidation of
+The behaviour of
.Fn telldir
-tokens when calling
+and
+.Fn seekdir
+is likely to be wrong if there are parallel unlinks happening
+and the directory is larger than one page.
+There is code to ensure that a
.Fn seekdir
-is non-standard.
+to the location given by a
+.Fn telldir
+immediately before the last
+.Fn readdir
+will always set the correct location to return the same value as that last
+.Fn readdir
+performed.
+This is enough for some applications which want to "push back the last entry read" E.g. Samba.
+Seeks back to any other location,
+other than the beginning of the directory,
+may result in unexpected behaviour if deletes are present.
+It is hoped that this situation will be resolved with changes to
+.Fn getdirentries
+and the VFS.
diff --git a/lib/libc/gen/disklabel.c b/lib/libc/gen/disklabel.c
index bd15a47..8780573 100644
--- a/lib/libc/gen/disklabel.c
+++ b/lib/libc/gen/disklabel.c
@@ -85,10 +85,13 @@ getdiskbyname(const char *name)
cq++, cp++;
*cq = '\0';
- if (cgetstr(buf, "ty", &cq) > 0 && strcmp(cq, "removable") == 0)
- dp->d_flags |= D_REMOVABLE;
- else if (cq && strcmp(cq, "simulated") == 0)
- dp->d_flags |= D_RAMDISK;
+ if (cgetstr(buf, "ty", &cq) > 0) {
+ if (strcmp(cq, "removable") == 0)
+ dp->d_flags |= D_REMOVABLE;
+ else if (cq && strcmp(cq, "simulated") == 0)
+ dp->d_flags |= D_RAMDISK;
+ free(cq);
+ }
if (cgetcap(buf, "sf", ':') != NULL)
dp->d_flags |= D_BADSECT;
@@ -100,9 +103,10 @@ getdiskbyname(const char *name)
getnumdflt(dp->d_nsectors, "ns", 0);
getnumdflt(dp->d_ncylinders, "nc", 0);
- if (cgetstr(buf, "dt", &cq) > 0)
+ if (cgetstr(buf, "dt", &cq) > 0) {
dp->d_type = gettype(cq, dktypenames);
- else
+ free(cq);
+ } else
getnumdflt(dp->d_type, "dt", 0);
getnumdflt(dp->d_secpercyl, "sc", dp->d_nsectors * dp->d_ntracks);
getnumdflt(dp->d_secperunit, "su", dp->d_secpercyl * dp->d_ncylinders);
@@ -140,8 +144,11 @@ getdiskbyname(const char *name)
pp->p_frag = 8;
}
getnumdflt(pp->p_fstype, ptype, 0);
- if (pp->p_fstype == 0 && cgetstr(buf, ptype, &cq) > 0)
- pp->p_fstype = gettype(cq, fstypenames);
+ if (pp->p_fstype == 0)
+ if (cgetstr(buf, ptype, &cq) >= 0) {
+ pp->p_fstype = gettype(cq, fstypenames);
+ free(cq);
+ }
max = p;
}
}
diff --git a/lib/libc/gen/dlfcn.c b/lib/libc/gen/dlfcn.c
index ad24bb4..7d28797 100644
--- a/lib/libc/gen/dlfcn.c
+++ b/lib/libc/gen/dlfcn.c
@@ -149,10 +149,8 @@ static void
dl_init_phdr_info(void)
{
Elf_Auxinfo *auxp;
- size_t phent;
unsigned int i;
- phent = 0;
for (auxp = __elf_aux_vector; auxp->a_type != AT_NULL; auxp++) {
switch (auxp->a_type) {
case AT_BASE:
@@ -165,9 +163,6 @@ dl_init_phdr_info(void)
phdr_info.dlpi_phdr =
(const Elf_Phdr *)auxp->a_un.a_ptr;
break;
- case AT_PHENT:
- phent = auxp->a_un.a_val;
- break;
case AT_PHNUM:
phdr_info.dlpi_phnum = (Elf_Half)auxp->a_un.a_val;
break;
@@ -233,3 +228,10 @@ _rtld_get_stack_prot(void)
return (PROT_EXEC | PROT_READ | PROT_WRITE);
}
+#pragma weak _rtld_is_dlopened
+int
+_rtld_is_dlopened(void *arg)
+{
+
+ return (0);
+}
diff --git a/lib/libc/gen/dlopen.3 b/lib/libc/gen/dlopen.3
index 089e631..1963528 100644
--- a/lib/libc/gen/dlopen.3
+++ b/lib/libc/gen/dlopen.3
@@ -32,7 +32,7 @@
.\" @(#) dlopen.3 1.6 90/01/31 SMI
.\" $FreeBSD$
.\"
-.Dd December 21, 2011
+.Dd February 14, 2015
.Dt DLOPEN 3
.Os
.Sh NAME
@@ -236,7 +236,7 @@ as follows, in the given order:
The referencing object itself (or the object from which the call to
.Fn dlsym
is made), if that object was linked using the
-.Fl Wsymbolic
+.Fl Bsymbolic
option to
.Xr ld 1 .
.It
diff --git a/lib/libc/gen/fstab.c b/lib/libc/gen/fstab.c
index 6a77abd..c21ceb3 100644
--- a/lib/libc/gen/fstab.c
+++ b/lib/libc/gen/fstab.c
@@ -181,7 +181,7 @@ fstabscan(void)
if (cp != NULL)
_fs_fstab.fs_passno = atoi(cp);
}
- strcpy(subline, _fs_fstab.fs_mntops);
+ (void)strlcpy(subline, _fs_fstab.fs_mntops, sizeof(subline));
p = subline;
for (typexx = 0, cp = strsep(&p, ","); cp;
cp = strsep(&p, ",")) {
diff --git a/lib/libc/gen/ftok.3 b/lib/libc/gen/ftok.3
index 98f8bad..b819dbd 100644
--- a/lib/libc/gen/ftok.3
+++ b/lib/libc/gen/ftok.3
@@ -64,9 +64,9 @@ function will return -1 if
.Fa path
does not exist or if it cannot be accessed by the calling process.
.Sh SEE ALSO
+.Xr msgget 2 ,
.Xr semget 2 ,
-.Xr shmget 2 ,
-.Xr msgget 2
+.Xr shmget 2
.Sh HISTORY
The
.Fn ftok
diff --git a/lib/libc/gen/fts.c b/lib/libc/gen/fts.c
index 7635fbc..1ca8334 100644
--- a/lib/libc/gen/fts.c
+++ b/lib/libc/gen/fts.c
@@ -905,12 +905,13 @@ fts_stat(FTS *sp, FTSENT *p, int follow, int dfd)
if (ISSET(FTS_LOGICAL) || follow) {
if (fstatat(dfd, path, sbp, 0)) {
saved_errno = errno;
- if (!fstatat(dfd, path, sbp, AT_SYMLINK_NOFOLLOW)) {
- errno = 0;
- return (FTS_SLNONE);
+ if (fstatat(dfd, path, sbp, AT_SYMLINK_NOFOLLOW)) {
+ p->fts_errno = saved_errno;
+ goto err;
}
- p->fts_errno = saved_errno;
- goto err;
+ errno = 0;
+ if (S_ISLNK(sbp->st_mode))
+ return (FTS_SLNONE);
}
} else if (fstatat(dfd, path, sbp, AT_SYMLINK_NOFOLLOW)) {
p->fts_errno = errno;
diff --git a/lib/libc/gen/ftw.3 b/lib/libc/gen/ftw.3
index ba8859b..df8abab 100644
--- a/lib/libc/gen/ftw.3
+++ b/lib/libc/gen/ftw.3
@@ -87,8 +87,9 @@ A directory which cannot be read.
The directory will not be descended into.
.It Dv FTW_DP
A directory being visited in post-order
-.Fn ( nftw
-only).
+.Po Fn nftw
+only
+.Pc .
.It Dv FTW_NS
A file for which no
.Xr stat 2
@@ -100,8 +101,9 @@ structure are undefined.
A symbolic link.
.It Dv FTW_SLN
A symbolic link with a non-existent target
-.Fn ( nftw
-only).
+.Po Fn nftw
+only
+.Pc .
.El
.Pp
The
diff --git a/lib/libc/gen/getcap.3 b/lib/libc/gen/getcap.3
index 73826ae..c3a9ce8 100644
--- a/lib/libc/gen/getcap.3
+++ b/lib/libc/gen/getcap.3
@@ -137,9 +137,10 @@ It must be called before the
call.
If a sequential access is being performed (see below), it must be called
before the first sequential access call
-.Fn ( cgetfirst
+.Po Fn cgetfirst
or
-.Fn cgetnext ) ,
+.Fn cgetnext
+.Pc ,
or be directly preceded by a
.Fn cgetclose
call.
diff --git a/lib/libc/gen/getgrent.c b/lib/libc/gen/getgrent.c
index f9480c3..1f4d7e9 100644
--- a/lib/libc/gen/getgrent.c
+++ b/lib/libc/gen/getgrent.c
@@ -896,7 +896,7 @@ files_group(void *retval, void *mdata, va_list ap)
break;
pos = ftello(st->fp);
}
- if (!stayopen && st->fp != NULL) {
+ if (st->fp != NULL && !stayopen) {
fclose(st->fp);
st->fp = NULL;
}
@@ -1173,8 +1173,10 @@ nis_group(void *retval, void *mdata, va_list ap)
* terminator, alignment padding, and one (char *)
* pointer for the member list terminator.
*/
- if (resultlen >= bufsize - _ALIGNBYTES - sizeof(char *))
+ if (resultlen >= bufsize - _ALIGNBYTES - sizeof(char *)) {
+ free(result);
goto erange;
+ }
memcpy(buffer, result, resultlen);
buffer[resultlen] = '\0';
free(result);
@@ -1450,7 +1452,7 @@ docompat:
pos = ftello(st->fp);
}
fin:
- if (!stayopen && st->fp != NULL) {
+ if (st->fp != NULL && !stayopen) {
fclose(st->fp);
st->fp = NULL;
}
diff --git a/lib/libc/gen/getpwent.c b/lib/libc/gen/getpwent.c
index f729cdf..09a6247 100644
--- a/lib/libc/gen/getpwent.c
+++ b/lib/libc/gen/getpwent.c
@@ -815,7 +815,7 @@ files_passwd(void *retval, void *mdata, va_list ap)
size_t bufsize, namesize;
uid_t uid;
uint32_t store;
- int rv, stayopen, *errnop;
+ int rv, stayopen = 0, *errnop;
name = NULL;
uid = (uid_t)-1;
@@ -921,7 +921,7 @@ files_passwd(void *retval, void *mdata, va_list ap)
errnop);
} while (how == nss_lt_all && !(rv & NS_TERMINATE));
fin:
- if (!stayopen && st->db != NULL) {
+ if (st->db != NULL && !stayopen) {
(void)st->db->close(st->db);
st->db = NULL;
}
@@ -1392,8 +1392,10 @@ nis_passwd(void *retval, void *mdata, va_list ap)
continue;
}
}
- if (resultlen >= bufsize)
+ if (resultlen >= bufsize) {
+ free(result);
goto erange;
+ }
memcpy(buffer, result, resultlen);
buffer[resultlen] = '\0';
free(result);
@@ -1940,7 +1942,7 @@ docompat:
break;
}
fin:
- if (!stayopen && st->db != NULL) {
+ if (st->db != NULL && !stayopen) {
(void)st->db->close(st->db);
st->db = NULL;
}
diff --git a/lib/libc/gen/getutxent.3 b/lib/libc/gen/getutxent.3
index 120f4a0..85c37b1 100644
--- a/lib/libc/gen/getutxent.3
+++ b/lib/libc/gen/getutxent.3
@@ -475,4 +475,4 @@ They replaced the
.In utmp.h
interface.
.Sh AUTHORS
-.An Ed Schouten Aq Mt ed@FreeBSD.org
+.An \&Ed Schouten Aq Mt ed@FreeBSD.org
diff --git a/lib/libc/gen/nice.3 b/lib/libc/gen/nice.3
index 9c39b78..b04c8f4 100644
--- a/lib/libc/gen/nice.3
+++ b/lib/libc/gen/nice.3
@@ -28,7 +28,7 @@
.\" @(#)nice.3 8.1 (Berkeley) 6/4/93
.\" $FreeBSD$
.\"
-.Dd June 4, 1993
+.Dd February 28, 2015
.Dt NICE 3
.Os
.Sh NAME
@@ -48,20 +48,48 @@ This interface is obsoleted by
.Pp
The
.Fn nice
-function obtains the scheduling priority of the process
-from the system and sets it to the priority value specified in
-.Fa incr .
+function adds
+.Fa incr
+to the scheduling priority of the process.
The priority is a value in the range -20 to 20.
The default priority is 0; lower priorities cause more favorable scheduling.
Only the super-user may lower priorities.
.Pp
Children inherit the priority of their parent processes via
.Xr fork 2 .
+.Sh RETURN VALUES
+Upon successful completion,
+.Fn nice
+returns 0, and
+.Va errno
+is unchanged.
+Otherwise, \-1 is returned, the process' nice value is not changed, and
+.Va errno
+is set to indicate the error.
+.Sh ERRORS
+The
+.Fn nice
+function will fail if:
+.Bl -tag -width Er
+.It Bq Er EPERM
+The
+.Fa incr
+argument is negative and the caller does not have appropriate privileges.
+.El
.Sh SEE ALSO
.Xr nice 1 ,
.Xr fork 2 ,
.Xr setpriority 2 ,
.Xr renice 8
+.Sh STANDARDS
+The
+.Fn nice
+function conforms to
+.St -p1003.1-2008
+except for the return value.
+This implementation returns 0 upon successful completion but
+the standard requires returning the new nice value,
+which could be \-1.
.Sh HISTORY
A
.Fn nice
diff --git a/lib/libc/gen/nice.c b/lib/libc/gen/nice.c
index e8375e8..ba9524b 100644
--- a/lib/libc/gen/nice.c
+++ b/lib/libc/gen/nice.c
@@ -43,14 +43,20 @@ __FBSDID("$FreeBSD$");
* Backwards compatible nice.
*/
int
-nice(incr)
- int incr;
+nice(int incr)
{
- int prio;
+ int saverrno, prio;
+ saverrno = errno;
errno = 0;
prio = getpriority(PRIO_PROCESS, 0);
- if (prio == -1 && errno)
+ if (prio == -1 && errno != 0)
return (-1);
- return (setpriority(PRIO_PROCESS, 0, prio + incr));
+ if (setpriority(PRIO_PROCESS, 0, prio + incr) == -1) {
+ if (errno == EACCES)
+ errno = EPERM;
+ return (-1);
+ }
+ errno = saverrno;
+ return (0);
}
diff --git a/lib/libc/gen/nlist.c b/lib/libc/gen/nlist.c
index bdadd55..ec878c5 100644
--- a/lib/libc/gen/nlist.c
+++ b/lib/libc/gen/nlist.c
@@ -47,7 +47,10 @@ __FBSDID("$FreeBSD$");
#include <unistd.h>
#include "un-namespace.h"
+/* There is no a.out support on arm64 */
+#ifndef __aarch64__
#define _NLIST_DO_AOUT
+#endif
#define _NLIST_DO_ELF
#ifdef _NLIST_DO_ELF
diff --git a/lib/libc/gen/pause.c b/lib/libc/gen/pause.c
index 51706cf..ef48c1c 100644
--- a/lib/libc/gen/pause.c
+++ b/lib/libc/gen/pause.c
@@ -33,10 +33,10 @@ static char sccsid[] = "@(#)pause.c 8.1 (Berkeley) 6/4/93";
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
-#include "namespace.h"
#include <signal.h>
#include <unistd.h>
-#include "un-namespace.h"
+
+#include "libc_private.h"
/*
* Backwards compatible pause.
@@ -46,9 +46,10 @@ __pause(void)
{
sigset_t oset;
- if (_sigprocmask(SIG_BLOCK, NULL, &oset) == -1)
+ if (sigprocmask(SIG_BLOCK, NULL, &oset) == -1)
return (-1);
- return (_sigsuspend(&oset));
+ return (sigsuspend(&oset));
}
+
__weak_reference(__pause, pause);
__weak_reference(__pause, _pause);
diff --git a/lib/libc/gen/posix_spawn.3 b/lib/libc/gen/posix_spawn.3
index dd5bd2b..2c9131b 100644
--- a/lib/libc/gen/posix_spawn.3
+++ b/lib/libc/gen/posix_spawn.3
@@ -413,6 +413,10 @@ including trying to close a descriptor that is not open.
.Xr execve 2 ,
.Xr fcntl 2 ,
.Xr open 2 ,
+.Xr sched_setparam 2 ,
+.Xr sched_setscheduler 2 ,
+.Xr setpgid 2 ,
+.Xr vfork 2 ,
.Xr posix_spawn_file_actions_addclose 3 ,
.Xr posix_spawn_file_actions_adddup2 3 ,
.Xr posix_spawn_file_actions_addopen 3 ,
@@ -431,11 +435,7 @@ including trying to close a descriptor that is not open.
.Xr posix_spawnattr_setschedparam 3 ,
.Xr posix_spawnattr_setschedpolicy 3 ,
.Xr posix_spawnattr_setsigdefault 3 ,
-.Xr posix_spawnattr_setsigmask 3 ,
-.Xr sched_setparam 2 ,
-.Xr sched_setscheduler 2 ,
-.Xr setpgid 2 ,
-.Xr vfork 2
+.Xr posix_spawnattr_setsigmask 3
.Sh STANDARDS
The
.Fn posix_spawn
@@ -457,4 +457,4 @@ and
functions first appeared in
.Fx 8.0 .
.Sh AUTHORS
-.An Ed Schouten Aq Mt ed@FreeBSD.org
+.An \&Ed Schouten Aq Mt ed@FreeBSD.org
diff --git a/lib/libc/gen/posix_spawn_file_actions_addopen.3 b/lib/libc/gen/posix_spawn_file_actions_addopen.3
index b28f396..0b57999b 100644
--- a/lib/libc/gen/posix_spawn_file_actions_addopen.3
+++ b/lib/libc/gen/posix_spawn_file_actions_addopen.3
@@ -200,4 +200,4 @@ and
functions first appeared in
.Fx 8.0 .
.Sh AUTHORS
-.An Ed Schouten Aq Mt ed@FreeBSD.org
+.An \&Ed Schouten Aq Mt ed@FreeBSD.org
diff --git a/lib/libc/gen/posix_spawn_file_actions_init.3 b/lib/libc/gen/posix_spawn_file_actions_init.3
index eda2a1d..380eed7 100644
--- a/lib/libc/gen/posix_spawn_file_actions_init.3
+++ b/lib/libc/gen/posix_spawn_file_actions_init.3
@@ -101,4 +101,4 @@ and
functions first appeared in
.Fx 8.0 .
.Sh AUTHORS
-.An Ed Schouten Aq Mt ed@FreeBSD.org
+.An \&Ed Schouten Aq Mt ed@FreeBSD.org
diff --git a/lib/libc/gen/posix_spawnattr_getflags.3 b/lib/libc/gen/posix_spawnattr_getflags.3
index b5995ce..2571f4a 100644
--- a/lib/libc/gen/posix_spawnattr_getflags.3
+++ b/lib/libc/gen/posix_spawnattr_getflags.3
@@ -108,4 +108,4 @@ and
functions first appeared in
.Fx 8.0 .
.Sh AUTHORS
-.An Ed Schouten Aq Mt ed@FreeBSD.org
+.An \&Ed Schouten Aq Mt ed@FreeBSD.org
diff --git a/lib/libc/gen/posix_spawnattr_getpgroup.3 b/lib/libc/gen/posix_spawnattr_getpgroup.3
index 91b3e5c..cfc1b54 100644
--- a/lib/libc/gen/posix_spawnattr_getpgroup.3
+++ b/lib/libc/gen/posix_spawnattr_getpgroup.3
@@ -93,4 +93,4 @@ and
functions first appeared in
.Fx 8.0 .
.Sh AUTHORS
-.An Ed Schouten Aq Mt ed@FreeBSD.org
+.An \&Ed Schouten Aq Mt ed@FreeBSD.org
diff --git a/lib/libc/gen/posix_spawnattr_getschedparam.3 b/lib/libc/gen/posix_spawnattr_getschedparam.3
index a137200..5eef96e 100644
--- a/lib/libc/gen/posix_spawnattr_getschedparam.3
+++ b/lib/libc/gen/posix_spawnattr_getschedparam.3
@@ -97,4 +97,4 @@ and
functions first appeared in
.Fx 8.0 .
.Sh AUTHORS
-.An Ed Schouten Aq Mt ed@FreeBSD.org
+.An \&Ed Schouten Aq Mt ed@FreeBSD.org
diff --git a/lib/libc/gen/posix_spawnattr_getschedpolicy.3 b/lib/libc/gen/posix_spawnattr_getschedpolicy.3
index 3e79d4b..5276de5 100644
--- a/lib/libc/gen/posix_spawnattr_getschedpolicy.3
+++ b/lib/libc/gen/posix_spawnattr_getschedpolicy.3
@@ -95,4 +95,4 @@ and
functions first appeared in
.Fx 8.0 .
.Sh AUTHORS
-.An Ed Schouten Aq Mt ed@FreeBSD.org
+.An \&Ed Schouten Aq Mt ed@FreeBSD.org
diff --git a/lib/libc/gen/posix_spawnattr_getsigdefault.3 b/lib/libc/gen/posix_spawnattr_getsigdefault.3
index 8878332..a81c714 100644
--- a/lib/libc/gen/posix_spawnattr_getsigdefault.3
+++ b/lib/libc/gen/posix_spawnattr_getsigdefault.3
@@ -95,4 +95,4 @@ and
functions first appeared in
.Fx 8.0 .
.Sh AUTHORS
-.An Ed Schouten Aq Mt ed@FreeBSD.org
+.An \&Ed Schouten Aq Mt ed@FreeBSD.org
diff --git a/lib/libc/gen/posix_spawnattr_getsigmask.3 b/lib/libc/gen/posix_spawnattr_getsigmask.3
index 4f9c014..be15d9d 100644
--- a/lib/libc/gen/posix_spawnattr_getsigmask.3
+++ b/lib/libc/gen/posix_spawnattr_getsigmask.3
@@ -95,4 +95,4 @@ and
functions first appeared in
.Fx 8.0 .
.Sh AUTHORS
-.An Ed Schouten Aq Mt ed@FreeBSD.org
+.An \&Ed Schouten Aq Mt ed@FreeBSD.org
diff --git a/lib/libc/gen/posix_spawnattr_init.3 b/lib/libc/gen/posix_spawnattr_init.3
index 388fe5a..b4ec52c 100644
--- a/lib/libc/gen/posix_spawnattr_init.3
+++ b/lib/libc/gen/posix_spawnattr_init.3
@@ -120,4 +120,4 @@ and
functions first appeared in
.Fx 8.0 .
.Sh AUTHORS
-.An Ed Schouten Aq Mt ed@FreeBSD.org
+.An \&Ed Schouten Aq Mt ed@FreeBSD.org
diff --git a/lib/libc/gen/raise.c b/lib/libc/gen/raise.c
index b3d0aae..994fea5 100644
--- a/lib/libc/gen/raise.c
+++ b/lib/libc/gen/raise.c
@@ -36,11 +36,17 @@ __FBSDID("$FreeBSD$");
#include <signal.h>
#include <unistd.h>
+#include "libc_private.h"
+
__weak_reference(__raise, raise);
__weak_reference(__raise, _raise);
int
__raise(int s)
{
- return(kill(getpid(), s));
+ long id;
+
+ if (__sys_thr_self(&id) == -1)
+ return (-1);
+ return (__sys_thr_kill(id, s));
}
diff --git a/lib/libc/gen/readdir.c b/lib/libc/gen/readdir.c
index 69f59d1..c6f5d3f 100644
--- a/lib/libc/gen/readdir.c
+++ b/lib/libc/gen/readdir.c
@@ -54,19 +54,25 @@ _readdir_unlocked(dirp, skip)
int skip;
{
struct dirent *dp;
+ long initial_seek;
+ long initial_loc = 0;
for (;;) {
if (dirp->dd_loc >= dirp->dd_size) {
if (dirp->dd_flags & __DTF_READALL)
return (NULL);
+ initial_loc = dirp->dd_loc;
+ dirp->dd_flags &= ~__DTF_SKIPREAD;
dirp->dd_loc = 0;
}
if (dirp->dd_loc == 0 &&
!(dirp->dd_flags & (__DTF_READALL | __DTF_SKIPREAD))) {
+ initial_seek = dirp->dd_seek;
dirp->dd_size = _getdirentries(dirp->dd_fd,
dirp->dd_buf, dirp->dd_len, &dirp->dd_seek);
if (dirp->dd_size <= 0)
return (NULL);
+ _fixtelldir(dirp, initial_seek, initial_loc);
}
dirp->dd_flags &= ~__DTF_SKIPREAD;
dp = (struct dirent *)(dirp->dd_buf + dirp->dd_loc);
diff --git a/lib/libc/gen/rewinddir.c b/lib/libc/gen/rewinddir.c
index 193f4b0..e157cd6 100644
--- a/lib/libc/gen/rewinddir.c
+++ b/lib/libc/gen/rewinddir.c
@@ -51,6 +51,7 @@ rewinddir(dirp)
if (__isthreaded)
_pthread_mutex_lock(&dirp->dd_lock);
+ dirp->dd_flags &= ~__DTF_SKIPREAD; /* current contents are invalid */
if (dirp->dd_flags & __DTF_READALL)
_filldir(dirp, false);
else {
diff --git a/lib/libc/gen/scandir.3 b/lib/libc/gen/scandir.3
index eaba754..aa8dea0 100644
--- a/lib/libc/gen/scandir.3
+++ b/lib/libc/gen/scandir.3
@@ -92,7 +92,7 @@ by freeing each pointer in the array and then the array itself.
.Pp
The
.Fn scandir_b
-function behaves in the same way as
+function behaves in the same way as
.Fn scandir ,
but takes blocks as arguments instead of function pointers and calls
.Fn qsort_b
@@ -106,8 +106,8 @@ cannot allocate enough memory to hold all the data structures.
.Xr directory 3 ,
.Xr malloc 3 ,
.Xr qsort 3 ,
-.Xr dir 5 ,
-.Xr strcoll 3
+.Xr strcoll 3 ,
+.Xr dir 5
.Sh HISTORY
The
.Fn scandir
diff --git a/lib/libc/gen/sem_new.c b/lib/libc/gen/sem_new.c
index 3ee0272..c5dc7e7 100644
--- a/lib/libc/gen/sem_new.c
+++ b/lib/libc/gen/sem_new.c
@@ -439,8 +439,10 @@ _sem_post(sem_t *sem)
do {
count = sem->_kern._count;
- if (USEM_COUNT(count) + 1 > SEM_VALUE_MAX)
- return (EOVERFLOW);
+ if (USEM_COUNT(count) + 1 > SEM_VALUE_MAX) {
+ errno = EOVERFLOW;
+ return (-1);
+ }
} while (!atomic_cmpset_rel_int(&sem->_kern._count, count, count + 1));
if (count & USEM_HAS_WAITERS)
usem_wake(&sem->_kern);
diff --git a/lib/libc/gen/sem_post.3 b/lib/libc/gen/sem_post.3
index 485d2fc..dea8eb6 100644
--- a/lib/libc/gen/sem_post.3
+++ b/lib/libc/gen/sem_post.3
@@ -27,7 +27,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd February 15, 2000
+.Dd January 28, 2015
.Dt SEM_POST 3
.Os
.Sh NAME
@@ -65,6 +65,9 @@ The
.Fa sem
argument
points to an invalid semaphore.
+.It Bq Er EOVERFLOW
+The semaphore value would exceed
+.Dv SEM_VALUE_MAX .
.El
.Sh SEE ALSO
.Xr sem_getvalue 3 ,
diff --git a/lib/libc/gen/setmode.3 b/lib/libc/gen/setmode.3
index 5cab44a..684c2e1 100644
--- a/lib/libc/gen/setmode.3
+++ b/lib/libc/gen/setmode.3
@@ -28,7 +28,7 @@
.\" @(#)setmode.3 8.2 (Berkeley) 4/28/95
.\" $FreeBSD$
.\"
-.Dd April 28, 1995
+.Dd February 22, 2015
.Dt SETMODE 3
.Os
.Sh NAME
@@ -99,7 +99,20 @@ The
function
may fail and set errno for any of the errors specified for the library
routine
-.Xr malloc 3 .
+.Xr malloc 3
+or
+.Xr strtol 3 .
+In addition,
+.Fn setmode
+will fail and set
+.Va errno
+to:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+The
+.Fa mode
+argument does not represent a valid mode.
+.El
.Sh SEE ALSO
.Xr chmod 1 ,
.Xr stat 2 ,
diff --git a/lib/libc/gen/setmode.c b/lib/libc/gen/setmode.c
index 3966fd0..815cf14 100644
--- a/lib/libc/gen/setmode.c
+++ b/lib/libc/gen/setmode.c
@@ -39,8 +39,11 @@ __FBSDID("$FreeBSD$");
#include "namespace.h"
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/sysctl.h>
#include <ctype.h>
+#include <errno.h>
+#include <limits.h>
#include <signal.h>
#include <stddef.h>
#include <stdlib.h>
@@ -66,7 +69,8 @@ typedef struct bitcmd {
#define CMD2_OBITS 0x08
#define CMD2_UBITS 0x10
-static BITCMD *addcmd(BITCMD *, int, int, int, u_int);
+static mode_t getumask(void);
+static BITCMD *addcmd(BITCMD *, mode_t, mode_t, mode_t, mode_t);
static void compress_mode(BITCMD *);
#ifdef SETMODE_DEBUG
static void dumpmode(BITCMD *);
@@ -151,45 +155,37 @@ common: if (set->cmd2 & CMD2_CLR) {
BITCMD *newset; \
setlen += SET_LEN_INCR; \
newset = realloc(saveset, sizeof(BITCMD) * setlen); \
- if (!newset) { \
- if (saveset) \
- free(saveset); \
- saveset = NULL; \
- return (NULL); \
- } \
+ if (newset == NULL) \
+ goto out; \
set = newset + (set - saveset); \
saveset = newset; \
endset = newset + (setlen - 2); \
} \
- set = addcmd(set, (a), (b), (c), (d))
+ set = addcmd(set, (mode_t)(a), (mode_t)(b), (mode_t)(c), (d))
#define STANDARD_BITS (S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO)
void *
setmode(const char *p)
{
- int perm, who;
+ int serrno;
char op, *ep;
BITCMD *set, *saveset, *endset;
- sigset_t sigset, sigoset;
- mode_t mask;
- int equalopdone=0, permXbits, setlen;
+ mode_t mask, perm, permXbits, who;
long perml;
+ int equalopdone;
+ int setlen;
- if (!*p)
+ if (!*p) {
+ errno = EINVAL;
return (NULL);
+ }
/*
* Get a copy of the mask for the permissions that are mask relative.
- * Flip the bits, we want what's not set. Since it's possible that
- * the caller is opening files inside a signal handler, protect them
- * as best we can.
+ * Flip the bits, we want what's not set.
*/
- sigfillset(&sigset);
- (void)_sigprocmask(SIG_BLOCK, &sigset, &sigoset);
- (void)umask(mask = umask(0));
- mask = ~mask;
- (void)_sigprocmask(SIG_SETMASK, &sigoset, NULL);
+ mask = ~getumask();
setlen = SET_LEN + 2;
@@ -203,10 +199,17 @@ setmode(const char *p)
* or illegal bits.
*/
if (isdigit((unsigned char)*p)) {
+ errno = 0;
perml = strtol(p, &ep, 8);
- if (*ep || perml < 0 || perml & ~(STANDARD_BITS|S_ISTXT)) {
- free(saveset);
- return (NULL);
+ if (*ep) {
+ errno = EINVAL;
+ goto out;
+ }
+ if (errno == ERANGE && (perml == LONG_MAX || perml == LONG_MIN))
+ goto out;
+ if (perml & ~(STANDARD_BITS|S_ISTXT)) {
+ errno = EINVAL;
+ goto out;
}
perm = (mode_t)perml;
ADDCMD('=', (STANDARD_BITS|S_ISTXT), perm, mask);
@@ -218,6 +221,7 @@ setmode(const char *p)
* Build list of structures to set/clear/copy bits as described by
* each clause of the symbolic mode.
*/
+ equalopdone = 0;
for (;;) {
/* First, find out which bits might be modified. */
for (who = 0;; ++p) {
@@ -240,8 +244,8 @@ setmode(const char *p)
}
getop: if ((op = *p++) != '+' && op != '-' && op != '=') {
- free(saveset);
- return (NULL);
+ errno = EINVAL;
+ goto out;
}
if (op == '=')
equalopdone = 0;
@@ -330,10 +334,44 @@ apply: if (!*p)
dumpmode(saveset);
#endif
return (saveset);
+out:
+ serrno = errno;
+ free(saveset);
+ errno = serrno;
+ return NULL;
+}
+
+static mode_t
+getumask(void)
+{
+ sigset_t sigset, sigoset;
+ size_t len;
+ mode_t mask;
+ u_short smask;
+
+ /*
+ * First try requesting the umask without temporarily modifying it.
+ * Note that this does not work if the sysctl
+ * security.bsd.unprivileged_proc_debug is set to 0.
+ */
+ len = sizeof(smask);
+ if (sysctl((int[4]){ CTL_KERN, KERN_PROC, KERN_PROC_UMASK, getpid() },
+ 4, &smask, &len, NULL, 0) == 0)
+ return (smask);
+
+ /*
+ * Since it's possible that the caller is opening files inside a signal
+ * handler, protect them as best we can.
+ */
+ sigfillset(&sigset);
+ (void)_sigprocmask(SIG_BLOCK, &sigset, &sigoset);
+ (void)umask(mask = umask(0));
+ (void)_sigprocmask(SIG_SETMASK, &sigoset, NULL);
+ return (mask);
}
static BITCMD *
-addcmd(BITCMD *set, int op, int who, int oparg, u_int mask)
+addcmd(BITCMD *set, mode_t op, mode_t who, mode_t oparg, mode_t mask)
{
switch (op) {
case '=':
diff --git a/lib/libc/gen/setproctitle.c b/lib/libc/gen/setproctitle.c
index cd705fb..9dff328 100644
--- a/lib/libc/gen/setproctitle.c
+++ b/lib/libc/gen/setproctitle.c
@@ -42,9 +42,10 @@ __FBSDID("$FreeBSD$");
* 1: old_ps_strings at the very top of the stack.
* 2: old_ps_strings at SPARE_USRSPACE below the top of the stack.
* 3: ps_strings at the very top of the stack.
- * This attempts to support a kernel built in the #2 and #3 era.
- */
-
+ * We only support a kernel providing #3 style ps_strings.
+ *
+ * For historical purposes, a definition of the old ps_strings structure
+ * and location is preserved below:
struct old_ps_strings {
char *old_ps_argvstr;
int old_ps_nargvstr;
@@ -53,6 +54,7 @@ struct old_ps_strings {
};
#define OLD_PS_STRINGS ((struct old_ps_strings *) \
(USRSTACK - SPARE_USRSPACE - sizeof(struct old_ps_strings)))
+ */
#include <stdarg.h>
@@ -136,41 +138,38 @@ setproctitle(const char *fmt, ...)
ps_strings = (struct ps_strings *)ul_ps_strings;
}
- /* PS_STRINGS points to zeroed memory on a style #2 kernel */
- if (ps_strings->ps_argvstr) {
- /* style #3 */
- if (oargc == -1) {
- /* Record our original args */
- oargc = ps_strings->ps_nargvstr;
- oargv = ps_strings->ps_argvstr;
- for (i = len = 0; i < oargc; i++) {
- /*
- * The program may have scribbled into its
- * argv array, e.g., to remove some arguments.
- * If that has happened, break out before
- * trying to call strlen on a NULL pointer.
- */
- if (oargv[i] == NULL) {
- oargc = i;
- break;
- }
- snprintf(obuf + len, SPT_BUFSIZE - len, "%s%s",
- len ? " " : "", oargv[i]);
- if (len)
- len++;
- len += strlen(oargv[i]);
- if (len >= SPT_BUFSIZE)
- break;
+ /*
+ * PS_STRINGS points to zeroed memory on a style #2 kernel.
+ * Should not happen.
+ */
+ if (ps_strings->ps_argvstr == NULL)
+ return;
+
+ /* style #3 */
+ if (oargc == -1) {
+ /* Record our original args */
+ oargc = ps_strings->ps_nargvstr;
+ oargv = ps_strings->ps_argvstr;
+ for (i = len = 0; i < oargc; i++) {
+ /*
+ * The program may have scribbled into its
+ * argv array, e.g., to remove some arguments.
+ * If that has happened, break out before
+ * trying to call strlen on a NULL pointer.
+ */
+ if (oargv[i] == NULL) {
+ oargc = i;
+ break;
}
+ snprintf(obuf + len, SPT_BUFSIZE - len, "%s%s",
+ len != 0 ? " " : "", oargv[i]);
+ if (len != 0)
+ len++;
+ len += strlen(oargv[i]);
+ if (len >= SPT_BUFSIZE)
+ break;
}
- ps_strings->ps_nargvstr = nargc;
- ps_strings->ps_argvstr = nargvp;
- } else {
- /* style #2 - we can only restore our first arg :-( */
- if (*obuf == '\0')
- strncpy(obuf, OLD_PS_STRINGS->old_ps_argvstr,
- SPT_BUFSIZE - 1);
- OLD_PS_STRINGS->old_ps_nargvstr = 1;
- OLD_PS_STRINGS->old_ps_argvstr = nargvp[0];
}
+ ps_strings->ps_nargvstr = nargc;
+ ps_strings->ps_argvstr = nargvp;
}
diff --git a/lib/libc/gen/sleep.3 b/lib/libc/gen/sleep.3
index ecfa237..00e8f8d 100644
--- a/lib/libc/gen/sleep.3
+++ b/lib/libc/gen/sleep.3
@@ -33,7 +33,7 @@
.Os
.Sh NAME
.Nm sleep
-.Nd suspend process execution for an interval measured in seconds
+.Nd suspend thread execution for an interval measured in seconds
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
@@ -43,11 +43,11 @@
.Sh DESCRIPTION
The
.Fn sleep
-function suspends execution of the calling process until either
+function suspends execution of the calling thread until either
.Fa seconds
-seconds have elapsed or a signal is delivered to the process and its
+seconds have elapsed or a signal is delivered to the thread and its
action is to invoke a signal-catching function or to terminate the
-process.
+thread or process.
System activity may lengthen the sleep by an indeterminate amount.
.Pp
This function is implemented using
diff --git a/lib/libc/gen/sleep.c b/lib/libc/gen/sleep.c
index b807c2d..6bb4ecd 100644
--- a/lib/libc/gen/sleep.c
+++ b/lib/libc/gen/sleep.c
@@ -40,6 +40,8 @@ __FBSDID("$FreeBSD$");
#include <unistd.h>
#include "un-namespace.h"
+#include "libc_private.h"
+
unsigned int
__sleep(unsigned int seconds)
{
@@ -55,12 +57,14 @@ __sleep(unsigned int seconds)
time_to_sleep.tv_sec = seconds;
time_to_sleep.tv_nsec = 0;
- if (_nanosleep(&time_to_sleep, &time_remaining) != -1)
+ if (((int (*)(const struct timespec *, struct timespec *))
+ __libc_interposing[INTERPOS_nanosleep])(
+ &time_to_sleep, &time_remaining) != -1)
return (0);
if (errno != EINTR)
return (seconds); /* best guess */
return (time_remaining.tv_sec +
- (time_remaining.tv_nsec != 0)); /* round up */
+ (time_remaining.tv_nsec != 0)); /* round up */
}
__weak_reference(__sleep, sleep);
diff --git a/lib/libc/gen/stringlist.c b/lib/libc/gen/stringlist.c
index a09a8e7..236af17 100644
--- a/lib/libc/gen/stringlist.c
+++ b/lib/libc/gen/stringlist.c
@@ -10,8 +10,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.
- * 4. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
diff --git a/lib/libc/gen/syslog.c b/lib/libc/gen/syslog.c
index 3a5cafe..003f24d 100644
--- a/lib/libc/gen/syslog.c
+++ b/lib/libc/gen/syslog.c
@@ -261,26 +261,45 @@ vsyslog(int pri, const char *fmt, va_list ap)
connectlog();
/*
- * If the send() failed, there are two likely scenarios:
+ * If the send() fails, there are two likely scenarios:
* 1) syslogd was restarted
* 2) /var/run/log is out of socket buffer space, which
* in most cases means local DoS.
- * We attempt to reconnect to /var/run/log[priv] to take care of
- * case #1 and keep send()ing data to cover case #2
- * to give syslogd a chance to empty its socket buffer.
+ * If the error does not indicate a full buffer, we address
+ * case #1 by attempting to reconnect to /var/run/log[priv]
+ * and resending the message once.
*
- * If we are working with a priveleged socket, then take
- * only one attempt, because we don't want to freeze a
+ * If we are working with a privileged socket, the retry
+ * attempts end there, because we don't want to freeze a
* critical application like su(1) or sshd(8).
*
+ * Otherwise, we address case #2 by repeatedly retrying the
+ * send() to give syslogd a chance to empty its socket buffer.
*/
if (send(LogFile, tbuf, cnt, 0) < 0) {
if (errno != ENOBUFS) {
+ /*
+ * Scenario 1: syslogd was restarted
+ * reconnect and resend once
+ */
disconnectlog();
connectlog();
+ if (send(LogFile, tbuf, cnt, 0) >= 0) {
+ THREAD_UNLOCK();
+ return;
+ }
+ /*
+ * if the resend failed, fall through to
+ * possible scenario 2
+ */
}
- do {
+ while (errno == ENOBUFS) {
+ /*
+ * Scenario 2: out of socket buffer space
+ * possible DoS, fail fast on a privileged
+ * socket
+ */
if (status == CONNPRIV)
break;
_usleep(1);
@@ -288,7 +307,7 @@ vsyslog(int pri, const char *fmt, va_list ap)
THREAD_UNLOCK();
return;
}
- } while (errno == ENOBUFS);
+ }
} else {
THREAD_UNLOCK();
return;
@@ -350,7 +369,7 @@ connectlog(void)
SyslogAddr.sun_family = AF_UNIX;
/*
- * First try priveleged socket. If no success,
+ * First try privileged socket. If no success,
* then try default socket.
*/
(void)strncpy(SyslogAddr.sun_path, _PATH_LOG_PRIV,
diff --git a/lib/libc/gen/telldir.c b/lib/libc/gen/telldir.c
index d72b500..19cd6ee 100644
--- a/lib/libc/gen/telldir.c
+++ b/lib/libc/gen/telldir.c
@@ -101,9 +101,22 @@ _seekdir(dirp, loc)
return;
if (lp->loc_loc == dirp->dd_loc && lp->loc_seek == dirp->dd_seek)
return;
+
+ /* If it's within the same chunk of data, don't bother reloading. */
+ if (lp->loc_seek == dirp->dd_seek) {
+ /*
+ * If we go back to 0 don't make the next readdir
+ * trigger a call to getdirentries().
+ */
+ if (lp->loc_loc == 0)
+ dirp->dd_flags |= __DTF_SKIPREAD;
+ dirp->dd_loc = lp->loc_loc;
+ return;
+ }
(void) lseek(dirp->dd_fd, (off_t)lp->loc_seek, SEEK_SET);
dirp->dd_seek = lp->loc_seek;
dirp->dd_loc = 0;
+ dirp->dd_flags &= ~__DTF_SKIPREAD; /* current contents are invalid */
while (dirp->dd_loc < lp->loc_loc) {
dp = _readdir_unlocked(dirp, 0);
if (dp == NULL)
@@ -112,6 +125,30 @@ _seekdir(dirp, loc)
}
/*
+ * After readdir returns the last entry in a block, a call to telldir
+ * returns a location that is after the end of that last entry.
+ * However, that location doesn't refer to a valid directory entry.
+ * Ideally, the call to telldir would return a location that refers to
+ * the first entry in the next block. That location is not known
+ * until the next block is read, so readdir calls this function after
+ * fetching a new block to fix any such telldir locations.
+ */
+void
+_fixtelldir(DIR *dirp, long oldseek, long oldloc)
+{
+ struct ddloc *lp;
+
+ lp = LIST_FIRST(&dirp->dd_td->td_locq);
+ if (lp != NULL) {
+ if (lp->loc_loc == oldloc &&
+ lp->loc_seek == oldseek) {
+ lp->loc_seek = dirp->dd_seek;
+ lp->loc_loc = dirp->dd_loc;
+ }
+ }
+}
+
+/*
* Reclaim memory for telldir cookies which weren't used.
*/
void
diff --git a/lib/libc/gen/telldir.h b/lib/libc/gen/telldir.h
index 04989bb..bccabb1 100644
--- a/lib/libc/gen/telldir.h
+++ b/lib/libc/gen/telldir.h
@@ -64,5 +64,6 @@ bool _filldir(DIR *, bool);
struct dirent *_readdir_unlocked(DIR *, int);
void _reclaim_telldir(DIR *);
void _seekdir(DIR *, long);
+void _fixtelldir(DIR *dirp, long oldseek, long oldloc);
#endif
diff --git a/lib/libc/gen/termios.c b/lib/libc/gen/termios.c
index 7e9f169..f8b7354 100644
--- a/lib/libc/gen/termios.c
+++ b/lib/libc/gen/termios.c
@@ -46,6 +46,8 @@ __FBSDID("$FreeBSD$");
#include <unistd.h>
#include "un-namespace.h"
+#include "libc_private.h"
+
int
tcgetattr(int fd, struct termios *t)
{
@@ -208,13 +210,23 @@ tcsendbreak(int fd, int len __unused)
}
int
-__tcdrain(int fd)
+__libc_tcdrain(int fd)
{
+
return (_ioctl(fd, TIOCDRAIN, 0));
}
-__weak_reference(__tcdrain, tcdrain);
-__weak_reference(__tcdrain, _tcdrain);
+#pragma weak tcdrain
+int
+tcdrain(int fd)
+{
+
+ return (((int (*)(int))
+ __libc_interposing[INTERPOS_tcdrain])(fd));
+}
+
+__weak_reference(__libc_tcdrain, __tcdrain);
+__weak_reference(__libc_tcdrain, _tcdrain);
int
tcflush(int fd, int which)
diff --git a/lib/libc/gen/tls.c b/lib/libc/gen/tls.c
index 5219418..58ebb55 100644
--- a/lib/libc/gen/tls.c
+++ b/lib/libc/gen/tls.c
@@ -65,13 +65,14 @@ void __libc_free_tls(void *tls, size_t tcbsize, size_t tcbalign);
#if defined(__amd64__)
#define TLS_TCB_ALIGN 16
#elif defined(__powerpc__) || defined(__i386__) || defined(__arm__) || \
- defined(__sparc64__) || defined(__mips__)
+ defined(__sparc64__) || defined(__mips__) || defined(__aarch64__)
#define TLS_TCB_ALIGN sizeof(void *)
#else
#error TLS_TCB_ALIGN undefined for target architecture
#endif
-#if defined(__arm__) || defined(__mips__) || defined(__powerpc__)
+#if defined(__arm__) || defined(__mips__) || defined(__powerpc__) || \
+ defined(__aarch64__)
#define TLS_VARIANT_I
#endif
#if defined(__i386__) || defined(__amd64__) || defined(__sparc64__)
diff --git a/lib/libc/arm/gen/getcontextx.c b/lib/libc/gen/trivial-getcontextx.c
index 54f8513..54f8513 100644
--- a/lib/libc/arm/gen/getcontextx.c
+++ b/lib/libc/gen/trivial-getcontextx.c
diff --git a/lib/libc/gen/ttyname.c b/lib/libc/gen/ttyname.c
index a21b77f..02aa158 100644
--- a/lib/libc/gen/ttyname.c
+++ b/lib/libc/gen/ttyname.c
@@ -65,7 +65,7 @@ ttyname_r(int fd, char *buf, size_t len)
/* Must be a terminal. */
if (!isatty(fd))
- return (ENOTTY);
+ return (errno);
/* Must have enough room */
if (len <= sizeof(_PATH_DEV))
return (ERANGE);
@@ -73,7 +73,7 @@ ttyname_r(int fd, char *buf, size_t len)
strcpy(buf, _PATH_DEV);
used = strlen(buf);
if (fdevname_r(fd, buf + used, len - used) == NULL)
- return (ENOTTY);
+ return (errno == EINVAL ? ERANGE : errno);
return (0);
}
diff --git a/lib/libc/gen/ulimit.c b/lib/libc/gen/ulimit.c
index e1bc020..2c090c0 100644
--- a/lib/libc/gen/ulimit.c
+++ b/lib/libc/gen/ulimit.c
@@ -40,7 +40,7 @@ ulimit(int cmd, ...)
{
struct rlimit limit;
va_list ap;
- long arg;
+ rlim_t arg;
if (cmd == UL_GETFSIZE) {
if (getrlimit(RLIMIT_FSIZE, &limit) == -1)
@@ -53,14 +53,16 @@ ulimit(int cmd, ...)
va_start(ap, cmd);
arg = va_arg(ap, long);
va_end(ap);
- limit.rlim_max = limit.rlim_cur = (rlim_t)arg * 512;
+ if (arg < 0)
+ arg = LONG_MAX;
+ if (arg > RLIM_INFINITY / 512)
+ arg = RLIM_INFINITY / 512;
+ limit.rlim_max = limit.rlim_cur = arg * 512;
/* The setrlimit() function sets errno to EPERM if needed. */
if (setrlimit(RLIMIT_FSIZE, &limit) == -1)
return (-1);
- if (arg * 512 > LONG_MAX)
- return (LONG_MAX);
- return (arg);
+ return ((long)arg);
} else {
errno = EINVAL;
return (-1);
diff --git a/lib/libc/gen/usleep.c b/lib/libc/gen/usleep.c
index 7d6559b..7c35f6c 100644
--- a/lib/libc/gen/usleep.c
+++ b/lib/libc/gen/usleep.c
@@ -38,6 +38,8 @@ __FBSDID("$FreeBSD$");
#include <unistd.h>
#include "un-namespace.h"
+#include "libc_private.h"
+
int
__usleep(useconds_t useconds)
{
@@ -45,7 +47,8 @@ __usleep(useconds_t useconds)
time_to_sleep.tv_nsec = (useconds % 1000000) * 1000;
time_to_sleep.tv_sec = useconds / 1000000;
- return (_nanosleep(&time_to_sleep, NULL));
+ return (((int (*)(const struct timespec *, struct timespec *))
+ __libc_interposing[INTERPOS_nanosleep])(&time_to_sleep, NULL));
}
__weak_reference(__usleep, usleep);
diff --git a/lib/libc/gen/wait.c b/lib/libc/gen/wait.c
index 2169b9d..46a3fdd 100644
--- a/lib/libc/gen/wait.c
+++ b/lib/libc/gen/wait.c
@@ -40,10 +40,14 @@ __FBSDID("$FreeBSD$");
#include <sys/resource.h>
#include "un-namespace.h"
+#include "libc_private.h"
+
pid_t
__wait(int *istat)
{
- return (_wait4(WAIT_ANY, istat, 0, (struct rusage *)0));
+
+ return (((pid_t (*)(pid_t, int *, int, struct rusage *))
+ __libc_interposing[INTERPOS_wait4])(WAIT_ANY, istat, 0, NULL));
}
__weak_reference(__wait, wait);
diff --git a/lib/libc/gen/wait3.c b/lib/libc/gen/wait3.c
index 6098773..965effe 100644
--- a/lib/libc/gen/wait3.c
+++ b/lib/libc/gen/wait3.c
@@ -40,11 +40,14 @@ __FBSDID("$FreeBSD$");
#include <sys/resource.h>
#include "un-namespace.h"
+#include "libc_private.h"
+
pid_t
-wait3(istat, options, rup)
- int *istat;
- int options;
- struct rusage *rup;
+__wait3(int *istat, int options, struct rusage *rup)
{
- return (_wait4(WAIT_ANY, istat, options, rup));
+
+ return (((pid_t (*)(pid_t, int *, int, struct rusage *))
+ __libc_interposing[INTERPOS_wait4])(WAIT_ANY, istat, options, rup));
}
+
+__weak_reference(__wait3, wait3);
diff --git a/lib/libc/gen/waitid.c b/lib/libc/gen/waitid.c
index 795b208..17a2dd6 100644
--- a/lib/libc/gen/waitid.c
+++ b/lib/libc/gen/waitid.c
@@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$");
#include <signal.h>
#include <errno.h>
#include "un-namespace.h"
+#include "libc_private.h"
int
__waitid(idtype_t idtype, id_t id, siginfo_t *info, int flags)
@@ -44,7 +45,9 @@ __waitid(idtype_t idtype, id_t id, siginfo_t *info, int flags)
int status;
pid_t ret;
- ret = _wait6(idtype, id, &status, flags, NULL, info);
+ ret = ((pid_t (*)(idtype_t, id_t, int *, int, struct __wrusage *,
+ siginfo_t *))__libc_interposing[INTERPOS_wait6])(idtype, id,
+ &status, flags, NULL, info);
/*
* According to SUSv4, waitid() shall not return a PID when a
diff --git a/lib/libc/gen/waitpid.c b/lib/libc/gen/waitpid.c
index b001837..5177591 100644
--- a/lib/libc/gen/waitpid.c
+++ b/lib/libc/gen/waitpid.c
@@ -40,10 +40,14 @@ __FBSDID("$FreeBSD$");
#include <sys/resource.h>
#include "un-namespace.h"
+#include "libc_private.h"
+
pid_t
__waitpid(pid_t pid, int *istat, int options)
{
- return (_wait4(pid, istat, options, (struct rusage *)0));
+
+ return (((pid_t (*)(pid_t, int *, int, struct rusage *))
+ __libc_interposing[INTERPOS_wait4])(pid, istat, options, NULL));
}
__weak_reference(__waitpid, waitpid);
diff --git a/lib/libc/gen/wordexp.c b/lib/libc/gen/wordexp.c
index 377caff..c7f4b1d 100644
--- a/lib/libc/gen/wordexp.c
+++ b/lib/libc/gen/wordexp.c
@@ -118,8 +118,10 @@ we_askshell(const char *words, wordexp_t *we, int flags)
char *nstrings; /* Temporary for realloc() */
char **nwv; /* Temporary for realloc() */
sigset_t newsigblock, oldsigblock;
+ const char *ifs;
serrno = errno;
+ ifs = getenv("IFS");
if (pipe2(pdes, O_CLOEXEC) < 0)
return (WRDE_NOSPACE); /* XXX */
@@ -145,7 +147,8 @@ we_askshell(const char *words, wordexp_t *we, int flags)
_fcntl(pdes[1], F_SETFD, 0)) < 0)
_exit(1);
execl(_PATH_BSHELL, "sh", flags & WRDE_UNDEF ? "-u" : "+u",
- "-c", "eval \"$1\";eval \"wordexp $2\"", "",
+ "-c", "IFS=$1;eval \"$2\";eval \"wordexp $3\"", "",
+ ifs != NULL ? ifs : " \t\n",
flags & WRDE_SHOWERR ? "" : "exec 2>/dev/null", words,
(char *)NULL);
_exit(1);
diff --git a/lib/libc/i386/sys/Makefile.inc b/lib/libc/i386/sys/Makefile.inc
index b56183c..ebaa462 100644
--- a/lib/libc/i386/sys/Makefile.inc
+++ b/lib/libc/i386/sys/Makefile.inc
@@ -15,9 +15,6 @@ MDASM= Ovfork.S brk.S cerror.S exect.S getcontext.S pipe.S ptrace.S \
NOASM= break.o exit.o getlogin.o openbsd_poll.o sstk.o vfork.o yield.o
PSEUDO= _getlogin.o _exit.o
-.if ${MK_SYSCALL_COMPAT} != "no"
-PSEUDO+= _pread.o _pwrite.o _lseek.o _mmap.o _ftruncate.o _truncate.o
-.endif
MAN+= i386_get_ioperm.2 i386_get_ldt.2 i386_vm86.2
MAN+= i386_set_watch.3
diff --git a/lib/libc/iconv/__iconv.c b/lib/libc/iconv/__iconv.c
index c9bee3f..85170b7 100644
--- a/lib/libc/iconv/__iconv.c
+++ b/lib/libc/iconv/__iconv.c
@@ -31,7 +31,7 @@
#include "iconv-internal.h"
size_t
-__iconv(iconv_t a, const char **b, size_t *c, char **d,
+__iconv(iconv_t a, char **b, size_t *c, char **d,
size_t *e, __uint32_t f, size_t *g)
{
return __bsd___iconv(a, b, c, d, e, f, g);
diff --git a/lib/libc/iconv/bsd_iconv.c b/lib/libc/iconv/bsd_iconv.c
index f764886..e032a5b 100644
--- a/lib/libc/iconv/bsd_iconv.c
+++ b/lib/libc/iconv/bsd_iconv.c
@@ -120,7 +120,7 @@ __bsd_iconv_close(iconv_t handle)
}
size_t
-__bsd_iconv(iconv_t handle, const char **in, size_t *szin, char **out, size_t *szout)
+__bsd_iconv(iconv_t handle, char **in, size_t *szin, char **out, size_t *szout)
{
size_t ret;
int err;
@@ -141,7 +141,7 @@ __bsd_iconv(iconv_t handle, const char **in, size_t *szin, char **out, size_t *s
}
size_t
-__bsd___iconv(iconv_t handle, const char **in, size_t *szin, char **out,
+__bsd___iconv(iconv_t handle, char **in, size_t *szin, char **out,
size_t *szout, uint32_t flags, size_t *invalids)
{
size_t ret;
diff --git a/lib/libc/iconv/citrus_iconv.c b/lib/libc/iconv/citrus_iconv.c
index 5c8bf49..5994063 100644
--- a/lib/libc/iconv/citrus_iconv.c
+++ b/lib/libc/iconv/citrus_iconv.c
@@ -278,7 +278,9 @@ _citrus_iconv_open(struct _citrus_iconv * __restrict * __restrict rcv,
struct _citrus_iconv *cv = NULL;
struct _citrus_iconv_shared *ci = NULL;
char realdst[PATH_MAX], realsrc[PATH_MAX];
+#ifdef _PATH_ICONV
char buf[PATH_MAX], path[PATH_MAX];
+#endif
int ret;
init_cache();
@@ -290,10 +292,16 @@ _citrus_iconv_open(struct _citrus_iconv * __restrict * __restrict rcv,
dst = nl_langinfo(CODESET);
/* resolve codeset name aliases */
+#ifdef _PATH_ICONV
+ snprintf(path, sizeof(path), "%s/%s", _PATH_ICONV, _CITRUS_ICONV_ALIAS);
strlcpy(realsrc, _lookup_alias(path, src, buf, (size_t)PATH_MAX,
_LOOKUP_CASE_IGNORE), (size_t)PATH_MAX);
strlcpy(realdst, _lookup_alias(path, dst, buf, (size_t)PATH_MAX,
_LOOKUP_CASE_IGNORE), (size_t)PATH_MAX);
+#else
+ strlcpy(realsrc, src, (size_t)PATH_MAX);
+ strlcpy(realdst, dst, (size_t)PATH_MAX);
+#endif
/* sanity check */
if (strchr(realsrc, '/') != NULL || strchr(realdst, '/'))
diff --git a/lib/libc/iconv/citrus_iconv.h b/lib/libc/iconv/citrus_iconv.h
index ac14ac3..99604e9 100644
--- a/lib/libc/iconv/citrus_iconv.h
+++ b/lib/libc/iconv/citrus_iconv.h
@@ -52,7 +52,7 @@ __END_DECLS
*/
static __inline int
_citrus_iconv_convert(struct _citrus_iconv * __restrict cv,
- const char * __restrict * __restrict in, size_t * __restrict inbytes,
+ char * __restrict * __restrict in, size_t * __restrict inbytes,
char * __restrict * __restrict out, size_t * __restrict outbytes,
uint32_t flags, size_t * __restrict nresults)
{
diff --git a/lib/libc/iconv/citrus_iconv_local.h b/lib/libc/iconv/citrus_iconv_local.h
index 12d2fa3..5392da1 100644
--- a/lib/libc/iconv/citrus_iconv_local.h
+++ b/lib/libc/iconv/citrus_iconv_local.h
@@ -46,7 +46,7 @@ static void _citrus_##_m_##_iconv_uninit_shared \
(struct _citrus_iconv_shared *); \
static int _citrus_##_m_##_iconv_convert \
(struct _citrus_iconv * __restrict, \
- const char * __restrict * __restrict, \
+ char * __restrict * __restrict, \
size_t * __restrict, \
char * __restrict * __restrict, \
size_t * __restrict outbytes, \
@@ -75,7 +75,7 @@ typedef void (*_citrus_iconv_uninit_shared_t)
(struct _citrus_iconv_shared *);
typedef int (*_citrus_iconv_convert_t)
(struct _citrus_iconv * __restrict,
- const char *__restrict* __restrict, size_t * __restrict,
+ char *__restrict* __restrict, size_t * __restrict,
char * __restrict * __restrict, size_t * __restrict, uint32_t,
size_t * __restrict);
typedef int (*_citrus_iconv_init_context_t)(struct _citrus_iconv *);
diff --git a/lib/libc/iconv/citrus_none.c b/lib/libc/iconv/citrus_none.c
index 4f9b254..9ec4bd3 100644
--- a/lib/libc/iconv/citrus_none.c
+++ b/lib/libc/iconv/citrus_none.c
@@ -83,7 +83,7 @@ _citrus_NONE_stdenc_init_state(struct _citrus_stdenc * __restrict ce __unused,
static int
_citrus_NONE_stdenc_mbtocs(struct _citrus_stdenc * __restrict ce __unused,
- _csid_t *csid, _index_t *idx, const char **s, size_t n,
+ _csid_t *csid, _index_t *idx, char **s, size_t n,
void *ps __unused, size_t *nresult, struct iconv_hooks *hooks)
{
@@ -159,7 +159,7 @@ _citrus_NONE_stdenc_cstomb(struct _citrus_stdenc * __restrict ce __unused,
static int
_citrus_NONE_stdenc_mbtowc(struct _citrus_stdenc * __restrict ce __unused,
- _wc_t * __restrict pwc, const char ** __restrict s, size_t n,
+ _wc_t * __restrict pwc, char ** __restrict s, size_t n,
void * __restrict pspriv __unused, size_t * __restrict nresult,
struct iconv_hooks *hooks)
{
diff --git a/lib/libc/iconv/citrus_prop.c b/lib/libc/iconv/citrus_prop.c
index 28318de..642e423 100644
--- a/lib/libc/iconv/citrus_prop.c
+++ b/lib/libc/iconv/citrus_prop.c
@@ -293,8 +293,10 @@ done:
}
_memstream_ungetc(ms, ch);
errnum = _citrus_prop_read_character_common(ms, &ch);
- if (errnum != 0)
+ if (errnum != 0) {
+ free(s);
return (errnum);
+ }
s[n] = ch;
++n, --m;
}
diff --git a/lib/libc/iconv/citrus_stdenc.h b/lib/libc/iconv/citrus_stdenc.h
index 28fa29d..50f4dff 100644
--- a/lib/libc/iconv/citrus_stdenc.h
+++ b/lib/libc/iconv/citrus_stdenc.h
@@ -69,7 +69,7 @@ _citrus_stdenc_init_state(struct _citrus_stdenc * __restrict ce,
static __inline int
_citrus_stdenc_mbtocs(struct _citrus_stdenc * __restrict ce,
_citrus_csid_t * __restrict csid, _citrus_index_t * __restrict idx,
- const char ** __restrict s, size_t n, void * __restrict ps,
+ char ** __restrict s, size_t n, void * __restrict ps,
size_t * __restrict nresult, struct iconv_hooks *hooks)
{
diff --git a/lib/libc/iconv/citrus_stdenc_local.h b/lib/libc/iconv/citrus_stdenc_local.h
index 7b627a0..141abff 100644
--- a/lib/libc/iconv/citrus_stdenc_local.h
+++ b/lib/libc/iconv/citrus_stdenc_local.h
@@ -55,7 +55,7 @@ static int _citrus_##_e_##_stdenc_mbtocs \
(struct _citrus_stdenc * __restrict, \
_citrus_csid_t * __restrict, \
_citrus_index_t * __restrict, \
- const char ** __restrict, size_t, \
+ char ** __restrict, size_t, \
void * __restrict, size_t * __restrict, \
struct iconv_hooks *); \
static int _citrus_##_e_##_stdenc_cstomb \
@@ -66,7 +66,7 @@ static int _citrus_##_e_##_stdenc_cstomb \
static int _citrus_##_e_##_stdenc_mbtowc \
(struct _citrus_stdenc * __restrict, \
_citrus_wc_t * __restrict, \
- const char ** __restrict, size_t, \
+ char ** __restrict, size_t, \
void * __restrict, size_t * __restrict, \
struct iconv_hooks *); \
static int _citrus_##_e_##_stdenc_wctomb \
@@ -106,7 +106,7 @@ typedef int (*_citrus_stdenc_init_state_t)
typedef int (*_citrus_stdenc_mbtocs_t)
(struct _citrus_stdenc * __restrict,
_citrus_csid_t * __restrict, _citrus_index_t * __restrict,
- const char ** __restrict, size_t,
+ char ** __restrict, size_t,
void * __restrict, size_t * __restrict,
struct iconv_hooks *);
typedef int (*_citrus_stdenc_cstomb_t)
@@ -116,7 +116,7 @@ typedef int (*_citrus_stdenc_cstomb_t)
typedef int (*_citrus_stdenc_mbtowc_t)
(struct _citrus_stdenc * __restrict,
_citrus_wc_t * __restrict,
- const char ** __restrict, size_t,
+ char ** __restrict, size_t,
void * __restrict, size_t * __restrict,
struct iconv_hooks *);
typedef int (*_citrus_stdenc_wctomb_t)
diff --git a/lib/libc/iconv/citrus_stdenc_template.h b/lib/libc/iconv/citrus_stdenc_template.h
index 21bc5cc..9a05fa7 100644
--- a/lib/libc/iconv/citrus_stdenc_template.h
+++ b/lib/libc/iconv/citrus_stdenc_template.h
@@ -112,7 +112,7 @@ _FUNCNAME(stdenc_init_state)(struct _citrus_stdenc * __restrict ce,
static int
_FUNCNAME(stdenc_mbtocs)(struct _citrus_stdenc * __restrict ce,
_citrus_csid_t * __restrict csid, _citrus_index_t * __restrict idx,
- const char ** __restrict s, size_t n, void * __restrict ps,
+ char ** __restrict s, size_t n, void * __restrict ps,
size_t * __restrict nresult, struct iconv_hooks *hooks)
{
wchar_t wc;
@@ -151,7 +151,7 @@ _FUNCNAME(stdenc_cstomb)(struct _citrus_stdenc * __restrict ce,
static int
_FUNCNAME(stdenc_mbtowc)(struct _citrus_stdenc * __restrict ce,
- _citrus_wc_t * __restrict wc, const char ** __restrict s, size_t n,
+ _citrus_wc_t * __restrict wc, char ** __restrict s, size_t n,
void * __restrict ps, size_t * __restrict nresult,
struct iconv_hooks *hooks)
{
diff --git a/lib/libc/iconv/iconv-internal.h b/lib/libc/iconv/iconv-internal.h
index 9a6b3d9..9937f09 100644
--- a/lib/libc/iconv/iconv-internal.h
+++ b/lib/libc/iconv/iconv-internal.h
@@ -29,11 +29,11 @@
/*
* Interal prototypes for our back-end functions.
*/
-size_t __bsd___iconv(iconv_t, const char **, size_t *, char **,
+size_t __bsd___iconv(iconv_t, char **, size_t *, char **,
size_t *, __uint32_t, size_t *);
void __bsd___iconv_free_list(char **, size_t);
int __bsd___iconv_get_list(char ***, size_t *, __iconv_bool);
-size_t __bsd_iconv(iconv_t, const char ** __restrict,
+size_t __bsd_iconv(iconv_t, char ** __restrict,
size_t * __restrict, char ** __restrict,
size_t * __restrict);
const char *__bsd_iconv_canonicalize(const char *);
diff --git a/lib/libc/iconv/iconv.3 b/lib/libc/iconv/iconv.3
index 6692c47..1a4f8c3 100644
--- a/lib/libc/iconv/iconv.3
+++ b/lib/libc/iconv/iconv.3
@@ -48,7 +48,7 @@
.Ft size_t
.Fn iconv "iconv_t cd" "char ** restrict src" "size_t * restrict srcleft" "char ** restrict dst" "size_t * restrict dstleft"
.Ft size_t
-.Fn __iconv "iconv_t cd" "const char ** restrict src" "size_t * restrict srcleft" "char ** restrict dst" "size_t * restrict dstleft" "uint32_t flags" "size_t invalids"
+.Fn __iconv "iconv_t cd" "char ** restrict src" "size_t * restrict srcleft" "char ** restrict dst" "size_t * restrict dstleft" "uint32_t flags" "size_t * invalids"
.Sh DESCRIPTION
The
.Fn iconv_open
@@ -176,8 +176,8 @@ may be
.Dv NULL .
In this case, the shift sequence for the destination switching
to the initial state is discarded.
-.Pp
.El
+.Pp
The
.Fn __iconv
function works just like
diff --git a/lib/libc/iconv/iconv.c b/lib/libc/iconv/iconv.c
index d13c1df..4bd9620 100644
--- a/lib/libc/iconv/iconv.c
+++ b/lib/libc/iconv/iconv.c
@@ -31,7 +31,7 @@
#include "iconv-internal.h"
size_t
-iconv(iconv_t a, const char ** __restrict b,
+iconv(iconv_t a, char ** __restrict b,
size_t * __restrict c, char ** __restrict d,
size_t * __restrict e)
{
diff --git a/lib/libc/iconv/iconv_compat.c b/lib/libc/iconv/iconv_compat.c
index dea968f..ded2499 100644
--- a/lib/libc/iconv/iconv_compat.c
+++ b/lib/libc/iconv/iconv_compat.c
@@ -37,7 +37,7 @@
#include "iconv-internal.h"
size_t
-__iconv_compat(iconv_t a, const char ** b, size_t * c, char ** d,
+__iconv_compat(iconv_t a, char ** b, size_t * c, char ** d,
size_t * e, __uint32_t f, size_t *g)
{
return __bsd___iconv(a, b, c, d, e, f, g);
@@ -56,7 +56,7 @@ __iconv_get_list_compat(char ***a, size_t *b, __iconv_bool c)
}
size_t
-iconv_compat(iconv_t a, const char ** __restrict b,
+iconv_compat(iconv_t a, char ** __restrict b,
size_t * __restrict c, char ** __restrict d,
size_t * __restrict e)
{
diff --git a/lib/libc/iconv/iconvlist.3 b/lib/libc/iconv/iconvlist.3
index bef609b..b1a6e05 100644
--- a/lib/libc/iconv/iconvlist.3
+++ b/lib/libc/iconv/iconvlist.3
@@ -78,9 +78,9 @@ If an error occurs,
will be NULL when calling
.Fn do_one .
.Sh SEE ALSO
-.Xr iconv 3 ,
+.Xr __iconv_free_list 3 ,
.Xr __iconv_get_list 3 ,
-.Xr __iconv_free_list 3
+.Xr iconv 3
.Sh STANDARDS
The
.Nm
diff --git a/lib/libc/include/compat.h b/lib/libc/include/compat.h
index 7694540..b20fac5 100644
--- a/lib/libc/include/compat.h
+++ b/lib/libc/include/compat.h
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2009 Advanced Computing Technologies LLC
+ * Copyright (c) 2009 Hudson River Trading LLC
* Written by: John H. Baldwin <jhb@FreeBSD.org>
* All rights reserved.
*
@@ -44,5 +44,12 @@ __sym_compat(shmctl, freebsd7_shmctl, FBSD_1.0);
#undef __sym_compat
+#define __weak_reference(sym,alias) \
+ .weak alias;.equ alias,sym
+
+__weak_reference(__sys_fcntl,__fcntl_compat)
+
+#undef __weak_reference
+
#endif /* __LIBC_COMPAT_H__ */
diff --git a/lib/libc/include/libc_private.h b/lib/libc/include/libc_private.h
index 40a5f72..a670d63 100644
--- a/lib/libc/include/libc_private.h
+++ b/lib/libc/include/libc_private.h
@@ -95,6 +95,9 @@ do { \
_SPINUNLOCK(&__stdio_thread_lock); \
} while (0)
+void __libc_spinlock_stub(struct _spinlock *);
+void __libc_spinunlock_stub(struct _spinlock *);
+
/*
* Indexes into the pthread jump table.
*
@@ -173,6 +176,57 @@ typedef pthread_func_t pthread_func_entry_t[2];
extern pthread_func_entry_t __thr_jtable[];
+void __set_error_selector(int *(*arg)(void));
+int _pthread_mutex_init_calloc_cb_stub(pthread_mutex_t *mutex,
+ void *(calloc_cb)(__size_t, __size_t));
+
+typedef int (*interpos_func_t)(void);
+interpos_func_t *__libc_interposing_slot(int interposno);
+extern interpos_func_t __libc_interposing[] __hidden;
+
+enum {
+ INTERPOS_accept,
+ INTERPOS_accept4,
+ INTERPOS_aio_suspend,
+ INTERPOS_close,
+ INTERPOS_connect,
+ INTERPOS_fcntl,
+ INTERPOS_fsync,
+ INTERPOS_fork,
+ INTERPOS_msync,
+ INTERPOS_nanosleep,
+ INTERPOS_openat,
+ INTERPOS_poll,
+ INTERPOS_pselect,
+ INTERPOS_recvfrom,
+ INTERPOS_recvmsg,
+ INTERPOS_select,
+ INTERPOS_sendmsg,
+ INTERPOS_sendto,
+ INTERPOS_setcontext,
+ INTERPOS_sigaction,
+ INTERPOS_sigprocmask,
+ INTERPOS_sigsuspend,
+ INTERPOS_sigwait,
+ INTERPOS_sigtimedwait,
+ INTERPOS_sigwaitinfo,
+ INTERPOS_swapcontext,
+ INTERPOS_system,
+ INTERPOS_tcdrain,
+ INTERPOS_read,
+ INTERPOS_readv,
+ INTERPOS_wait4,
+ INTERPOS_write,
+ INTERPOS_writev,
+ INTERPOS__pthread_mutex_init_calloc_cb,
+ INTERPOS_spinlock,
+ INTERPOS_spinunlock,
+ INTERPOS_kevent,
+ INTERPOS_wait6,
+ INTERPOS_ppoll,
+ INTERPOS_MAX
+};
+
/*
* yplib internal interfaces
*/
@@ -215,6 +269,8 @@ void _malloc_thread_cleanup(void);
void _malloc_prefork(void);
void _malloc_postfork(void);
+void _malloc_first_thread(void);
+
/*
* Function to clean up streams, called from abort() and exit().
*/
@@ -222,35 +278,96 @@ extern void (*__cleanup)(void) __hidden;
/*
* Get kern.osreldate to detect ABI revisions. Explicitly
- * ignores value of $OSVERSION and caches result. Prototypes
- * for the wrapped "new" pad-less syscalls are here for now.
+ * ignores value of $OSVERSION and caches result.
*/
-extern int __getosreldate(void);
+int __getosreldate(void);
#include <sys/_types.h>
-/* Without pad */
-extern __off_t __sys_lseek(int, __off_t, int);
-extern int __sys_ftruncate(int, __off_t);
-extern int __sys_truncate(const char *, __off_t);
-extern __ssize_t __sys_pread(int, void *, __size_t, __off_t);
-extern __ssize_t __sys_pwrite(int, const void *, __size_t, __off_t);
-extern void * __sys_mmap(void *, __size_t, int, int, int, __off_t);
-
-/* With pad */
-extern __off_t __sys_freebsd6_lseek(int, int, __off_t, int);
-extern int __sys_freebsd6_ftruncate(int, int, __off_t);
-extern int __sys_freebsd6_truncate(const char *, int, __off_t);
-extern __ssize_t __sys_freebsd6_pread(int, void *, __size_t, int, __off_t);
-extern __ssize_t __sys_freebsd6_pwrite(int, const void *, __size_t, int, __off_t);
-extern void * __sys_freebsd6_mmap(void *, __size_t, int, int, int, int, __off_t);
-
-/* Without back-compat translation */
-extern int __sys_fcntl(int, int, ...);
+#include <sys/_sigset.h>
+struct aiocb;
+struct fd_set;
+struct iovec;
+struct kevent;
+struct msghdr;
+struct pollfd;
+struct rusage;
+struct sigaction;
+struct sockaddr;
struct timespec;
struct timeval;
struct timezone;
-int __sys_gettimeofday(struct timeval *, struct timezone *);
-int __sys_clock_gettime(__clockid_t, struct timespec *ts);
+struct __siginfo;
+struct __ucontext;
+struct __wrusage;
+enum idtype;
+int __sys_aio_suspend(const struct aiocb * const[], int,
+ const struct timespec *);
+int __sys_accept(int, struct sockaddr *, __socklen_t *);
+int __sys_accept4(int, struct sockaddr *, __socklen_t *, int);
+int __sys_clock_gettime(__clockid_t, struct timespec *ts);
+int __sys_close(int);
+int __sys_connect(int, const struct sockaddr *, __socklen_t);
+int __sys_fcntl(int, int, ...);
+int __sys_fsync(int);
+__pid_t __sys_fork(void);
+int __sys_ftruncate(int, __off_t);
+int __sys_gettimeofday(struct timeval *, struct timezone *);
+int __sys_kevent(int, const struct kevent *, int, struct kevent *,
+ int, const struct timespec *);
+__off_t __sys_lseek(int, __off_t, int);
+void *__sys_mmap(void *, __size_t, int, int, int, __off_t);
+int __sys_msync(void *, __size_t, int);
+int __sys_nanosleep(const struct timespec *, struct timespec *);
+int __sys_open(const char *, int, ...);
+int __sys_openat(int, const char *, int, ...);
+int __sys_pselect(int, struct fd_set *, struct fd_set *,
+ struct fd_set *, const struct timespec *,
+ const __sigset_t *);
+int __sys_poll(struct pollfd *, unsigned, int);
+int __sys_ppoll(struct pollfd *, unsigned, const struct timespec *,
+ const __sigset_t *);
+__ssize_t __sys_pread(int, void *, __size_t, __off_t);
+__ssize_t __sys_pwrite(int, const void *, __size_t, __off_t);
+__ssize_t __sys_read(int, void *, __size_t);
+__ssize_t __sys_readv(int, const struct iovec *, int);
+__ssize_t __sys_recv(int, void *, __size_t, int);
+__ssize_t __sys_recvfrom(int, void *, __size_t, int, struct sockaddr *,
+ __socklen_t *);
+__ssize_t __sys_recvmsg(int, struct msghdr *, int);
+int __sys_select(int, struct fd_set *, struct fd_set *,
+ struct fd_set *, struct timeval *);
+__ssize_t __sys_sendmsg(int, const struct msghdr *, int);
+__ssize_t __sys_sendto(int, const void *, __size_t, int,
+ const struct sockaddr *, __socklen_t);
+int __sys_setcontext(const struct __ucontext *);
+int __sys_sigaction(int, const struct sigaction *,
+ struct sigaction *);
+int __sys_sigprocmask(int, const __sigset_t *, __sigset_t *);
+int __sys_sigsuspend(const __sigset_t *);
+int __sys_sigtimedwait(const __sigset_t *, struct __siginfo *,
+ const struct timespec *);
+int __sys_sigwait(const __sigset_t *, int *);
+int __sys_sigwaitinfo(const __sigset_t *, struct __siginfo *);
+int __sys_swapcontext(struct __ucontext *,
+ const struct __ucontext *);
+int __sys_thr_kill(long, int);
+int __sys_thr_self(long *);
+int __sys_truncate(const char *, __off_t);
+__pid_t __sys_wait4(__pid_t, int *, int, struct rusage *);
+__pid_t __sys_wait6(enum idtype, __id_t, int *, int,
+ struct __wrusage *, struct __siginfo *);
+__ssize_t __sys_write(int, const void *, __size_t);
+__ssize_t __sys_writev(int, const struct iovec *, int);
+
+int __libc_sigwait(const __sigset_t * __restrict,
+ int * restrict sig);
+int __libc_system(const char *);
+int __libc_tcdrain(int);
+int __fcntl_compat(int fd, int cmd, ...);
+
+int __sys_futimens(int fd, const struct timespec *times) __hidden;
+int __sys_utimensat(int fd, const char *path,
+ const struct timespec *times, int flag) __hidden;
/* execve() with PATH processing to implement posix_spawnp() */
int _execvpe(const char *, char * const *, char * const *);
diff --git a/lib/libc/locale/cXXrtomb_iconv.h b/lib/libc/locale/cXXrtomb_iconv.h
index 0ea553b..d6e7ce0 100644
--- a/lib/libc/locale/cXXrtomb_iconv.h
+++ b/lib/libc/locale/cXXrtomb_iconv.h
@@ -57,8 +57,7 @@ cXXrtomb_l(char * __restrict s, charXX_t c, mbstate_t * __restrict ps,
{
_ConversionState *cs;
struct _citrus_iconv *handle;
- const char *src;
- char *dst;
+ char *src, *dst;
size_t srcleft, dstleft, invlen;
int err;
diff --git a/lib/libc/locale/digittoint.3 b/lib/libc/locale/digittoint.3
index 4a7f2e2..6670abe 100644
--- a/lib/libc/locale/digittoint.3
+++ b/lib/libc/locale/digittoint.3
@@ -64,5 +64,5 @@ the function will return 0.
.Sh SEE ALSO
.Xr ctype 3 ,
.Xr isdigit 3 ,
-.Xr isxdigit 3,
+.Xr isxdigit 3 ,
.Xr xlocale 3
diff --git a/lib/libc/locale/duplocale.3 b/lib/libc/locale/duplocale.3
index f2e8215..bc0c4bc 100644
--- a/lib/libc/locale/duplocale.3
+++ b/lib/libc/locale/duplocale.3
@@ -36,7 +36,7 @@
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
-.In xlocale.h
+.In locale.h
.Ft locale_t
.Fn duplocale "locale_t locale"
.Sh DESCRIPTION
diff --git a/lib/libc/locale/freelocale.3 b/lib/libc/locale/freelocale.3
index 86f4809..0df80e7 100644
--- a/lib/libc/locale/freelocale.3
+++ b/lib/libc/locale/freelocale.3
@@ -38,7 +38,7 @@ or
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
-.In xlocale.h
+.In locale.h
.Ft int
.Fn freelocale "locale_t locale"
.Sh DESCRIPTION
diff --git a/lib/libc/locale/mbrtocXX_iconv.h b/lib/libc/locale/mbrtocXX_iconv.h
index ac85a5a..9eb6f68 100644
--- a/lib/libc/locale/mbrtocXX_iconv.h
+++ b/lib/libc/locale/mbrtocXX_iconv.h
@@ -99,8 +99,7 @@ mbrtocXX_l(charXX_t * __restrict pc, const char * __restrict s, size_t n,
/* Convert as few characters to the dst buffer as possible. */
for (i = 0; ; i++) {
- const char *src;
- char *dst;
+ char *src, *dst;
size_t srcleft, dstleft, invlen;
int err;
diff --git a/lib/libc/locale/newlocale.3 b/lib/libc/locale/newlocale.3
index a639c37..c7414be 100644
--- a/lib/libc/locale/newlocale.3
+++ b/lib/libc/locale/newlocale.3
@@ -35,7 +35,7 @@
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
-.In xlocale
+.In locale.h
.Ft locale_t
.Fn newlocale "int mask" "const char * locale" "locale_t base"
.Sh DESCRIPTION
diff --git a/lib/libc/locale/none.c b/lib/libc/locale/none.c
index 75adffa..cacfd73 100644
--- a/lib/libc/locale/none.c
+++ b/lib/libc/locale/none.c
@@ -209,7 +209,7 @@ struct xlocale_ctype __xlocale_global_ctype = {
256 /* __mb_sb_limit */
};
-const struct xlocale_ctype __xlocale_C_ctype = {
+struct xlocale_ctype __xlocale_C_ctype = {
{{0}, "C"},
(_RuneLocale*)&_DefaultRuneLocale,
_none_mbrtowc,
diff --git a/lib/libc/locale/querylocale.3 b/lib/libc/locale/querylocale.3
index f90d626..d1bb688 100644
--- a/lib/libc/locale/querylocale.3
+++ b/lib/libc/locale/querylocale.3
@@ -36,7 +36,7 @@
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
-.In xlocale.h
+.In locale.h
.Ft const char *
.Fn querylocale "int mask" "locale_t locale"
.Sh DESCRIPTION
diff --git a/lib/libc/locale/uselocale.3 b/lib/libc/locale/uselocale.3
index df29a62..96d0008 100644
--- a/lib/libc/locale/uselocale.3
+++ b/lib/libc/locale/uselocale.3
@@ -36,7 +36,7 @@
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
-.In xlocale.h
+.In locale.h
.Ft locale_t
.Fn uselocale "locale_t locale"
.Sh DESCRIPTION
diff --git a/lib/libc/locale/xlocale.3 b/lib/libc/locale/xlocale.3
index d467a10..da217c6 100644
--- a/lib/libc/locale/xlocale.3
+++ b/lib/libc/locale/xlocale.3
@@ -71,7 +71,7 @@ function.
.Xr localeconv 3 ,
.Xr newlocale 3 ,
.Xr querylocale 3 ,
-.Xr uselocale 3 ,
+.Xr uselocale 3
.Sh CONVENIENCE FUNCTIONS
The xlocale API includes a number of
.Fa _l
diff --git a/lib/libc/mips/gen/Makefile.inc b/lib/libc/mips/gen/Makefile.inc
index 9d9cc7a..a186fda 100644
--- a/lib/libc/mips/gen/Makefile.inc
+++ b/lib/libc/mips/gen/Makefile.inc
@@ -6,5 +6,6 @@ SRCS+= infinity.c fabs.c ldexp.c
# SRCS+= flt_rounds.c fpgetmask.c fpgetround.c fpgetsticky.c fpsetmask.c \
# fpsetround.c fpsetsticky.c
-SRCS+= _ctx_start.S _set_tp.c _setjmp.S getcontextx.c makecontext.c \
- setjmp.S signalcontext.c sigsetjmp.S
+SRCS+= _ctx_start.S _set_tp.c _setjmp.S makecontext.c \
+ setjmp.S signalcontext.c sigsetjmp.S \
+ trivial-getcontextx.c
diff --git a/lib/libc/mips/gen/_setjmp.S b/lib/libc/mips/gen/_setjmp.S
index 3918407..0f7a75a 100644
--- a/lib/libc/mips/gen/_setjmp.S
+++ b/lib/libc/mips/gen/_setjmp.S
@@ -61,9 +61,16 @@ __FBSDID("$FreeBSD$");
LEAF(_setjmp)
REG_PROLOGUE
- REG_LI v0, _JB_MAGIC__SETJMP
+ REG_LI v0, _JB_MAGIC__SETJMP # sigcontext magic number
REG_S v0, (_JB_MAGIC * SZREG)(a0)
REG_S ra, (_JB_REG_RA * SZREG)(a0)
+ /*
+ * From "MIPSpro N32 ABI Handbook", Table 2-1:
+ * Registers s0..s7 are callee-saved.
+ * The sp register is callee-saved.
+ * The fp (or s8) register is callee-saved.
+ * The gp register is callee-saved (for n32/n64).
+ */
REG_S s0, (_JB_REG_S0 * SZREG)(a0)
REG_S s1, (_JB_REG_S1 * SZREG)(a0)
REG_S s2, (_JB_REG_S2 * SZREG)(a0)
@@ -72,11 +79,41 @@ LEAF(_setjmp)
REG_S s5, (_JB_REG_S5 * SZREG)(a0)
REG_S s6, (_JB_REG_S6 * SZREG)(a0)
REG_S s7, (_JB_REG_S7 * SZREG)(a0)
+ REG_S sp, (_JB_REG_SP * SZREG)(a0)
REG_S s8, (_JB_REG_S8 * SZREG)(a0)
#if defined(__mips_n32) || defined(__mips_n64)
REG_S gp, (_JB_REG_GP * SZREG)(a0) # newabi gp is callee-saved
#endif
- REG_S sp, (_JB_REG_SP * SZREG)(a0)
+ /*
+ * From "MIPSpro N32 ABI Handbook", Table 2-1:
+ * In N32, FP registers F20, F22, F24, F26, F28, F30 are callee-saved.
+ * In N64, FP registers F24 .. F31 are callee-saved.
+ * In O32, FP registers F20 .. F23 are callee-saved.
+ */
+#ifndef SOFTFLOAT
+ cfc1 v0, $31 # too bad can't check if FP used
+#if defined(__mips_n64) || defined(__mips_n32)
+ FP_S $f30, (_JB_FPREG_F30 * SZREG)(a0)
+ FP_S $f28, (_JB_FPREG_F28 * SZREG)(a0)
+ FP_S $f26, (_JB_FPREG_F26 * SZREG)(a0)
+ FP_S $f24, (_JB_FPREG_F24 * SZREG)(a0)
+#endif
+#if defined(__mips_n32) || defined(__mips_o32) || defined(__mips_o64)
+ FP_S $f22, (_JB_FPREG_F22 * SZREG)(a0)
+ FP_S $f20, (_JB_FPREG_F20 * SZREG)(a0)
+#endif
+#if defined(__mips_o32) || defined(__mips_o64)
+ FP_S $f21, (_JB_FPREG_F21 * SZREG)(a0)
+ FP_S $f23, (_JB_FPREG_F23 * SZREG)(a0)
+#endif
+#if defined(__mips_n64)
+ FP_S $f25, (_JB_FPREG_F25 * SZREG)(a0)
+ FP_S $f27, (_JB_FPREG_F27 * SZREG)(a0)
+ FP_S $f29, (_JB_FPREG_F29 * SZREG)(a0)
+ FP_S $f31, (_JB_FPREG_F31 * SZREG)(a0)
+#endif
+ INT_S v0, (_JB_FPREG_FCSR * SZREG)(a0)
+#endif /* ! SOFTFLOAT */
REG_EPILOGUE
j ra
@@ -94,6 +131,13 @@ LEAF(_longjmp)
REG_LI t0, _JB_MAGIC__SETJMP
bne v0, t0, botch # jump if error
PTR_ADDU sp, sp, CALLFRAME_SIZ # does not matter, sanity
+ /*
+ * From "MIPSpro N32 ABI Handbook", Table 2-1:
+ * Registers s0..s7 are callee-saved.
+ * The sp register is callee-saved.
+ * The fp (or s8) register is callee-saved.
+ * The gp register is callee-saved (for n32/n64).
+ */
REG_L s0, (_JB_REG_S0 * SZREG)(a0)
REG_L s1, (_JB_REG_S1 * SZREG)(a0)
REG_L s2, (_JB_REG_S2 * SZREG)(a0)
@@ -102,11 +146,42 @@ LEAF(_longjmp)
REG_L s5, (_JB_REG_S5 * SZREG)(a0)
REG_L s6, (_JB_REG_S6 * SZREG)(a0)
REG_L s7, (_JB_REG_S7 * SZREG)(a0)
+ REG_L sp, (_JB_REG_SP * SZREG)(a0)
+ REG_L s8, (_JB_REG_S8 * SZREG)(a0)
#if defined(__mips_n32) || defined(__mips_n64)
REG_L gp, (_JB_REG_GP * SZREG)(a0)
#endif
- REG_L sp, (_JB_REG_SP * SZREG)(a0)
- REG_L s8, (_JB_REG_S8 * SZREG)(a0)
+#ifndef SOFTFLOAT
+ # get fpu status
+ INT_L v0, (_JB_FPREG_FCSR * SZREG)(a0)
+ ctc1 v0, $31
+ /*
+ * From "MIPSpro N32 ABI Handbook", Table 2-1:
+ * In N32, FP registers F20, F22, F24, F26, F28, F30 are callee-saved.
+ * In N64, FP registers F24 .. F31 are callee-saved.
+ * In O32, FP registers F20 .. F23 are callee-saved.
+ */
+#if defined(__mips_n64) || defined(__mips_n32)
+ FP_L $f30, (_JB_FPREG_F30 * SZREG)(a0)
+ FP_L $f28, (_JB_FPREG_F28 * SZREG)(a0)
+ FP_L $f26, (_JB_FPREG_F26 * SZREG)(a0)
+ FP_L $f24, (_JB_FPREG_F24 * SZREG)(a0)
+#endif
+#if defined(__mips_n32) || defined(__mips_o32) || defined(__mips_o64)
+ FP_L $f22, (_JB_FPREG_F22 * SZREG)(a0)
+ FP_L $f20, (_JB_FPREG_F20 * SZREG)(a0)
+#endif
+#if defined(__mips_o32) || defined(__mips_o64)
+ FP_L $f21, (_JB_FPREG_F21 * SZREG)(a0)
+ FP_L $f23, (_JB_FPREG_F23 * SZREG)(a0)
+#endif
+#if defined(__mips_n64)
+ FP_L $f25, (_JB_FPREG_F25 * SZREG)(a0)
+ FP_L $f27, (_JB_FPREG_F27 * SZREG)(a0)
+ FP_L $f29, (_JB_FPREG_F29 * SZREG)(a0)
+ FP_L $f31, (_JB_FPREG_F31 * SZREG)(a0)
+#endif
+#endif /* ! SOFTFLOAT */
REG_EPILOGUE
move v0, a1 # get return value in 1st arg
diff --git a/lib/libc/mips/gen/getcontextx.c b/lib/libc/mips/gen/getcontextx.c
deleted file mode 100644
index 54f8513..0000000
--- a/lib/libc/mips/gen/getcontextx.c
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright (c) 2011 Konstantin Belousov <kib@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 ``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$");
-
-#include <sys/types.h>
-#include <sys/ucontext.h>
-#include <errno.h>
-#include <stdlib.h>
-
-int
-__getcontextx_size(void)
-{
-
- return (sizeof(ucontext_t));
-}
-
-int
-__fillcontextx2(char *ctx)
-{
-
- return (0);
-}
-
-int
-__fillcontextx(char *ctx)
-{
- ucontext_t *ucp;
-
- ucp = (ucontext_t *)ctx;
- return (getcontext(ucp));
-}
-
-__weak_reference(__getcontextx, getcontextx);
-
-ucontext_t *
-__getcontextx(void)
-{
- char *ctx;
- int error;
-
- ctx = malloc(__getcontextx_size());
- if (ctx == NULL)
- return (NULL);
- if (__fillcontextx(ctx) == -1) {
- error = errno;
- free(ctx);
- errno = error;
- return (NULL);
- }
- return ((ucontext_t *)ctx);
-}
diff --git a/lib/libc/mips/gen/setjmp.S b/lib/libc/mips/gen/setjmp.S
index deeb892..9c9e8b8 100644
--- a/lib/libc/mips/gen/setjmp.S
+++ b/lib/libc/mips/gen/setjmp.S
@@ -86,6 +86,13 @@ NESTED(setjmp, SETJMP_FRAME_SIZE, ra)
REG_LI v0, _JB_MAGIC_SETJMP
REG_S v0, (_JB_MAGIC * SZREG)(a0)
REG_S ra, (_JB_REG_RA * SZREG)(a0)
+ /*
+ * From "MIPSpro N32 ABI Handbook", Table 2-1:
+ * Registers s0..s7 are callee-saved.
+ * The sp register is callee-saved.
+ * The fp (or s8) register is callee-saved.
+ * The gp register is callee-saved (for n32/n64).
+ */
REG_S s0, (_JB_REG_S0 * SZREG)(a0)
REG_S s1, (_JB_REG_S1 * SZREG)(a0)
REG_S s2, (_JB_REG_S2 * SZREG)(a0)
@@ -99,6 +106,36 @@ NESTED(setjmp, SETJMP_FRAME_SIZE, ra)
#if defined(__mips_n32) || defined(__mips_n64)
REG_S gp, (_JB_REG_GP * SZREG)(a0)
#endif
+#ifndef SOFTFLOAT
+ /*
+ * From "MIPSpro N32 ABI Handbook", Table 2-1:
+ * In N32, FP registers F20, F22, F24, F26, F28, F30 are callee-saved.
+ * In N64, FP registers F24 .. F31 are callee-saved.
+ * In O32, FP registers F20 .. F23 are callee-saved.
+ */
+ cfc1 v0, $31
+ INT_S v0, (_JB_FPREG_FCSR * SZREG)(a0)
+#if defined(__mips_o32) || defined(__mips_o64) || defined(__mips_n32)
+ FP_S $f20, (_JB_FPREG_F20 * SZREG)(a0)
+ FP_S $f22, (_JB_FPREG_F22 * SZREG)(a0)
+#endif
+#if defined(__mips_o32) || defined(__mips_o64)
+ FP_S $f21, (_JB_FPREG_F21 * SZREG)(a0)
+ FP_S $f23, (_JB_FPREG_F23 * SZREG)(a0)
+#endif
+#if defined(__mips_n32) || defined(__mips_n64)
+ FP_S $f24, (_JB_FPREG_F24 * SZREG)(a0)
+ FP_S $f26, (_JB_FPREG_F26 * SZREG)(a0)
+ FP_S $f28, (_JB_FPREG_F28 * SZREG)(a0)
+ FP_S $f30, (_JB_FPREG_F30 * SZREG)(a0)
+#endif
+#if defined(__mips_n64)
+ FP_S $f25, (_JB_FPREG_F25 * SZREG)(a0)
+ FP_S $f27, (_JB_FPREG_F27 * SZREG)(a0)
+ FP_S $f29, (_JB_FPREG_F29 * SZREG)(a0)
+ FP_S $f31, (_JB_FPREG_F31 * SZREG)(a0)
+#endif
+#endif /* ! SOFTFLOAT */
move v0, zero
jr ra
@@ -133,6 +170,13 @@ NESTED(longjmp, LONGJMP_FRAME_SIZE, ra)
REG_L a1, (CALLFRAME_SIZ + SZREG)(sp) # restore return value
REG_L ra, (_JB_REG_RA * SZREG)(a0)
+ /*
+ * From "MIPSpro N32 ABI Handbook", Table 2-1:
+ * Registers s0..s7 are callee-saved.
+ * The sp register is callee-saved.
+ * The fp (or s8) register is callee-saved.
+ * The gp register is callee-saved (for n32/n64).
+ */
REG_L s0, (_JB_REG_S0 * SZREG)(a0)
REG_L s1, (_JB_REG_S1 * SZREG)(a0)
REG_L s2, (_JB_REG_S2 * SZREG)(a0)
@@ -146,6 +190,36 @@ NESTED(longjmp, LONGJMP_FRAME_SIZE, ra)
#if defined(__mips_n32) || defined(__mips_n64)
REG_L gp, (_JB_REG_GP * SZREG)(a0)
#endif
+#ifndef SOFTFLOAT
+ /*
+ * From "MIPSpro N32 ABI Handbook", Table 2-1:
+ * In N32, FP registers F20, F22, F24, F26, F28, F30 are callee-saved.
+ * In N64, FP registers F23 .. F31 are callee-saved.
+ * In O32, FP registers F20 .. F23 are callee-saved.
+ */
+ INT_L v0, (_JB_FPREG_FCSR * SZREG)(a0)
+ ctc1 v0, $31
+#if defined(__mips_n64) || defined(__mips_n32)
+ FP_L $f30, (_JB_FPREG_F30 * SZREG)(a0)
+ FP_L $f28, (_JB_FPREG_F28 * SZREG)(a0)
+ FP_L $f26, (_JB_FPREG_F26 * SZREG)(a0)
+ FP_L $f24, (_JB_FPREG_F24 * SZREG)(a0)
+#endif
+#if defined(__mips_n32) || defined(__mips_o32) || defined(__mips_o64)
+ FP_L $f22, (_JB_FPREG_F22 * SZREG)(a0)
+ FP_L $f20, (_JB_FPREG_F20 * SZREG)(a0)
+#endif
+#if defined(__mips_o32) || defined(__mips_o64)
+ FP_L $f21, (_JB_FPREG_F21 * SZREG)(a0)
+ FP_L $f23, (_JB_FPREG_F23 * SZREG)(a0)
+#endif
+#if defined(__mips_n64)
+ FP_L $f25, (_JB_FPREG_F25 * SZREG)(a0)
+ FP_L $f27, (_JB_FPREG_F27 * SZREG)(a0)
+ FP_L $f29, (_JB_FPREG_F29 * SZREG)(a0)
+ FP_L $f31, (_JB_FPREG_F31 * SZREG)(a0)
+#endif
+#endif /* ! SOFTFLOAT */
move v0, a1
j ra
diff --git a/lib/libc/mips/gen/sigsetjmp.S b/lib/libc/mips/gen/sigsetjmp.S
index 7705c29..41c47f2 100644
--- a/lib/libc/mips/gen/sigsetjmp.S
+++ b/lib/libc/mips/gen/sigsetjmp.S
@@ -61,7 +61,7 @@ __FBSDID("$FreeBSD$");
LEAF(sigsetjmp)
PIC_PROLOGUE(sigsetjmp)
- bne a1, 0x0, 1f # do saving of signal mask?
+ bne a1, zero, 1f # do saving of signal mask?
PIC_TAILCALL(_setjmp)
1: PIC_TAILCALL(setjmp)
diff --git a/lib/libc/mips/sys/Makefile.inc b/lib/libc/mips/sys/Makefile.inc
index c754f36..460e69b 100644
--- a/lib/libc/mips/sys/Makefile.inc
+++ b/lib/libc/mips/sys/Makefile.inc
@@ -1,15 +1,11 @@
# $FreeBSD$
-SRCS+= __vdso_gettc.c
+SRCS+= trivial-vdso_tc.c
MDASM= Ovfork.S brk.S cerror.S exect.S \
fork.S pipe.S ptrace.S sbrk.S syscall.S
# Don't generate default code for these syscalls:
-NOASM= break.o exit.o ftruncate.o getlogin.o lseek.o mmap.o \
- openbsd_poll.o pread.o pwrite.o sstk.o truncate.o vfork.o yield.o
+NOASM= break.o exit.o getlogin.o openbsd_poll.o sstk.o vfork.o yield.o
PSEUDO= _exit.o _getlogin.o
-.if ${MK_SYSCALL_COMPAT} != "no"
-PSEUDO+= _pread.o _pwrite.o _lseek.o _mmap.o _ftruncate.o _truncate.o
-.endif
diff --git a/lib/libc/net/Symbol.map b/lib/libc/net/Symbol.map
index 2eddc47..01d3bcb 100644
--- a/lib/libc/net/Symbol.map
+++ b/lib/libc/net/Symbol.map
@@ -124,6 +124,7 @@ FBSD_1.0 {
in6addr_nodelocal_allnodes;
in6addr_linklocal_allnodes;
sctp_getaddrlen;
+ sctp_getassocid;
sctp_bindx;
sctp_connectx;
sctp_peeloff;
diff --git a/lib/libc/net/base64.c b/lib/libc/net/base64.c
index 4335030..8a9c59e 100644
--- a/lib/libc/net/base64.c
+++ b/lib/libc/net/base64.c
@@ -193,12 +193,10 @@ b64_ntop(u_char const *src, size_t srclength, char *target, size_t targsize) {
*/
int
-b64_pton(src, target, targsize)
- char const *src;
- u_char *target;
- size_t targsize;
+b64_pton(const char *src, u_char *target, size_t targsize)
{
int tarindex, state, ch;
+ u_char nextbyte;
char *pos;
state = 0;
@@ -226,22 +224,28 @@ b64_pton(src, target, targsize)
break;
case 1:
if (target) {
- if ((size_t)tarindex + 1 >= targsize)
+ if ((size_t)tarindex >= targsize)
return (-1);
target[tarindex] |= (pos - Base64) >> 4;
- target[tarindex+1] = ((pos - Base64) & 0x0f)
- << 4 ;
+ nextbyte = ((pos - Base64) & 0x0f) << 4;
+ if ((size_t)tarindex + 1 < targsize)
+ target[tarindex + 1] = nextbyte;
+ else if (nextbyte)
+ return (-1);
}
tarindex++;
state = 2;
break;
case 2:
if (target) {
- if ((size_t)tarindex + 1 >= targsize)
+ if ((size_t)tarindex >= targsize)
return (-1);
target[tarindex] |= (pos - Base64) >> 2;
- target[tarindex+1] = ((pos - Base64) & 0x03)
- << 6;
+ nextbyte = ((pos - Base64) & 0x03) << 6;
+ if ((size_t)tarindex + 1 < targsize)
+ target[tarindex + 1] = nextbyte;
+ else if (nextbyte)
+ return (-1);
}
tarindex++;
state = 3;
@@ -299,7 +303,8 @@ b64_pton(src, target, targsize)
* zeros. If we don't check them, they become a
* subliminal channel.
*/
- if (target && target[tarindex] != 0)
+ if (target && (size_t)tarindex < targsize &&
+ target[tarindex] != 0)
return (-1);
}
} else {
diff --git a/lib/libc/net/eui64.c b/lib/libc/net/eui64.c
index d9ed76c..bb3077f 100644
--- a/lib/libc/net/eui64.c
+++ b/lib/libc/net/eui64.c
@@ -132,6 +132,7 @@ eui64_line(const char *l, struct eui64 *e, char *hostname, size_t len)
goto bad;
}
+ free(linehead);
return (0);
bad:
diff --git a/lib/libc/net/getaddrinfo.3 b/lib/libc/net/getaddrinfo.3
index 5d03aab..570fc2e 100644
--- a/lib/libc/net/getaddrinfo.3
+++ b/lib/libc/net/getaddrinfo.3
@@ -237,8 +237,8 @@ pointer in each
.Li addrinfo
structure until a null pointer is encountered.
The three members
-.Fa ai_family,
-.Fa ai_socktype,
+.Fa ai_family ,
+.Fa ai_socktype ,
and
.Fa ai_protocol
in each returned
diff --git a/lib/libc/net/getaddrinfo.c b/lib/libc/net/getaddrinfo.c
index c50374e..17c9b65 100644
--- a/lib/libc/net/getaddrinfo.c
+++ b/lib/libc/net/getaddrinfo.c
@@ -64,7 +64,6 @@ __FBSDID("$FreeBSD$");
#include <ifaddrs.h>
#include <sys/queue.h>
#ifdef INET6
-#include <net/if_var.h>
#include <sys/sysctl.h>
#include <sys/ioctl.h>
#include <netinet6/in6_var.h>
diff --git a/lib/libc/net/getifaddrs.3 b/lib/libc/net/getifaddrs.3
index ff3f774..b0b17bb 100644
--- a/lib/libc/net/getifaddrs.3
+++ b/lib/libc/net/getifaddrs.3
@@ -24,7 +24,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd May 21, 2013
+.Dd November 25, 2014
.Dt GETIFADDRS 3
.Os
.Sh NAME
@@ -110,19 +110,17 @@ if one exists, otherwise it is NULL.
.Pp
The
.Li ifa_data
-field references address family specific data.
-For
-.Dv AF_LINK
-addresses it contains a pointer to the
+field references address family specific data
+in a pointer to the
.Fa struct if_data
(as defined in include file
-.In net/if.h )
-which contains various interface attributes and statistics.
-For all other address families, it contains a pointer to the
-.Fa struct ifa_data
-(as defined in include file
-.In net/if.h )
-which contains per-address interface statistics.
+.In net/if.h ) .
+For
+.Dv AF_LINK
+addresses,
+it contains various interface attributes and statistics.
+For all other address families,
+it contains per-address interface statistics.
.Pp
The data returned by
.Fn getifaddrs
diff --git a/lib/libc/net/ip6opt.c b/lib/libc/net/ip6opt.c
index a467758..2f0c51d 100644
--- a/lib/libc/net/ip6opt.c
+++ b/lib/libc/net/ip6opt.c
@@ -419,7 +419,7 @@ inet6_opt_append(void *extbuf, socklen_t extlen, int offset, u_int8_t type,
* The option data length must have a value between 0 and 255,
* inclusive, and is the length of the option data that follows.
*/
- if (len < 0 || len > 255)
+ if (len > 255 || len < 0 )
return(-1);
/*
diff --git a/lib/libc/net/name6.c b/lib/libc/net/name6.c
index 97880a2..89effe6 100644
--- a/lib/libc/net/name6.c
+++ b/lib/libc/net/name6.c
@@ -94,7 +94,6 @@ __FBSDID("$FreeBSD$");
#include <netinet/in.h>
#ifdef INET6
#include <net/if.h>
-#include <net/if_var.h>
#include <sys/sysctl.h>
#include <sys/ioctl.h>
#include <netinet6/in6_var.h> /* XXX */
diff --git a/lib/libc/net/nsdispatch.c b/lib/libc/net/nsdispatch.c
index c23315c..4de1df3 100644
--- a/lib/libc/net/nsdispatch.c
+++ b/lib/libc/net/nsdispatch.c
@@ -132,14 +132,17 @@ static void *nss_cache_cycle_prevention_func = NULL;
#endif
/*
- * When this is set to 1, nsdispatch won't use nsswitch.conf
- * but will consult the 'defaults' source list only.
- * NOTE: nested fallbacks (when nsdispatch calls fallback functions,
- * which in turn calls nsdispatch, which should call fallback
- * function) are not supported
+ * We keep track of nsdispatch() nesting depth in dispatch_depth. When a
+ * fallback method is invoked from nsdispatch(), we temporarily set
+ * fallback_depth to the current dispatch depth plus one. Subsequent
+ * calls at that exact depth will run in fallback mode (restricted to the
+ * same source as the call that was handled by the fallback method), while
+ * calls below that depth will be handled normally, allowing fallback
+ * methods to perform arbitrary lookups.
*/
struct fb_state {
- int fb_dispatch;
+ int dispatch_depth;
+ int fallback_depth;
};
static void fb_endstate(void *);
NSS_TLS_HANDLING(fb);
@@ -613,6 +616,7 @@ _nsdispatch(void *retval, const ns_dtab disp_tab[], const char *database,
void *mdata;
int isthreaded, serrno, i, result, srclistsize;
struct fb_state *st;
+ int saved_depth;
#ifdef NS_CACHING
nss_cache_data cache_data;
@@ -644,7 +648,8 @@ _nsdispatch(void *retval, const ns_dtab disp_tab[], const char *database,
result = NS_UNAVAIL;
goto fin;
}
- if (st->fb_dispatch == 0) {
+ ++st->dispatch_depth;
+ if (st->dispatch_depth > st->fallback_depth) {
dbt = vector_search(&database, _nsmap, _nsmapsize, sizeof(*_nsmap),
string_compare);
fb_method = nss_method_lookup(NSSRC_FALLBACK, database,
@@ -713,12 +718,13 @@ _nsdispatch(void *retval, const ns_dtab disp_tab[], const char *database,
break;
} else {
if (fb_method != NULL) {
- st->fb_dispatch = 1;
+ saved_depth = st->fallback_depth;
+ st->fallback_depth = st->dispatch_depth + 1;
va_start(ap, defaults);
result = fb_method(retval,
(void *)srclist[i].name, ap);
va_end(ap);
- st->fb_dispatch = 0;
+ st->fallback_depth = saved_depth;
} else
nss_log(LOG_DEBUG, "%s, %s, %s, not found, "
"and no fallback provided",
@@ -750,6 +756,7 @@ _nsdispatch(void *retval, const ns_dtab disp_tab[], const char *database,
if (isthreaded)
(void)_pthread_rwlock_unlock(&nss_lock);
+ --st->dispatch_depth;
fin:
errno = serrno;
return (result);
diff --git a/lib/libc/net/recv.c b/lib/libc/net/recv.c
index f71d478..6a584ca 100644
--- a/lib/libc/net/recv.c
+++ b/lib/libc/net/recv.c
@@ -35,6 +35,7 @@ __FBSDID("$FreeBSD$");
#include <sys/types.h>
#include <sys/socket.h>
+#include "libc_private.h"
#include <stddef.h>
@@ -48,5 +49,8 @@ recv(s, buf, len, flags)
* POSIX says recv() shall be a cancellation point, so call the
* cancellation-enabled recvfrom() and not _recvfrom().
*/
- return (recvfrom(s, buf, len, flags, NULL, 0));
+ return (((ssize_t (*)(int, void *, size_t, int,
+ struct sockaddr *, socklen_t *))
+ __libc_interposing[INTERPOS_recvfrom])(s, buf, len, flags,
+ NULL, NULL));
}
diff --git a/lib/libc/net/sctp_recvmsg.3 b/lib/libc/net/sctp_recvmsg.3
index e3ced9c..945797d 100644
--- a/lib/libc/net/sctp_recvmsg.3
+++ b/lib/libc/net/sctp_recvmsg.3
@@ -27,7 +27,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd August 13, 2007
+.Dd April 23, 2015
.Dt SCTP_RECVMSG 3
.Os
.Sh NAME
@@ -98,13 +98,13 @@ receive buffer, then the
argument will
.Em not
have the
-.Dv MSG_EOF
+.Dv MSG_EOR
flag applied.
If the message is a complete message then
the
.Fa flags
argument will have
-.Dv MSG_EOF
+.Dv MSG_EOR
set.
Locally detected errors are
indicated by a return value of -1 with
@@ -282,12 +282,12 @@ This typically means that the socket
is not connected and is a one-to-one style socket.
.El
.Sh SEE ALSO
+.Xr getsockopt 2 ,
.Xr recv 2 ,
.Xr select 2 ,
+.Xr setsockopt 2 ,
.Xr socket 2 ,
.Xr write 2 ,
-.Xr getsockopt 2 ,
-.Xr setsockopt 2 ,
.Xr sctp_send 3 ,
.Xr sctp_sendmsg 3 ,
.Xr sendmsg 3 ,
diff --git a/lib/libc/net/sctp_send.3 b/lib/libc/net/sctp_send.3
index 37b0b71..9c7f833 100644
--- a/lib/libc/net/sctp_send.3
+++ b/lib/libc/net/sctp_send.3
@@ -337,7 +337,7 @@ is not connected and is a one-to-one style socket.
.Xr select 2 ,
.Xr sendmsg 2 ,
.Xr socket 2 ,
-.Xr write 2
+.Xr write 2 ,
.Xr sctp_connectx 3 ,
.Xr sctp_recvmsg 3 ,
.Xr sctp_sendmsg 3 ,
diff --git a/lib/libc/net/sctp_sys_calls.c b/lib/libc/net/sctp_sys_calls.c
index 91527c3..f07aa43 100644
--- a/lib/libc/net/sctp_sys_calls.c
+++ b/lib/libc/net/sctp_sys_calls.c
@@ -383,6 +383,9 @@ sctp_opt_info(int sd, sctp_assoc_t id, int opt, void *arg, socklen_t * size)
case SCTP_PR_ASSOC_STATUS:
((struct sctp_prstatus *)arg)->sprstat_assoc_id = id;
break;
+ case SCTP_MAX_CWND:
+ ((struct sctp_assoc_value *)arg)->assoc_id = id;
+ break;
default:
break;
}
@@ -597,6 +600,7 @@ sctp_sendmsg(int s,
msg.msg_iovlen = 1;
msg.msg_control = cmsgbuf;
msg.msg_controllen = CMSG_SPACE(sizeof(struct sctp_sndrcvinfo));
+ msg.msg_flags = 0;
cmsg = (struct cmsghdr *)cmsgbuf;
cmsg->cmsg_level = IPPROTO_SCTP;
cmsg->cmsg_type = SCTP_SNDRCV;
@@ -663,6 +667,7 @@ sctp_send(int sd, const void *data, size_t len,
msg.msg_iovlen = 1;
msg.msg_control = cmsgbuf;
msg.msg_controllen = CMSG_SPACE(sizeof(struct sctp_sndrcvinfo));
+ msg.msg_flags = 0;
cmsg = (struct cmsghdr *)cmsgbuf;
cmsg->cmsg_level = IPPROTO_SCTP;
cmsg->cmsg_type = SCTP_SNDRCV;
@@ -820,7 +825,6 @@ sctp_recvmsg(int s,
errno = EINVAL;
return (-1);
}
- msg.msg_flags = 0;
iov.iov_base = dbuf;
iov.iov_len = len;
msg.msg_name = (caddr_t)from;
@@ -832,6 +836,7 @@ sctp_recvmsg(int s,
msg.msg_iovlen = 1;
msg.msg_control = cmsgbuf;
msg.msg_controllen = sizeof(cmsgbuf);
+ msg.msg_flags = 0;
sz = recvmsg(s, &msg, *msg_flags);
*msg_flags = msg.msg_flags;
if (sz <= 0) {
@@ -886,7 +891,7 @@ sctp_recvv(int sd,
struct sctp_rcvinfo *rcvinfo;
struct sctp_nxtinfo *nxtinfo;
- if (((info != NULL) && (infolen == NULL)) |
+ if (((info != NULL) && (infolen == NULL)) ||
((info == NULL) && (infolen != NULL) && (*infolen != 0)) ||
((info != NULL) && (infotype == NULL))) {
errno = EINVAL;
@@ -905,6 +910,7 @@ sctp_recvv(int sd,
msg.msg_iovlen = iovlen;
msg.msg_control = cmsgbuf;
msg.msg_controllen = sizeof(cmsgbuf);
+ msg.msg_flags = 0;
ret = recvmsg(sd, &msg, *flags);
*flags = msg.msg_flags;
if ((ret > 0) &&
diff --git a/lib/libc/net/send.c b/lib/libc/net/send.c
index 93cdfda..c44f4b9 100644
--- a/lib/libc/net/send.c
+++ b/lib/libc/net/send.c
@@ -35,6 +35,7 @@ __FBSDID("$FreeBSD$");
#include <sys/types.h>
#include <sys/socket.h>
+#include "libc_private.h"
#include <stddef.h>
@@ -48,5 +49,8 @@ send(s, msg, len, flags)
* POSIX says send() shall be a cancellation point, so call the
* cancellation-enabled sendto() and not _sendto().
*/
- return (sendto(s, msg, len, flags, NULL, 0));
+ return (((ssize_t (*)(int, const void *, size_t, int,
+ const struct sockaddr *, socklen_t))
+ __libc_interposing[INTERPOS_sendto])(s, msg, len, flags,
+ NULL, 0));
}
diff --git a/lib/libc/nls/catopen.3 b/lib/libc/nls/catopen.3
index 7a16ee5..7744b0b 100644
--- a/lib/libc/nls/catopen.3
+++ b/lib/libc/nls/catopen.3
@@ -94,7 +94,7 @@ An empty string is substituted for undefined values.
Path names templates defined in
.Ev NLSPATH
are separated by colons
-.No ( Sq \&: ) .
+.Pq Sq \&: .
A leading or two adjacent colons
is equivalent to specifying %N.
.Pp
diff --git a/lib/libc/nls/msgcat.c b/lib/libc/nls/msgcat.c
index 2859916..0cba460 100644
--- a/lib/libc/nls/msgcat.c
+++ b/lib/libc/nls/msgcat.c
@@ -83,6 +83,7 @@ __FBSDID("$FreeBSD$");
np->name = strdup(n); \
np->path = NULL; \
np->catd = NLERR; \
+ np->refcount = 0; \
np->lang = (l == NULL) ? NULL : \
strdup(l); \
np->caterrno = e; \
diff --git a/lib/libc/posix1e/acl_calc_mask.c b/lib/libc/posix1e/acl_calc_mask.c
index a2d1527..56215b9 100644
--- a/lib/libc/posix1e/acl_calc_mask.c
+++ b/lib/libc/posix1e/acl_calc_mask.c
@@ -104,6 +104,7 @@ acl_calc_mask(acl_t *acl_p)
/* if no mask exists, check acl_cnt... */
if (acl_int_new->acl_cnt == ACL_MAX_ENTRIES) {
errno = ENOMEM;
+ acl_free(acl_new);
return (-1);
}
/* ...and add the mask entry */
diff --git a/lib/libc/posix1e/acl_set_flagset_np.3 b/lib/libc/posix1e/acl_set_flagset_np.3
index 2230c48..685680d 100644
--- a/lib/libc/posix1e/acl_set_flagset_np.3
+++ b/lib/libc/posix1e/acl_set_flagset_np.3
@@ -64,9 +64,9 @@ ACL is already branded as POSIX.1e.
.Sh SEE ALSO
.Xr acl 3 ,
.Xr acl_add_flag_np 3 ,
-.Xr acl_get_brand_np 3 ,
.Xr acl_clear_flags_np 3 ,
.Xr acl_delete_flag_np 3 ,
+.Xr acl_get_brand_np 3 ,
.Xr acl_get_flagset_np 3 ,
.Xr posix1e 3
.Sh STANDARDS
diff --git a/lib/libc/posix1e/acl_strip.c b/lib/libc/posix1e/acl_strip.c
index ae37b38..85dfb47 100644
--- a/lib/libc/posix1e/acl_strip.c
+++ b/lib/libc/posix1e/acl_strip.c
@@ -82,8 +82,10 @@ _posix1e_acl_strip_np(const acl_t aclp, int recalculate_mask)
have_mask_entry = 0;
acl_new = acl_init(ACL_MAX_ENTRIES);
- if (acl_new == NULL)
+ if (acl_new == NULL) {
+ acl_free(acl_old);
return (NULL);
+ }
tag = ACL_UNDEFINED_TAG;
/* only save the default user/group/other entries */
@@ -94,16 +96,16 @@ _posix1e_acl_strip_np(const acl_t aclp, int recalculate_mask)
assert(_entry_brand(entry) == ACL_BRAND_POSIX);
if (acl_get_tag_type(entry, &tag) == -1)
- return (NULL);
+ goto fail;
switch(tag) {
case ACL_USER_OBJ:
case ACL_GROUP_OBJ:
case ACL_OTHER:
if (acl_get_tag_type(entry, &tag) == -1)
- return (NULL);
+ goto fail;
if (acl_get_permset(entry, &perm) == -1)
- return (NULL);
+ goto fail;
if (acl_create_entry(&acl_new, &entry_new) == -1)
return (NULL);
if (acl_set_tag_type(entry_new, tag) == -1)
@@ -120,6 +122,10 @@ _posix1e_acl_strip_np(const acl_t aclp, int recalculate_mask)
default:
break;
}
+fail:
+ acl_free(acl_new);
+ acl_free(acl_old);
+ return (NULL);
}
assert(_acl_brand(acl_new) == ACL_BRAND_POSIX);
diff --git a/lib/libc/powerpc/Makefile.inc b/lib/libc/powerpc/Makefile.inc
index f378780..42982671 100644
--- a/lib/libc/powerpc/Makefile.inc
+++ b/lib/libc/powerpc/Makefile.inc
@@ -1,6 +1,6 @@
# $FreeBSD$
-SRCS+= __vdso_gettc.c
+SRCS+= trivial-vdso_tc.c
# Long double is 64-bits
MDSRCS+=machdep_ldisd.c
diff --git a/lib/libc/powerpc/gen/Makefile.inc b/lib/libc/powerpc/gen/Makefile.inc
index 81c6a69..2a00ba3 100644
--- a/lib/libc/powerpc/gen/Makefile.inc
+++ b/lib/libc/powerpc/gen/Makefile.inc
@@ -1,9 +1,11 @@
# $FreeBSD$
SRCS += _ctx_start.S eabi.S fabs.S flt_rounds.c fpgetmask.c fpgetround.c \
- fpgetsticky.c fpsetmask.c fpsetround.c getcontextx.c \
+ fpgetsticky.c fpsetmask.c fpsetround.c \
infinity.c ldexp.c makecontext.c _setjmp.S \
setjmp.S sigsetjmp.S signalcontext.c syncicache.c \
- _set_tp.c
+ _set_tp.c \
+ trivial-getcontextx.c
+
diff --git a/lib/libc/powerpc/gen/_set_tp.c b/lib/libc/powerpc/gen/_set_tp.c
index 5a89698..aa1150a 100644
--- a/lib/libc/powerpc/gen/_set_tp.c
+++ b/lib/libc/powerpc/gen/_set_tp.c
@@ -29,7 +29,6 @@
void
_set_tp(void *tpval)
{
- register void *tp __asm__("r2");
- __asm __volatile("mr %0,%1" : "=r"(tp) : "r"((char*)tpval + 0x7008));
+ __asm __volatile("mr 2,%0" :: "r"((char*)tpval + 0x7008));
}
diff --git a/lib/libc/powerpc/gen/_setjmp.S b/lib/libc/powerpc/gen/_setjmp.S
index e28386c..663a8b6 100644
--- a/lib/libc/powerpc/gen/_setjmp.S
+++ b/lib/libc/powerpc/gen/_setjmp.S
@@ -56,12 +56,54 @@ ENTRY(_setjmp)
mr %r10,%r1
mr %r9,%r2
stmw %r9,20(%r3)
+
+ /* FPRs */
+ stfd %f14,112+0*8(%r3)
+ stfd %f15,112+1*8(%r3)
+ stfd %f16,112+2*8(%r3)
+ stfd %f17,112+3*8(%r3)
+ stfd %f18,112+4*8(%r3)
+ stfd %f19,112+5*8(%r3)
+ stfd %f20,112+6*8(%r3)
+ stfd %f21,112+7*8(%r3)
+ stfd %f22,112+8*8(%r3)
+ stfd %f23,112+9*8(%r3)
+ stfd %f24,112+10*8(%r3)
+ stfd %f25,112+11*8(%r3)
+ stfd %f26,112+12*8(%r3)
+ stfd %f27,112+13*8(%r3)
+ stfd %f28,112+14*8(%r3)
+ stfd %f29,112+15*8(%r3)
+ stfd %f30,112+16*8(%r3)
+ stfd %f31,112+17*8(%r3)
+
li %r3,0
blr
END(_setjmp)
ENTRY(_longjmp)
lmw %r9,20(%r3)
+
+ /* FPRs */
+ lfd %f14,112+0*8(%r3)
+ lfd %f15,112+1*8(%r3)
+ lfd %f16,112+2*8(%r3)
+ lfd %f17,112+3*8(%r3)
+ lfd %f18,112+4*8(%r3)
+ lfd %f19,112+5*8(%r3)
+ lfd %f20,112+6*8(%r3)
+ lfd %f21,112+7*8(%r3)
+ lfd %f22,112+8*8(%r3)
+ lfd %f23,112+9*8(%r3)
+ lfd %f24,112+10*8(%r3)
+ lfd %f25,112+11*8(%r3)
+ lfd %f26,112+12*8(%r3)
+ lfd %f27,112+13*8(%r3)
+ lfd %f28,112+14*8(%r3)
+ lfd %f29,112+15*8(%r3)
+ lfd %f30,112+16*8(%r3)
+ lfd %f31,112+17*8(%r3)
+
mtlr %r11
mtcr %r12
mr %r1,%r10
diff --git a/lib/libc/powerpc/gen/setjmp.S b/lib/libc/powerpc/gen/setjmp.S
index 9325fc2..ef7cb7e 100644
--- a/lib/libc/powerpc/gen/setjmp.S
+++ b/lib/libc/powerpc/gen/setjmp.S
@@ -66,6 +66,27 @@ ENTRY(setjmp)
mr %r10,%r1 /* r10 <- stackptr */
mr %r9,%r2 /* r9 <- global ptr */
stmw %r9,20(%r6)
+
+ /* FPRs */
+ stfd %f14,112+0*8(%r6)
+ stfd %f15,112+1*8(%r6)
+ stfd %f16,112+2*8(%r6)
+ stfd %f17,112+3*8(%r6)
+ stfd %f18,112+4*8(%r6)
+ stfd %f19,112+5*8(%r6)
+ stfd %f20,112+6*8(%r6)
+ stfd %f21,112+7*8(%r6)
+ stfd %f22,112+8*8(%r6)
+ stfd %f23,112+9*8(%r6)
+ stfd %f24,112+10*8(%r6)
+ stfd %f25,112+11*8(%r6)
+ stfd %f26,112+12*8(%r6)
+ stfd %f27,112+13*8(%r6)
+ stfd %f28,112+14*8(%r6)
+ stfd %f29,112+15*8(%r6)
+ stfd %f30,112+16*8(%r6)
+ stfd %f31,112+17*8(%r6)
+
li %r3,0 /* return (0) */
blr
END(setjmp)
@@ -73,6 +94,27 @@ END(setjmp)
WEAK_REFERENCE(CNAME(__longjmp), longjmp)
ENTRY(__longjmp)
lmw %r9,20(%r3) /* restore regs */
+
+ /* FPRs */
+ lfd %f14,112+0*8(%r3)
+ lfd %f15,112+1*8(%r3)
+ lfd %f16,112+2*8(%r3)
+ lfd %f17,112+3*8(%r3)
+ lfd %f18,112+4*8(%r3)
+ lfd %f19,112+5*8(%r3)
+ lfd %f20,112+6*8(%r3)
+ lfd %f21,112+7*8(%r3)
+ lfd %f22,112+8*8(%r3)
+ lfd %f23,112+9*8(%r3)
+ lfd %f24,112+10*8(%r3)
+ lfd %f25,112+11*8(%r3)
+ lfd %f26,112+12*8(%r3)
+ lfd %f27,112+13*8(%r3)
+ lfd %f28,112+14*8(%r3)
+ lfd %f29,112+15*8(%r3)
+ lfd %f30,112+16*8(%r3)
+ lfd %f31,112+17*8(%r3)
+
mr %r6,%r4 /* save val param */
mtlr %r11 /* r11 -> link reg */
mtcr %r12 /* r12 -> condition reg */
diff --git a/lib/libc/powerpc/gen/sigsetjmp.S b/lib/libc/powerpc/gen/sigsetjmp.S
index c67afc6..9c75f4f 100644
--- a/lib/libc/powerpc/gen/sigsetjmp.S
+++ b/lib/libc/powerpc/gen/sigsetjmp.S
@@ -71,12 +71,54 @@ ENTRY(sigsetjmp)
mr %r10,%r1
mr %r9,%r2
stmw %r9,20(%r6)
+
+ /* FPRs */
+ stfd %f14,112+0*8(%r6)
+ stfd %f15,112+1*8(%r6)
+ stfd %f16,112+2*8(%r6)
+ stfd %f17,112+3*8(%r6)
+ stfd %f18,112+4*8(%r6)
+ stfd %f19,112+5*8(%r6)
+ stfd %f20,112+6*8(%r6)
+ stfd %f21,112+7*8(%r6)
+ stfd %f22,112+8*8(%r6)
+ stfd %f23,112+9*8(%r6)
+ stfd %f24,112+10*8(%r6)
+ stfd %f25,112+11*8(%r6)
+ stfd %f26,112+12*8(%r6)
+ stfd %f27,112+13*8(%r6)
+ stfd %f28,112+14*8(%r6)
+ stfd %f29,112+15*8(%r6)
+ stfd %f30,112+16*8(%r6)
+ stfd %f31,112+17*8(%r6)
+
li %r3,0
blr
END(sigsetjmp)
ENTRY(siglongjmp)
lmw %r9,20(%r3)
+
+ /* FPRs */
+ lfd %f14,112+0*8(%r3)
+ lfd %f15,112+1*8(%r3)
+ lfd %f16,112+2*8(%r3)
+ lfd %f17,112+3*8(%r3)
+ lfd %f18,112+4*8(%r3)
+ lfd %f19,112+5*8(%r3)
+ lfd %f20,112+6*8(%r3)
+ lfd %f21,112+7*8(%r3)
+ lfd %f22,112+8*8(%r3)
+ lfd %f23,112+9*8(%r3)
+ lfd %f24,112+10*8(%r3)
+ lfd %f25,112+11*8(%r3)
+ lfd %f26,112+12*8(%r3)
+ lfd %f27,112+13*8(%r3)
+ lfd %f28,112+14*8(%r3)
+ lfd %f29,112+15*8(%r3)
+ lfd %f30,112+16*8(%r3)
+ lfd %f31,112+17*8(%r3)
+
lwz %r7,0(%r3)
mr %r6,%r4
mtlr %r11
diff --git a/lib/libc/powerpc/sys/Makefile.inc b/lib/libc/powerpc/sys/Makefile.inc
index ad98ba1..98ec888 100644
--- a/lib/libc/powerpc/sys/Makefile.inc
+++ b/lib/libc/powerpc/sys/Makefile.inc
@@ -6,6 +6,3 @@ MDASM+= brk.S cerror.S exect.S pipe.S ptrace.S sbrk.S setlogin.S
NOASM= break.o exit.o getlogin.o openbsd_poll.o sstk.o yield.o
PSEUDO= _getlogin.o _exit.o
-.if ${MK_SYSCALL_COMPAT} != "no"
-PSEUDO+= _pread.o _pwrite.o _lseek.o _mmap.o _ftruncate.o _truncate.o
-.endif
diff --git a/lib/libc/powerpc64/Makefile.inc b/lib/libc/powerpc64/Makefile.inc
index 2a080f6..8e9bcc5 100644
--- a/lib/libc/powerpc64/Makefile.inc
+++ b/lib/libc/powerpc64/Makefile.inc
@@ -1,6 +1,6 @@
# $FreeBSD$
-SRCS+= __vdso_gettc.c
+SRCS+= trivial-vdso_tc.c
# Long double is 64-bits
MDSRCS+=machdep_ldisd.c
diff --git a/lib/libc/powerpc64/gen/Makefile.inc b/lib/libc/powerpc64/gen/Makefile.inc
index 79a2746..864fb9e 100644
--- a/lib/libc/powerpc64/gen/Makefile.inc
+++ b/lib/libc/powerpc64/gen/Makefile.inc
@@ -1,9 +1,10 @@
# $FreeBSD$
SRCS += _ctx_start.S fabs.S flt_rounds.c fpgetmask.c fpgetround.c \
- fpgetsticky.c fpsetmask.c fpsetround.c getcontextx.c \
+ fpgetsticky.c fpsetmask.c fpsetround.c \
infinity.c ldexp.c makecontext.c _setjmp.S \
setjmp.S sigsetjmp.S signalcontext.c syncicache.c \
- _set_tp.c
+ _set_tp.c \
+ trivial-getcontextx.c
diff --git a/lib/libc/powerpc64/gen/_set_tp.c b/lib/libc/powerpc64/gen/_set_tp.c
index 9adb6a5..32137e5 100644
--- a/lib/libc/powerpc64/gen/_set_tp.c
+++ b/lib/libc/powerpc64/gen/_set_tp.c
@@ -29,7 +29,6 @@
void
_set_tp(void *tpval)
{
- register void *tp __asm__("r13");
- __asm __volatile("mr %0,%1" : "=r"(tp) : "r"((char*)tpval + 0x7010));
+ __asm __volatile("mr 13,%0" :: "r"((char*)tpval + 0x7010));
}
diff --git a/lib/libc/powerpc64/gen/_setjmp.S b/lib/libc/powerpc64/gen/_setjmp.S
index 207c4f7..f7689ae 100644
--- a/lib/libc/powerpc64/gen/_setjmp.S
+++ b/lib/libc/powerpc64/gen/_setjmp.S
@@ -56,23 +56,41 @@ ENTRY(_setjmp)
mr %r10,%r1
mr %r9,%r2
std %r9,40 + 0*8(%r3)
+ stfd %f14,40 + 23*8(%r3)
std %r10,40 + 1*8(%r3)
+ stfd %f15,40 + 24*8(%r3)
std %r11,40 + 2*8(%r3)
+ stfd %f16,40 + 25*8(%r3)
std %r12,40 + 3*8(%r3)
+ stfd %f17,40 + 26*8(%r3)
std %r13,40 + 4*8(%r3)
+ stfd %f18,40 + 27*8(%r3)
std %r14,40 + 5*8(%r3)
+ stfd %f19,40 + 28*8(%r3)
std %r15,40 + 6*8(%r3)
+ stfd %f20,40 + 29*8(%r3)
std %r16,40 + 7*8(%r3)
+ stfd %f21,40 + 30*8(%r3)
std %r17,40 + 8*8(%r3)
+ stfd %f22,40 + 31*8(%r3)
std %r18,40 + 9*8(%r3)
+ stfd %f23,40 + 32*8(%r3)
std %r19,40 + 10*8(%r3)
+ stfd %f24,40 + 33*8(%r3)
std %r20,40 + 11*8(%r3)
+ stfd %f25,40 + 34*8(%r3)
std %r21,40 + 12*8(%r3)
+ stfd %f26,40 + 35*8(%r3)
std %r22,40 + 13*8(%r3)
+ stfd %f27,40 + 36*8(%r3)
std %r23,40 + 14*8(%r3)
+ stfd %f28,40 + 37*8(%r3)
std %r24,40 + 15*8(%r3)
+ stfd %f29,40 + 38*8(%r3)
std %r25,40 + 16*8(%r3)
+ stfd %f30,40 + 39*8(%r3)
std %r26,40 + 17*8(%r3)
+ stfd %f31,40 + 40*8(%r3)
std %r27,40 + 18*8(%r3)
std %r28,40 + 19*8(%r3)
std %r29,40 + 20*8(%r3)
@@ -84,23 +102,41 @@ END(_setjmp)
ENTRY(_longjmp)
ld %r9,40 + 0*8(%r3)
+ lfd %f14,40 + 23*8(%r3)
ld %r10,40 + 1*8(%r3)
+ lfd %f15,40 + 24*8(%r3)
ld %r11,40 + 2*8(%r3)
+ lfd %f16,40 + 25*8(%r3)
ld %r12,40 + 3*8(%r3)
+ lfd %f17,40 + 26*8(%r3)
ld %r14,40 + 5*8(%r3)
+ lfd %f18,40 + 27*8(%r3)
ld %r15,40 + 6*8(%r3)
+ lfd %f19,40 + 28*8(%r3)
ld %r16,40 + 7*8(%r3)
+ lfd %f20,40 + 29*8(%r3)
ld %r17,40 + 8*8(%r3)
+ lfd %f21,40 + 30*8(%r3)
ld %r18,40 + 9*8(%r3)
+ lfd %f22,40 + 31*8(%r3)
ld %r19,40 + 10*8(%r3)
+ lfd %f23,40 + 32*8(%r3)
ld %r20,40 + 11*8(%r3)
+ lfd %f24,40 + 33*8(%r3)
ld %r21,40 + 12*8(%r3)
+ lfd %f25,40 + 34*8(%r3)
ld %r22,40 + 13*8(%r3)
+ lfd %f26,40 + 35*8(%r3)
ld %r23,40 + 14*8(%r3)
+ lfd %f27,40 + 36*8(%r3)
ld %r24,40 + 15*8(%r3)
+ lfd %f28,40 + 37*8(%r3)
ld %r25,40 + 16*8(%r3)
+ lfd %f29,40 + 38*8(%r3)
ld %r26,40 + 17*8(%r3)
+ lfd %f30,40 + 39*8(%r3)
ld %r27,40 + 18*8(%r3)
+ lfd %f31,40 + 40*8(%r3)
ld %r28,40 + 19*8(%r3)
ld %r29,40 + 20*8(%r3)
ld %r30,40 + 21*8(%r3)
diff --git a/lib/libc/powerpc64/gen/setjmp.S b/lib/libc/powerpc64/gen/setjmp.S
index 1495466..5eb395e 100644
--- a/lib/libc/powerpc64/gen/setjmp.S
+++ b/lib/libc/powerpc64/gen/setjmp.S
@@ -67,29 +67,49 @@ ENTRY(setjmp)
mr %r9,%r2 /* r9 <- global ptr */
std %r9,40 + 0*8(%r6)
+ stfd %f14,40 + 23*8(%r6)
std %r10,40 + 1*8(%r6)
+ stfd %f15,40 + 24*8(%r6)
std %r11,40 + 2*8(%r6)
+ stfd %f16,40 + 25*8(%r6)
std %r12,40 + 3*8(%r6)
+ stfd %f17,40 + 26*8(%r6)
std %r13,40 + 4*8(%r6)
+ stfd %f18,40 + 27*8(%r6)
std %r14,40 + 5*8(%r6)
+ stfd %f19,40 + 28*8(%r6)
std %r15,40 + 6*8(%r6)
+ stfd %f20,40 + 29*8(%r6)
std %r16,40 + 7*8(%r6)
+ stfd %f21,40 + 30*8(%r6)
std %r17,40 + 8*8(%r6)
+ stfd %f22,40 + 31*8(%r6)
std %r18,40 + 9*8(%r6)
+ stfd %f23,40 + 32*8(%r6)
std %r19,40 + 10*8(%r6)
+ stfd %f24,40 + 33*8(%r6)
std %r20,40 + 11*8(%r6)
+ stfd %f25,40 + 34*8(%r6)
std %r21,40 + 12*8(%r6)
+ stfd %f26,40 + 35*8(%r6)
std %r22,40 + 13*8(%r6)
+ stfd %f27,40 + 36*8(%r6)
std %r23,40 + 14*8(%r6)
+ stfd %f28,40 + 37*8(%r6)
std %r24,40 + 15*8(%r6)
+ stfd %f29,40 + 38*8(%r6)
std %r25,40 + 16*8(%r6)
+ stfd %f30,40 + 39*8(%r6)
std %r26,40 + 17*8(%r6)
+ stfd %f31,40 + 40*8(%r6)
std %r27,40 + 18*8(%r6)
std %r28,40 + 19*8(%r6)
std %r29,40 + 20*8(%r6)
std %r30,40 + 21*8(%r6)
std %r31,40 + 22*8(%r6)
+ /* XXX Altivec regs */
+
li %r3,0 /* return (0) */
blr
END(setjmp)
@@ -97,23 +117,41 @@ END(setjmp)
WEAK_REFERENCE(__longjmp, longjmp)
ENTRY(__longjmp)
ld %r9,40 + 0*8(%r3)
+ lfd %f14,40 + 23*8(%r3)
ld %r10,40 + 1*8(%r3)
+ lfd %f15,40 + 24*8(%r3)
ld %r11,40 + 2*8(%r3)
+ lfd %f16,40 + 25*8(%r3)
ld %r12,40 + 3*8(%r3)
+ lfd %f17,40 + 26*8(%r3)
ld %r14,40 + 5*8(%r3)
+ lfd %f18,40 + 27*8(%r3)
ld %r15,40 + 6*8(%r3)
+ lfd %f19,40 + 28*8(%r3)
ld %r16,40 + 7*8(%r3)
+ lfd %f20,40 + 29*8(%r3)
ld %r17,40 + 8*8(%r3)
+ lfd %f21,40 + 30*8(%r3)
ld %r18,40 + 9*8(%r3)
+ lfd %f22,40 + 31*8(%r3)
ld %r19,40 + 10*8(%r3)
+ lfd %f23,40 + 32*8(%r3)
ld %r20,40 + 11*8(%r3)
+ lfd %f24,40 + 33*8(%r3)
ld %r21,40 + 12*8(%r3)
+ lfd %f25,40 + 34*8(%r3)
ld %r22,40 + 13*8(%r3)
+ lfd %f26,40 + 35*8(%r3)
ld %r23,40 + 14*8(%r3)
+ lfd %f27,40 + 36*8(%r3)
ld %r24,40 + 15*8(%r3)
+ lfd %f28,40 + 37*8(%r3)
ld %r25,40 + 16*8(%r3)
+ lfd %f29,40 + 38*8(%r3)
ld %r26,40 + 17*8(%r3)
+ lfd %f30,40 + 39*8(%r3)
ld %r27,40 + 18*8(%r3)
+ lfd %f31,40 + 40*8(%r3)
ld %r28,40 + 19*8(%r3)
ld %r29,40 + 20*8(%r3)
ld %r30,40 + 21*8(%r3)
diff --git a/lib/libc/powerpc64/gen/sigsetjmp.S b/lib/libc/powerpc64/gen/sigsetjmp.S
index 5cfd684..c0648a6 100644
--- a/lib/libc/powerpc64/gen/sigsetjmp.S
+++ b/lib/libc/powerpc64/gen/sigsetjmp.S
@@ -72,23 +72,41 @@ ENTRY(sigsetjmp)
mr %r9,%r2
std %r9,40 + 0*8(%r6)
+ stfd %f14,40 + 23*8(%r6)
std %r10,40 + 1*8(%r6)
+ stfd %f15,40 + 24*8(%r6)
std %r11,40 + 2*8(%r6)
+ stfd %f16,40 + 25*8(%r6)
std %r12,40 + 3*8(%r6)
+ stfd %f17,40 + 26*8(%r6)
std %r13,40 + 4*8(%r6)
+ stfd %f18,40 + 27*8(%r6)
std %r14,40 + 5*8(%r6)
+ stfd %f19,40 + 28*8(%r6)
std %r15,40 + 6*8(%r6)
+ stfd %f20,40 + 29*8(%r6)
std %r16,40 + 7*8(%r6)
+ stfd %f21,40 + 30*8(%r6)
std %r17,40 + 8*8(%r6)
+ stfd %f22,40 + 31*8(%r6)
std %r18,40 + 9*8(%r6)
+ stfd %f23,40 + 32*8(%r6)
std %r19,40 + 10*8(%r6)
+ stfd %f24,40 + 33*8(%r6)
std %r20,40 + 11*8(%r6)
+ stfd %f25,40 + 34*8(%r6)
std %r21,40 + 12*8(%r6)
+ stfd %f26,40 + 35*8(%r6)
std %r22,40 + 13*8(%r6)
+ stfd %f27,40 + 36*8(%r6)
std %r23,40 + 14*8(%r6)
+ stfd %f28,40 + 37*8(%r6)
std %r24,40 + 15*8(%r6)
+ stfd %f29,40 + 38*8(%r6)
std %r25,40 + 16*8(%r6)
+ stfd %f30,40 + 39*8(%r6)
std %r26,40 + 17*8(%r6)
+ stfd %f31,40 + 40*8(%r6)
std %r27,40 + 18*8(%r6)
std %r28,40 + 19*8(%r6)
std %r29,40 + 20*8(%r6)
@@ -101,23 +119,41 @@ END(sigsetjmp)
ENTRY(siglongjmp)
ld %r9,40 + 0*8(%r3)
+ lfd %f14,40 + 23*8(%r3)
ld %r10,40 + 1*8(%r3)
+ lfd %f15,40 + 24*8(%r3)
ld %r11,40 + 2*8(%r3)
+ lfd %f16,40 + 25*8(%r3)
ld %r12,40 + 3*8(%r3)
+ lfd %f17,40 + 26*8(%r3)
ld %r14,40 + 5*8(%r3)
+ lfd %f18,40 + 27*8(%r3)
ld %r15,40 + 6*8(%r3)
+ lfd %f19,40 + 28*8(%r3)
ld %r16,40 + 7*8(%r3)
+ lfd %f20,40 + 29*8(%r3)
ld %r17,40 + 8*8(%r3)
+ lfd %f21,40 + 30*8(%r3)
ld %r18,40 + 9*8(%r3)
+ lfd %f22,40 + 31*8(%r3)
ld %r19,40 + 10*8(%r3)
+ lfd %f23,40 + 32*8(%r3)
ld %r20,40 + 11*8(%r3)
+ lfd %f24,40 + 33*8(%r3)
ld %r21,40 + 12*8(%r3)
+ lfd %f25,40 + 34*8(%r3)
ld %r22,40 + 13*8(%r3)
+ lfd %f26,40 + 35*8(%r3)
ld %r23,40 + 14*8(%r3)
+ lfd %f27,40 + 36*8(%r3)
ld %r24,40 + 15*8(%r3)
+ lfd %f28,40 + 37*8(%r3)
ld %r25,40 + 16*8(%r3)
+ lfd %f29,40 + 38*8(%r3)
ld %r26,40 + 17*8(%r3)
+ lfd %f30,40 + 39*8(%r3)
ld %r27,40 + 18*8(%r3)
+ lfd %f31,40 + 40*8(%r3)
ld %r28,40 + 19*8(%r3)
ld %r29,40 + 20*8(%r3)
ld %r30,40 + 21*8(%r3)
diff --git a/lib/libc/powerpc64/sys/Makefile.inc b/lib/libc/powerpc64/sys/Makefile.inc
index ad98ba1..98ec888 100644
--- a/lib/libc/powerpc64/sys/Makefile.inc
+++ b/lib/libc/powerpc64/sys/Makefile.inc
@@ -6,6 +6,3 @@ MDASM+= brk.S cerror.S exect.S pipe.S ptrace.S sbrk.S setlogin.S
NOASM= break.o exit.o getlogin.o openbsd_poll.o sstk.o yield.o
PSEUDO= _getlogin.o _exit.o
-.if ${MK_SYSCALL_COMPAT} != "no"
-PSEUDO+= _pread.o _pwrite.o _lseek.o _mmap.o _ftruncate.o _truncate.o
-.endif
diff --git a/lib/libc/regex/engine.c b/lib/libc/regex/engine.c
index 589bb9d..436370d 100644
--- a/lib/libc/regex/engine.c
+++ b/lib/libc/regex/engine.c
@@ -157,7 +157,7 @@ matcher(struct re_guts *g,
int i;
struct match mv;
struct match *m = &mv;
- const char *dp;
+ const char *dp = NULL;
const sopno gf = g->firststate+1; /* +1 for OEND */
const sopno gl = g->laststate;
const char *start;
@@ -244,7 +244,7 @@ matcher(struct re_guts *g,
ZAPSTATE(&m->mbs);
/* Adjust start according to moffset, to speed things up */
- if (g->moffset > -1)
+ if (dp != NULL && g->moffset > -1)
start = ((dp - g->moffset) < start) ? start : dp - g->moffset;
SP("mloop", m->st, *start);
diff --git a/lib/libc/regex/re_format.7 b/lib/libc/regex/re_format.7
index 05b1494..b3f9561 100644
--- a/lib/libc/regex/re_format.7
+++ b/lib/libc/regex/re_format.7
@@ -314,10 +314,10 @@ compatible with but not specified by
.St -p1003.2 ,
and should be used with
caution in software intended to be portable to other systems.
-The additional word delimiters
+The additional word delimiters
.Ql \e<
and
-.Ql \e>
+.Ql \e>
are provided to ease compatibility with traditional
.Xr svr4 4
systems but are not portable and should be avoided.
@@ -392,10 +392,12 @@ and
.Ql ?\&
are ordinary characters, and their functionality
can be expressed using bounds
-.No ( Ql {1,}
+.Po
+.Ql {1,}
or
.Ql {0,1}
-respectively).
+respectively
+.Pc .
Also note that
.Ql x+
in modern REs is equivalent to
diff --git a/lib/libc/regex/regcomp.c b/lib/libc/regex/regcomp.c
index a01bb95..2f2d827 100644
--- a/lib/libc/regex/regcomp.c
+++ b/lib/libc/regex/regcomp.c
@@ -192,6 +192,7 @@ regcomp(regex_t * __restrict preg,
struct parse *p = &pa;
int i;
size_t len;
+ size_t maxlen;
#ifdef REDEBUG
# define GOODFLAGS(f) (f)
#else
@@ -213,7 +214,23 @@ regcomp(regex_t * __restrict preg,
g = (struct re_guts *)malloc(sizeof(struct re_guts));
if (g == NULL)
return(REG_ESPACE);
+ /*
+ * Limit the pattern space to avoid a 32-bit overflow on buffer
+ * extension. Also avoid any signed overflow in case of conversion
+ * so make the real limit based on a 31-bit overflow.
+ *
+ * Likely not applicable on 64-bit systems but handle the case
+ * generically (who are we to stop people from using ~715MB+
+ * patterns?).
+ */
+ maxlen = ((size_t)-1 >> 1) / sizeof(sop) * 2 / 3;
+ if (len >= maxlen) {
+ free((char *)g);
+ return(REG_ESPACE);
+ }
p->ssize = len/(size_t)2*(size_t)3 + (size_t)1; /* ugh */
+ assert(p->ssize >= len);
+
p->strip = (sop *)malloc(p->ssize * sizeof(sop));
p->slen = 0;
if (p->strip == NULL) {
@@ -1405,8 +1422,8 @@ static void
findmust(struct parse *p, struct re_guts *g)
{
sop *scan;
- sop *start;
- sop *newstart;
+ sop *start = NULL;
+ sop *newstart = NULL;
sopno newlen;
sop s;
char *cp;
@@ -1709,15 +1726,17 @@ computematchjumps(struct parse *p, struct re_guts *g)
if (p->error != 0)
return;
- pmatches = (int*) malloc(g->mlen * sizeof(unsigned int));
+ pmatches = (int*) malloc(g->mlen * sizeof(int));
if (pmatches == NULL) {
g->matchjump = NULL;
return;
}
- g->matchjump = (int*) malloc(g->mlen * sizeof(unsigned int));
- if (g->matchjump == NULL) /* Not a fatal error */
+ g->matchjump = (int*) malloc(g->mlen * sizeof(int));
+ if (g->matchjump == NULL) { /* Not a fatal error */
+ free(pmatches);
return;
+ }
/* Set maximum possible jump for each character in the pattern */
for (mindex = 0; mindex < g->mlen; mindex++)
diff --git a/lib/libc/regex/regex.3 b/lib/libc/regex/regex.3
index ea1ba25..6df2f09 100644
--- a/lib/libc/regex/regex.3
+++ b/lib/libc/regex/regex.3
@@ -420,10 +420,12 @@ it should have been the result from the most recent
using that
.Ft regex_t .
The
-.Fn ( regerror
+.Po
+.Fn regerror
may be able to supply a more detailed message using information
from the
-.Ft regex_t . )
+.Ft regex_t .
+.Pc
The
.Fn regerror
function
diff --git a/lib/libc/rpc/clnt_dg.c b/lib/libc/rpc/clnt_dg.c
index 5feab88..cebbaf9 100644
--- a/lib/libc/rpc/clnt_dg.c
+++ b/lib/libc/rpc/clnt_dg.c
@@ -327,7 +327,7 @@ clnt_dg_call(cl, proc, xargs, argsp, xresults, resultsp, utimeout)
struct sockaddr *sa;
sigset_t mask;
sigset_t newmask;
- socklen_t inlen, salen;
+ socklen_t salen;
ssize_t recvlen = 0;
int kin_len, n, rpc_lock_value;
u_int32_t xid;
@@ -520,7 +520,6 @@ get_reply:
goto call_again_same_xid;
}
}
- inlen = (socklen_t)recvlen;
/*
* now decode and validate the response
diff --git a/lib/libc/rpc/crypt_client.c b/lib/libc/rpc/crypt_client.c
index 4e5c793..5290021 100644
--- a/lib/libc/rpc/crypt_client.c
+++ b/lib/libc/rpc/crypt_client.c
@@ -64,6 +64,7 @@ _des_crypt_call(buf, len, dparms)
}
if (nconf == NULL) {
warnx("getnetconfig: %s", nc_sperror());
+ endnetconfig(localhandle);
return(DESERR_HWERROR);
}
clnt = clnt_tp_create(NULL, CRYPT_PROG, CRYPT_VERS, nconf);
diff --git a/lib/libc/rpc/rpc.3 b/lib/libc/rpc/rpc.3
index 4fa3e2c..988b5f1 100644
--- a/lib/libc/rpc/rpc.3
+++ b/lib/libc/rpc/rpc.3
@@ -504,7 +504,6 @@ pages on which they are described:
.Sh SEE ALSO
.Xr getnetconfig 3 ,
.Xr getnetpath 3 ,
-.Xr rpcbind 3 ,
.Xr rpc_clnt_auth 3 ,
.Xr rpc_clnt_calls 3 ,
.Xr rpc_clnt_create 3 ,
@@ -513,5 +512,6 @@ pages on which they are described:
.Xr rpc_svc_err 3 ,
.Xr rpc_svc_reg 3 ,
.Xr rpc_xdr 3 ,
+.Xr rpcbind 3 ,
.Xr xdr 3 ,
.Xr netconfig 5
diff --git a/lib/libc/rpc/rpc_soc.c b/lib/libc/rpc/rpc_soc.c
index d7702f5..febc597 100644
--- a/lib/libc/rpc/rpc_soc.c
+++ b/lib/libc/rpc/rpc_soc.c
@@ -462,12 +462,10 @@ clntunix_create(raddr, prog, vers, sockp, sendsz, recvsz)
u_int recvsz;
{
struct netbuf *svcaddr;
- struct netconfig *nconf;
CLIENT *cl;
int len;
cl = NULL;
- nconf = NULL;
svcaddr = NULL;
if ((raddr->sun_len == 0) ||
((svcaddr = malloc(sizeof(struct netbuf))) == NULL ) ||
diff --git a/lib/libc/rpc/rpc_svc_reg.3 b/lib/libc/rpc/rpc_svc_reg.3
index aed2ba1..81a749a 100644
--- a/lib/libc/rpc/rpc_svc_reg.3
+++ b/lib/libc/rpc/rpc_svc_reg.3
@@ -176,8 +176,8 @@ Service implementors usually do not need this routine.
.Sh SEE ALSO
.Xr select 2 ,
.Xr rpc 3 ,
-.Xr rpcbind 3 ,
.Xr rpc_svc_calls 3 ,
.Xr rpc_svc_create 3 ,
.Xr rpc_svc_err 3 ,
+.Xr rpcbind 3 ,
.Xr rpcbind 8
diff --git a/lib/libc/rpc/rpcbind.3 b/lib/libc/rpc/rpcbind.3
index 0b716ca..3bf8be9 100644
--- a/lib/libc/rpc/rpcbind.3
+++ b/lib/libc/rpc/rpcbind.3
@@ -25,7 +25,7 @@
.Ft bool_t
.Fn rpcb_gettime "const char *host" "time_t * timep"
.Ft "enum clnt_stat"
-.Fn rpcb_rmtcall "const struct netconfig *netconf" "const char *host" "const rpcprog_t prognum, const rpcvers_t versnum" "const rpcproc_t procnum, const xdrproc_t inproc" "const caddr_t in" "const xdrproc_t outproc" "const caddr_t out" "const struct timeval tout, const struct netbuf *svcaddr"
+.Fn rpcb_rmtcall "const struct netconfig *netconf" "const char *host" "const rpcprog_t prognum" "const rpcvers_t versnum" "const rpcproc_t procnum" "const xdrproc_t inproc" "const caddr_t in" "const xdrproc_t outproc" "const caddr_t out" "const struct timeval tout" "const struct netbuf *svcaddr"
.Ft bool_t
.Fn rpcb_set "const rpcprog_t prognum" "const rpcvers_t versnum" "const struct netconfig *netconf" "const struct netbuf *svcaddr"
.Ft bool_t
diff --git a/lib/libc/rpc/svc_vc.c b/lib/libc/rpc/svc_vc.c
index f830425..aa45396 100644
--- a/lib/libc/rpc/svc_vc.c
+++ b/lib/libc/rpc/svc_vc.c
@@ -128,7 +128,7 @@ svc_vc_create(fd, sendsize, recvsize)
u_int sendsize;
u_int recvsize;
{
- SVCXPRT *xprt;
+ SVCXPRT *xprt = NULL;
struct cf_rendezvous *r = NULL;
struct __rpc_sockinfo si;
struct sockaddr_storage sslocal;
diff --git a/lib/libc/sparc64/Makefile.inc b/lib/libc/sparc64/Makefile.inc
index af23ae4..74fb7cd 100644
--- a/lib/libc/sparc64/Makefile.inc
+++ b/lib/libc/sparc64/Makefile.inc
@@ -5,7 +5,7 @@
.include "fpu/Makefile.inc"
-SRCS+= __vdso_gettc.c
+SRCS+= trivial-vdso_tc.c
# Long double is quad precision
GDTOASRCS+=strtorQ.c
diff --git a/lib/libc/sparc64/gen/Makefile.inc b/lib/libc/sparc64/gen/Makefile.inc
index d3fbfe4..5442a33 100644
--- a/lib/libc/sparc64/gen/Makefile.inc
+++ b/lib/libc/sparc64/gen/Makefile.inc
@@ -2,5 +2,6 @@
SRCS+= _ctx_start.S _setjmp.S fabs.S fixunsdfsi.S flt_rounds.c fpgetmask.c \
fpgetround.c fpgetsticky.c fpsetmask.c fpsetround.c \
- getcontextx.c infinity.c ldexp.c makecontext.c \
- signalcontext.c setjmp.S sigsetjmp.S _set_tp.c
+ infinity.c ldexp.c makecontext.c \
+ signalcontext.c setjmp.S sigsetjmp.S _set_tp.c \
+ trivial-getcontextx.c
diff --git a/lib/libc/sparc64/gen/getcontextx.c b/lib/libc/sparc64/gen/getcontextx.c
deleted file mode 100644
index 54f8513..0000000
--- a/lib/libc/sparc64/gen/getcontextx.c
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright (c) 2011 Konstantin Belousov <kib@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 ``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$");
-
-#include <sys/types.h>
-#include <sys/ucontext.h>
-#include <errno.h>
-#include <stdlib.h>
-
-int
-__getcontextx_size(void)
-{
-
- return (sizeof(ucontext_t));
-}
-
-int
-__fillcontextx2(char *ctx)
-{
-
- return (0);
-}
-
-int
-__fillcontextx(char *ctx)
-{
- ucontext_t *ucp;
-
- ucp = (ucontext_t *)ctx;
- return (getcontext(ucp));
-}
-
-__weak_reference(__getcontextx, getcontextx);
-
-ucontext_t *
-__getcontextx(void)
-{
- char *ctx;
- int error;
-
- ctx = malloc(__getcontextx_size());
- if (ctx == NULL)
- return (NULL);
- if (__fillcontextx(ctx) == -1) {
- error = errno;
- free(ctx);
- errno = error;
- return (NULL);
- }
- return ((ucontext_t *)ctx);
-}
diff --git a/lib/libc/sparc64/sys/Makefile.inc b/lib/libc/sparc64/sys/Makefile.inc
index 031af19..a62aac2 100644
--- a/lib/libc/sparc64/sys/Makefile.inc
+++ b/lib/libc/sparc64/sys/Makefile.inc
@@ -12,12 +12,9 @@ SRCS+= __sparc_sigtramp_setup.c \
CFLAGS+= -I${LIBC_SRCTOP}/sparc64/fpu
-MDASM+= brk.S cerror.S exect.S pipe.S ptrace.S sbrk.S setlogin.S sigaction.S
+MDASM+= brk.S cerror.S exect.S pipe.S ptrace.S sbrk.S setlogin.S sigaction1.S
# Don't generate default code for these syscalls:
NOASM= break.o exit.o getlogin.o openbsd_poll.o sstk.o yield.o
PSEUDO= _getlogin.o _exit.o
-.if ${MK_SYSCALL_COMPAT} != "no"
-PSEUDO+= _pread.o _pwrite.o _lseek.o _mmap.o _ftruncate.o _truncate.o
-.endif
diff --git a/lib/libc/sparc64/sys/__vdso_gettc.c b/lib/libc/sparc64/sys/__vdso_gettc.c
deleted file mode 100644
index b99bbc4..0000000
--- a/lib/libc/sparc64/sys/__vdso_gettc.c
+++ /dev/null
@@ -1,48 +0,0 @@
-/*-
- * Copyright (c) 2013 Konstantin Belousov <kib@FreeBSD.org>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/vdso.h>
-#include <errno.h>
-
-#pragma weak __vdso_gettc
-u_int
-__vdso_gettc(const struct vdso_timehands *th)
-{
-
- return (0);
-}
-
-#pragma weak __vdso_gettimekeep
-int
-__vdso_gettimekeep(struct vdso_timekeep **tk)
-{
-
- return (ENOSYS);
-}
diff --git a/lib/libc/sparc64/sys/sigaction.S b/lib/libc/sparc64/sys/sigaction1.S
index 7d32f97..219a238 100644
--- a/lib/libc/sparc64/sys/sigaction.S
+++ b/lib/libc/sparc64/sys/sigaction1.S
@@ -29,7 +29,8 @@ __FBSDID("$FreeBSD$");
#include "SYS.h"
-_SYSENTRY(sigaction)
+ WEAK_REFERENCE(__sys_sigaction, _sigaction)
+ENTRY(__sys_sigaction)
PIC_PROLOGUE(%o3, %o4)
SET(sigcode_installed, %o4, %o3)
lduw [%o3], %o4
@@ -44,6 +45,6 @@ _SYSENTRY(sigaction)
1: _SYSCALL(sigaction)
retl
nop
-_SYSEND(sigaction)
+END(__sys_sigaction)
.comm sigcode_installed, 4, 4
diff --git a/lib/libc/stdio/fflush.c b/lib/libc/stdio/fflush.c
index ef9b45b..123167a 100644
--- a/lib/libc/stdio/fflush.c
+++ b/lib/libc/stdio/fflush.c
@@ -124,11 +124,13 @@ __sflush(FILE *fp)
t = _swrite(fp, (char *)p, n);
if (t <= 0) {
/* Reset _p and _w. */
- if (p > fp->_p) /* Some was written. */
+ if (p > fp->_p) {
+ /* Some was written. */
memmove(fp->_p, p, n);
- fp->_p += n;
- if ((fp->_flags & (__SLBF | __SNBF)) == 0)
- fp->_w -= n;
+ fp->_p += n;
+ if ((fp->_flags & (__SLBF | __SNBF)) == 0)
+ fp->_w -= n;
+ }
fp->_flags |= __SERR;
return (EOF);
}
diff --git a/lib/libc/stdio/flags.c b/lib/libc/stdio/flags.c
index b7552a4..9eed6d7 100644
--- a/lib/libc/stdio/flags.c
+++ b/lib/libc/stdio/flags.c
@@ -97,6 +97,10 @@ __sflags(const char *mode, int *optr)
/* set close-on-exec */
o |= O_CLOEXEC;
break;
+ case 'v':
+ /* verify */
+ o |= O_VERIFY;
+ break;
default:
known = 0;
break;
diff --git a/lib/libc/stdio/open_memstream.3 b/lib/libc/stdio/open_memstream.3
index 117dcb2..e01952b 100644
--- a/lib/libc/stdio/open_memstream.3
+++ b/lib/libc/stdio/open_memstream.3
@@ -1,4 +1,4 @@
-.\" Copyright (c) 2013 Advanced Computing Technologies LLC
+.\" Copyright (c) 2013 Hudson River Trading LLC
.\" Written by: John H. Baldwin <jhb@FreeBSD.org>
.\" All rights reserved.
.\"
diff --git a/lib/libc/stdio/open_memstream.c b/lib/libc/stdio/open_memstream.c
index aa50822..baa71e4 100644
--- a/lib/libc/stdio/open_memstream.c
+++ b/lib/libc/stdio/open_memstream.c
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2013 Advanced Computing Technologies LLC
+ * Copyright (c) 2013 Hudson River Trading LLC
* Written by: John H. Baldwin <jhb@FreeBSD.org>
* All rights reserved.
*
diff --git a/lib/libc/stdio/open_wmemstream.c b/lib/libc/stdio/open_wmemstream.c
index cf2968a..299e3d8 100644
--- a/lib/libc/stdio/open_wmemstream.c
+++ b/lib/libc/stdio/open_wmemstream.c
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2013 Advanced Computing Technologies LLC
+ * Copyright (c) 2013 Hudson River Trading LLC
* Written by: John H. Baldwin <jhb@FreeBSD.org>
* All rights reserved.
*
diff --git a/lib/libc/stdio/xprintf_float.c b/lib/libc/stdio/xprintf_float.c
index b719aac..ad17eb2 100644
--- a/lib/libc/stdio/xprintf_float.c
+++ b/lib/libc/stdio/xprintf_float.c
@@ -168,7 +168,6 @@ __printf_render_float(struct __printf_io *io, const struct printf_info *pi, cons
int realsz; /* field size expanded by dprec, sign, etc */
int dprec; /* a copy of prec if [diouxX], 0 otherwise */
char ox[2]; /* space for 0x; ox[1] is either x, X, or \0 */
- int prsize; /* max size of printed field */
int ret; /* return value accumulator */
char *decimal_point; /* locale specific decimal point */
int n2; /* XXX: for PRINTANDPAD */
@@ -344,8 +343,6 @@ here:
if (ox[1])
realsz += 2;
- prsize = pi->width > realsz ? pi->width : realsz;
-
/* right-adjusting blank padding */
if (pi->pad != '0' && pi->left == 0)
ret += __printf_pad(io, pi->width - realsz, 0);
diff --git a/lib/libc/stdlib/Makefile.inc b/lib/libc/stdlib/Makefile.inc
index 57205a7..7cee03a 100644
--- a/lib/libc/stdlib/Makefile.inc
+++ b/lib/libc/stdlib/Makefile.inc
@@ -10,7 +10,8 @@ MISRCS+=_Exit.c a64l.c abort.c abs.c atexit.c atof.c atoi.c atol.c atoll.c \
insque.c l64a.c labs.c ldiv.c llabs.c lldiv.c lsearch.c \
merge.c mergesort_b.c ptsname.c qsort.c qsort_r.c quick_exit.c \
radixsort.c rand.c \
- random.c reallocf.c realpath.c remque.c strfmon.c strtoimax.c \
+ random.c reallocarray.c reallocf.c realpath.c remque.c strfmon.c \
+ strtoimax.c \
strtol.c strtoll.c strtoq.c strtoul.c strtonum.c strtoull.c \
strtoumax.c strtouq.c system.c tdelete.c tfind.c tsearch.c twalk.c
@@ -25,7 +26,7 @@ MAN+= a64l.3 abort.3 abs.3 alloca.3 atexit.3 atof.3 \
hcreate.3 imaxabs.3 imaxdiv.3 insque.3 labs.3 ldiv.3 llabs.3 lldiv.3 \
lsearch.3 memory.3 ptsname.3 qsort.3 \
quick_exit.3 \
- radixsort.3 rand.3 random.3 reallocf.3 \
+ radixsort.3 rand.3 random.3 reallocarray.3 reallocf.3 \
realpath.3 strfmon.3 strtod.3 strtol.3 strtonum.3 strtoul.3 system.3 \
tsearch.3
diff --git a/lib/libc/stdlib/Symbol.map b/lib/libc/stdlib/Symbol.map
index 8355f9a..782023e 100644
--- a/lib/libc/stdlib/Symbol.map
+++ b/lib/libc/stdlib/Symbol.map
@@ -113,9 +113,11 @@ FBSD_1.4 {
hcreate_r;
hdestroy_r;
hsearch_r;
+ reallocarray;
};
FBSDprivate_1.0 {
__system;
_system;
+ __libc_system;
};
diff --git a/lib/libc/stdlib/atexit.3 b/lib/libc/stdlib/atexit.3
index 68f4e8f..3cdc59f 100644
--- a/lib/libc/stdlib/atexit.3
+++ b/lib/libc/stdlib/atexit.3
@@ -88,12 +88,12 @@ The existing list of functions is unmodified.
.It Bq Er ENOSYS
The
.Fn atexit_b
-function was called by a program that did not supply a
+function was called by a program that did not supply a
.Fn _Block_copy
implementation.
.El
.Sh SEE ALSO
-.Xr at_quick_exit 3
+.Xr at_quick_exit 3 ,
.Xr exit 3
.Sh STANDARDS
The
diff --git a/lib/libc/stdlib/exit.3 b/lib/libc/stdlib/exit.3
index 07ce0d7..7d657c9 100644
--- a/lib/libc/stdlib/exit.3
+++ b/lib/libc/stdlib/exit.3
@@ -117,8 +117,8 @@ never return.
.Sh SEE ALSO
.Xr _exit 2 ,
.Xr wait 2 ,
-.Xr atexit 3 ,
.Xr at_quick_exit 3 ,
+.Xr atexit 3 ,
.Xr intro 3 ,
.Xr quick_exit 3 ,
.Xr sysexits 3 ,
diff --git a/lib/libc/stdlib/jemalloc/Symbol.map b/lib/libc/stdlib/jemalloc/Symbol.map
index 35a5dad..132664a 100644
--- a/lib/libc/stdlib/jemalloc/Symbol.map
+++ b/lib/libc/stdlib/jemalloc/Symbol.map
@@ -55,4 +55,5 @@ FBSDprivate_1.0 {
_malloc_thread_cleanup;
_malloc_prefork;
_malloc_postfork;
+ _malloc_first_thread;
};
diff --git a/lib/libc/stdlib/qsort.c b/lib/libc/stdlib/qsort.c
index 93e22cd..e97ea92 100644
--- a/lib/libc/stdlib/qsort.c
+++ b/lib/libc/stdlib/qsort.c
@@ -41,47 +41,55 @@ typedef int cmp_t(void *, const void *, const void *);
typedef int cmp_t(const void *, const void *);
#endif
static inline char *med3(char *, char *, char *, cmp_t *, void *);
-static inline void swapfunc(char *, char *, int, int);
+static inline void swapfunc(char *, char *, int, int, int);
-#define min(a, b) (a) < (b) ? a : b
+#define MIN(a, b) ((a) < (b) ? a : b)
/*
* Qsort routine from Bentley & McIlroy's "Engineering a Sort Function".
*/
-#define swapcode(TYPE, parmi, parmj, n) { \
- long i = (n) / sizeof (TYPE); \
- TYPE *pi = (TYPE *) (parmi); \
- TYPE *pj = (TYPE *) (parmj); \
+#define swapcode(TYPE, parmi, parmj, n) { \
+ long i = (n) / sizeof (TYPE); \
+ TYPE *pi = (TYPE *) (parmi); \
+ TYPE *pj = (TYPE *) (parmj); \
do { \
TYPE t = *pi; \
*pi++ = *pj; \
*pj++ = t; \
- } while (--i > 0); \
+ } while (--i > 0); \
}
-#define SWAPINIT(a, es) swaptype = ((char *)a - (char *)0) % sizeof(long) || \
- es % sizeof(long) ? 2 : es == sizeof(long)? 0 : 1;
+#define SWAPINIT(TYPE, a, es) swaptype_ ## TYPE = \
+ ((char *)a - (char *)0) % sizeof(TYPE) || \
+ es % sizeof(TYPE) ? 2 : es == sizeof(TYPE) ? 0 : 1;
static inline void
-swapfunc(a, b, n, swaptype)
+swapfunc(a, b, n, swaptype_long, swaptype_int)
char *a, *b;
- int n, swaptype;
+ int n, swaptype_long, swaptype_int;
{
- if(swaptype <= 1)
+ if (swaptype_long <= 1)
swapcode(long, a, b, n)
+ else if (swaptype_int <= 1)
+ swapcode(int, a, b, n)
else
swapcode(char, a, b, n)
}
-#define swap(a, b) \
- if (swaptype == 0) { \
+#define swap(a, b) \
+ if (swaptype_long == 0) { \
long t = *(long *)(a); \
*(long *)(a) = *(long *)(b); \
*(long *)(b) = t; \
+ } else if (swaptype_int == 0) { \
+ int t = *(int *)(a); \
+ *(int *)(a) = *(int *)(b); \
+ *(int *)(b) = t; \
} else \
- swapfunc(a, b, es, swaptype)
+ swapfunc(a, b, es, swaptype_long, swaptype_int)
-#define vecswap(a, b, n) if ((n) > 0) swapfunc(a, b, n, swaptype)
+#define vecswap(a, b, n) \
+ if ((n) > 0) swapfunc(a, b, n, swaptype_long, swaptype_int)
#ifdef I_AM_QSORT_R
#define CMP(t, x, y) (cmp((t), (x), (y)))
@@ -98,14 +106,14 @@ __unused
{
return CMP(thunk, a, b) < 0 ?
(CMP(thunk, b, c) < 0 ? b : (CMP(thunk, a, c) < 0 ? c : a ))
- :(CMP(thunk, b, c) > 0 ? b : (CMP(thunk, a, c) < 0 ? a : c ));
+ :(CMP(thunk, b, c) > 0 ? b : (CMP(thunk, a, c) < 0 ? a : c ));
}
#ifdef I_AM_QSORT_R
void
qsort_r(void *a, size_t n, size_t es, void *thunk, cmp_t *cmp)
#else
-#define thunk NULL
+#define thunk NULL
void
qsort(void *a, size_t n, size_t es, cmp_t *cmp)
#endif
@@ -113,9 +121,10 @@ qsort(void *a, size_t n, size_t es, cmp_t *cmp)
char *pa, *pb, *pc, *pd, *pl, *pm, *pn;
size_t d, r;
int cmp_result;
- int swaptype, swap_cnt;
+ int swaptype_long, swaptype_int, swap_cnt;
-loop: SWAPINIT(a, es);
+loop: SWAPINIT(long, a, es);
+ SWAPINIT(int, a, es);
swap_cnt = 0;
if (n < 7) {
for (pm = (char *)a + es; pm < (char *)a + n * es; pm += es)
@@ -175,9 +184,9 @@ loop: SWAPINIT(a, es);
}
pn = (char *)a + n * es;
- r = min(pa - (char *)a, pb - pa);
+ r = MIN(pa - (char *)a, pb - pa);
vecswap(a, pb - r, r);
- r = min(pd - pc, pn - pd - es);
+ r = MIN(pd - pc, pn - pd - es);
vecswap(pb, pn - r, r);
if ((r = pb - pa) > es)
#ifdef I_AM_QSORT_R
diff --git a/lib/libc/stdlib/quick_exit.3 b/lib/libc/stdlib/quick_exit.3
index f2ea379..7bbd2f3 100644
--- a/lib/libc/stdlib/quick_exit.3
+++ b/lib/libc/stdlib/quick_exit.3
@@ -24,7 +24,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd December 7, 2011
+.Dd December 13, 2014
.Dt QUICK_EXIT 3
.Os
.Sh NAME
@@ -35,7 +35,7 @@
.Sh SYNOPSIS
.In stdlib.h
.Ft _Noreturn void
-.Fn quick_exit "void"
+.Fn quick_exit "int status"
.Sh DESCRIPTION
The
.Fn quick_exit
diff --git a/lib/libc/stdlib/random.3 b/lib/libc/stdlib/random.3
index dc8e961..254be0a 100644
--- a/lib/libc/stdlib/random.3
+++ b/lib/libc/stdlib/random.3
@@ -54,9 +54,8 @@
.Fn setstate "char *state"
.Sh DESCRIPTION
.Bf -symbolic
-The functions described in this manual page are not cryptographically
-secure.
-Cryptographic applications should use
+The functions described in this manual page are not secure.
+Applications which require unpredictable random numbers should use
.Xr arc4random 3
instead.
.Ef
diff --git a/lib/libc/stdlib/reallocarray.3 b/lib/libc/stdlib/reallocarray.3
new file mode 100644
index 0000000..8e714f4
--- /dev/null
+++ b/lib/libc/stdlib/reallocarray.3
@@ -0,0 +1,142 @@
+.\" Copyright (c) 1980, 1991, 1993
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" This code is derived from software contributed to Berkeley by
+.\" the American National Standards Committee X3, on Information
+.\" Processing Systems.
+.\"
+.\" 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 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$
+.\"
+.Dd May 1, 2015
+.Dt REALLOCARRAY 3
+.Os
+.Sh NAME
+.Nm reallocarray
+.Nd memory reallocation function
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In stdlib.h
+.Ft void *
+.Fn reallocarray "void *ptr" "size_t nmemb" "size_t size"
+.Sh DESCRIPTION
+The
+.Fn reallocarray
+function is similar to the
+.Fn realloc
+function
+except it operates on
+.Fa nmemb
+members of size
+.Fa size
+and checks for integer overflow in the calculation
+.Fa nmemb
+*
+.Fa size .
+.Sh RETURN VALUES
+The
+.Fn reallocarray
+function returns a pointer to the allocated space; otherwise, a
+.Dv NULL
+pointer is returned and
+.Va errno
+is set to
+.Er ENOMEM .
+.Sh EXAMPLES
+Consider
+.Fn reallocarray
+when there is multiplication in the
+.Fa size
+argument of
+.Fn malloc
+or
+.Fn realloc .
+For example, avoid this common idiom as it may lead to integer overflow:
+.Bd -literal -offset indent
+if ((p = malloc(num * size)) == NULL)
+ err(1, "malloc");
+.Ed
+.Pp
+A drop-in replacement is the
+.Ox
+extension
+.Fn reallocarray :
+.Bd -literal -offset indent
+if ((p = reallocarray(NULL, num, size)) == NULL)
+ err(1, "reallocarray");
+.Ed
+.Pp
+When using
+.Fn realloc ,
+be careful to avoid the following idiom:
+.Bd -literal -offset indent
+size += 50;
+if ((p = realloc(p, size)) == NULL)
+ return (NULL);
+.Ed
+.Pp
+Do not adjust the variable describing how much memory has been allocated
+until the allocation has been successful.
+This can cause aberrant program behavior if the incorrect size value is used.
+In most cases, the above sample will also result in a leak of memory.
+As stated earlier, a return value of
+.Dv NULL
+indicates that the old object still remains allocated.
+Better code looks like this:
+.Bd -literal -offset indent
+newsize = size + 50;
+if ((newp = realloc(p, newsize)) == NULL) {
+ free(p);
+ p = NULL;
+ size = 0;
+ return (NULL);
+}
+p = newp;
+size = newsize;
+.Ed
+.Pp
+As with
+.Fn malloc ,
+it is important to ensure the new size value will not overflow;
+i.e. avoid allocations like the following:
+.Bd -literal -offset indent
+if ((newp = realloc(p, num * size)) == NULL) {
+ ...
+.Ed
+.Pp
+Instead, use
+.Fn reallocarray :
+.Bd -literal -offset indent
+if ((newp = reallocarray(p, num, size)) == NULL) {
+ ...
+.Ed
+.Sh SEE ALSO
+.Xr realloc 3
+.Sh HISTORY
+The
+.Fn reallocarray
+function first appeared in
+.Ox 5.6
+and
+.Fx 11.0 .
diff --git a/lib/libc/stdlib/reallocarray.c b/lib/libc/stdlib/reallocarray.c
new file mode 100644
index 0000000..e1e9b7c
--- /dev/null
+++ b/lib/libc/stdlib/reallocarray.c
@@ -0,0 +1,42 @@
+/* $OpenBSD: reallocarray.c,v 1.2 2014/12/08 03:45:00 bcook Exp $ */
+/*
+ * Copyright (c) 2008 Otto Moerbeek <otto@drijf.net>
+ *
+ * Permission to use, copy, modify, and 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 THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <errno.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+/*
+ * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX
+ * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW
+ */
+#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4))
+
+void *
+reallocarray(void *optr, size_t nmemb, size_t size)
+{
+
+ if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
+ nmemb > 0 && SIZE_MAX / nmemb < size) {
+ errno = ENOMEM;
+ return (NULL);
+ }
+ return (realloc(optr, size * nmemb));
+}
diff --git a/lib/libc/stdlib/system.c b/lib/libc/stdlib/system.c
index e018e6f..bd9ea5a 100644
--- a/lib/libc/stdlib/system.c
+++ b/lib/libc/stdlib/system.c
@@ -46,8 +46,17 @@ __FBSDID("$FreeBSD$");
#include "un-namespace.h"
#include "libc_private.h"
+#pragma weak system
int
-__system(const char *command)
+system(const char *command)
+{
+
+ return (((int (*)(const char *))
+ __libc_interposing[INTERPOS_system])(command));
+}
+
+int
+__libc_system(const char *command)
{
pid_t pid, savedpid;
int pstat;
@@ -95,5 +104,5 @@ __system(const char *command)
return(pid == -1 ? -1 : pstat);
}
-__weak_reference(__system, system);
-__weak_reference(__system, _system);
+__weak_reference(__libc_system, __system);
+__weak_reference(__libc_system, _system);
diff --git a/lib/libc/stdlib/tdelete.c b/lib/libc/stdlib/tdelete.c
index c83afb8..bef187e 100644
--- a/lib/libc/stdlib/tdelete.c
+++ b/lib/libc/stdlib/tdelete.c
@@ -14,7 +14,7 @@
#include <sys/cdefs.h>
#if 0
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: tdelete.c,v 1.2 1999/09/16 11:45:37 lukem Exp $");
+__RCSID("$NetBSD: tdelete.c,v 1.6 2012/06/25 22:32:45 abs Exp $");
#endif /* LIBC_SCCS and not lint */
#endif
__FBSDID("$FreeBSD$");
@@ -25,9 +25,9 @@ __FBSDID("$FreeBSD$");
/*
- * delete node with given key
+ * find a node with given key
*
- * vkey: key to be deleted
+ * vkey: key to be found
* vrootp: address of the root of the tree
* compar: function to carry out node comparisons
*/
@@ -65,7 +65,8 @@ tdelete(const void * __restrict vkey, void ** __restrict vrootp,
q->rlink = (*rootp)->rlink;
}
}
- free(*rootp); /* D4: Free node */
+ if (p != *rootp)
+ free(*rootp); /* D4: Free node */
*rootp = q; /* link parent to new node */
return p;
}
diff --git a/lib/libc/string/strlcat.c b/lib/libc/string/strlcat.c
index 2d13be7..f5ed6c6 100644
--- a/lib/libc/string/strlcat.c
+++ b/lib/libc/string/strlcat.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: strlcat.c,v 1.13 2005/08/08 08:05:37 espie Exp $ */
+/* $OpenBSD: strlcat.c,v 1.15 2015/03/02 21:41:08 millert Exp $ */
/*
- * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 1998, 2015 Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -23,36 +23,36 @@ __FBSDID("$FreeBSD$");
#include <string.h>
/*
- * Appends src to string dst of size siz (unlike strncat, siz is the
- * full size of dst, not space left). At most siz-1 characters
- * will be copied. Always NUL terminates (unless siz <= strlen(dst)).
- * Returns strlen(src) + MIN(siz, strlen(initial dst)).
- * If retval >= siz, truncation occurred.
+ * Appends src to string dst of size dsize (unlike strncat, dsize is the
+ * full size of dst, not space left). At most dsize-1 characters
+ * will be copied. Always NUL terminates (unless dsize <= strlen(dst)).
+ * Returns strlen(src) + MIN(dsize, strlen(initial dst)).
+ * If retval >= dsize, truncation occurred.
*/
size_t
-strlcat(char * __restrict dst, const char * __restrict src, size_t siz)
+strlcat(char * __restrict dst, const char * __restrict src, size_t dsize)
{
- char *d = dst;
- const char *s = src;
- size_t n = siz;
+ const char *odst = dst;
+ const char *osrc = src;
+ size_t n = dsize;
size_t dlen;
- /* Find the end of dst and adjust bytes left but don't go past end */
- while (n-- != 0 && *d != '\0')
- d++;
- dlen = d - dst;
- n = siz - dlen;
+ /* Find the end of dst and adjust bytes left but don't go past end. */
+ while (n-- != 0 && *dst != '\0')
+ dst++;
+ dlen = dst - odst;
+ n = dsize - dlen;
- if (n == 0)
- return(dlen + strlen(s));
- while (*s != '\0') {
- if (n != 1) {
- *d++ = *s;
+ if (n-- == 0)
+ return(dlen + strlen(src));
+ while (*src != '\0') {
+ if (n != 0) {
+ *dst++ = *src;
n--;
}
- s++;
+ src++;
}
- *d = '\0';
+ *dst = '\0';
- return(dlen + (s - src)); /* count does not include NUL */
+ return(dlen + (src - osrc)); /* count does not include NUL */
}
diff --git a/lib/libc/string/strlcpy.c b/lib/libc/string/strlcpy.c
index 451b6df..019d231 100644
--- a/lib/libc/string/strlcpy.c
+++ b/lib/libc/string/strlcpy.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: strlcpy.c,v 1.11 2006/05/05 15:27:38 millert Exp $ */
+/* $OpenBSD: strlcpy.c,v 1.12 2015/01/15 03:54:12 millert Exp $ */
/*
- * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 1998, 2015 Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -23,32 +23,31 @@ __FBSDID("$FreeBSD$");
#include <string.h>
/*
- * Copy src to string dst of size siz. At most siz-1 characters
- * will be copied. Always NUL terminates (unless siz == 0).
- * Returns strlen(src); if retval >= siz, truncation occurred.
+ * Copy string src to buffer dst of size dsize. At most dsize-1
+ * chars will be copied. Always NUL terminates (unless dsize == 0).
+ * Returns strlen(src); if retval >= dsize, truncation occurred.
*/
size_t
-strlcpy(char * __restrict dst, const char * __restrict src, size_t siz)
+strlcpy(char * __restrict dst, const char * __restrict src, size_t dsize)
{
- char *d = dst;
- const char *s = src;
- size_t n = siz;
+ const char *osrc = src;
+ size_t nleft = dsize;
- /* Copy as many bytes as will fit */
- if (n != 0) {
- while (--n != 0) {
- if ((*d++ = *s++) == '\0')
+ /* Copy as many bytes as will fit. */
+ if (nleft != 0) {
+ while (--nleft != 0) {
+ if ((*dst++ = *src++) == '\0')
break;
}
}
- /* Not enough room in dst, add NUL and traverse rest of src */
- if (n == 0) {
- if (siz != 0)
- *d = '\0'; /* NUL-terminate dst */
- while (*s++)
+ /* Not enough room in dst, add NUL and traverse rest of src. */
+ if (nleft == 0) {
+ if (dsize != 0)
+ *dst = '\0'; /* NUL-terminate dst */
+ while (*src++)
;
}
- return(s - src - 1); /* count does not include NUL */
+ return(src - osrc - 1); /* count does not include NUL */
}
diff --git a/lib/libc/string/strspn.3 b/lib/libc/string/strspn.3
index 542b190..4a8e3f4 100644
--- a/lib/libc/string/strspn.3
+++ b/lib/libc/string/strspn.3
@@ -71,7 +71,7 @@ spans the initial part of the null-terminated string
.Fa s
as long as the characters from
.Fa s
-.Sy do not
+.Sy do not
occur in the null-terminated string
.Fa charset
.Po it spans the
diff --git a/lib/libc/sys/Makefile.inc b/lib/libc/sys/Makefile.inc
index c14b351..5162563 100644
--- a/lib/libc/sys/Makefile.inc
+++ b/lib/libc/sys/Makefile.inc
@@ -20,17 +20,62 @@ 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 ${MK_SYSCALL_COMPAT} != "no"
-SYSCALL_COMPAT_SRCS= fcntl.c ftruncate.c lseek.c mmap.c pread.c \
- pwrite.c truncate.c
-SRCS+= ${SYSCALL_COMPAT_SRCS}
-NOASM+= ${SYSCALL_COMPAT_SRCS:S/.c/.o/}
-PSEUDO+= _fcntl.o
+SRCS+= \
+ stack_protector.c \
+ stack_protector_compat.c \
+ __error.c \
+ interposing_table.c
+
+SRCS+= futimens.c utimensat.c
+NOASM+= futimens.o utimensat.o
+PSEUDO+= _futimens.o _utimensat.o
+
+INTERPOSED = \
+ accept \
+ accept4 \
+ aio_suspend \
+ close \
+ connect \
+ fcntl \
+ fsync \
+ fork \
+ kevent \
+ msync \
+ nanosleep \
+ open \
+ openat \
+ poll \
+ ppoll \
+ pselect \
+ read \
+ readv \
+ recvfrom \
+ recvmsg \
+ select \
+ sendmsg \
+ sendto \
+ setcontext \
+ sigprocmask \
+ sigsuspend \
+ sigtimedwait \
+ sigwait \
+ sigwaitinfo \
+ swapcontext \
+ wait4 \
+ wait6 \
+ write \
+ writev
+
+.if ${MACHINE_CPUARCH} == "sparc64"
+SRCS+= sigaction.c
+NOASM+= sigaction.o
+.else
+INTERPOSED+= sigaction
.endif
-SRCS+= sigwait.c
-NOASM+= sigwait.o
-PSEUDO+= _sigwait.o
+
+SRCS+= ${INTERPOSED:S/$/.c/}
+NOASM+= ${INTERPOSED:S/$/.o/}
+PSEUDO+= ${INTERPOSED:C/^.*$/_&.o/}
# Add machine dependent asm sources:
SRCS+=${MDASM}
@@ -266,6 +311,7 @@ MAN+= sctp_generic_recvmsg.2 \
umask.2 \
undelete.2 \
unlink.2 \
+ utimensat.2 \
utimes.2 \
utrace.2 \
uuidgen.2 \
@@ -398,6 +444,7 @@ MLINKS+=timer_settime.2 timer_getoverrun.2 \
timer_settime.2 timer_gettime.2
MLINKS+=truncate.2 ftruncate.2
MLINKS+=unlink.2 unlinkat.2
+MLINKS+=utimensat.2 futimens.2
MLINKS+=utimes.2 futimes.2 \
utimes.2 futimesat.2 \
utimes.2 lutimes.2
diff --git a/lib/libc/sys/Symbol.map b/lib/libc/sys/Symbol.map
index 448bcce..194aa5b 100644
--- a/lib/libc/sys/Symbol.map
+++ b/lib/libc/sys/Symbol.map
@@ -245,7 +245,6 @@ FBSD_1.0 {
setaudit;
setaudit_addr;
setauid;
- setcontext;
setegid;
seteuid;
setgid;
@@ -286,7 +285,6 @@ FBSD_1.0 {
__stack_chk_guard;
stat;
statfs;
- swapcontext;
swapoff;
swapon;
symlink;
@@ -351,7 +349,6 @@ FBSD_1.1 {
mkfifoat;
mknodat;
msgctl;
- openat;
readlinkat;
renameat;
setfib;
@@ -400,7 +397,9 @@ FBSD_1.3 {
};
FBSD_1.4 {
+ futimens;
ppoll;
+ utimensat;
};
FBSDprivate_1.0 {
@@ -1048,7 +1047,9 @@ FBSDprivate_1.0 {
__sys_write;
_writev;
__sys_writev;
- __error_unthreaded;
+ __set_error_selector;
nlm_syscall;
gssd_syscall;
+ __libc_interposing_slot;
+ __libc_sigwait;
};
diff --git a/lib/libc/sys/__error.c b/lib/libc/sys/__error.c
index c3f59f8..28cc31d 100644
--- a/lib/libc/sys/__error.c
+++ b/lib/libc/sys/__error.c
@@ -32,14 +32,25 @@ __FBSDID("$FreeBSD$");
extern int errno;
-/*
- * Declare a weak reference in case the application is not linked
- * with libpthread.
- */
-__weak_reference(__error_unthreaded, __error);
+static int *
+__error_unthreaded(void)
+{
+
+ return (&errno);
+}
+
+static int *(*__error_selector)(void) = __error_unthreaded;
+
+void
+__set_error_selector(int *(*arg)(void))
+{
+
+ __error_selector = arg;
+}
int *
-__error_unthreaded(void)
+__error(void)
{
- return(&errno);
+
+ return (__error_selector());
}
diff --git a/lib/libc/sys/accept.c b/lib/libc/sys/accept.c
new file mode 100644
index 0000000..38e32f2
--- /dev/null
+++ b/lib/libc/sys/accept.c
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2014 The FreeBSD Foundation.
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Konstantin Belousov
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * 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(s), this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified other than the possible
+ * addition of one or more copyright notices.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/syscall.h>
+#include <sys/socket.h>
+#include "libc_private.h"
+
+__weak_reference(__sys_accept, __accept);
+
+#pragma weak accept
+int
+accept(int s, struct sockaddr *addr, socklen_t *addrlen)
+{
+
+ return (((int (*)(int, struct sockaddr *, socklen_t *))
+ __libc_interposing[INTERPOS_accept])(s, addr, addrlen));
+}
diff --git a/lib/libc/sys/accept4.c b/lib/libc/sys/accept4.c
new file mode 100644
index 0000000..2907b04
--- /dev/null
+++ b/lib/libc/sys/accept4.c
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2014 The FreeBSD Foundation.
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Konstantin Belousov
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * 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(s), this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified other than the possible
+ * addition of one or more copyright notices.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/syscall.h>
+#include <sys/socket.h>
+#include "libc_private.h"
+
+__weak_reference(__sys_accept4, __accept4);
+
+#pragma weak accept4
+int
+accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags)
+{
+
+ return (((int (*)(int, struct sockaddr *, socklen_t *, int))
+ __libc_interposing[INTERPOS_accept4])(s, addr, addrlen, flags));
+}
diff --git a/lib/libc/sys/access.2 b/lib/libc/sys/access.2
index 46bf948..c70e7a2 100644
--- a/lib/libc/sys/access.2
+++ b/lib/libc/sys/access.2
@@ -136,7 +136,7 @@ and
.Fn access ,
.Fn eaccess ,
or
-.Fn faccessat
+.Fn faccessat
will fail if:
.Bl -tag -width Er
.It Bq Er EINVAL
diff --git a/lib/libc/sys/aio_suspend.c b/lib/libc/sys/aio_suspend.c
new file mode 100644
index 0000000..020edf8
--- /dev/null
+++ b/lib/libc/sys/aio_suspend.c
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2014 The FreeBSD Foundation.
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Konstantin Belousov
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * 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(s), this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified other than the possible
+ * addition of one or more copyright notices.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/aio.h>
+#include "libc_private.h"
+
+__weak_reference(__sys_aio_suspend, __aio_suspend);
+
+#pragma weak aio_suspend
+int
+aio_suspend(const struct aiocb * const iocbs[], int niocb,
+ const struct timespec *timeout)
+{
+
+ return (((int (*)(const struct aiocb * const[], int,
+ const struct timespec *))
+ __libc_interposing[INTERPOS_aio_suspend])(iocbs, niocb, timeout));
+}
diff --git a/lib/libc/sys/cap_ioctls_limit.2 b/lib/libc/sys/cap_ioctls_limit.2
index 2d1eef9..39f117f 100644
--- a/lib/libc/sys/cap_ioctls_limit.2
+++ b/lib/libc/sys/cap_ioctls_limit.2
@@ -28,7 +28,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd March 27, 2014
+.Dd March 6, 2015
.Dt CAP_IOCTLS_LIMIT 2
.Os
.Sh NAME
@@ -61,6 +61,8 @@ argument specifies the number of elements in the array.
There can be up to
.Va 256
elements in the array.
+Including an element that has been previously revoked will generate an error.
+After a successful call only those listed in the array may be used.
.Pp
The list of allowed ioctl commands for a given file descriptor can be obtained
with the
@@ -92,7 +94,7 @@ system call was never called for this file descriptor), the
.Fn cap_ioctls_get
system call will return
.Dv CAP_IOCTLS_ALL
-and won't modify the buffer pointed to by the
+and will not modify the buffer pointed to by the
.Fa cmds
argument.
.Sh RETURN VALUES
diff --git a/lib/libc/sys/close.c b/lib/libc/sys/close.c
new file mode 100644
index 0000000..02e74c6
--- /dev/null
+++ b/lib/libc/sys/close.c
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2014 The FreeBSD Foundation.
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Konstantin Belousov
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * 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(s), this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified other than the possible
+ * addition of one or more copyright notices.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/fcntl.h>
+#include "libc_private.h"
+
+__weak_reference(__sys_close, __close);
+
+#pragma weak close
+int
+close(int fd)
+{
+
+ return (((int (*)(int))__libc_interposing[INTERPOS_close])(fd));
+}
diff --git a/lib/libc/sys/closefrom.2 b/lib/libc/sys/closefrom.2
index ffaa001..a0b5fc2 100644
--- a/lib/libc/sys/closefrom.2
+++ b/lib/libc/sys/closefrom.2
@@ -1,4 +1,4 @@
-.\" Copyright (c) 2009 Advanced Computing Technologies LLC
+.\" Copyright (c) 2009 Hudson River Trading LLC
.\" Written by: John H. Baldwin <jhb@FreeBSD.org>
.\" All rights reserved.
.\"
diff --git a/lib/libc/sys/connect.c b/lib/libc/sys/connect.c
new file mode 100644
index 0000000..7969142
--- /dev/null
+++ b/lib/libc/sys/connect.c
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2014 The FreeBSD Foundation.
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Konstantin Belousov
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * 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(s), this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified other than the possible
+ * addition of one or more copyright notices.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/syscall.h>
+#include <sys/socket.h>
+#include "libc_private.h"
+
+__weak_reference(__sys_connect, __connect);
+
+#pragma weak connect
+int
+connect(int s, const struct sockaddr *addr, socklen_t addrlen)
+{
+
+ return (((int (*)(int, const struct sockaddr *, socklen_t))
+ __libc_interposing[INTERPOS_connect])(s, addr, addrlen));
+}
diff --git a/lib/libc/sys/cpuset.2 b/lib/libc/sys/cpuset.2
index 0c32b42..8349566 100644
--- a/lib/libc/sys/cpuset.2
+++ b/lib/libc/sys/cpuset.2
@@ -25,7 +25,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd February 14, 2014
+.Dd January 8, 2015
.Dt CPUSET 2
.Os
.Sh NAME
@@ -101,6 +101,7 @@ argument may have the following values:
.It Dv CPU_WHICH_JAIL Ta "id is jid (jail id)"
.It Dv CPU_WHICH_CPUSET Ta "id is a cpusetid_t (cpuset id)"
.It Dv CPU_WHICH_IRQ Ta "id is an irq number"
+.It Dv CPU_WHICH_DOMAIN Ta "id is a NUMA domain"
.El
.Pp
An
diff --git a/lib/libc/sys/fcntl.c b/lib/libc/sys/fcntl.c
index 480cc40..e85574a 100644
--- a/lib/libc/sys/fcntl.c
+++ b/lib/libc/sys/fcntl.c
@@ -3,6 +3,12 @@
* Authors: Doug Rabson <dfr@rabson.org>
* Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
*
+ * Copyright (c) 2014-2015 The FreeBSD Foundation.
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Konstantin Belousov
+ * under sponsorship from the FreeBSD Foundation.
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -34,56 +40,17 @@ __FBSDID("$FreeBSD$");
#include <sys/syscall.h>
#include "libc_private.h"
-__weak_reference(__fcntl_compat, fcntl);
-
+#pragma weak fcntl
int
-__fcntl_compat(int fd, int cmd, ...)
+fcntl(int fd, int cmd, ...)
{
va_list args;
long arg;
- struct __oflock ofl;
- struct flock *flp;
- int res;
va_start(args, cmd);
arg = va_arg(args, long);
va_end(args);
- if (__getosreldate() >= 800028) {
- return (__sys_fcntl(fd, cmd, arg));
- } else {
- if (cmd == F_GETLK || cmd == F_SETLK || cmd == F_SETLKW) {
- /*
- * Convert new-style struct flock (which
- * includes l_sysid) to old-style.
- */
- flp = (struct flock *) (uintptr_t) arg;
- ofl.l_start = flp->l_start;
- ofl.l_len = flp->l_len;
- ofl.l_pid = flp->l_pid;
- ofl.l_type = flp->l_type;
- ofl.l_whence = flp->l_whence;
-
- switch (cmd) {
- case F_GETLK:
- res = __sys_fcntl(fd, F_OGETLK, &ofl);
- if (res >= 0) {
- flp->l_start = ofl.l_start;
- flp->l_len = ofl.l_len;
- flp->l_pid = ofl.l_pid;
- flp->l_type = ofl.l_type;
- flp->l_whence = ofl.l_whence;
- flp->l_sysid = 0;
- }
- return (res);
-
- case F_SETLK:
- return (__sys_fcntl(fd, F_OSETLK, &ofl));
-
- case F_SETLKW:
- return (__sys_fcntl(fd, F_OSETLKW, &ofl));
- }
- }
- return (__sys_fcntl(fd, cmd, arg));
- }
+ return (((int (*)(int, int, ...))
+ __libc_interposing[INTERPOS_fcntl])(fd, cmd, arg));
}
diff --git a/lib/libc/sys/fork.2 b/lib/libc/sys/fork.2
index 1ad2052f..4fda74d 100644
--- a/lib/libc/sys/fork.2
+++ b/lib/libc/sys/fork.2
@@ -28,7 +28,7 @@
.\" @(#)fork.2 8.1 (Berkeley) 6/4/93
.\" $FreeBSD$
.\"
-.Dd May 31, 2013
+.Dd May 1, 2015
.Dt FORK 2
.Os
.Sh NAME
@@ -53,7 +53,10 @@ The child process has a unique process ID.
The child process has a different parent
process ID (i.e., the process ID of the parent process).
.It
-The child process has its own copy of the parent's descriptors.
+The child process has its own copy of the parent's descriptors,
+except for descriptors returned by
+.Xr kqueue 2 ,
+which are not inherited from the parent process.
These descriptors reference the same underlying objects, so that,
for instance, file pointers in file objects are shared between
the child and the parent, so that an
diff --git a/lib/libc/sys/fork.c b/lib/libc/sys/fork.c
new file mode 100644
index 0000000..695540a
--- /dev/null
+++ b/lib/libc/sys/fork.c
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2014 The FreeBSD Foundation.
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Konstantin Belousov
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * 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(s), this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified other than the possible
+ * addition of one or more copyright notices.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <unistd.h>
+#include "libc_private.h"
+
+__weak_reference(__sys_fork, __fork);
+
+#pragma weak fork
+pid_t
+fork(void)
+{
+
+ return (((pid_t (*)(void))__libc_interposing[INTERPOS_fork])());
+}
diff --git a/lib/libc/sys/fsync.c b/lib/libc/sys/fsync.c
new file mode 100644
index 0000000..3fff428
--- /dev/null
+++ b/lib/libc/sys/fsync.c
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2014 The FreeBSD Foundation.
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Konstantin Belousov
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * 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(s), this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified other than the possible
+ * addition of one or more copyright notices.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/fcntl.h>
+#include "libc_private.h"
+
+__weak_reference(__sys_fsync, __fsync);
+
+int
+fsync(int fd)
+{
+
+ return (((int (*)(int))__libc_interposing[INTERPOS_fsync])(fd));
+}
diff --git a/lib/libc/sys/ftruncate.c b/lib/libc/sys/ftruncate.c
deleted file mode 100644
index 78b5a36..0000000
--- a/lib/libc/sys/ftruncate.c
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (c) 1992, 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.
- * 4. 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)ftruncate.c 8.1 (Berkeley) 6/17/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/types.h>
-#include <sys/syscall.h>
-#include <unistd.h>
-#include "libc_private.h"
-
-/*
- * This function provides 64-bit offset padding that
- * is not supplied by GCC 1.X but is supplied by GCC 2.X.
- */
-int
-ftruncate(fd, length)
- int fd;
- off_t length;
-{
-
- if (__getosreldate() >= 700051)
- return(__sys_ftruncate(fd, length));
- else
- return(__sys_freebsd6_ftruncate(fd, 0, length));
-}
diff --git a/lib/libc/sys/futimens.c b/lib/libc/sys/futimens.c
new file mode 100644
index 0000000..2014cc5
--- /dev/null
+++ b/lib/libc/sys/futimens.c
@@ -0,0 +1,97 @@
+/*-
+ * Copyright (c) 2015 Jilles Tjoelker
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include "namespace.h"
+#include <sys/stat.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <time.h>
+#include "un-namespace.h"
+
+#include "libc_private.h"
+
+int
+futimens(int fd, const struct timespec times[2])
+{
+ struct timeval now, tv[2], *tvp;
+ struct stat sb;
+
+ if (__getosreldate() >= 1100056)
+ return (__sys_futimens(fd, times));
+
+ if (times == NULL || (times[0].tv_nsec == UTIME_NOW &&
+ times[1].tv_nsec == UTIME_NOW))
+ tvp = NULL;
+ else if (times[0].tv_nsec == UTIME_OMIT &&
+ times[1].tv_nsec == UTIME_OMIT)
+ return (0);
+ else {
+ if ((times[0].tv_nsec < 0 || times[0].tv_nsec > 999999999) &&
+ times[0].tv_nsec != UTIME_NOW &&
+ times[0].tv_nsec != UTIME_OMIT) {
+ errno = EINVAL;
+ return (-1);
+ }
+ if ((times[1].tv_nsec < 0 || times[1].tv_nsec > 999999999) &&
+ times[1].tv_nsec != UTIME_NOW &&
+ times[1].tv_nsec != UTIME_OMIT) {
+ errno = EINVAL;
+ return (-1);
+ }
+ tv[0].tv_sec = times[0].tv_sec;
+ tv[0].tv_usec = times[0].tv_nsec / 1000;
+ tv[1].tv_sec = times[1].tv_sec;
+ tv[1].tv_usec = times[1].tv_nsec / 1000;
+ tvp = tv;
+ if (times[0].tv_nsec == UTIME_OMIT ||
+ times[1].tv_nsec == UTIME_OMIT) {
+ if (_fstat(fd, &sb) == -1)
+ return (-1);
+ if (times[0].tv_nsec == UTIME_OMIT) {
+ tv[0].tv_sec = sb.st_atim.tv_sec;
+ tv[0].tv_usec = sb.st_atim.tv_nsec / 1000;
+ }
+ if (times[1].tv_nsec == UTIME_OMIT) {
+ tv[1].tv_sec = sb.st_mtim.tv_sec;
+ tv[1].tv_usec = sb.st_mtim.tv_nsec / 1000;
+ }
+ }
+ if (times[0].tv_nsec == UTIME_NOW ||
+ times[1].tv_nsec == UTIME_NOW) {
+ if (gettimeofday(&now, NULL) == -1)
+ return (-1);
+ if (times[0].tv_nsec == UTIME_NOW)
+ tv[0] = now;
+ if (times[1].tv_nsec == UTIME_NOW)
+ tv[1] = now;
+ }
+ }
+ return (futimes(fd, tvp));
+}
diff --git a/lib/libc/sys/getdirentries.2 b/lib/libc/sys/getdirentries.2
index 3fe1632..ab60ed2 100644
--- a/lib/libc/sys/getdirentries.2
+++ b/lib/libc/sys/getdirentries.2
@@ -134,8 +134,9 @@ The current position pointer should only be set to a value returned by
.Xr lseek 2 ,
a value returned in the location pointed to by
.Fa basep
-.Fn ( getdirentries
-only)
+.Po Fn getdirentries
+only
+.Pc
or zero.
.Sh RETURN VALUES
If successful, the number of bytes actually transferred is returned.
diff --git a/lib/libc/sys/getrlimit.2 b/lib/libc/sys/getrlimit.2
index 1f84bfb..5fdd58b 100644
--- a/lib/libc/sys/getrlimit.2
+++ b/lib/libc/sys/getrlimit.2
@@ -194,8 +194,8 @@ raised the maximum limit value, and the caller is not the super-user.
.Xr csh 1 ,
.Xr quota 1 ,
.Xr quotactl 2 ,
-.Xr sigaltstack 2 ,
.Xr sigaction 2 ,
+.Xr sigaltstack 2 ,
.Xr sysctl 3 ,
.Xr ulimit 3
.Sh HISTORY
diff --git a/lib/libc/sys/interposing_table.c b/lib/libc/sys/interposing_table.c
new file mode 100644
index 0000000..08dfbb1
--- /dev/null
+++ b/lib/libc/sys/interposing_table.c
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2014 The FreeBSD Foundation.
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Konstantin Belousov
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * 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(s), this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified other than the possible
+ * addition of one or more copyright notices.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include "libc_private.h"
+
+#define SLOT(a, b) \
+ [INTERPOS_##a] = (interpos_func_t)b
+interpos_func_t __libc_interposing[INTERPOS_MAX] = {
+ SLOT(accept, __sys_accept),
+ SLOT(accept4, __sys_accept4),
+ SLOT(aio_suspend, __sys_aio_suspend),
+ SLOT(close, __sys_close),
+ SLOT(connect, __sys_connect),
+ SLOT(fcntl, __sys_fcntl),
+ SLOT(fsync, __sys_fsync),
+ SLOT(fork, __sys_fork),
+ SLOT(msync, __sys_msync),
+ SLOT(nanosleep, __sys_nanosleep),
+ SLOT(openat, __sys_openat),
+ SLOT(poll, __sys_poll),
+ SLOT(pselect, __sys_pselect),
+ SLOT(read, __sys_read),
+ SLOT(readv, __sys_readv),
+ SLOT(recvfrom, __sys_recvfrom),
+ SLOT(recvmsg, __sys_recvmsg),
+ SLOT(select, __sys_select),
+ SLOT(sendmsg, __sys_sendmsg),
+ SLOT(sendto, __sys_sendto),
+ SLOT(setcontext, __sys_setcontext),
+ SLOT(sigaction, __sys_sigaction),
+ SLOT(sigprocmask, __sys_sigprocmask),
+ SLOT(sigsuspend, __sys_sigsuspend),
+ SLOT(sigwait, __libc_sigwait),
+ SLOT(sigtimedwait, __sys_sigtimedwait),
+ SLOT(sigwaitinfo, __sys_sigwaitinfo),
+ SLOT(swapcontext, __sys_swapcontext),
+ SLOT(system, __libc_system),
+ SLOT(tcdrain, __libc_tcdrain),
+ SLOT(wait4, __sys_wait4),
+ SLOT(write, __sys_write),
+ SLOT(writev, __sys_writev),
+ SLOT(_pthread_mutex_init_calloc_cb, _pthread_mutex_init_calloc_cb_stub),
+ SLOT(spinlock, __libc_spinlock_stub),
+ SLOT(spinunlock, __libc_spinunlock_stub),
+ SLOT(kevent, __sys_kevent),
+ SLOT(wait6, __sys_wait6),
+ SLOT(ppoll, __sys_ppoll),
+};
+#undef SLOT
+
+interpos_func_t *
+__libc_interposing_slot(int interposno)
+{
+
+ return (&__libc_interposing[interposno]);
+}
diff --git a/lib/libc/sys/kevent.c b/lib/libc/sys/kevent.c
new file mode 100644
index 0000000..5f84ef8
--- /dev/null
+++ b/lib/libc/sys/kevent.c
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2015 The FreeBSD Foundation.
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Konstantin Belousov
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * 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(s), this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified other than the possible
+ * addition of one or more copyright notices.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/event.h>
+#include <sys/time.h>
+#include "libc_private.h"
+
+__weak_reference(__sys_kevent, __kevent);
+
+#pragma weak kevent
+int
+kevent(int kq, const struct kevent *changelist, int nchanges,
+ struct kevent *eventlist, int nevents, const struct timespec *timeout)
+{
+
+ return (((int (*)(int, const struct kevent *, int,
+ struct kevent *, int, const struct timespec *))
+ __libc_interposing[INTERPOS_kevent])(kq, changelist, nchanges,
+ eventlist, nevents, timeout));
+}
diff --git a/lib/libc/sys/kqueue.2 b/lib/libc/sys/kqueue.2
index 9a7cc23..c5e8caf 100644
--- a/lib/libc/sys/kqueue.2
+++ b/lib/libc/sys/kqueue.2
@@ -24,7 +24,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd July 18, 2014
+.Dd March 29, 2015
.Dt KQUEUE 2
.Os
.Sh NAME
@@ -41,7 +41,7 @@
.Fn kqueue "void"
.Ft int
.Fn kevent "int kq" "const struct kevent *changelist" "int nchanges" "struct kevent *eventlist" "int nevents" "const struct timespec *timeout"
-.Fn EV_SET "&kev" ident filter flags fflags data udata
+.Fn EV_SET "kev" ident filter flags fflags data udata
.Sh DESCRIPTION
The
.Fn kqueue
@@ -162,56 +162,56 @@ struct kevent {
The fields of
.Fa struct kevent
are:
-.Bl -tag -width XXXfilter
-.It ident
+.Bl -tag -width "Fa filter"
+.It Fa ident
Value used to identify this event.
The exact interpretation is determined by the attached filter,
but often is a file descriptor.
-.It filter
+.It Fa filter
Identifies the kernel filter used to process this event.
The pre-defined
system filters are described below.
-.It flags
+.It Fa flags
Actions to perform on the event.
-.It fflags
+.It Fa fflags
Filter-specific flags.
-.It data
+.It Fa data
Filter-specific data value.
-.It udata
+.It Fa udata
Opaque user-defined value passed through the kernel unchanged.
.El
.Pp
The
.Va flags
field can contain the following values:
-.Bl -tag -width XXXEV_ONESHOT
-.It EV_ADD
+.Bl -tag -width EV_DISPATCH
+.It Dv EV_ADD
Adds the event to the kqueue.
Re-adding an existing event
will modify the parameters of the original event, and not result
in a duplicate entry.
Adding an event automatically enables it,
unless overridden by the EV_DISABLE flag.
-.It EV_ENABLE
+.It Dv EV_ENABLE
Permit
.Fn kevent
to return the event if it is triggered.
-.It EV_DISABLE
+.It Dv EV_DISABLE
Disable the event so
.Fn kevent
will not return it.
The filter itself is not disabled.
-.It EV_DISPATCH
+.It Dv EV_DISPATCH
Disable the event source immediately after delivery of an event.
See
.Dv EV_DISABLE
above.
-.It EV_DELETE
+.It Dv EV_DELETE
Removes the event from the kqueue.
Events which are attached to
file descriptors are automatically deleted on the last close of
the descriptor.
-.It EV_RECEIPT
+.It Dv EV_RECEIPT
This flag is useful for making bulk changes to a kqueue without draining
any pending events.
When passed as input, it forces
@@ -220,20 +220,20 @@ to always be returned.
When a filter is successfully added the
.Va data
field will be zero.
-.It EV_ONESHOT
+.It Dv EV_ONESHOT
Causes the event to return only the first occurrence of the filter
being triggered.
After the user retrieves the event from the kqueue,
it is deleted.
-.It EV_CLEAR
+.It Dv EV_CLEAR
After the event is retrieved by the user, its state is reset.
This is useful for filters which report state transitions
instead of the current state.
Note that some filters may automatically
set this flag internally.
-.It EV_EOF
+.It Dv EV_EOF
Filters may set this flag to indicate filter-specific EOF condition.
-.It EV_ERROR
+.It Dv EV_ERROR
See
.Sx RETURN VALUES
below.
@@ -245,8 +245,8 @@ Arguments may be passed to and from the filter via the
and
.Va data
fields in the kevent structure.
-.Bl -tag -width EVFILT_PROCDESC
-.It EVFILT_READ
+.Bl -tag -width "Dv EVFILT_PROCDESC"
+.It Dv EVFILT_READ
Takes a descriptor as the identifier, and returns whenever
there is data available to read.
The behavior of the filter is slightly different depending
@@ -265,7 +265,7 @@ subject to the
value of the socket buffer.
This may be overridden with a per-filter low water mark at the
time the filter is added by setting the
-NOTE_LOWAT
+.Dv NOTE_LOWAT
flag in
.Va fflags ,
and specifying the new low water mark in
@@ -275,7 +275,9 @@ On return,
contains the number of bytes of protocol data available to read.
.Pp
If the read direction of the socket has shutdown, then the filter
-also sets EV_EOF in
+also sets
+.Dv EV_EOF
+in
.Va flags ,
and returns the socket error (if any) in
.Va fflags .
@@ -291,9 +293,13 @@ Returns when the there is data to read;
.Va data
contains the number of bytes available.
.Pp
-When the last writer disconnects, the filter will set EV_EOF in
+When the last writer disconnects, the filter will set
+.Dv EV_EOF
+in
.Va flags .
-This may be cleared by passing in EV_CLEAR, at which point the
+This may be cleared by passing in
+.Dv EV_CLEAR ,
+at which point the
filter will resume waiting for data to become available before
returning.
.It "BPF devices"
@@ -304,7 +310,7 @@ enabled and there is any data to read;
.Va data
contains the number of bytes available.
.El
-.It EVFILT_WRITE
+.It Dv EVFILT_WRITE
Takes a descriptor as the identifier, and returns whenever
it is possible to write to the descriptor.
For sockets, pipes
@@ -312,23 +318,30 @@ and fifos,
.Va data
will contain the amount of space remaining in the write buffer.
The filter will set EV_EOF when the reader disconnects, and for
-the fifo case, this may be cleared by use of EV_CLEAR.
+the fifo case, this may be cleared by use of
+.Dv EV_CLEAR .
Note that this filter is not supported for vnodes or BPF devices.
.Pp
For sockets, the low water mark and socket error handling is
-identical to the EVFILT_READ case.
-.It EVFILT_AIO
+identical to the
+.Dv EVFILT_READ
+case.
+.It Dv EVFILT_AIO
The sigevent portion of the AIO request is filled in, with
.Va sigev_notify_kqueue
containing the descriptor of the kqueue that the event should
be attached to,
.Va sigev_notify_kevent_flags
-containing the kevent flags which should be EV_ONESHOT, EV_CLEAR or
-EV_DISPATCH,
+containing the kevent flags which should be
+.Dv EV_ONESHOT ,
+.Dv EV_CLEAR
+or
+.Dv EV_DISPATCH ,
.Va sigev_value
containing the udata value, and
.Va sigev_notify
-set to SIGEV_KEVENT.
+set to
+.Dv SIGEV_KEVENT .
When the
.Fn aio_*
system call is made, the event will be registered
@@ -339,29 +352,30 @@ argument set to the
returned by the
.Fn aio_*
system call.
-The filter returns under the same conditions as aio_error.
-.It EVFILT_VNODE
+The filter returns under the same conditions as
+.Fn aio_error .
+.It Dv EVFILT_VNODE
Takes a file descriptor as the identifier and the events to watch for in
.Va fflags ,
and returns when one or more of the requested events occurs on the descriptor.
The events to monitor are:
-.Bl -tag -width XXNOTE_RENAME
-.It NOTE_DELETE
+.Bl -tag -width "Dv NOTE_RENAME"
+.It Dv NOTE_DELETE
The
.Fn unlink
system call
was called on the file referenced by the descriptor.
-.It NOTE_WRITE
+.It Dv NOTE_WRITE
A write occurred on the file referenced by the descriptor.
-.It NOTE_EXTEND
+.It Dv NOTE_EXTEND
The file referenced by the descriptor was extended.
-.It NOTE_ATTRIB
+.It Dv NOTE_ATTRIB
The file referenced by the descriptor had its attributes changed.
-.It NOTE_LINK
+.It Dv NOTE_LINK
The link count on the file changed.
-.It NOTE_RENAME
+.It Dv NOTE_RENAME
The file referenced by the descriptor was renamed.
-.It NOTE_REVOKE
+.It Dv NOTE_REVOKE
Access to the file was revoked via
.Xr revoke 2
or the underlying file system was unmounted.
@@ -370,26 +384,26 @@ or the underlying file system was unmounted.
On return,
.Va fflags
contains the events which triggered the filter.
-.It EVFILT_PROC
+.It Dv EVFILT_PROC
Takes the process ID to monitor as the identifier and the events to watch for
in
.Va fflags ,
and returns when the process performs one or more of the requested events.
If a process can normally see another process, it can attach an event to it.
The events to monitor are:
-.Bl -tag -width XXNOTE_TRACKERR
-.It NOTE_EXIT
+.Bl -tag -width "Dv NOTE_TRACKERR"
+.It Dv NOTE_EXIT
The process has exited.
The exit status will be stored in
.Va data .
-.It NOTE_FORK
+.It Dv NOTE_FORK
The process has called
.Fn fork .
-.It NOTE_EXEC
+.It Dv NOTE_EXEC
The process has executed a new process via
.Xr execve 2
or a similar call.
-.It NOTE_TRACK
+.It Dv NOTE_TRACK
Follow a process across
.Fn fork
calls.
@@ -397,22 +411,28 @@ The parent process registers a new kevent to monitor the child process
using the same
.Va fflags
as the original event.
-The child process will signal an event with NOTE_CHILD set in
+The child process will signal an event with
+.Dv NOTE_CHILD
+set in
.Va fflags
and the parent PID in
.Va data .
.Pp
If the parent process fails to register a new kevent
.Pq usually due to resource limitations ,
-it will signal an event with NOTE_TRACKERR set in
+it will signal an event with
+.Dv NOTE_TRACKERR
+set in
.Va fflags ,
-and the child process will not signal a NOTE_CHILD event.
+and the child process will not signal a
+.Dv NOTE_CHILD
+event.
.El
.Pp
On return,
.Va fflags
contains the events which triggered the filter.
-.It EVFILT_PROCDESC
+.It Dv EVFILT_PROCDESC
Takes the process descriptor created by
.Xr pdfork 2
to monitor as the identifier and the events to watch for in
@@ -420,8 +440,8 @@ to monitor as the identifier and the events to watch for in
and returns when the associated process performs one or more of the
requested events.
The events to monitor are:
-.Bl -tag -width XXNOTE_EXIT
-.It NOTE_EXIT
+.Bl -tag -width "Dv NOTE_EXIT"
+.It Dv NOTE_EXIT
The process has exited.
The exit status will be stored in
.Va data .
@@ -430,7 +450,7 @@ The exit status will be stored in
On return,
.Va fflags
contains the events which triggered the filter.
-.It EVFILT_SIGNAL
+.It Dv EVFILT_SIGNAL
Takes the signal number to monitor as the identifier and returns
when the given signal is delivered to the process.
This coexists with the
@@ -440,7 +460,9 @@ and
facilities, and has a lower precedence.
The filter will record
all attempts to deliver a signal to a process, even if the signal has
-been marked as SIG_IGN, except for the
+been marked as
+.Dv SIG_IGN ,
+except for the
.Dv SIGCHLD
signal, which, if ignored, won't be recorded by the filter.
Event notification happens after normal
@@ -448,14 +470,18 @@ signal delivery processing.
.Va data
returns the number of times the signal has occurred since the last call to
.Fn kevent .
-This filter automatically sets the EV_CLEAR flag internally.
-.It EVFILT_TIMER
+This filter automatically sets the
+.Dv EV_CLEAR
+flag internally.
+.It Dv EVFILT_TIMER
Establishes an arbitrary timer identified by
.Va ident .
When adding a timer,
.Va data
specifies the timeout period.
-The timer will be periodic unless EV_ONESHOT is specified.
+The timer will be periodic unless
+.Dv EV_ONESHOT
+is specified.
On return,
.Va data
contains the number of times the timeout has expired since the last call to
@@ -465,7 +491,7 @@ There is a system wide limit on the number of timers
which is controlled by the
.Va kern.kq_calloutmax
sysctl.
-.Bl -tag -width XXNOTE_USECONDS
+.Bl -tag -width "Dv NOTE_USECONDS"
.It Dv NOTE_SECONDS
.Va data
is in seconds.
@@ -493,7 +519,7 @@ user level code.
The lower 24 bits of the
.Va fflags
may be used for user defined flags and manipulated using the following:
-.Bl -tag -width XXNOTE_FFLAGSMASK
+.Bl -tag -width "Dv NOTE_FFLAGSMASK"
.It Dv NOTE_FFNOP
Ignore the input
.Va fflags .
@@ -515,7 +541,7 @@ User defined flag mask for
.El
.Pp
A user event is triggered for output with the following:
-.Bl -tag -width XXNOTE_FFLAGSMASK
+.Bl -tag -width "Dv NOTE_FFLAGSMASK"
.It Dv NOTE_TRIGGER
Cause the event to be triggered.
.El
@@ -524,6 +550,16 @@ On return,
.Va fflags
contains the users defined flags in the lower 24 bits.
.El
+.Sh CANCELLATION BEHAVIOUR
+If
+.Fa nevents
+is non-zero, i.e. the function is potentially blocking, the call
+is a cancellation point.
+Otherwise, i.e. if
+.Fa nevents
+is zero, the call is not cancellable.
+Cancellation can only occur before any changes are made to the kqueue,
+or when the call was blocked and no changes to the queue were requested.
.Sh RETURN VALUES
The
.Fn kqueue
@@ -594,6 +630,8 @@ The specified descriptor is invalid.
.It Bq Er EINTR
A signal was delivered before the timeout expired and before any
events were placed on the kqueue for return.
+.It Bq Er EINTR
+A cancellation request was delivered to the thread, but not yet handled.
.It Bq Er EINVAL
The specified time limit or filter is invalid.
.It Bq Er ENOENT
@@ -608,6 +646,14 @@ sysctl.
.It Bq Er ESRCH
The specified process to attach to does not exist.
.El
+.Pp
+When
+.Fn kevent
+call fails with
+.Er EINTR
+error, all changes in the
+.Fa changelist
+have been applied.
.Sh SEE ALSO
.Xr aio_error 2 ,
.Xr aio_read 2 ,
@@ -617,6 +663,7 @@ The specified process to attach to does not exist.
.Xr select 2 ,
.Xr sigaction 2 ,
.Xr write 2 ,
+.Xr pthread_setcancelstate 3 ,
.Xr signal 3
.Sh HISTORY
The
diff --git a/lib/libc/sys/lseek.c b/lib/libc/sys/lseek.c
deleted file mode 100644
index a086be1..0000000
--- a/lib/libc/sys/lseek.c
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (c) 1992, 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.
- * 4. 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)lseek.c 8.1 (Berkeley) 6/17/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/types.h>
-#include <sys/syscall.h>
-#include <unistd.h>
-#include "libc_private.h"
-
-/*
- * This function provides 64-bit offset padding that
- * is not supplied by GCC 1.X but is supplied by GCC 2.X.
- */
-off_t
-lseek(fd, offset, whence)
- int fd;
- off_t offset;
- int whence;
-{
-
- if (__getosreldate() >= 700051)
- return(__sys_lseek(fd, offset, whence));
- else
- return(__sys_freebsd6_lseek(fd, 0, offset, whence));
-}
diff --git a/lib/libc/sys/mmap.2 b/lib/libc/sys/mmap.2
index 7380a7f..c818342 100644
--- a/lib/libc/sys/mmap.2
+++ b/lib/libc/sys/mmap.2
@@ -28,7 +28,7 @@
.\" @(#)mmap.2 8.4 (Berkeley) 5/11/95
.\" $FreeBSD$
.\"
-.Dd September 17, 2014
+.Dd February 18, 2015
.Dt MMAP 2
.Os
.Sh NAME
@@ -160,7 +160,7 @@ is specified,
must be a multiple of the pagesize.
If
.Dv MAP_EXCL
-is not specified, a successfull
+is not specified, a successful
.Dv MAP_FIXED
request replaces any previous mappings for the process'
pages in the range from
@@ -225,7 +225,7 @@ it.
You can test file fragmentation by observing the KB/t (kilobytes per
transfer) results from an
.Dq Li iostat 1
-while reading a large file sequentially, e.g.\& using
+while reading a large file sequentially, e.g.,\& using
.Dq Li dd if=filename of=/dev/null bs=32k .
.Pp
The
@@ -448,17 +448,3 @@ was specified and insufficient memory was available.
.Xr munmap 2 ,
.Xr getpagesize 3 ,
.Xr getpagesizes 3
-.Sh BUGS
-The
-.Fa len
-argument
-is limited to the maximum file size or available userland address
-space.
-Files may not be able to be made more than 1TB large on 32 bit systems
-due to file systems restrictions and bugs, but address space is far more
-restrictive.
-Larger files may be possible on 64 bit systems.
-.Pp
-The previous documented limit of 2GB was a documentation bug.
-That limit has not existed since
-.Fx 2.2 .
diff --git a/lib/libc/sys/mmap.c b/lib/libc/sys/mmap.c
deleted file mode 100644
index 0fa03ba..0000000
--- a/lib/libc/sys/mmap.c
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (c) 1992, 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.
- * 4. 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)mmap.c 8.1 (Berkeley) 6/17/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/types.h>
-#include <sys/mman.h>
-#include <sys/syscall.h>
-#include <unistd.h>
-#include "libc_private.h"
-
-/*
- * This function provides 64-bit offset padding that
- * is not supplied by GCC 1.X but is supplied by GCC 2.X.
- */
-void *
-mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset)
-{
-
- if (__getosreldate() >= 700051) {
- return (__sys_mmap(addr, len, prot, flags, fd, offset));
- } else {
- return (__sys_freebsd6_mmap(addr, len, prot, flags, fd, 0,
- offset));
- }
-}
diff --git a/lib/libc/sys/mount.2 b/lib/libc/sys/mount.2
index 57ad428..881d830 100644
--- a/lib/libc/sys/mount.2
+++ b/lib/libc/sys/mount.2
@@ -28,7 +28,7 @@
.\" @(#)mount.2 8.3 (Berkeley) 5/24/95
.\" $FreeBSD$
.\"
-.Dd January 26, 2010
+.Dd April 13, 2015
.Dt MOUNT 2
.Os
.Sh NAME
@@ -86,7 +86,7 @@ containing
.Fa niov
elements.
The following options are required by all file systems:
-.Bl -item -offset indent -compact
+.Bl -column fstype -offset indent
.It
.Li fstype Ta file system type name (e.g., Dq Li procfs )
.It
@@ -351,11 +351,6 @@ The
argument
points outside the process's allocated address space.
.El
-.Pp
-A
-.Em ufs
-mount can also fail if the maximum number of file systems are currently
-mounted.
.Sh SEE ALSO
.Xr lsvfs 1 ,
.Xr mksnap_ffs 8 ,
diff --git a/lib/libc/sys/msync.c b/lib/libc/sys/msync.c
new file mode 100644
index 0000000..3c6879f
--- /dev/null
+++ b/lib/libc/sys/msync.c
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2014 The FreeBSD Foundation.
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Konstantin Belousov
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * 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(s), this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified other than the possible
+ * addition of one or more copyright notices.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/fcntl.h>
+#include "libc_private.h"
+
+__weak_reference(__sys_msync, __msync);
+
+#pragma weak msync
+int
+msync(void *addr, size_t len, int flags)
+{
+
+ return (((int (*)(void *, size_t, int))
+ __libc_interposing[INTERPOS_msync])(addr, len, flags));
+}
diff --git a/lib/libc/sys/nanosleep.c b/lib/libc/sys/nanosleep.c
new file mode 100644
index 0000000..412b05e
--- /dev/null
+++ b/lib/libc/sys/nanosleep.c
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2014 The FreeBSD Foundation.
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Konstantin Belousov
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * 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(s), this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified other than the possible
+ * addition of one or more copyright notices.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <time.h>
+#include "libc_private.h"
+
+__weak_reference(__sys_nanosleep, __nanosleep);
+
+#pragma weak nanosleep
+int
+nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
+{
+
+ return (((int (*)(const struct timespec *, struct timespec *))
+ __libc_interposing[INTERPOS_nanosleep])(rqtp, rmtp));
+}
diff --git a/lib/libc/sys/open.2 b/lib/libc/sys/open.2
index 41a6c64..acd376c 100644
--- a/lib/libc/sys/open.2
+++ b/lib/libc/sys/open.2
@@ -28,7 +28,7 @@
.\" @(#)open.2 8.2 (Berkeley) 11/16/93
.\" $FreeBSD$
.\"
-.Dd February 7, 2013
+.Dd April 2, 2015
.Dt OPEN 2
.Os
.Sh NAME
@@ -115,8 +115,8 @@ O_DIRECT eliminate or reduce cache effects
O_FSYNC synchronous writes
O_SYNC synchronous writes
O_NOFOLLOW do not follow symlinks
-O_NOCTTY don't assign controlling terminal
-O_TTY_INIT restore default terminal attributes
+O_NOCTTY ignored
+O_TTY_INIT ignored
O_DIRECTORY error if file is not a directory
O_CLOEXEC set FD_CLOEXEC upon open
.Ed
diff --git a/lib/libc/sys/open.c b/lib/libc/sys/open.c
new file mode 100644
index 0000000..e0273c6
--- /dev/null
+++ b/lib/libc/sys/open.c
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2014 The FreeBSD Foundation.
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Konstantin Belousov
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * 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(s), this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified other than the possible
+ * addition of one or more copyright notices.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/fcntl.h>
+#include <stdarg.h>
+#include "libc_private.h"
+
+__weak_reference(__sys_open, __open);
+
+#pragma weak open
+int
+open(const char *path, int flags, ...)
+{
+ va_list ap;
+ int mode;
+
+ if ((flags & O_CREAT) != 0) {
+ va_start(ap, flags);
+ mode = va_arg(ap, int);
+ va_end(ap);
+ } else {
+ mode = 0;
+ }
+ return (((int (*)(int, const char *, int, ...))
+ __libc_interposing[INTERPOS_openat])(AT_FDCWD, path, flags, mode));
+}
diff --git a/lib/libc/sys/openat.c b/lib/libc/sys/openat.c
new file mode 100644
index 0000000..1bd12ea
--- /dev/null
+++ b/lib/libc/sys/openat.c
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2014 The FreeBSD Foundation.
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Konstantin Belousov
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * 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(s), this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified other than the possible
+ * addition of one or more copyright notices.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/fcntl.h>
+#include <stdarg.h>
+#include "libc_private.h"
+
+__weak_reference(__sys_openat, __openat);
+__sym_compat(openat, __impl_openat, FBSD_1.1);
+__weak_reference(openat, __impl_openat);
+__sym_default(openat, openat, FBSD_1.2);
+
+#pragma weak openat
+int
+openat(int fd, const char *path, int flags, ...)
+{
+ va_list ap;
+ int mode;
+
+ if ((flags & O_CREAT) != 0) {
+ va_start(ap, flags);
+ mode = va_arg(ap, int);
+ va_end(ap);
+ } else {
+ mode = 0;
+ }
+ return (((int (*)(int, const char *, int, ...))
+ __libc_interposing[INTERPOS_openat])(fd, path, flags, mode));
+}
diff --git a/lib/libc/sys/poll.2 b/lib/libc/sys/poll.2
index a1c7ada..dbd641f 100644
--- a/lib/libc/sys/poll.2
+++ b/lib/libc/sys/poll.2
@@ -148,8 +148,8 @@ is zero, then
will return without blocking.
.Pp
The
-.Fn ppoll
-system call, unlike
+.Fn ppoll
+system call, unlike
.Fn poll ,
is used to safely wait until either a set of file descriptors becomes
ready or until a signal is caught.
@@ -174,13 +174,12 @@ used by
A null pointer may be passed to indicate that
.Fn ppoll
should wait indefinitely.
-Finally,
+Finally,
.Fa newsigmask
specifies a signal mask which is set while waiting for input.
-When
+When
.Fn ppoll
returns, the original signal mask is restored.
-.Pp
.Bd -literal
struct timespec {
time_t tv_sec; /* seconds */
@@ -247,11 +246,11 @@ The specified time limit is invalid. One of its components is negative or too la
.Xr write 2
.Sh STANDARDS
The
-.Fn poll
+.Fn poll
function conforms to
.St -p1003.1-2001 .
The
-.Fn ppoll
+.Fn ppoll
is not specified by POSIX.
.Sh HISTORY
The
@@ -262,8 +261,8 @@ This manual page and the core of the implementation was taken from
.Nx .
The
.Fn ppoll
-function first appeared in
-.Fx 11.0
+function first appeared in
+.Fx 11.0
.Sh BUGS
The distinction between some of the fields in the
.Fa events
diff --git a/lib/libc/sys/poll.c b/lib/libc/sys/poll.c
new file mode 100644
index 0000000..43c17d2
--- /dev/null
+++ b/lib/libc/sys/poll.c
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2014 The FreeBSD Foundation.
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Konstantin Belousov
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * 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(s), this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified other than the possible
+ * addition of one or more copyright notices.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/poll.h>
+#include "libc_private.h"
+
+__weak_reference(__sys_poll, __poll);
+
+#pragma weak poll
+int
+poll(struct pollfd pfd[], nfds_t nfds, int timeout)
+{
+
+ return (((int (*)(struct pollfd *, nfds_t, int))
+ __libc_interposing[INTERPOS_poll])(pfd, nfds, timeout));
+}
diff --git a/lib/libc/sys/posix_openpt.2 b/lib/libc/sys/posix_openpt.2
index 916e75a..b7e345c 100644
--- a/lib/libc/sys/posix_openpt.2
+++ b/lib/libc/sys/posix_openpt.2
@@ -110,8 +110,8 @@ is not valid.
Out of pseudo-terminal resources.
.El
.Sh SEE ALSO
-.Xr pts 4 ,
.Xr ptsname 3 ,
+.Xr pts 4 ,
.Xr tty 4
.Sh STANDARDS
The
@@ -137,4 +137,4 @@ is included for compatibility; in
opening a terminal does not cause it to become a process's controlling
terminal.
.Sh AUTHORS
-.An Ed Schouten Aq Mt ed@FreeBSD.org
+.An \&Ed Schouten Aq Mt ed@FreeBSD.org
diff --git a/lib/libc/sys/ppoll.c b/lib/libc/sys/ppoll.c
new file mode 100644
index 0000000..f62fd19
--- /dev/null
+++ b/lib/libc/sys/ppoll.c
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2015 The FreeBSD Foundation.
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Konstantin Belousov
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * 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(s), this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified other than the possible
+ * addition of one or more copyright notices.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/poll.h>
+#include "libc_private.h"
+
+__weak_reference(__sys_ppoll, __ppoll);
+
+#pragma weak ppoll
+int
+ppoll(struct pollfd pfd[], nfds_t nfds, const struct timespec *__restrict
+ timeout, const sigset_t *__restrict newsigmask)
+{
+
+ return (((int (*)(struct pollfd *, nfds_t, const struct timespec *,
+ const sigset_t *)) __libc_interposing[INTERPOS_ppoll])(pfd, nfds,
+ timeout, newsigmask));
+}
diff --git a/lib/libc/sys/pread.c b/lib/libc/sys/pread.c
deleted file mode 100644
index 7566566..0000000
--- a/lib/libc/sys/pread.c
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (c) 1992, 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.
- * 4. 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)mmap.c 8.1 (Berkeley) 6/17/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/types.h>
-#include <sys/syscall.h>
-#include <unistd.h>
-#include "libc_private.h"
-
-/*
- * This function provides 64-bit offset padding that
- * is not supplied by GCC 1.X but is supplied by GCC 2.X.
- */
-ssize_t
-pread(fd, buf, nbyte, offset)
- int fd;
- void *buf;
- size_t nbyte;
- off_t offset;
-{
-
- if (__getosreldate() >= 700051)
- return (__sys_pread(fd, buf, nbyte, offset));
- else
- return (__sys_freebsd6_pread(fd, buf, nbyte, 0, offset));
-}
diff --git a/lib/libc/sys/procctl.2 b/lib/libc/sys/procctl.2
index 6ad0590..76a3cef 100644
--- a/lib/libc/sys/procctl.2
+++ b/lib/libc/sys/procctl.2
@@ -1,7 +1,11 @@
-.\" Copyright (c) 2013 Advanced Computing Technologies LLC
+.\" Copyright (c) 2013 Hudson River Trading LLC
.\" Written by: John H. Baldwin <jhb@FreeBSD.org>
.\" All rights reserved.
.\"
+.\" Copyright (c) 2014 The FreeBSD Foundation
+.\" Portions of this documentation were written by Konstantin Belousov
+.\" under sponsorship from the FreeBSD Foundation.
+.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
@@ -25,7 +29,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd September 19, 2013
+.Dd December 29, 2014
.Dt PROCCTL 2
.Os
.Sh NAME
@@ -67,7 +71,7 @@ The control request to perform is specified by the
.Fa cmd
argument.
The following commands are supported:
-.Bl -tag -width "Dv PROC_SPROTECT"
+.Bl -tag -width "Dv PROC_REAP_GETPIDS"
.It Dv PROC_SPROTECT
Set process protection state.
This is used to mark a process as protected from being killed if the system
@@ -95,7 +99,237 @@ When used with
mark all future child processes of each selected process as protected.
Future child processes will also mark all of their future child processes.
.El
+.It Dv PROC_REAP_ACQUIRE
+Acquires the reaper status for the current process.
+The status means that children orphaned by the reaper's descendants
+that were forked after the acquisition of the status are reparented to the
+reaper.
+After the system initialization,
+.Xr init 8
+is the default reaper.
+.It Dv PROC_REAP_RELEASE
+Releases the reaper state for the current process.
+The reaper of the current process becomes the new reaper of the
+current process's descendants.
+.It Dv PROC_REAP_STATUS
+Provides the information about the reaper of the specified process,
+or the process itself when it is a reaper.
+The
+.Fa data
+argument must point to a
+.Vt procctl_reaper_status
+structure which is filled in by the syscall on successful return.
+.Bd -literal
+struct procctl_reaper_status {
+ u_int rs_flags;
+ u_int rs_children;
+ u_int rs_descendants;
+ pid_t rs_reaper;
+ pid_t rs_pid;
+};
+.Ed
+The
+.Fa rs_flags
+may have the following flags returned:
+.Bl -tag -width "Dv REAPER_STATUS_REALINIT"
+.It Dv REAPER_STATUS_OWNED
+The specified process has acquired the reaper status and has not
+released it.
+When the flag is returned, the specified process
+.Fa id ,
+pid, identifies the reaper, otherwise the
+.Fa rs_reaper
+field of the structure is set to the pid of the reaper
+for the specified process id.
+.It Dv REAPER_STATUS_REALINIT
+The specified process is the root of the reaper tree, i.e.
+.Xr init 8 .
+.El
+.Pp
+The
+.Fa rs_children
+field returns the number of children of the reaper.
+The
+.Fa rs_descendants
+field returns the total number of descendants of the reaper(s),
+not counting descendants of the reaper in the subtree.
+The
+.Fa rs_reaper
+field returns the reaper pid.
+The
+.Fa rs_pid
+returns the pid of one reaper child if there are any descendants.
+.It Dv PROC_REAP_GETPIDS
+Queries the list of descendants of the reaper of the specified process.
+The request takes a pointer to a
+.Vt procctl_reaper_pids
+structure in the
+.Fa data
+parameter.
+.Bd -literal
+struct procctl_reaper_pids {
+ u_int rp_count;
+ struct procctl_reaper_pidinfo *rp_pids;
+};
+.Ed
+When called, the
+.Fa rp_pids
+field must point to an array of
+.Vt procctl_reaper_pidinfo
+structures, to be filled in on return,
+and the
+.Fa rp_count
+field must specify the size of the array,
+into which no more than
+.Fa rp_count
+elements will be filled in by the kernel.
+.Pp
+The
+.Vt "struct procctl_reaper_pidinfo"
+structure provides some information about one of the reaper's descendants.
+Note that for a descendant that is not a child, it may be incorrectly
+identified because of a race in which the original child process exited
+and the exited process's pid was reused for an unrelated process.
+.Bd -literal
+struct procctl_reaper_pidinfo {
+ pid_t pi_pid;
+ pid_t pi_subtree;
+ u_int pi_flags;
+};
+.Ed
+The
+.Fa pi_pid
+field is the process id of the descendant.
+The
+.Fa pi_subtree
+field provides the pid of the child of the reaper, which is the (grand-)parent
+of the process.
+The
+.Fa pi_flags
+field returns the following flags, further describing the descendant:
+.Bl -tag -width "Dv REAPER_PIDINFO_VALID"
+.It Dv REAPER_PIDINFO_VALID
+Set to indicate that the
+.Vt procctl_reaper_pidinfo
+structure was filled in by the kernel.
+Zero-filling the
+.Fa rp_pids
+array and testing the
+.Dv REAPER_PIDINFO_VALID
+flag allows the caller to detect the end
+of the returned array.
+.It Dv REAPER_PIDINFO_CHILD
+The
+.Fa pi_pid
+field identifies the direct child of the reaper.
+.El
+.It Dv PROC_REAP_KILL
+Request to deliver a signal to some subset of the descendants of the reaper.
+The
+.Fa data
+parameter must point to a
+.Vt procctl_reaper_kill
+structure, which is used both for parameters and status return.
+.Bd -literal
+struct procctl_reaper_kill {
+ int rk_sig;
+ u_int rk_flags;
+ pid_t rk_subtree;
+ u_int rk_killed;
+ pid_t rk_fpid;
+};
+.Ed
+The
+.Fa rk_sig
+field specifies the signal to be delivered.
+Zero is not a valid signal number, unlike
+.Xr kill 2 .
+The
+.Fa rk_flags
+field further directs the operation.
+It is or-ed from the following flags:
+.Bl -tag -width "Dv REAPER_KILL_CHILDREN"
+.It Dv REAPER_KILL_CHILDREN
+Deliver the specified signal only to direct children of the reaper.
+.It Dv REAPER_KILL_SUBTREE
+Deliver the specified signal only to descendants that were forked by
+the direct child with pid specified in the
+.Fa rk_subtree
+field.
+.El
+If neither the
+.Dv REAPER_KILL_CHILDREN
+nor the
+.Dv REAPER_KILL_SUBTREE
+flags are specified, all current descendants of the reaper are signalled.
+.Pp
+If a signal was delivered to any process, the return value from the request
+is zero.
+In this case, the
+.Fa rk_killed
+field identifies the number of processes signalled.
+The
+.Fa rk_fpid
+field is set to the pid of the first process for which signal
+delivery failed, e.g. due to the permission problems.
+If no such process exist, the
+.Fa rk_fpid
+field is set to -1.
+.It Dv PROC_TRACE_CTL
+Enable or disable tracing of the specified process(es), according to the
+value of the integer argument.
+Tracing includes attachment to the process using
+.Xr ptrace 2
+and
+.Xr ktrace 2 ,
+debugging sysctls,
+.Xr hwpmc 4 ,
+.Xr dtrace 1
+and core dumping.
+Possible values for the
+.Fa data
+argument are:
+.Bl -tag -width "Dv PROC_TRACE_CTL_DISABLE_EXEC"
+.It Dv PROC_TRACE_CTL_ENABLE
+Enable tracing, after it was disabled by
+.Dv PROC_TRACE_CTL_DISABLE .
+Only allowed for self.
+.It Dv PROC_TRACE_CTL_DISABLE
+Disable tracing for the specified process.
+Tracing is re-enabled when the process changes the executing
+program with
+.Xr execve 2
+syscall.
+A child inherits the trace settings from the parent on
+.Xr fork 2 .
+.It Dv PROC_TRACE_CTL_DISABLE_EXEC
+Same as
+.Dv PROC_TRACE_CTL_DISABLE ,
+but the setting persist for the process even after
+.Xr execve 2 .
+.El
+.It Dv PROC_TRACE_STATUS
+Returns the current tracing status for the specified process in
+the integer variable pointed to by
+.Fa data .
+If tracing is disabled,
+.Fa data
+is set to -1.
+If tracing is enabled, but no debugger is attached by
+.Xr ptrace 2
+syscall,
+.Fa data
+is set to 0.
+If a debugger is attached,
+.Fa data
+is set to the pid of the debugger process.
.El
+.Sh NOTES
+Disabling tracing on a process should not be considered a security
+feature, as it is bypassable both by the kernel and privileged processes,
+and via other system mechanisms.
+As such, it should not be relied on to reliably protect cryptographic
+keying material or other confidential data.
.Sh RETURN VALUES
If an error occurs, a value of -1 is returned and
.Va errno
@@ -109,7 +343,7 @@ will fail if:
.It Bq Er EFAULT
The
.Fa arg
-points outside the process's allocated address space.
+parameter points outside the process's allocated address space.
.It Bq Er EINVAL
The
.Fa cmd
@@ -132,11 +366,71 @@ An invalid operation or flag was passed in
for a
.Dv PROC_SPROTECT
command.
+.It Bq Er EPERM
+The
+.Fa idtype
+argument is not equal to
+.Dv P_PID ,
+or
+.Fa id
+is not equal to the pid of the calling process, for
+.Dv PROC_REAP_ACQUIRE
+or
+.Dv PROC_REAP_RELEASE
+requests.
+.It Bq Er EINVAL
+Invalid or undefined flags were passed to a
+.Dv PROC_REAP_KILL
+request.
+.It Bq Er EINVAL
+An invalid or zero signal number was requested for a
+.Dv PROC_REAP_KILL
+request.
+.It Bq Er EINVAL
+The
+.Dv PROC_REAP_RELEASE
+request was issued by the
+.Xr init 8
+process.
+.It Bq Er EBUSY
+The
+.Dv PROC_REAP_ACQUIRE
+request was issued by a process that had already acquired reaper status
+and has not yet released it.
+.It Bq Er EBUSY
+The
+.Dv PROC_TRACE_CTL
+request was issued for a process already being traced.
+.It Bq Er EPERM
+The
+.Dv PROC_TRACE_CTL
+request to re-enable tracing of the process (
+.Dv PROC_TRACE_CTL_ENABLE ) ,
+or to disable persistence of the
+.Dv PROC_TRACE_CTL_DISABLE
+on
+.Xr execve 2
+was issued for a non-current process.
+.It Bq Er EINVAL
+The value of the integer
+.Fa data
+parameter for the
+.Dv PROC_TRACE_CTL
+request is invalid.
.El
.Sh SEE ALSO
-.Xr ptrace 2
+.Xr dtrace 1 ,
+.Xr kill 2 ,
+.Xr ktrace 2 ,
+.Xr ptrace 2 ,
+.Xr wait 2 ,
+.Xr hwpmc 4 ,
+.Xr init 8
.Sh HISTORY
The
.Fn procctl
function appeared in
.Fx 10.0 .
+The reaper facility is based on a similar feature of Linux and
+DragonflyBSD, and first appeared in
+.Fx 10.2 .
diff --git a/lib/libc/sys/pselect.c b/lib/libc/sys/pselect.c
new file mode 100644
index 0000000..a623a7d
--- /dev/null
+++ b/lib/libc/sys/pselect.c
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2014 The FreeBSD Foundation.
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Konstantin Belousov
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * 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(s), this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified other than the possible
+ * addition of one or more copyright notices.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/select.h>
+#include "libc_private.h"
+
+__weak_reference(__sys_pselect, __pselect);
+
+#pragma weak pselect
+int
+pselect(int n, fd_set *rs, fd_set *ws, fd_set *es, const struct timespec *t,
+ const sigset_t *s)
+{
+
+ return (((int (*)(int, fd_set *, fd_set *, fd_set *,
+ const struct timespec *, const sigset_t *))
+ __libc_interposing[INTERPOS_pselect])(n, rs, ws, es, t, s));
+}
diff --git a/lib/libc/sys/pwrite.c b/lib/libc/sys/pwrite.c
deleted file mode 100644
index d17ed29..0000000
--- a/lib/libc/sys/pwrite.c
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (c) 1992, 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.
- * 4. 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)mmap.c 8.1 (Berkeley) 6/17/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/types.h>
-#include <sys/syscall.h>
-#include <unistd.h>
-#include "libc_private.h"
-
-/*
- * This function provides 64-bit offset padding that
- * is not supplied by GCC 1.X but is supplied by GCC 2.X.
- */
-ssize_t
-pwrite(fd, buf, nbyte, offset)
- int fd;
- const void *buf;
- size_t nbyte;
- off_t offset;
-{
- if (__getosreldate() >= 700051)
- return (__sys_pwrite(fd, buf, nbyte, offset));
- else
- return (__sys_freebsd6_pwrite(fd, buf, nbyte, 0, offset));
-}
diff --git a/lib/libc/sys/read.c b/lib/libc/sys/read.c
new file mode 100644
index 0000000..ab30189
--- /dev/null
+++ b/lib/libc/sys/read.c
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2014 The FreeBSD Foundation.
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Konstantin Belousov
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * 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(s), this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified other than the possible
+ * addition of one or more copyright notices.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+#include "libc_private.h"
+
+__weak_reference(__sys_read, __read);
+
+#pragma weak read
+ssize_t
+read(int fd, void *buf, size_t nbytes)
+{
+
+ return (((ssize_t (*)(int, void *, size_t))
+ __libc_interposing[INTERPOS_read])(fd, buf, nbytes));
+}
diff --git a/lib/libc/sys/readv.c b/lib/libc/sys/readv.c
new file mode 100644
index 0000000..8c82040
--- /dev/null
+++ b/lib/libc/sys/readv.c
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2014 The FreeBSD Foundation.
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Konstantin Belousov
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * 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(s), this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified other than the possible
+ * addition of one or more copyright notices.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+#include "libc_private.h"
+
+__weak_reference(__sys_readv, __readv);
+
+#pragma weak readv
+ssize_t
+readv(int fd, const struct iovec *iov, int iovcnt)
+{
+
+ return (((ssize_t (*)(int, const struct iovec *, int))
+ __libc_interposing[INTERPOS_readv])(fd, iov, iovcnt));
+}
diff --git a/lib/libc/sys/recvfrom.c b/lib/libc/sys/recvfrom.c
new file mode 100644
index 0000000..aa6ef3f
--- /dev/null
+++ b/lib/libc/sys/recvfrom.c
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2014 The FreeBSD Foundation.
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Konstantin Belousov
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * 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(s), this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified other than the possible
+ * addition of one or more copyright notices.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/syscall.h>
+#include <sys/socket.h>
+#include "libc_private.h"
+
+__weak_reference(__sys_recvfrom, __recvfrom);
+
+#pragma weak recvfrom
+ssize_t
+recvfrom(int s, void *buf, size_t len, int flags,
+ struct sockaddr * __restrict from, socklen_t * __restrict fromlen)
+{
+
+ return (((ssize_t (*)(int, void *, size_t, int,
+ struct sockaddr *, socklen_t *))
+ __libc_interposing[INTERPOS_recvfrom])(s, buf, len, flags,
+ from, fromlen));
+}
diff --git a/lib/libc/sys/recvmsg.c b/lib/libc/sys/recvmsg.c
new file mode 100644
index 0000000..282ede9
--- /dev/null
+++ b/lib/libc/sys/recvmsg.c
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2014 The FreeBSD Foundation.
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Konstantin Belousov
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * 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(s), this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified other than the possible
+ * addition of one or more copyright notices.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/syscall.h>
+#include <sys/socket.h>
+#include "libc_private.h"
+
+__weak_reference(__sys_recvmsg, __recvmsg);
+
+#pragma weak recvmsg
+ssize_t
+recvmsg(int s, struct msghdr *msg, int flags)
+{
+
+ return (((int (*)(int, struct msghdr *, int))
+ __libc_interposing[INTERPOS_recvmsg])(s, msg, flags));
+}
diff --git a/lib/libc/sys/revoke.2 b/lib/libc/sys/revoke.2
index 57abdbb..482cbf6 100644
--- a/lib/libc/sys/revoke.2
+++ b/lib/libc/sys/revoke.2
@@ -97,8 +97,8 @@ operation on the named file.
The caller is neither the owner of the file nor the super user.
.El
.Sh SEE ALSO
-.Xr close 2 ,
-.Xr revoke 1
+.Xr revoke 1 ,
+.Xr close 2
.Sh HISTORY
The
.Fn revoke
diff --git a/lib/libc/sys/sched_setscheduler.2 b/lib/libc/sys/sched_setscheduler.2
index 3e7c42b..b84c1a1 100644
--- a/lib/libc/sys/sched_setscheduler.2
+++ b/lib/libc/sys/sched_setscheduler.2
@@ -151,9 +151,9 @@ argument is invalid, or one or more of the parameters contained in
is outside the valid range for the specified scheduling policy.
.El
.Sh SEE ALSO
-.Xr sched_getparam 2 ,
.Xr sched_get_priority_max 2 ,
.Xr sched_get_priority_min 2 ,
+.Xr sched_getparam 2 ,
.Xr sched_rr_get_interval 2 ,
.Xr sched_setparam 2 ,
.Xr sched_yield 2
diff --git a/lib/libc/sys/select.c b/lib/libc/sys/select.c
new file mode 100644
index 0000000..3990496
--- /dev/null
+++ b/lib/libc/sys/select.c
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2014 The FreeBSD Foundation.
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Konstantin Belousov
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * 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(s), this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified other than the possible
+ * addition of one or more copyright notices.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/select.h>
+#include "libc_private.h"
+
+__weak_reference(__sys_select, __select);
+
+#pragma weak select
+int
+select(int n, fd_set *rs, fd_set *ws, fd_set *es, struct timeval *t)
+{
+
+ return (((int (*)(int, fd_set *, fd_set *, fd_set *, struct timeval *))
+ __libc_interposing[INTERPOS_select])(n, rs, ws, es, t));
+}
diff --git a/lib/libc/sys/sendmsg.c b/lib/libc/sys/sendmsg.c
new file mode 100644
index 0000000..7944643
--- /dev/null
+++ b/lib/libc/sys/sendmsg.c
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2014 The FreeBSD Foundation.
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Konstantin Belousov
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * 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(s), this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified other than the possible
+ * addition of one or more copyright notices.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/syscall.h>
+#include <sys/socket.h>
+#include "libc_private.h"
+
+__weak_reference(__sys_sendmsg, __sendmsg);
+
+#pragma weak sendmsg
+ssize_t
+sendmsg(int s, const struct msghdr *msg, int flags)
+{
+
+ return (((int (*)(int, const struct msghdr *, int))
+ __libc_interposing[INTERPOS_sendmsg])(s, msg, flags));
+}
diff --git a/lib/libc/sys/sendto.c b/lib/libc/sys/sendto.c
new file mode 100644
index 0000000..ecf98ee
--- /dev/null
+++ b/lib/libc/sys/sendto.c
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2014 The FreeBSD Foundation.
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Konstantin Belousov
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * 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(s), this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified other than the possible
+ * addition of one or more copyright notices.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/syscall.h>
+#include <sys/socket.h>
+#include "libc_private.h"
+
+__weak_reference(__sys_sendto, __sendto);
+
+#pragma weak sendto
+ssize_t
+sendto(int s, const void *msg, size_t len, int flags,
+ const struct sockaddr *to, socklen_t tolen)
+{
+
+ return (((ssize_t (*)(int, const void *, size_t, int,
+ const struct sockaddr *, socklen_t))
+ __libc_interposing[INTERPOS_sendto])(s, msg, len, flags,
+ to, tolen));
+}
diff --git a/lib/libc/sys/setcontext.c b/lib/libc/sys/setcontext.c
new file mode 100644
index 0000000..31b888f
--- /dev/null
+++ b/lib/libc/sys/setcontext.c
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2014 The FreeBSD Foundation.
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Konstantin Belousov
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * 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(s), this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified other than the possible
+ * addition of one or more copyright notices.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <ucontext.h>
+#include "libc_private.h"
+
+__weak_reference(__sys_setcontext, __setcontext);
+__sym_compat(setcontext, __impl_setcontext, FBSD_1.0);
+__weak_reference(setcontext, __impl_setcontext);
+__sym_default(setcontext, setcontext, FBSD_1.2);
+
+#pragma weak setcontext
+int
+setcontext(const ucontext_t *uc)
+{
+
+ return (((int (*)(const ucontext_t *))
+ __libc_interposing[INTERPOS_setcontext])(uc));
+}
diff --git a/lib/libc/sys/setresuid.2 b/lib/libc/sys/setresuid.2
index 08d07f3..602166f 100644
--- a/lib/libc/sys/setresuid.2
+++ b/lib/libc/sys/setresuid.2
@@ -19,7 +19,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd April 13, 2001
+.Dd February 7, 2015
.Dt SETRESUID 2
.Os
.Sh NAME
@@ -90,10 +90,5 @@ was invalid.
.Xr setregid 2 ,
.Xr setreuid 2 ,
.Xr setuid 2
-.Sh STANDARDS
-These system calls are not available on many platforms.
-They exist in
-.Fx
-to support Linux binaries linked against GNU libc2.
.Sh HISTORY
These functions first appeared in HP-UX.
diff --git a/lib/libc/sys/sigaction.c b/lib/libc/sys/sigaction.c
new file mode 100644
index 0000000..7645538
--- /dev/null
+++ b/lib/libc/sys/sigaction.c
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2014 The FreeBSD Foundation.
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Konstantin Belousov
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * 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(s), this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified other than the possible
+ * addition of one or more copyright notices.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <signal.h>
+#include "libc_private.h"
+
+__weak_reference(__sys_sigaction, __sigaction);
+
+#pragma weak sigaction
+int
+sigaction(int sig, const struct sigaction *act, struct sigaction *oact)
+{
+
+ return (((int (*)(int, const struct sigaction *, struct sigaction *))
+ __libc_interposing[INTERPOS_sigaction])(sig, act, oact));
+}
diff --git a/lib/libc/sys/sigprocmask.c b/lib/libc/sys/sigprocmask.c
new file mode 100644
index 0000000..40dba95
--- /dev/null
+++ b/lib/libc/sys/sigprocmask.c
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2014 The FreeBSD Foundation.
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Konstantin Belousov
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * 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(s), this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified other than the possible
+ * addition of one or more copyright notices.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <signal.h>
+#include "libc_private.h"
+
+__weak_reference(__sys_sigprocmask, __sigprocmask);
+
+#pragma weak sigprocmask
+int
+sigprocmask(int how, const sigset_t *set, sigset_t *oset)
+{
+
+ return (((int (*)(int, const sigset_t *, sigset_t *))
+ __libc_interposing[INTERPOS_sigprocmask])(how, set, oset));
+}
diff --git a/lib/libc/sys/sigsuspend.c b/lib/libc/sys/sigsuspend.c
new file mode 100644
index 0000000..6e47368
--- /dev/null
+++ b/lib/libc/sys/sigsuspend.c
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2014 The FreeBSD Foundation.
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Konstantin Belousov
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * 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(s), this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified other than the possible
+ * addition of one or more copyright notices.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <signal.h>
+#include "libc_private.h"
+
+__weak_reference(__sys_sigsuspend, __sigsuspend);
+
+#pragma weak sigsuspend
+int
+sigsuspend(const sigset_t *set)
+{
+
+ return (((int (*)(const sigset_t *))
+ __libc_interposing[INTERPOS_sigsuspend])(set));
+}
diff --git a/lib/libc/sys/sigtimedwait.c b/lib/libc/sys/sigtimedwait.c
new file mode 100644
index 0000000..4e06719
--- /dev/null
+++ b/lib/libc/sys/sigtimedwait.c
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2014 The FreeBSD Foundation.
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Konstantin Belousov
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * 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(s), this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified other than the possible
+ * addition of one or more copyright notices.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <signal.h>
+#include "libc_private.h"
+
+__weak_reference(__sys_sigtimedwait, __sigtimedwait);
+
+#pragma weak sigtimedwait
+int
+sigtimedwait(const sigset_t * __restrict set, siginfo_t * __restrict info,
+ const struct timespec * __restrict t)
+{
+
+ return (((int (*)(const sigset_t *, siginfo_t *,
+ const struct timespec *))
+ __libc_interposing[INTERPOS_sigtimedwait])(set, info, t));
+}
diff --git a/lib/libc/sys/sigwait.c b/lib/libc/sys/sigwait.c
index 2fdffdd..b21cabd 100644
--- a/lib/libc/sys/sigwait.c
+++ b/lib/libc/sys/sigwait.c
@@ -28,13 +28,21 @@ __FBSDID("$FreeBSD$");
#include <errno.h>
#include <signal.h>
+#include "libc_private.h"
-int __sys_sigwait(const sigset_t * restrict, int * restrict);
+__weak_reference(__libc_sigwait, __sigwait);
-__weak_reference(__sigwait, sigwait);
+#pragma weak sigwait
+int
+sigwait(const sigset_t *set, int *sig)
+{
+
+ return (((int (*)(const sigset_t *, int *))
+ __libc_interposing[INTERPOS_sigwait])(set, sig));
+}
int
-__sigwait(const sigset_t * restrict set, int * restrict sig)
+__libc_sigwait(const sigset_t *set, int *sig)
{
int ret;
diff --git a/lib/libc/sys/sigwaitinfo.2 b/lib/libc/sys/sigwaitinfo.2
index 9109759..b497592 100644
--- a/lib/libc/sys/sigwaitinfo.2
+++ b/lib/libc/sys/sigwaitinfo.2
@@ -172,8 +172,8 @@ system calls fail if:
.Bl -tag -width Er
.It Bq Er EINTR
The wait was interrupted by an unblocked, caught signal.
-.Pp
.El
+.Pp
The
.Fn sigtimedwait
system call may also fail if:
diff --git a/lib/libc/sys/sigwaitinfo.c b/lib/libc/sys/sigwaitinfo.c
new file mode 100644
index 0000000..b9cdc79
--- /dev/null
+++ b/lib/libc/sys/sigwaitinfo.c
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2014 The FreeBSD Foundation.
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Konstantin Belousov
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * 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(s), this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified other than the possible
+ * addition of one or more copyright notices.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <signal.h>
+#include "libc_private.h"
+
+__weak_reference(__sys_sigwaitinfo, __sigwaitinfo);
+
+#pragma weak sigwaitinfo
+int
+sigwaitinfo(const sigset_t * __restrict set, siginfo_t * __restrict info)
+{
+
+ return (((int (*)(const sigset_t *, siginfo_t *))
+ __libc_interposing[INTERPOS_sigwaitinfo])(set, info));
+}
diff --git a/lib/libc/sys/socketpair.2 b/lib/libc/sys/socketpair.2
index d3a47eb..b15553a 100644
--- a/lib/libc/sys/socketpair.2
+++ b/lib/libc/sys/socketpair.2
@@ -28,7 +28,7 @@
.\" @(#)socketpair.2 8.1 (Berkeley) 6/4/93
.\" $FreeBSD$
.\"
-.Dd September 11, 2013
+.Dd May 4, 2015
.Dt SOCKETPAIR 2
.Os
.Sh NAME
@@ -40,13 +40,13 @@
.In sys/types.h
.In sys/socket.h
.Ft int
-.Fn socketpair "int fd" "int type" "int protocol" "int *sv"
+.Fn socketpair "int domain" "int type" "int protocol" "int *sv"
.Sh DESCRIPTION
The
.Fn socketpair
system call creates an unnamed pair of connected sockets in
-the specified domain
-.Fa fd ,
+the specified communications
+.Fa domain ,
of the specified
.Fa type ,
and using the optionally specified
diff --git a/lib/libc/gen/swapcontext.c b/lib/libc/sys/swapcontext.c
index c34cb23..0a8125e 100644
--- a/lib/libc/gen/swapcontext.c
+++ b/lib/libc/sys/swapcontext.c
@@ -1,7 +1,11 @@
/*
* Copyright (c) 2001 Daniel M. Eischen <deischen@freebsd.org>
+ * Copyright (c) 2014 The FreeBSD Foundation.
* All rights reserved.
*
+ * Portions of this software were developed by Konstantin Belousov
+ * under sponsorship from the FreeBSD Foundation.
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -30,26 +34,20 @@ __FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/signal.h>
#include <sys/ucontext.h>
-
#include <errno.h>
#include <stddef.h>
+#include "libc_private.h"
-__weak_reference(__swapcontext, swapcontext);
+__weak_reference(__sys_swapcontext, __swapcontext);
+__sym_compat(swapcontext, __impl_swapcontext, FBSD_1.0);
+__weak_reference(swapcontext, __impl_swapcontext);
+__sym_default(swapcontext, swapcontext, FBSD_1.2);
+#pragma weak swapcontext
int
-__swapcontext(ucontext_t *oucp, const ucontext_t *ucp)
+swapcontext(ucontext_t *oucp, const ucontext_t *ucp)
{
- int ret;
- if ((oucp == NULL) || (ucp == NULL)) {
- errno = EINVAL;
- return (-1);
- }
- oucp->uc_flags &= ~UCF_SWAPPED;
- ret = getcontext(oucp);
- if ((ret == 0) && !(oucp->uc_flags & UCF_SWAPPED)) {
- oucp->uc_flags |= UCF_SWAPPED;
- ret = setcontext(ucp);
- }
- return (ret);
+ return (((int (*)(ucontext_t *, const ucontext_t *))
+ __libc_interposing[INTERPOS_swapcontext])(oucp, ucp));
}
diff --git a/lib/libc/arm/sys/__vdso_gettc.c b/lib/libc/sys/trivial-vdso_tc.c
index b99bbc4..b99bbc4 100644
--- a/lib/libc/arm/sys/__vdso_gettc.c
+++ b/lib/libc/sys/trivial-vdso_tc.c
diff --git a/lib/libc/sys/truncate.2 b/lib/libc/sys/truncate.2
index f06c1eb..0734464 100644
--- a/lib/libc/sys/truncate.2
+++ b/lib/libc/sys/truncate.2
@@ -28,7 +28,7 @@
.\" @(#)truncate.2 8.1 (Berkeley) 6/4/93
.\" $FreeBSD$
.\"
-.Dd December 13, 2006
+.Dd May 4, 2015
.Dt TRUNCATE 2
.Os
.Sh NAME
@@ -60,9 +60,18 @@ is lost.
If the file was smaller than this size,
it will be extended as if by writing bytes
with the value zero.
-With
-.Fn ftruncate ,
-the file must be open for writing.
+.Pp
+The
+.Fn ftruncate
+system call causes the file or shared memory object backing the file descriptor
+.Fa fd
+to be truncated or extended to
+.Fa length
+bytes in size.
+The file descriptor must be a valid file descriptor open for writing.
+The file position pointer associated with the file descriptor
+.Fa fd
+will not be modified.
.Sh RETURN VALUES
.Rv -std
If the file to be modified is not a directory or
@@ -129,7 +138,7 @@ is not a valid descriptor.
The
.Fa fd
argument
-references a socket, not a file.
+references a file descriptor that is not a regular file or shared memory object.
.It Bq Er EINVAL
The
.Fa fd
@@ -138,11 +147,14 @@ is not open for writing.
.El
.Sh SEE ALSO
.Xr chflags 2 ,
-.Xr open 2
+.Xr open 2 ,
+.Xr shm_open 2
.Sh HISTORY
The
.Fn truncate
-system call appeared in
+and
+.Fn ftruncate
+system calls appeared in
.Bx 4.2 .
.Sh BUGS
These calls should be generalized to allow ranges
diff --git a/lib/libc/sys/truncate.c b/lib/libc/sys/truncate.c
deleted file mode 100644
index 375c9d9..0000000
--- a/lib/libc/sys/truncate.c
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (c) 1992, 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.
- * 4. 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)truncate.c 8.1 (Berkeley) 6/17/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/types.h>
-#include <sys/syscall.h>
-#include <unistd.h>
-#include "libc_private.h"
-
-/*
- * This function provides 64-bit offset padding that
- * is not supplied by GCC 1.X but is supplied by GCC 2.X.
- */
-int
-truncate(path, length)
- const char *path;
- off_t length;
-{
-
- if (__getosreldate() >= 700051)
- return(__sys_truncate(path, length));
- else
- return(__sys_freebsd6_truncate(path, 0, length));
-}
diff --git a/lib/libc/sys/utimensat.2 b/lib/libc/sys/utimensat.2
new file mode 100644
index 0000000..0f397c6
--- /dev/null
+++ b/lib/libc/sys/utimensat.2
@@ -0,0 +1,292 @@
+.\" $NetBSD: utimes.2,v 1.13 1999/03/22 19:45:11 garbled Exp $
+.\"
+.\" Copyright (c) 1990, 1993
+.\" The Regents of the University of California. All rights reserved.
+.\" Copyright (c) 2012, Jilles Tjoelker
+.\"
+.\" 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.
+.\" 4. 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.
+.\"
+.\" @(#)utimes.2 8.1 (Berkeley) 6/4/93
+.\" $FreeBSD$
+.\"
+.Dd January 23, 2015
+.Dt UTIMENSAT 2
+.Os
+.Sh NAME
+.Nm futimens ,
+.Nm utimensat
+.Nd set file access and modification times
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In sys/stat.h
+.Ft int
+.Fn futimens "int fd" "const struct timespec times[2]"
+.Ft int
+.Fo utimensat
+.Fa "int fd"
+.Fa "const char *path"
+.Fa "const struct timespec times[2]"
+.Fa "int flag"
+.Fc
+.Sh DESCRIPTION
+The access and modification times of the file named by
+.Fa path
+or referenced by
+.Fa fd
+are changed as specified by the argument
+.Fa times .
+The inode-change-time of the file is set to the current time.
+.Pp
+If
+.Fa path
+specifies a relative path,
+it is relative to the current working directory if
+.Fa fd
+is
+.Dv AT_FDCWD
+and otherwise relative to the directory associated with the file descriptor
+.Fa fd .
+.Pp
+The
+.Va tv_nsec
+field of a
+.Vt timespec
+structure
+can be set to the special value
+.Dv UTIME_NOW
+to set the current time, or to
+.Dv UTIME_OMIT
+to leave the time unchanged.
+In either case, the
+.Va tv_sec
+field is ignored.
+.Pp
+If
+.Fa times
+is
+.No non- Ns Dv NULL ,
+it is assumed to point to an array of two timespec structures.
+The access time is set to the value of the first element, and the
+modification time is set to the value of the second element.
+For file systems that support file birth (creation) times (such as
+.Dv UFS2 ) ,
+the birth time will be set to the value of the second element
+if the second element is older than the currently set birth time.
+To set both a birth time and a modification time,
+two calls are required; the first to set the birth time
+and the second to set the (presumably newer) modification time.
+Ideally a new system call will be added that allows the setting
+of all three times at once.
+If
+.Fa times
+is
+.Dv NULL ,
+this is equivalent to passing
+a pointer to an array of two timespec structures
+with both
+.Va tv_nsec
+fields set to
+.Dv UTIME_NOW .
+.Pp
+If both
+.Va tv_nsec
+fields are
+.Dv UTIME_OMIT ,
+the timestamps remain unchanged and
+no permissions are needed for the file itself,
+although search permissions may be required for the path prefix.
+The call may or may not succeed if the named file does not exist.
+.Pp
+If both
+.Va tv_nsec
+fields are
+.Dv UTIME_NOW ,
+the caller must be the owner of the file, have permission to
+write the file, or be the super-user.
+.Pp
+For all other values of the timestamps,
+the caller must be the owner of the file or be the super-user.
+.Pp
+The values for the
+.Fa flag
+argument of the
+.Fn utimensat
+system call
+are constructed by a bitwise-inclusive OR of flags from the following list,
+defined in
+.In fcntl.h :
+.Bl -tag -width indent
+.It Dv AT_SYMLINK_NOFOLLOW
+If
+.Fa path
+names a symbolic link, the symbolic link's times are changed.
+By default,
+.Fn utimensat
+changes the times of the file referenced by the symbolic link.
+.El
+.Sh RETURN VALUES
+.Rv -std
+.Sh COMPATIBILITY
+If the running kernel does not support this system call,
+a wrapper emulates it using
+.Xr fstatat 2 ,
+.Xr futimesat 2
+and
+.Xr lutimes 2 .
+As a result, timestamps will be rounded down to the nearest microsecond,
+.Dv UTIME_OMIT
+is not atomic and
+.Dv AT_SYMLINK_NOFOLLOW
+is not available with a path relative to a file descriptor.
+.Sh ERRORS
+These system calls will fail if:
+.Bl -tag -width Er
+.It Bq Er EACCES
+The
+.Fa times
+argument is
+.Dv NULL ,
+or both
+.Va tv_nsec
+values are
+.Dv UTIME_NOW ,
+and the effective user ID of the process does not
+match the owner of the file, and is not the super-user, and write
+access is denied.
+.It Bq Er EFAULT
+The
+.Fa times
+argument
+points outside the process's allocated address space.
+.It Bq Er EINVAL
+The
+.Va tv_usec
+component of at least one of the values specified by the
+.Fa times
+argument has a value less than 0 or greater than 999999.
+.It Bq Er EIO
+An I/O error occurred while reading or writing the affected inode.
+.It Bq Er EPERM
+The
+.Fa times
+argument is not
+.Dv NULL
+nor are both
+.Va tv_nsec
+values
+.Dv UTIME_NOW ,
+nor are both
+.Va tv_nsec
+values
+.Dv UTIME_OMIT
+and the calling process's effective user ID
+does not match the owner of the file and is not the super-user.
+.It Bq Er EPERM
+The named file has its immutable or append-only flag set, see the
+.Xr chflags 2
+manual page for more information.
+.It Bq Er EROFS
+The file system containing the file is mounted read-only.
+.El
+.Pp
+The
+.Fn futimens
+system call
+will fail if:
+.Bl -tag -width Er
+.It Bq Er EBADF
+The
+.Fa fd
+argument
+does not refer to a valid descriptor.
+.El
+.Pp
+The
+.Fn utimensat
+system call
+will fail if:
+.Bl -tag -width Er
+.It Bq Er EACCES
+Search permission is denied for a component of the path prefix.
+.It Bq Er EBADF
+The
+.Fa path
+argument does not specify an absolute path and the
+.Fa fd
+argument is neither
+.Dv AT_FDCWD
+nor a valid file descriptor.
+.It Bq Er EFAULT
+The
+.Fa path
+argument
+points outside the process's allocated address space.
+.It Bq Er ELOOP
+Too many symbolic links were encountered in translating the pathname.
+.It Bq Er ENAMETOOLONG
+A component of a pathname exceeded
+.Dv NAME_MAX
+characters, or an entire path name exceeded
+.Dv PATH_MAX
+characters.
+.It Bq Er ENOENT
+The named file does not exist.
+.It Bq Er ENOTDIR
+A component of the path prefix is not a directory.
+.It Bq Er ENOTDIR
+The
+.Fa path
+argument is not an absolute path and
+.Fa fd
+is neither
+.Dv AT_FDCWD
+nor a file descriptor associated with a directory.
+.It Bq Er ENOTSUP
+The running kernel does not support this system call and
+.Dv AT_SYMLINK_NOFOLLOW
+is used with a path relative to a file descriptor.
+.El
+.Sh SEE ALSO
+.Xr chflags 2 ,
+.Xr stat 2 ,
+.Xr symlink 2 ,
+.Xr utimes 2 ,
+.Xr utime 3 ,
+.Xr symlink 7
+.Sh STANDARDS
+The
+.Fn futimens
+and
+.Fn utimensat
+system calls are expected to conform to
+.St -p1003.1-2008 .
+.Sh HISTORY
+The
+.Fn futimens
+and
+.Fn utimensat
+system calls appeared in
+.Fx 11.0 .
diff --git a/lib/libc/sys/utimensat.c b/lib/libc/sys/utimensat.c
new file mode 100644
index 0000000..67d19cb
--- /dev/null
+++ b/lib/libc/sys/utimensat.c
@@ -0,0 +1,109 @@
+/*-
+ * Copyright (c) 2015 Jilles Tjoelker
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include "namespace.h"
+#include <sys/stat.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <time.h>
+#include "un-namespace.h"
+
+#include "libc_private.h"
+
+int
+utimensat(int fd, const char *path, const struct timespec times[2], int flag)
+{
+ struct timeval now, tv[2], *tvp;
+ struct stat sb;
+
+ if (__getosreldate() >= 1100056)
+ return (__sys_utimensat(fd, path, times, flag));
+
+ if ((flag & ~AT_SYMLINK_NOFOLLOW) != 0) {
+ errno = EINVAL;
+ return (-1);
+ }
+ if (times == NULL || (times[0].tv_nsec == UTIME_NOW &&
+ times[1].tv_nsec == UTIME_NOW))
+ tvp = NULL;
+ else if (times[0].tv_nsec == UTIME_OMIT &&
+ times[1].tv_nsec == UTIME_OMIT)
+ return (0);
+ else {
+ if ((times[0].tv_nsec < 0 || times[0].tv_nsec > 999999999) &&
+ times[0].tv_nsec != UTIME_NOW &&
+ times[0].tv_nsec != UTIME_OMIT) {
+ errno = EINVAL;
+ return (-1);
+ }
+ if ((times[1].tv_nsec < 0 || times[1].tv_nsec > 999999999) &&
+ times[1].tv_nsec != UTIME_NOW &&
+ times[1].tv_nsec != UTIME_OMIT) {
+ errno = EINVAL;
+ return (-1);
+ }
+ tv[0].tv_sec = times[0].tv_sec;
+ tv[0].tv_usec = times[0].tv_nsec / 1000;
+ tv[1].tv_sec = times[1].tv_sec;
+ tv[1].tv_usec = times[1].tv_nsec / 1000;
+ tvp = tv;
+ if (times[0].tv_nsec == UTIME_OMIT ||
+ times[1].tv_nsec == UTIME_OMIT) {
+ if (fstatat(fd, path, &sb, flag) == -1)
+ return (-1);
+ if (times[0].tv_nsec == UTIME_OMIT) {
+ tv[0].tv_sec = sb.st_atim.tv_sec;
+ tv[0].tv_usec = sb.st_atim.tv_nsec / 1000;
+ }
+ if (times[1].tv_nsec == UTIME_OMIT) {
+ tv[1].tv_sec = sb.st_mtim.tv_sec;
+ tv[1].tv_usec = sb.st_mtim.tv_nsec / 1000;
+ }
+ }
+ if (times[0].tv_nsec == UTIME_NOW ||
+ times[1].tv_nsec == UTIME_NOW) {
+ if (gettimeofday(&now, NULL) == -1)
+ return (-1);
+ if (times[0].tv_nsec == UTIME_NOW)
+ tv[0] = now;
+ if (times[1].tv_nsec == UTIME_NOW)
+ tv[1] = now;
+ }
+ }
+ if ((flag & AT_SYMLINK_NOFOLLOW) == 0)
+ return (futimesat(fd, path, tvp));
+ else if ((flag & AT_SYMLINK_NOFOLLOW) != 0 &&
+ (fd == AT_FDCWD || path[0] == '/'))
+ return (lutimes(path, tvp));
+ else {
+ errno = ENOTSUP;
+ return (-1);
+ }
+}
diff --git a/lib/libc/sys/vfork.2 b/lib/libc/sys/vfork.2
index 1cfaa61..0518262 100644
--- a/lib/libc/sys/vfork.2
+++ b/lib/libc/sys/vfork.2
@@ -28,7 +28,7 @@
.\" @(#)vfork.2 8.1 (Berkeley) 6/4/93
.\" $FreeBSD$
.\"
-.Dd November 13, 2009
+.Dd April 6, 2015
.Dt VFORK 2
.Os
.Sh NAME
@@ -100,8 +100,8 @@ since buffered data would then be flushed twice.)
Same as for
.Xr fork 2 .
.Sh SEE ALSO
-.Xr execve 2 ,
.Xr _exit 2 ,
+.Xr execve 2 ,
.Xr fork 2 ,
.Xr rfork 2 ,
.Xr sigaction 2 ,
@@ -111,7 +111,7 @@ Same as for
The
.Fn vfork
system call appeared in
-.Bx 2.9 .
+.Bx 3 .
.Sh BUGS
To avoid a possible deadlock situation,
processes that are children in the middle
diff --git a/lib/libc/sys/wait4.c b/lib/libc/sys/wait4.c
new file mode 100644
index 0000000..a5dbd0f
--- /dev/null
+++ b/lib/libc/sys/wait4.c
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2014 The FreeBSD Foundation.
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Konstantin Belousov
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * 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(s), this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified other than the possible
+ * addition of one or more copyright notices.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/wait.h>
+#include "libc_private.h"
+
+__weak_reference(__sys_wait4, __wait4);
+
+#pragma weak wait4
+pid_t
+wait4(pid_t pid, int *status, int options, struct rusage *ru)
+{
+
+ return (((pid_t (*)(pid_t, int *, int, struct rusage *))
+ __libc_interposing[INTERPOS_wait4])(pid, status, options, ru));
+}
diff --git a/lib/libc/sys/wait6.c b/lib/libc/sys/wait6.c
new file mode 100644
index 0000000..d280a76
--- /dev/null
+++ b/lib/libc/sys/wait6.c
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2015 The FreeBSD Foundation.
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Konstantin Belousov
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * 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(s), this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified other than the possible
+ * addition of one or more copyright notices.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <signal.h>
+#include "libc_private.h"
+
+__weak_reference(__sys_wait6, __wait6);
+
+#pragma weak wait6
+pid_t
+wait6(idtype_t idtype, id_t id, int *status, int options, struct __wrusage *ru,
+ siginfo_t *infop)
+{
+
+ return (((pid_t (*)(idtype_t, id_t, int *, int, struct __wrusage *,
+ siginfo_t *))__libc_interposing[INTERPOS_wait6])(idtype, id,
+ status, options, ru, infop));
+}
diff --git a/lib/libc/sys/write.c b/lib/libc/sys/write.c
new file mode 100644
index 0000000..ffb1aa5
--- /dev/null
+++ b/lib/libc/sys/write.c
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2014 The FreeBSD Foundation.
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Konstantin Belousov
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * 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(s), this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified other than the possible
+ * addition of one or more copyright notices.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+#include "libc_private.h"
+
+__weak_reference(__sys_write, __write);
+
+#pragma weak write
+ssize_t
+write(int fd, const void *buf, size_t nbytes)
+{
+
+ return (((ssize_t (*)(int, const void *, size_t))
+ __libc_interposing[INTERPOS_write])(fd, buf, nbytes));
+}
diff --git a/lib/libc/sys/writev.c b/lib/libc/sys/writev.c
new file mode 100644
index 0000000..6be74b3
--- /dev/null
+++ b/lib/libc/sys/writev.c
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2014 The FreeBSD Foundation.
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Konstantin Belousov
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * 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(s), this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified other than the possible
+ * addition of one or more copyright notices.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+#include "libc_private.h"
+
+__weak_reference(__sys_writev, __writev);
+
+#pragma weak writev
+ssize_t
+writev(int fd, const struct iovec *iov, int iovcnt)
+{
+
+ return (((ssize_t (*)(int, const struct iovec *, int))
+ __libc_interposing[INTERPOS_writev])(fd, iov, iovcnt));
+}
diff --git a/lib/libc/tests/c063/Makefile b/lib/libc/tests/c063/Makefile
index b743165..5f4e1ca 100644
--- a/lib/libc/tests/c063/Makefile
+++ b/lib/libc/tests/c063/Makefile
@@ -2,23 +2,26 @@
TESTSDIR= ${TESTSBASE}/lib/libc/c063
-#TODO: t_o_search, t_utimensat
+#TODO: t_o_search
-NETBSD_ATF_TESTS_C= t_faccessat
-NETBSD_ATF_TESTS_C+= t_fchmodat
-NETBSD_ATF_TESTS_C+= t_fchownat
-NETBSD_ATF_TESTS_C+= t_fexecve
-NETBSD_ATF_TESTS_C+= t_fstatat
-NETBSD_ATF_TESTS_C+= t_linkat
-NETBSD_ATF_TESTS_C+= t_mkdirat
-NETBSD_ATF_TESTS_C+= t_mkfifoat
-NETBSD_ATF_TESTS_C+= t_mknodat
-NETBSD_ATF_TESTS_C+= t_openat
-NETBSD_ATF_TESTS_C+= t_readlinkat
-NETBSD_ATF_TESTS_C+= t_renameat
-NETBSD_ATF_TESTS_C+= t_symlinkat
-NETBSD_ATF_TESTS_C+= t_unlinkat
+NETBSD_ATF_TESTS_C= faccessat
+NETBSD_ATF_TESTS_C+= fchmodat
+NETBSD_ATF_TESTS_C+= fchownat
+NETBSD_ATF_TESTS_C+= fexecve
+NETBSD_ATF_TESTS_C+= fstatat
+NETBSD_ATF_TESTS_C+= linkat
+NETBSD_ATF_TESTS_C+= mkdirat
+NETBSD_ATF_TESTS_C+= mkfifoat
+NETBSD_ATF_TESTS_C+= mknodat
+NETBSD_ATF_TESTS_C+= openat
+NETBSD_ATF_TESTS_C+= readlinkat
+NETBSD_ATF_TESTS_C+= renameat
+NETBSD_ATF_TESTS_C+= symlinkat
+NETBSD_ATF_TESTS_C+= unlinkat
+NETBSD_ATF_TESTS_C+= utimensat
CFLAGS+= -D_INCOMPLETE_XOPEN_C063
+.include "../Makefile.netbsd-tests"
+
.include <bsd.test.mk>
diff --git a/lib/libc/tests/db/Makefile b/lib/libc/tests/db/Makefile
index 323a9f0..ed1d6ca 100644
--- a/lib/libc/tests/db/Makefile
+++ b/lib/libc/tests/db/Makefile
@@ -11,6 +11,7 @@ FILESDIR= ${TESTSDIR}
FILES= README
NETBSD_ATF_TESTS_SH+= db_test
+ATF_TESTS_SH_SED_db_test= -e 's,/bin/csh,/bin/cat,g'
.include "../Makefile.netbsd-tests"
diff --git a/lib/libc/tests/hash/Makefile b/lib/libc/tests/hash/Makefile
index df9d6d9..52fd569 100644
--- a/lib/libc/tests/hash/Makefile
+++ b/lib/libc/tests/hash/Makefile
@@ -1,8 +1,14 @@
# $FreeBSD$
+.include <src.opts.mk>
+
TESTSDIR= ${TESTSBASE}/lib/libc/hash
-NETBSD_ATF_TESTS_C= sha2_test
+NETBSD_ATF_TESTS_C=
+
+.if ${MK_OPENSSL} != "no"
+NETBSD_ATF_TESTS_C+= sha2_test
+.endif
NETBSD_ATF_TESTS_SH= hash_test
diff --git a/lib/libc/tests/ssp/Makefile b/lib/libc/tests/ssp/Makefile
index cf767ce..7bc8660 100644
--- a/lib/libc/tests/ssp/Makefile
+++ b/lib/libc/tests/ssp/Makefile
@@ -26,7 +26,11 @@ PROGS+= h_getcwd
PROGS+= h_memcpy
PROGS+= h_memmove
PROGS+= h_memset
+# This testcase doesn't run properly when not compiled with -fsantize=bounds
+# with clang, which is currently contingent on a compiler_rt update
+.if ${COMPILER_TYPE} == "clang" && ${COMPILER_VERSION} < 30500
PROGS+= h_raw
+.endif
PROGS+= h_read
PROGS+= h_readlink
PROGS+= h_snprintf
diff --git a/lib/libc/tests/sys/Makefile b/lib/libc/tests/sys/Makefile
index 89431bc..5e457fd 100644
--- a/lib/libc/tests/sys/Makefile
+++ b/lib/libc/tests/sys/Makefile
@@ -12,7 +12,9 @@ NETBSD_ATF_TESTS_C+= clock_gettime_test
NETBSD_ATF_TESTS_C+= connect_test
NETBSD_ATF_TESTS_C+= dup_test
NETBSD_ATF_TESTS_C+= fsync_test
+.if ${MACHINE} != "arm64" # ARM64TODO: Missing makecontext
NETBSD_ATF_TESTS_C+= getcontext_test
+.endif
NETBSD_ATF_TESTS_C+= getgroups_test
NETBSD_ATF_TESTS_C+= getitimer_test
NETBSD_ATF_TESTS_C+= getlogin_test
diff --git a/lib/libc/xdr/xdr_float.c b/lib/libc/xdr/xdr_float.c
index 1135806..1d3bb61 100644
--- a/lib/libc/xdr/xdr_float.c
+++ b/lib/libc/xdr/xdr_float.c
@@ -64,7 +64,8 @@ __FBSDID("$FreeBSD$");
#if defined(__m68k__) || defined(__sparc__) || defined(__i386__) || \
defined(__mips__) || defined(__ns32k__) || defined(__alpha__) || \
defined(__arm__) || defined(__ppc__) || \
- defined(__arm26__) || defined(__sparc64__) || defined(__amd64__)
+ defined(__arm26__) || defined(__sparc64__) || defined(__amd64__) || \
+ defined(__aarch64__)
#include <machine/endian.h>
#define IEEEFP
#endif
diff --git a/lib/libcam/Makefile b/lib/libcam/Makefile
index 1621fe6..c448369 100644
--- a/lib/libcam/Makefile
+++ b/lib/libcam/Makefile
@@ -6,8 +6,7 @@ SRCS= camlib.c scsi_cmdparse.c scsi_all.c scsi_da.c scsi_sa.c cam.c \
ata_all.c smp_all.c
INCS= camlib.h
-DPADD= ${LIBSBUF}
-LDADD= -lsbuf
+LIBADD= sbuf
MAN= cam.3 cam_cdbparse.3
diff --git a/lib/libcapsicum/Makefile b/lib/libcapsicum/Makefile
index 061edfc..6ee5bb8 100644
--- a/lib/libcapsicum/Makefile
+++ b/lib/libcapsicum/Makefile
@@ -21,8 +21,7 @@ INCS+= libcapsicum_random.h
INCS+= libcapsicum_service.h
INCS+= libcapsicum_sysctl.h
-DPADD= ${LIBNV}
-LDADD= -lnv
+LIBADD= nv
CFLAGS+=-I${.CURDIR}
CFLAGS+=-I${.CURDIR}/../libnv
diff --git a/lib/libcapsicum/libcapsicum.3 b/lib/libcapsicum/libcapsicum.3
index 9df565a..cbfd214 100644
--- a/lib/libcapsicum/libcapsicum.3
+++ b/lib/libcapsicum/libcapsicum.3
@@ -27,7 +27,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd April 14, 2014
+.Dd May 2, 2015
.Dt LIBCAPSICUM 3
.Os
.Sh NAME
@@ -68,9 +68,9 @@
.Ft "int"
.Fn cap_send_nvlist "const cap_channel_t *chan" "const nvlist_t *nvl"
.Ft "nvlist_t *"
-.Fn cap_recv_nvlist "const cap_channel_t *chan"
+.Fn cap_recv_nvlist "const cap_channel_t *chan" "int flags"
.Ft "nvlist_t *"
-.Fn cap_xfer_nvlist "const cap_channel_t *chan" "nvlist_t *nvl"
+.Fn cap_xfer_nvlist "const cap_channel_t *chan" "nvlist_t *nvl" "int flags"
.In libcapsicum_service.h
.Ft "cap_channel_t *"
.Fn cap_service_open "const cap_channel_t *chan" "const char *name"
@@ -171,11 +171,23 @@ Most services should provide higher level API.
The
.Fn cap_recv_nvlist
function receives the given nvlist over the given capability.
+The
+.Fa flags
+argument defines what type the top nvlist is expected to be.
+If the nvlist flags do not match the flags passed to
+.Fn cap_recv_nvlist ,
+the nvlist will not be returned.
.Pp
The
.Fn cap_xfer_nvlist
function sends the given nvlist, destroys it and receives new nvlist in
response over the given capability.
+The
+.Fa flags
+argument defines what type the top nvlist is expected to be.
+If the nvlist flags do not match the flags passed to
+.Fn cap_xfer_nvlist ,
+the nvlist will not be returned.
It does not matter if the function succeeds or fails, the nvlist given
for sending will always be destroyed once the function returns.
.Pp
diff --git a/lib/libcapsicum/libcapsicum.c b/lib/libcapsicum/libcapsicum.c
index 79ca871..79c570f 100644
--- a/lib/libcapsicum/libcapsicum.c
+++ b/lib/libcapsicum/libcapsicum.c
@@ -142,7 +142,7 @@ cap_clone(const cap_channel_t *chan)
nvl = nvlist_create(0);
nvlist_add_string(nvl, "cmd", "clone");
- nvl = cap_xfer_nvlist(chan, nvl);
+ nvl = cap_xfer_nvlist(chan, nvl, 0);
if (nvl == NULL)
return (NULL);
if (nvlist_get_number(nvl, "error") != 0) {
@@ -195,7 +195,7 @@ cap_limit_set(const cap_channel_t *chan, nvlist_t *limits)
nvlmsg = nvlist_create(0);
nvlist_add_string(nvlmsg, "cmd", "limit_set");
nvlist_add_nvlist(nvlmsg, "limits", limits);
- nvlmsg = cap_xfer_nvlist(chan, nvlmsg);
+ nvlmsg = cap_xfer_nvlist(chan, nvlmsg, 0);
if (nvlmsg == NULL) {
nvlist_destroy(limits);
return (-1);
@@ -218,7 +218,7 @@ cap_limit_get(const cap_channel_t *chan, nvlist_t **limitsp)
nvlmsg = nvlist_create(0);
nvlist_add_string(nvlmsg, "cmd", "limit_get");
- nvlmsg = cap_xfer_nvlist(chan, nvlmsg);
+ nvlmsg = cap_xfer_nvlist(chan, nvlmsg, 0);
if (nvlmsg == NULL)
return (-1);
error = (int)nvlist_get_number(nvlmsg, "error");
@@ -246,21 +246,21 @@ cap_send_nvlist(const cap_channel_t *chan, const nvlist_t *nvl)
}
nvlist_t *
-cap_recv_nvlist(const cap_channel_t *chan)
+cap_recv_nvlist(const cap_channel_t *chan, int flags)
{
assert(chan != NULL);
assert(chan->cch_magic == CAP_CHANNEL_MAGIC);
- return (nvlist_recv(chan->cch_sock));
+ return (nvlist_recv(chan->cch_sock, flags));
}
nvlist_t *
-cap_xfer_nvlist(const cap_channel_t *chan, nvlist_t *nvl)
+cap_xfer_nvlist(const cap_channel_t *chan, nvlist_t *nvl, int flags)
{
assert(chan != NULL);
assert(chan->cch_magic == CAP_CHANNEL_MAGIC);
- return (nvlist_xfer(chan->cch_sock, nvl));
+ return (nvlist_xfer(chan->cch_sock, nvl, flags));
}
diff --git a/lib/libcapsicum/libcapsicum.h b/lib/libcapsicum/libcapsicum.h
index 4f8c597..c7110d8 100644
--- a/lib/libcapsicum/libcapsicum.h
+++ b/lib/libcapsicum/libcapsicum.h
@@ -105,11 +105,11 @@ int cap_send_nvlist(const cap_channel_t *chan, const nvlist_t *nvl);
/*
* Function receives nvlist over the given capability.
*/
-nvlist_t *cap_recv_nvlist(const cap_channel_t *chan);
+nvlist_t *cap_recv_nvlist(const cap_channel_t *chan, int flags);
/*
* Function sends the given nvlist, destroys it and receives new nvlist in
* response over the given capability.
*/
-nvlist_t *cap_xfer_nvlist(const cap_channel_t *chan, nvlist_t *nvl);
+nvlist_t *cap_xfer_nvlist(const cap_channel_t *chan, nvlist_t *nvl, int flags);
#endif /* !_LIBCAPSICUM_H_ */
diff --git a/lib/libcapsicum/libcapsicum_dns.c b/lib/libcapsicum/libcapsicum_dns.c
index 113f8dc..a180b6b 100644
--- a/lib/libcapsicum/libcapsicum_dns.c
+++ b/lib/libcapsicum/libcapsicum_dns.c
@@ -30,6 +30,7 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
+#include <assert.h>
#include <netdb.h>
#include <stdlib.h>
#include <string.h>
@@ -67,6 +68,8 @@ static struct hostent *
hostent_unpack(const nvlist_t *nvl, struct hostent *hp)
{
unsigned int ii, nitems;
+ char nvlname[64];
+ int n;
hostent_free(hp);
@@ -81,8 +84,10 @@ hostent_unpack(const nvlist_t *nvl, struct hostent *hp)
if (hp->h_aliases == NULL)
goto fail;
for (ii = 0; ii < nitems; ii++) {
+ n = snprintf(nvlname, sizeof(nvlname), "alias%u", ii);
+ assert(n > 0 && n < (int)sizeof(nvlname));
hp->h_aliases[ii] =
- strdup(nvlist_getf_string(nvl, "alias%u", ii));
+ strdup(nvlist_get_string(nvl, nvlname));
if (hp->h_aliases[ii] == NULL)
goto fail;
}
@@ -96,7 +101,9 @@ hostent_unpack(const nvlist_t *nvl, struct hostent *hp)
hp->h_addr_list[ii] = malloc(hp->h_length);
if (hp->h_addr_list[ii] == NULL)
goto fail;
- bcopy(nvlist_getf_binary(nvl, NULL, "addr%u", ii),
+ n = snprintf(nvlname, sizeof(nvlname), "addr%u", ii);
+ assert(n > 0 && n < (int)sizeof(nvlname));
+ bcopy(nvlist_get_binary(nvl, nvlname, NULL),
hp->h_addr_list[ii], hp->h_length);
}
hp->h_addr_list[ii] = NULL;
@@ -125,7 +132,7 @@ cap_gethostbyname2(cap_channel_t *chan, const char *name, int type)
nvlist_add_string(nvl, "cmd", "gethostbyname");
nvlist_add_number(nvl, "family", (uint64_t)type);
nvlist_add_string(nvl, "name", name);
- nvl = cap_xfer_nvlist(chan, nvl);
+ nvl = cap_xfer_nvlist(chan, nvl, 0);
if (nvl == NULL) {
h_errno = NO_RECOVERY;
return (NULL);
@@ -152,7 +159,7 @@ cap_gethostbyaddr(cap_channel_t *chan, const void *addr, socklen_t len,
nvlist_add_string(nvl, "cmd", "gethostbyaddr");
nvlist_add_binary(nvl, "addr", addr, (size_t)len);
nvlist_add_number(nvl, "family", (uint64_t)type);
- nvl = cap_xfer_nvlist(chan, nvl);
+ nvl = cap_xfer_nvlist(chan, nvl, 0);
if (nvl == NULL) {
h_errno = NO_RECOVERY;
return (NULL);
@@ -208,8 +215,9 @@ cap_getaddrinfo(cap_channel_t *chan, const char *hostname, const char *servname,
struct addrinfo *firstai, *prevai, *curai;
unsigned int ii;
const nvlist_t *nvlai;
+ char nvlname[64];
nvlist_t *nvl;
- int error;
+ int error, n;
nvl = nvlist_create(0);
nvlist_add_string(nvl, "cmd", "getaddrinfo");
@@ -225,7 +233,7 @@ cap_getaddrinfo(cap_channel_t *chan, const char *hostname, const char *servname,
nvlist_add_number(nvl, "hints.ai_protocol",
(uint64_t)hints->ai_protocol);
}
- nvl = cap_xfer_nvlist(chan, nvl);
+ nvl = cap_xfer_nvlist(chan, nvl, 0);
if (nvl == NULL)
return (EAI_MEMORY);
if (nvlist_get_number(nvl, "error") != 0) {
@@ -237,9 +245,11 @@ cap_getaddrinfo(cap_channel_t *chan, const char *hostname, const char *servname,
nvlai = NULL;
firstai = prevai = curai = NULL;
for (ii = 0; ; ii++) {
- if (!nvlist_existsf_nvlist(nvl, "res%u", ii))
+ n = snprintf(nvlname, sizeof(nvlname), "res%u", ii);
+ assert(n > 0 && n < (int)sizeof(nvlname));
+ if (!nvlist_exists_nvlist(nvl, nvlname))
break;
- nvlai = nvlist_getf_nvlist(nvl, "res%u", ii);
+ nvlai = nvlist_get_nvlist(nvl, nvlname);
curai = addrinfo_unpack(nvlai);
if (curai == NULL)
break;
@@ -273,7 +283,7 @@ cap_getnameinfo(cap_channel_t *chan, const struct sockaddr *sa, socklen_t salen,
nvlist_add_number(nvl, "servlen", (uint64_t)servlen);
nvlist_add_binary(nvl, "sa", sa, (size_t)salen);
nvlist_add_number(nvl, "flags", (uint64_t)flags);
- nvl = cap_xfer_nvlist(chan, nvl);
+ nvl = cap_xfer_nvlist(chan, nvl, 0);
if (nvl == NULL)
return (EAI_MEMORY);
if (nvlist_get_number(nvl, "error") != 0) {
@@ -314,6 +324,8 @@ cap_dns_type_limit(cap_channel_t *chan, const char * const *types,
{
nvlist_t *limits;
unsigned int i;
+ char nvlname[64];
+ int n;
if (cap_limit_get(chan, &limits) < 0)
return (-1);
@@ -321,8 +333,11 @@ cap_dns_type_limit(cap_channel_t *chan, const char * const *types,
limits = nvlist_create(0);
else
limit_remove(limits, "type");
- for (i = 0; i < ntypes; i++)
- nvlist_addf_string(limits, types[i], "type%u", i);
+ for (i = 0; i < ntypes; i++) {
+ n = snprintf(nvlname, sizeof(nvlname), "type%u", i);
+ assert(n > 0 && n < (int)sizeof(nvlname));
+ nvlist_add_string(limits, nvlname, types[i]);
+ }
return (cap_limit_set(chan, limits));
}
@@ -332,6 +347,8 @@ cap_dns_family_limit(cap_channel_t *chan, const int *families,
{
nvlist_t *limits;
unsigned int i;
+ char nvlname[64];
+ int n;
if (cap_limit_get(chan, &limits) < 0)
return (-1);
@@ -340,8 +357,9 @@ cap_dns_family_limit(cap_channel_t *chan, const int *families,
else
limit_remove(limits, "family");
for (i = 0; i < nfamilies; i++) {
- nvlist_addf_number(limits, (uint64_t)families[i],
- "family%u", i);
+ n = snprintf(nvlname, sizeof(nvlname), "family%u", i);
+ assert(n > 0 && n < (int)sizeof(nvlname));
+ nvlist_add_number(limits, nvlname, (uint64_t)families[i]);
}
return (cap_limit_set(chan, limits));
}
diff --git a/lib/libcapsicum/libcapsicum_grp.c b/lib/libcapsicum/libcapsicum_grp.c
index c679ce9..267ac68 100644
--- a/lib/libcapsicum/libcapsicum_grp.c
+++ b/lib/libcapsicum/libcapsicum_grp.c
@@ -94,9 +94,10 @@ group_unpack_members(const nvlist_t *nvl, char ***fieldp, char **bufferp,
size_t *bufsizep)
{
const char *mem;
- char **outstrs, *str;
+ char **outstrs, *str, nvlname[64];
size_t nmem, datasize, strsize;
unsigned int ii;
+ int n;
if (!nvlist_exists_number(nvl, "gr_nmem")) {
datasize = _ALIGNBYTES + sizeof(char *);
@@ -113,7 +114,9 @@ group_unpack_members(const nvlist_t *nvl, char ***fieldp, char **bufferp,
nmem = (size_t)nvlist_get_number(nvl, "gr_nmem");
datasize = _ALIGNBYTES + sizeof(char *) * (nmem + 1);
for (ii = 0; ii < nmem; ii++) {
- mem = dnvlist_getf_string(nvl, NULL, "gr_mem[%u]", ii);
+ n = snprintf(nvlname, sizeof(nvlname), "gr_mem[%u]", ii);
+ assert(n > 0 && n < (int)sizeof(nvlname));
+ mem = dnvlist_get_string(nvl, nvlname, NULL);
if (mem == NULL)
return (EINVAL);
datasize += strlen(mem) + 1;
@@ -125,7 +128,9 @@ group_unpack_members(const nvlist_t *nvl, char ***fieldp, char **bufferp,
outstrs = (char **)_ALIGN(*bufferp);
str = (char *)outstrs + sizeof(char *) * (nmem + 1);
for (ii = 0; ii < nmem; ii++) {
- mem = nvlist_getf_string(nvl, "gr_mem[%u]", ii);
+ n = snprintf(nvlname, sizeof(nvlname), "gr_mem[%u]", ii);
+ assert(n > 0 && n < (int)sizeof(nvlname));
+ mem = nvlist_get_string(nvl, nvlname);
strsize = strlen(mem) + 1;
memcpy(str, mem, strsize);
outstrs[ii] = str;
@@ -190,7 +195,7 @@ cap_getgrcommon_r(cap_channel_t *chan, const char *cmd, const char *name,
} else {
abort();
}
- nvl = cap_xfer_nvlist(chan, nvl);
+ nvl = cap_xfer_nvlist(chan, nvl, 0);
if (nvl == NULL) {
assert(errno != 0);
*result = NULL;
@@ -314,7 +319,7 @@ cap_setgroupent(cap_channel_t *chan, int stayopen)
nvl = nvlist_create(0);
nvlist_add_string(nvl, "cmd", "setgroupent");
nvlist_add_bool(nvl, "stayopen", stayopen != 0);
- nvl = cap_xfer_nvlist(chan, nvl);
+ nvl = cap_xfer_nvlist(chan, nvl, 0);
if (nvl == NULL)
return (0);
if (nvlist_get_number(nvl, "error") != 0) {
@@ -334,7 +339,7 @@ cap_setgrent(cap_channel_t *chan)
nvl = nvlist_create(0);
nvlist_add_string(nvl, "cmd", "setgrent");
- nvl = cap_xfer_nvlist(chan, nvl);
+ nvl = cap_xfer_nvlist(chan, nvl, 0);
if (nvl == NULL)
return (0);
if (nvlist_get_number(nvl, "error") != 0) {
@@ -355,7 +360,7 @@ cap_endgrent(cap_channel_t *chan)
nvl = nvlist_create(0);
nvlist_add_string(nvl, "cmd", "endgrent");
/* Ignore any errors, we have no way to report them. */
- nvlist_destroy(cap_xfer_nvlist(chan, nvl));
+ nvlist_destroy(cap_xfer_nvlist(chan, nvl, 0));
}
int
@@ -407,6 +412,8 @@ cap_grp_limit_groups(cap_channel_t *chan, const char * const *names,
{
nvlist_t *limits, *groups;
unsigned int i;
+ char nvlname[64];
+ int n;
if (cap_limit_get(chan, &limits) < 0)
return (-1);
@@ -417,10 +424,16 @@ cap_grp_limit_groups(cap_channel_t *chan, const char * const *names,
nvlist_free_nvlist(limits, "groups");
}
groups = nvlist_create(0);
- for (i = 0; i < ngids; i++)
- nvlist_addf_number(groups, (uint64_t)gids[i], "gid%u", i);
- for (i = 0; i < nnames; i++)
- nvlist_addf_string(groups, names[i], "name%u", i);
+ for (i = 0; i < ngids; i++) {
+ n = snprintf(nvlname, sizeof(nvlname), "gid%u", i);
+ assert(n > 0 && n < (int)sizeof(nvlname));
+ nvlist_add_number(groups, nvlname, (uint64_t)gids[i]);
+ }
+ for (i = 0; i < nnames; i++) {
+ n = snprintf(nvlname, sizeof(nvlname), "gid%u", i);
+ assert(n > 0 && n < (int)sizeof(nvlname));
+ nvlist_add_string(groups, nvlname, names[i]);
+ }
nvlist_move_nvlist(limits, "groups", groups);
return (cap_limit_set(chan, limits));
}
diff --git a/lib/libcapsicum/libcapsicum_pwd.c b/lib/libcapsicum/libcapsicum_pwd.c
index 792fb66..32eeeb0 100644
--- a/lib/libcapsicum/libcapsicum_pwd.c
+++ b/lib/libcapsicum/libcapsicum_pwd.c
@@ -154,7 +154,7 @@ cap_getpwcommon_r(cap_channel_t *chan, const char *cmd, const char *login,
} else {
abort();
}
- nvl = cap_xfer_nvlist(chan, nvl);
+ nvl = cap_xfer_nvlist(chan, nvl, 0);
if (nvl == NULL) {
assert(errno != 0);
*result = NULL;
@@ -278,7 +278,7 @@ cap_setpassent(cap_channel_t *chan, int stayopen)
nvl = nvlist_create(0);
nvlist_add_string(nvl, "cmd", "setpassent");
nvlist_add_bool(nvl, "stayopen", stayopen != 0);
- nvl = cap_xfer_nvlist(chan, nvl);
+ nvl = cap_xfer_nvlist(chan, nvl, 0);
if (nvl == NULL)
return (0);
if (nvlist_get_number(nvl, "error") != 0) {
@@ -299,7 +299,7 @@ cap_set_end_pwent(cap_channel_t *chan, const char *cmd)
nvl = nvlist_create(0);
nvlist_add_string(nvl, "cmd", cmd);
/* Ignore any errors, we have no way to report them. */
- nvlist_destroy(cap_xfer_nvlist(chan, nvl));
+ nvlist_destroy(cap_xfer_nvlist(chan, nvl, 0));
}
void
@@ -364,7 +364,9 @@ cap_pwd_limit_users(cap_channel_t *chan, const char * const *names,
size_t nnames, uid_t *uids, size_t nuids)
{
nvlist_t *limits, *users;
+ char nvlname[64];
unsigned int i;
+ int n;
if (cap_limit_get(chan, &limits) < 0)
return (-1);
@@ -375,10 +377,16 @@ cap_pwd_limit_users(cap_channel_t *chan, const char * const *names,
nvlist_free_nvlist(limits, "users");
}
users = nvlist_create(0);
- for (i = 0; i < nuids; i++)
- nvlist_addf_number(users, (uint64_t)uids[i], "uid%u", i);
- for (i = 0; i < nnames; i++)
- nvlist_addf_string(users, names[i], "name%u", i);
+ for (i = 0; i < nuids; i++) {
+ n = snprintf(nvlname, sizeof(nvlname), "uid%u", i);
+ assert(n > 0 && n < (int)sizeof(nvlname));
+ nvlist_add_number(users, nvlname, (uint64_t)uids[i]);
+ }
+ for (i = 0; i < nnames; i++) {
+ n = snprintf(nvlname, sizeof(nvlname), "name%u", i);
+ assert(n > 0 && n < (int)sizeof(nvlname));
+ nvlist_add_string(users, nvlname, names[i]);
+ }
nvlist_move_nvlist(limits, "users", users);
return (cap_limit_set(chan, limits));
}
diff --git a/lib/libcapsicum/libcapsicum_random.c b/lib/libcapsicum/libcapsicum_random.c
index eed97e2..2c3eb36 100644
--- a/lib/libcapsicum/libcapsicum_random.c
+++ b/lib/libcapsicum/libcapsicum_random.c
@@ -57,7 +57,7 @@ cap_random_buf(cap_channel_t *chan, void *buf, size_t nbytes)
nvlist_add_string(nvl, "cmd", "generate");
nvlist_add_number(nvl, "size",
(uint64_t)(left > MAXSIZE ? MAXSIZE : left));
- nvl = cap_xfer_nvlist(chan, nvl);
+ nvl = cap_xfer_nvlist(chan, nvl, 0);
if (nvl == NULL)
return (-1);
if (nvlist_get_number(nvl, "error") != 0) {
diff --git a/lib/libcapsicum/libcapsicum_service.c b/lib/libcapsicum/libcapsicum_service.c
index 4127668..edfde8c 100644
--- a/lib/libcapsicum/libcapsicum_service.c
+++ b/lib/libcapsicum/libcapsicum_service.c
@@ -56,7 +56,7 @@ cap_service_open(const cap_channel_t *chan, const char *name)
nvlist_add_string(nvl, "service", name);
if (fd_is_valid(STDERR_FILENO))
nvlist_add_descriptor(nvl, "stderrfd", STDERR_FILENO);
- nvl = cap_xfer_nvlist(chan, nvl);
+ nvl = cap_xfer_nvlist(chan, nvl, 0);
if (nvl == NULL)
return (NULL);
error = (int)nvlist_get_number(nvl, "error");
diff --git a/lib/libcapsicum/libcapsicum_sysctl.c b/lib/libcapsicum/libcapsicum_sysctl.c
index 6ea951b..fc69113 100644
--- a/lib/libcapsicum/libcapsicum_sysctl.c
+++ b/lib/libcapsicum/libcapsicum_sysctl.c
@@ -63,7 +63,7 @@ cap_sysctlbyname(cap_channel_t *chan, const char *name, void *oldp,
nvlist_add_number(nvl, "oldlen", (uint64_t)*oldlenp);
if (newp != NULL)
nvlist_add_binary(nvl, "newp", newp, newlen);
- nvl = cap_xfer_nvlist(chan, nvl);
+ nvl = cap_xfer_nvlist(chan, nvl, 0);
if (nvl == NULL)
return (-1);
if (nvlist_get_number(nvl, "error") != 0) {
diff --git a/lib/libcasper/Makefile b/lib/libcasper/Makefile
index ddcfba5..e57accd 100644
--- a/lib/libcasper/Makefile
+++ b/lib/libcasper/Makefile
@@ -8,8 +8,7 @@ SHLIBDIR?= /lib
SRCS= libcasper.c
INCS= libcasper.h
-DPADD= ${LIBCAPSICUM} ${LIBNV} ${LIBPJDLOG}
-LDADD= -lcapsicum -lnv -lpjdlog
+LIBADD= capsicum nv pjdlog
CFLAGS+=-I${.CURDIR}
CFLAGS+=-I${.CURDIR}/../libpjdlog
diff --git a/lib/libcasper/libcasper.c b/lib/libcasper/libcasper.c
index 7545baa..cb95346 100644
--- a/lib/libcasper/libcasper.c
+++ b/lib/libcasper/libcasper.c
@@ -279,7 +279,7 @@ casper_message(const cap_channel_t *capcas, struct service *service)
const char *cmd;
nvlist_t *nvl;
- nvl = cap_recv_nvlist(capcas);
+ nvl = cap_recv_nvlist(capcas, 0);
if (nvl == NULL)
pjdlog_exit(1, "Unable to receive message from Casper");
cmd = nvlist_get_string(nvl, "cmd");
@@ -297,7 +297,7 @@ service_message(struct service *service, struct service_connection *sconn)
const char *cmd;
int error;
- nvlin = cap_recv_nvlist(service_connection_get_chan(sconn));
+ nvlin = cap_recv_nvlist(service_connection_get_chan(sconn), 0);
if (nvlin == NULL) {
if (errno == ENOTCONN) {
pjdlog_debug(1, "Connection closed by the client.");
diff --git a/lib/libclang_rt/Makefile b/lib/libclang_rt/Makefile
new file mode 100644
index 0000000..b082e38
--- /dev/null
+++ b/lib/libclang_rt/Makefile
@@ -0,0 +1,18 @@
+# $FreeBSD$
+
+.include <src.opts.mk>
+
+.if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64"
+SUBDIR+= asan\
+ asan_cxx\
+ san\
+ ubsan\
+ ubsan_cxx
+.endif
+
+.if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64" || \
+ (${MACHINE_CPUARCH} == "arm" && ${MACHINE_ARCH} != "armeb")
+SUBDIR+= profile
+.endif
+
+.include <bsd.subdir.mk>
diff --git a/lib/libclang_rt/Makefile.inc b/lib/libclang_rt/Makefile.inc
new file mode 100644
index 0000000..be0122e
--- /dev/null
+++ b/lib/libclang_rt/Makefile.inc
@@ -0,0 +1,26 @@
+# $FreeBSD$
+
+.include <src.opts.mk>
+
+CRTARCH=${MACHINE_CPUARCH:C/amd64/x86_64/}
+CRTSRC=${.CURDIR}/../../../contrib/compiler-rt
+
+LIBDIR=/usr/lib/clang/3.6.0/lib/freebsd
+
+NO_PIC=
+MK_PROFILE=no
+
+WARNS?=0
+
+SSP_CFLAGS=
+CFLAGS+=-DNDEBUG
+CFLAGS+=${PICFLAG}
+CFLAGS+=-fno-builtin
+CFLAGS+=-fno-exceptions
+CFLAGS+=-fno-rtti
+CFLAGS+=-fno-stack-protector
+CFLAGS+=-funwind-tables
+CFLAGS+=-fvisibility-inlines-hidden
+CFLAGS+=-fvisibility=hidden
+CFLAGS+=-I${CRTSRC}/lib
+CXXFLAGS+=-std=c++11
diff --git a/lib/libclang_rt/asan/Makefile b/lib/libclang_rt/asan/Makefile
new file mode 100644
index 0000000..e751970
--- /dev/null
+++ b/lib/libclang_rt/asan/Makefile
@@ -0,0 +1,80 @@
+# $FreeBSD$
+
+.include <bsd.init.mk>
+
+LIB= clang_rt.asan-${CRTARCH}
+
+.PATH: ${CRTSRC}/lib/asan\
+ ${CRTSRC}/lib/interception\
+ ${CRTSRC}/lib/sanitizer_common\
+ ${CRTSRC}/lib/lsan
+
+SRCS= asan_preinit.cc\
+ asan_allocator.cc\
+ asan_activation.cc\
+ asan_debugging.cc\
+ asan_fake_stack.cc\
+ asan_flags.cc\
+ asan_globals.cc\
+ asan_interceptors.cc\
+ asan_linux.cc\
+ asan_mac.cc\
+ asan_malloc_linux.cc\
+ asan_malloc_mac.cc\
+ asan_malloc_win.cc\
+ asan_poisoning.cc\
+ asan_posix.cc\
+ asan_report.cc\
+ asan_rtl.cc\
+ asan_stack.cc\
+ asan_stats.cc\
+ asan_suppressions.cc\
+ asan_thread.cc\
+ asan_win.cc\
+ interception_linux.cc\
+ interception_mac.cc\
+ interception_win.cc\
+ interception_type_test.cc\
+ sanitizer_allocator.cc\
+ sanitizer_common.cc\
+ sanitizer_deadlock_detector1.cc\
+ sanitizer_deadlock_detector2.cc\
+ sanitizer_flags.cc\
+ sanitizer_flag_parser.cc\
+ sanitizer_libc.cc\
+ sanitizer_libignore.cc\
+ sanitizer_linux.cc\
+ sanitizer_mac.cc\
+ sanitizer_persistent_allocator.cc\
+ sanitizer_platform_limits_linux.cc\
+ sanitizer_platform_limits_posix.cc\
+ sanitizer_posix.cc\
+ sanitizer_printf.cc\
+ sanitizer_procmaps_common.cc\
+ sanitizer_procmaps_freebsd.cc\
+ sanitizer_procmaps_linux.cc\
+ sanitizer_procmaps_mac.cc\
+ sanitizer_stackdepot.cc\
+ sanitizer_stacktrace.cc\
+ sanitizer_stacktrace_printer.cc\
+ sanitizer_suppressions.cc\
+ sanitizer_symbolizer.cc\
+ sanitizer_symbolizer_libbacktrace.cc\
+ sanitizer_symbolizer_win.cc\
+ sanitizer_tls_get_addr.cc\
+ sanitizer_thread_registry.cc\
+ sanitizer_win.cc\
+ sanitizer_common_libcdep.cc\
+ sanitizer_coverage_libcdep.cc\
+ sanitizer_coverage_mapping_libcdep.cc\
+ sanitizer_linux_libcdep.cc\
+ sanitizer_posix_libcdep.cc\
+ sanitizer_stacktrace_libcdep.cc\
+ sanitizer_stoptheworld_linux_libcdep.cc\
+ sanitizer_symbolizer_libcdep.cc\
+ sanitizer_symbolizer_posix_libcdep.cc\
+ sanitizer_unwind_posix_libcdep.cc\
+ lsan_common.cc\
+ lsan_common_linux.cc
+
+.include <bsd.lib.mk>
diff --git a/lib/libclang_rt/asan_cxx/Makefile b/lib/libclang_rt/asan_cxx/Makefile
new file mode 100644
index 0000000..9763c16
--- /dev/null
+++ b/lib/libclang_rt/asan_cxx/Makefile
@@ -0,0 +1,11 @@
+# $FreeBSD$
+
+.include <bsd.init.mk>
+
+LIB= clang_rt.asan_cxx-${CRTARCH}
+
+.PATH: ${CRTSRC}/lib/asan
+
+SRCS= asan_new_delete.cc
+
+.include <bsd.lib.mk>
diff --git a/lib/libclang_rt/profile/Makefile b/lib/libclang_rt/profile/Makefile
new file mode 100644
index 0000000..058a8f1
--- /dev/null
+++ b/lib/libclang_rt/profile/Makefile
@@ -0,0 +1,17 @@
+# $FreeBSD$
+
+.include <bsd.init.mk>
+
+LIB= clang_rt.profile-${CRTARCH}
+
+.PATH: ${CRTSRC}/lib/profile
+
+SRCS= GCDAProfiling.c\
+ InstrProfiling.c\
+ InstrProfilingBuffer.c\
+ InstrProfilingFile.c\
+ InstrProfilingPlatformDarwin.c\
+ InstrProfilingPlatformOther.c\
+ InstrProfilingRuntime.cc\
+
+.include <bsd.lib.mk>
diff --git a/lib/libclang_rt/san/Makefile b/lib/libclang_rt/san/Makefile
new file mode 100644
index 0000000..da8fe13
--- /dev/null
+++ b/lib/libclang_rt/san/Makefile
@@ -0,0 +1,49 @@
+# $FreeBSD$
+
+.include <bsd.init.mk>
+
+LIB= clang_rt.san-${CRTARCH}
+
+.PATH: ${CRTSRC}/lib/sanitizer_common\
+
+SRCS= sanitizer_allocator.cc\
+ sanitizer_common.cc\
+ sanitizer_deadlock_detector1.cc\
+ sanitizer_deadlock_detector2.cc\
+ sanitizer_flags.cc\
+ sanitizer_flag_parser.cc\
+ sanitizer_libc.cc\
+ sanitizer_libignore.cc\
+ sanitizer_linux.cc\
+ sanitizer_mac.cc\
+ sanitizer_persistent_allocator.cc\
+ sanitizer_platform_limits_linux.cc\
+ sanitizer_platform_limits_posix.cc\
+ sanitizer_posix.cc\
+ sanitizer_printf.cc\
+ sanitizer_procmaps_common.cc\
+ sanitizer_procmaps_freebsd.cc\
+ sanitizer_procmaps_linux.cc\
+ sanitizer_procmaps_mac.cc\
+ sanitizer_stackdepot.cc\
+ sanitizer_stacktrace.cc\
+ sanitizer_stacktrace_printer.cc\
+ sanitizer_suppressions.cc\
+ sanitizer_symbolizer.cc\
+ sanitizer_symbolizer_libbacktrace.cc\
+ sanitizer_symbolizer_win.cc\
+ sanitizer_tls_get_addr.cc\
+ sanitizer_thread_registry.cc\
+ sanitizer_win.cc\
+ sanitizer_common_libcdep.cc\
+ sanitizer_coverage_libcdep.cc\
+ sanitizer_coverage_mapping_libcdep.cc\
+ sanitizer_linux_libcdep.cc\
+ sanitizer_posix_libcdep.cc\
+ sanitizer_stacktrace_libcdep.cc\
+ sanitizer_stoptheworld_linux_libcdep.cc\
+ sanitizer_symbolizer_libcdep.cc\
+ sanitizer_symbolizer_posix_libcdep.cc\
+ sanitizer_unwind_posix_libcdep.cc
+
+.include <bsd.lib.mk>
diff --git a/lib/libclang_rt/ubsan/Makefile b/lib/libclang_rt/ubsan/Makefile
new file mode 100644
index 0000000..34bca81
--- /dev/null
+++ b/lib/libclang_rt/ubsan/Makefile
@@ -0,0 +1,17 @@
+# $FreeBSD$
+
+.include <bsd.init.mk>
+
+LIB= clang_rt.ubsan-${CRTARCH}
+
+.PATH: ${CRTSRC}/lib/ubsan
+
+SRCS= ubsan_diag.cc\
+ ubsan_init.cc\
+ ubsan_flags.cc\
+ ubsan_handlers.cc\
+ ubsan_value.cc
+
+.include <bsd.lib.mk>
+
+
diff --git a/lib/libclang_rt/ubsan_cxx/Makefile b/lib/libclang_rt/ubsan_cxx/Makefile
new file mode 100644
index 0000000..e577a15
--- /dev/null
+++ b/lib/libclang_rt/ubsan_cxx/Makefile
@@ -0,0 +1,14 @@
+# $FreeBSD$
+
+.include <bsd.init.mk>
+
+LIB= clang_rt.ubsan_cxx-${CRTARCH}
+
+CXXFLAGS+=-frtti
+
+.PATH: ${CRTSRC}/lib/ubsan
+
+SRCS= ubsan_handlers_cxx.cc\
+ ubsan_type_hash.cc
+
+.include <bsd.lib.mk>
diff --git a/lib/libcom_err/Makefile b/lib/libcom_err/Makefile
index 78014ad..72260fe 100644
--- a/lib/libcom_err/Makefile
+++ b/lib/libcom_err/Makefile
@@ -10,8 +10,6 @@ CFLAGS+= -I${COM_ERRDIR}
LDFLAGS= -Wl,--no-undefined
VERSION_MAP= ${COM_ERRDIR}/version-script.map
-SUBDIR= doc
-
.include <bsd.lib.mk>
.PATH: ${COM_ERRDIR}
diff --git a/lib/libcom_err/doc/Makefile b/lib/libcom_err/doc/Makefile
deleted file mode 100644
index 4c3c0bb..0000000
--- a/lib/libcom_err/doc/Makefile
+++ /dev/null
@@ -1,7 +0,0 @@
-# $FreeBSD$
-
-INFO= com_err
-INFOSECTION= "Programming & development tools."
-INFOENTRY_com_err= "* libcom_err: (com_err). A Common Error Description Library for UNIX."
-
-.include <bsd.info.mk>
diff --git a/lib/libcom_err/doc/com_err.texinfo b/lib/libcom_err/doc/com_err.texinfo
deleted file mode 100644
index 6c71da8..0000000
--- a/lib/libcom_err/doc/com_err.texinfo
+++ /dev/null
@@ -1,615 +0,0 @@
-\input texinfo @c -*-texinfo-*-
-
-@c $FreeBSD$
-
-@c Note that although this source file is in texinfo format (more
-@c or less), it is not yet suitable for turning into an ``info''
-@c file. Sorry, maybe next time.
-@c
-@c In order to produce hardcopy documentation from a texinfo file,
-@c run ``tex com_err.texinfo'' which will load in texinfo.tex,
-@c provided in this distribution. (texinfo.tex is from the Free
-@c Software Foundation, and is under different copyright restrictions
-@c from the rest of this package.)
-
-@ifinfo
-@barfo
-@end ifinfo
-
-@iftex
-@tolerance 10000
-
-@c Mutate section headers...
-@begingroup
- @catcode#=6
- @gdef@secheading#1#2#3{@secheadingi {#3@enspace #1}}
-@endgroup
-@end iftex
-
-@c %**start of header (This is for running Texinfo on a region.)
-@setfilename com_err
-@settitle A Common Error Description Library for UNIX
-@c %**end of header (This is for running Texinfo on a region.)
-
-@ifinfo
-This file documents the use of the Common Error Description library.
-
-Copyright (C) 1987, 1988 Student Information Processing Board of the
-Massachusetts Institute of Technology.
-
-Permission to use, copy, modify, and distribute this software and its
-documentation for any purpose and without fee is hereby granted, provided
-that the above copyright notice appear in all copies and that both that
-copyright notice and this permission notice appear in supporting
-documentation, and that the names of M.I.T. and the M.I.T. S.I.P.B. not be
-used in advertising or publicity pertaining to distribution of the software
-without specific, written prior permission. M.I.T. and the M.I.T. S.I.P.B.
-make no representations about the suitability of this software for any
-purpose. It is provided "as is" without express or implied warranty.
-
-Note that the file texinfo.tex, provided with this distribution, is from
-the Free Software Foundation, and is under different copyright restrictions
-from the remainder of this package.
-
-@end ifinfo
-
-@ignore
-Permission is granted to process this file through Tex and print the
-results, provided the printed document carries copying permission
-notice identical to this one except for the removal of this paragraph
-(this paragraph not being relevant to the printed manual).
-
-@end ignore
-
-@setchapternewpage odd
-
-@titlepage
-@center @titlefont{A Common Error Description}
-@center @titlefont{Library for UNIX}
-@sp 2
-@center Ken Raeburn
-@center Bill Sommerfeld
-@sp 1
-@center MIT Student Information Processing Board
-@sp 3
-@center last updated 1 January 1989
-@center for version 1.2
-@center ***DRAFT COPY ONLY***
-
-@vskip 2in
-
-@center @b{Abstract}
-
-UNIX has always had a clean and simple system call interface, with a
-standard set of error codes passed between the kernel and user
-programs. Unfortunately, the same cannot be said of many of the
-libraries layered on top of the primitives provided by the kernel.
-Typically, each one has used a different style of indicating errors to
-their callers, leading to a total hodgepodge of error handling, and
-considerable amounts of work for the programmer. This paper describes
-a library and associated utilities which allows a more uniform way for
-libraries to return errors to their callers, and for programs to
-describe errors and exceptional conditions to their users.
-
-@page
-@vskip 0pt plus 1filll
-
-Copyright @copyright{} 1987, 1988 by the Student Information Processing
-Board of the Massachusetts Institute of Technology.
-
-Permission to use, copy, modify, and distribute this software and its
-documentation for any purpose and without fee is hereby granted, provided
-that the above copyright notice appear in all copies and that both that
-copyright notice and this permission notice appear in supporting
-documentation, and that the names of M.I.T. and the M.I.T. S.I.P.B. not be
-used in advertising or publicity pertaining to distribution of the software
-without specific, written prior permission. M.I.T. and the M.I.T. S.I.P.B.
-make no representations about the suitability of this software for any
-purpose. It is provided "as is" without express or implied warranty.
-
-Note that the file texinfo.tex, provided with this distribution, is from
-the Free Software Foundation, and is under different copyright restrictions
-from the remainder of this package.
-
-@end titlepage
-
-@ifinfo
-@node Top, Why com_err?, (dir), (dir)
-@comment node-name, next, previous, up
-@top General Introduction
-
-@menu
-* Why com_err?:: What is all this for?
-* Error codes:: What's an error code, anyway?
-* Error table source file:: How to describe an error table.
-* The error-table compiler:: How to compile the table.
-* Run-time support routines:: How to use from within your program.
-* Coding Conventions:: Stylistic issues.
-* Building and Installation:: How to build and install.
-* Bug Reports:: You have found a bug? Report it.
-* Acknowledgements:: Whom to thank...
-
-@end menu
-
-@end ifinfo
-
-@page
-
-@ifinfo
-@node Why com_err?, Error codes, Top, (dir)
-@comment node-name, next, previous, up
-@end ifinfo
-
-@section Why com_err?
-
-In building application software packages, a programmer often has to
-deal with a number of libraries, each of which can use a different
-error-reporting mechanism. Sometimes one of two values is returned,
-indicating simply SUCCESS or FAILURE, with no description of errors
-encountered. Sometimes it is an index into a table of text strings,
-where the name of the table used is dependent on the library being
-used when the error is generated; since each table starts numbering at
-0 or 1, additional information as to the source of the error code is
-needed to determine which table to look at. Sometimes no text messages are
-supplied at all, and the programmer must supply them at any point at which
-he may wish to report error conditions.
-Often, a global variable is assigned some value describing the error, but
-the programmer has to know in each case whether to look at @code{errno},
-@code{h_errno}, the return value from @code{hes_err()}, or whatever other
-variables or routines are specified.
-And what happens if something
-in the procedure of
-examining or reporting the error changes the same variable?
-
-The package we have developed is an attempt to present a common
-error-handling mechanism to manipulate the most common form of error code
-in a fashion that does not have the problems listed above.
-
-A list of up to 256 text messages is supplied to a translator we have
-written, along with the three- to four-character ``name'' of the error
-table. The library using this error table need only call a routine
-generated from this error-table source to make the table ``known'' to the
-com_err library, and any error code the library generates can be converted
-to the corresponding error message. There is also a default format for
-error codes accidentally returned before making the table known, which is
-of the form @samp{unknown code foo 32}, where @samp{foo} would be the name
-of the table.
-
-@ifinfo
-@node Error codes, Error table source file, Why com_err?, (dir)
-@comment node-name, next, previous, up
-@end ifinfo
-
-@section Error codes
-
-Error codes themselves are 32 bit (signed) integers, of which the high
-order 24 bits are an identifier of which error table the error code is
-from, and the low order 8 bits are a sequential error number within
-the table. An error code may thus be easily decomposed into its component
-parts. Only the lowest 32 bits of an error code are considered significant
-on systems which support wider values.
-
-Error table 0 is defined to match the UNIX system call error table
-(@code{sys_errlist}); this allows @code{errno} values to be used directly
-in the library (assuming that @code{errno} is of a type with the same width
-as @t{long}). Other error table numbers are formed by compacting together
-the first four characters of the error table name. The mapping between
-characters in the name and numeric values in the error code are defined in
-a system-independent fashion, so that two systems that can pass integral
-values between them can reliably pass error codes without loss of meaning;
-this should work even if the character sets used are not the same.
-(However, if this is to be done, error table 0 should be avoided, since the
-local system call error tables may differ.)
-
-Any variable which is to contain an error code should be declared @t{long}.
-The draft proposed American National Standard for C (as of May, 1988)
-requires that @t{long} variables be at least 32 bits; any system which does
-not support 32-bit @t{long} values cannot make use of this package (nor
-much other software that assumes an ANSI-C environment base) without
-significant effort.
-
-@ifinfo
-@node Error table source file, The error-table compiler, Error codes, (dir)
-@comment node-name, next, previous, up
-@end ifinfo
-
-@section Error table source file
-
-The error table source file begins with the declaration of the table name,
-as
-
-@example
-error_table @var{tablename}
-@end example
-
-Individual error codes are
-specified with
-
-@example
-error_code @var{ERROR_NAME}, @var{"text message"}
-@end example
-
-where @samp{ec} can also be used as a short form of @samp{error_code}. To
-indicate the end of the table, use @samp{end}. Thus, a (short) sample
-error table might be:
-
-@example
-
- error_table dsc
-
- error_code DSC_DUP_MTG_NAME,
- "Meeting already exists"
-
- ec DSC_BAD_PATH,
- "A bad meeting pathname was given"
-
- ec DSC_BAD_MODES,
- "Invalid mode for this access control list"
-
- end
-
-@end example
-
-@ifinfo
-@node The error-table compiler, Run-time support routines, Error table source file, (dir)
-@comment node-name, next, previous, up
-@end ifinfo
-
-@section The error-table compiler
-
-The error table compiler is named @code{compile_et}. It takes one
-argument, the pathname of a file (ending in @samp{.et}, e.g.,
-@samp{dsc_err.et}) containing an error table source file. It parses the
-error table, and generates two output files -- a C header file
-(@samp{discuss_err.h}) which contains definitions of the numerical values
-of the error codes defined in the error table, and a C source file which
-should be compiled and linked with the executable. The header file must be
-included in the source of a module which wishes to reference the error
-codes defined; the object module generated from the C code may be linked in
-to a program which wishes to use the printed forms of the error codes.
-
-This translator accepts a @kbd{-language @var{lang}} argument, which
-determines for which language (or language variant) the output should be
-written. At the moment, @var{lang} is currently limited to @kbd{ANSI-C}
-and @kbd{K&R-C}, and some abbreviated forms of each. Eventually, this will
-be extended to include some support for C++. The default is currently
-@kbd{K&R-C}, though the generated sources will have ANSI-C code
-conditionalized on the symbol @t{__STDC__}.
-
-@ifinfo
-@node Run-time support routines, Coding Conventions, The error-table compiler, (dir)
-@comment node-name, next, previous, up
-@end ifinfo
-
-@section Run-time support routines
-
-Any source file which uses the routines supplied with or produced by the
-com_err package should include the header file @file{<com_err.h>}. It
-contains declarations and definitions which may be needed on some systems.
-(Some functions cannot be referenced properly without the return type
-declarations in this file. Some functions may work properly on most
-architectures even without the header file, but relying on this is not
-recommended.)
-
-The run-time support routines and variables provided via this package
-include the following:
-
-@example
-void initialize_@var{xxxx}_error_table (void);
-@end example
-
-One of these routines is built by the error compiler for each error table.
-It makes the @var{xxxx} error table ``known'' to the error reporting
-system. By convention, this routine should be called in the initialization
-routine of the @var{xxxx} library. If the library has no initialization
-routine, some combination of routines which form the core of the library
-should ensure that this routine is called. It is not advised to leave it
-the caller to make this call.
-
-There is no harm in calling this routine more than once.
-
-@example
-#define ERROR_TABLE_BASE_@var{xxxx} @var{nnnnn}L
-@end example
-
-This symbol contains the value of the first error code entry in the
-specified table.
-This rarely needs be used by the
-programmer.
-
-@example
-const char *error_message (long code);
-@end example
-
-This routine returns the character string error message associated
-with @code{code}; if this is associated with an unknown error table, or
-if the code is associated with a known error table but the code is not
-in the table, a string of the form @samp{Unknown code @var{xxxx nn}} is
-returned, where @var{xxxx} is the error table name produced by
-reversing the compaction performed on the error table number implied
-by that error code, and @var{nn} is the offset from that base value.
-
-Although this routine is available for use when needed, its use should be
-left to circumstances which render @code{com_err} (below) unusable.
-
-@example
-void com_err (const char *whoami, /* module reporting error */
- long code, /* error code */
- const char *format, /* format for additional detail */
- ...); /* (extra parameters) */
-@end example
-
-This routine provides an alternate way to print error messages to
-standard error; it allows the error message to be passed in as a
-parameter, rather than in an external variable. @emph{Provide grammatical
-context for ``message.''}
-
-If @var{format} is @code{(char *)NULL}, the formatted message will not be
-printed. @var{format} may not be omitted.
-
-@example
-#include <stdarg.h>
-
-void com_err_va (const char *whoami,
- long code,
- const char *format,
- va_list args);
-@end example
-
-This routine provides an interface, equivalent to @code{com_err} above,
-which may be used by higher-level variadic functions (functions which
-accept variable numbers of arguments).
-
-@example
-#include <stdarg.h>
-
-void (*set_com_err_hook (void (*proc) ())) ();
-
-void (*@var{proc}) (const char *whoami, long code, va_list args);
-
-void reset_com_err_hook ();
-@end example
-
-These two routines allow a routine to be dynamically substituted for
-@samp{com_err}. After @samp{set_com_err_hook} has been called,
-calls to @samp{com_err} will turn into calls to the new hook routine.
-@samp{reset_com_err_hook} turns off this hook. This may intended to
-be used in daemons (to use a routine which calls @var{syslog(3)}), or
-in a window system application (which could pop up a dialogue box).
-
-If a program is to be used in an environment in which simply printing
-messages to the @code{stderr} stream would be inappropriate (such as in a
-daemon program which runs without a terminal attached),
-@code{set_com_err_hook} may be used to redirect output from @code{com_err}.
-The following is an example of an error handler which uses @var{syslog(3)}
-as supplied in BSD 4.3:
-
-@example
-#include <stdio.h>
-#include <stdarg.h>
-#include <syslog.h>
-
-/* extern openlog (const char * name, int logopt, int facility); */
-/* extern syslog (int priority, char * message, ...); */
-
-void hook (const char * whoami, long code,
- const char * format, va_list args)
-@{
- char buffer[BUFSIZ];
- static int initialized = 0;
- if (!initialized) @{
- openlog (whoami,
- LOG_NOWAIT|LOG_CONS|LOG_PID|LOG_NDELAY,
- LOG_DAEMON);
- initialized = 1;
- @}
- vsprintf (buffer, format, args);
- syslog (LOG_ERR, "%s %s", error_message (code), buffer);
-@}
-@end example
-
-After making the call
-@code{set_com_err_hook (hook);},
-any calls to @code{com_err} will result in messages being sent to the
-@var{syslogd} daemon for logging.
-The name of the program, @samp{whoami}, is supplied to the
-@samp{openlog()} call, and the message is formatted into a buffer and
-passed to @code{syslog}.
-
-Note that since the extra arguments to @code{com_err} are passed by
-reference via the @code{va_list} value @code{args}, the hook routine may
-place any form of interpretation on them, including ignoring them. For
-consistency, @code{printf}-style interpretation is suggested, via
-@code{vsprintf} (or @code{_doprnt} on BSD systems without full support for
-the ANSI C library).
-
-@ifinfo
-@node Coding Conventions, Building and Installation, Run-time support routines, (dir)
-@comment node-name, next, previous, up
-@end ifinfo
-
-@section Coding Conventions
-
-The following conventions are just some general stylistic conventions
-to follow when writing robust libraries and programs. Conventions
-similar to this are generally followed inside the UNIX kernel and most
-routines in the Multics operating system. In general, a routine
-either succeeds (returning a zero error code, and doing some side
-effects in the process), or it fails, doing minimal side effects; in
-any event, any invariant which the library assumes must be maintained.
-
-In general, it is not in the domain of non user-interface library
-routines to write error messages to the user's terminal, or halt the
-process. Such forms of ``error handling'' should be reserved for
-failures of internal invariants and consistancy checks only, as it
-provides the user of the library no way to clean up for himself in the
-event of total failure.
-
-Library routines which can fail should be set up to return an error
-code. This should usually be done as the return value of the
-function; if this is not acceptable, the routine should return a
-``null'' value, and put the error code into a parameter passed by
-reference.
-
-Routines which use the first style of interface can be used from
-user-interface levels of a program as follows:
-
-@example
-@{
- if ((code = initialize_world(getuid(), random())) != 0) @{
- com_err("demo", code,
- "when trying to initialize world");
- exit(1);
- @}
- if ((database = open_database("my_secrets", &code))==NULL) @{
- com_err("demo", code,
- "while opening my_secrets");
- exit(1);
- @}
-@}
-@end example
-
-A caller which fails to check the return status is in error. It is
-possible to look for code which ignores error returns by using lint;
-look for error messages of the form ``foobar returns value which is
-sometimes ignored'' or ``foobar returns value which is always
-ignored.''
-
-Since libraries may be built out of other libraries, it is often necessary
-for the success of one routine to depend on another. When a lower level
-routine returns an error code, the middle level routine has a few possible
-options. It can simply return the error code to its caller after doing
-some form of cleanup, it can substitute one of its own, or it can take
-corrective action of its own and continue normally. For instance, a
-library routine which makes a ``connect'' system call to make a network
-connection may reflect the system error code @code{ECONNREFUSED}
-(Connection refused) to its caller, or it may return a ``server not
-available, try again later,'' or it may try a different server.
-
-Cleanup which is typically necessary may include, but not be limited
-to, freeing allocated memory which will not be needed any more,
-unlocking concurrancy locks, dropping reference counts, closing file
-descriptors, or otherwise undoing anything which the procedure did up
-to this point. When there are a lot of things which can go wrong, it
-is generally good to write one block of error-handling code which is
-branched to, using a goto, in the event of failure. A common source
-of errors in UNIX programs is failing to close file descriptors on
-error returns; this leaves a number of ``zombied'' file descriptors
-open, which eventually causes the process to run out of file
-descriptors and fall over.
-
-@example
-@{
- FILE *f1=NULL, *f2=NULL, *f3=NULL;
- int status = 0;
-
- if ( (f1 = fopen(FILE1, "r")) == NULL) @{
- status = errno;
- goto error;
- @}
-
- /*
- * Crunch for a while
- */
-
- if ( (f2 = fopen(FILE2, "w")) == NULL) @{
- status = errno;
- goto error;
- @}
-
- if ( (f3 = fopen(FILE3, "a+")) == NULL) @{
- status = errno;
- goto error;
- @}
-
- /*
- * Do more processing.
- */
- fclose(f1);
- fclose(f2);
- fclose(f3);
- return 0;
-
-error:
- if (f1) fclose(f1);
- if (f2) fclose(f2);
- if (f3) fclose(f3);
- return status;
-@}
-@end example
-
-@ifinfo
-@node Building and Installation, Bug Reports, Coding Conventions, (dir)
-@comment node-name, next, previous, up
-@end ifinfo
-
-@section Building and Installation
-
-The distribution of this package will probably be done as a compressed
-``tar''-format file available via anonymous FTP from SIPB.MIT.EDU.
-Retrieve @samp{pub/com_err.tar.Z} and extract the contents. A subdirectory
-@t{profiled} should be created to hold objects compiled for profiling.
-Running ``make all'' should then be sufficient to build the library and
-error-table compiler. The files @samp{libcom_err.a},
-@samp{libcom_err_p.a}, @samp{com_err.h}, and @samp{compile_et} should be
-installed for use; @samp{com_err.3} and @samp{compile_et.1} can also be
-installed as manual pages.
-
-Potential problems:
-
-@itemize @bullet
-
-@item Use of @code{strcasecmp}, a routine provided in BSD for
-case-insensitive string comparisons. If an equivalent routine is
-available, you can modify @code{CFLAGS} in the makefile to define
-@code{strcasecmp} to the name of that routine.
-
-@item Compilers that defined @code{__STDC__} without providing the header
-file @code{<stdarg.h>}. One such example is Metaware's High ``C''
-compiler, as provided at Project Athena on the IBM RT/PC workstation; if
-@code{__HIGHC__} is defined, it is assumed that @code{<stdarg.h>} is not
-available, and therefore @code{<varargs.h>} must be used. If the symbol
-@code{VARARGS} is defined (e.g., in the makefile), @code{<varargs.h>} will
-be used.
-
-@item If your linker rejects symbols that are simultaneously defined in two
-library files, edit @samp{Makefile} to remove @samp{perror.c} from the
-library. This file contains a version of @var{perror(3)} which calls
-@code{com_err} instead of calling @code{write} directly.
-
-@end itemize
-
-As I do not have access to non-BSD systems, there are probably
-bugs present that may interfere with building or using this package on
-other systems. If they are reported to me, they can probably be fixed for
-the next version.
-
-@ifinfo
-@node Bug Reports, Acknowledgements, Building and Installation, (dir)
-@comment node-name, next, previous, up
-@end ifinfo
-
-@section Bug Reports
-
-Please send any comments or bug reports to the principal author: Ken
-Raeburn, @t{Raeburn@@Athena.MIT.EDU}.
-
-@ifinfo
-@node Acknowledgements, , Bug Reports, (dir)
-@comment node-name, next, previous, up
-@end ifinfo
-
-@section Acknowledgements
-
-I would like to thank: Bill Sommerfeld, for his help with some of this
-documentation, and catching some of the bugs the first time around;
-Honeywell Information Systems, for not killing off the @emph{Multics}
-operating system before I had an opportunity to use it; Honeywell's
-customers, who persuaded them not to do so, for a while; Ted Anderson of
-CMU, for catching some problems before version 1.2 left the nest; Stan
-Zanarotti and several others of MIT's Student Information Processing Board,
-for getting us started with ``discuss,'' for which this package was
-originally written; and everyone I've talked into --- I mean, asked to read
-this document and the ``man'' pages.
-
-@bye
diff --git a/lib/libcompat/4.3/rexec.c b/lib/libcompat/4.3/rexec.c
index 4e01eb6..92357aa 100644
--- a/lib/libcompat/4.3/rexec.c
+++ b/lib/libcompat/4.3/rexec.c
@@ -332,10 +332,10 @@ retry:
perror(hp->h_name);
return (-1);
}
- if (fd2p == 0) {
- (void) write(s, "", 1);
- port = 0;
- } else {
+ port = 0;
+ if (fd2p == 0)
+ (void) write(s, "", 1);
+ else {
char num[8];
int s2, sin2len;
diff --git a/lib/libcompiler_rt/Makefile b/lib/libcompiler_rt/Makefile
index c31eced..5e21883 100644
--- a/lib/libcompiler_rt/Makefile
+++ b/lib/libcompiler_rt/Makefile
@@ -7,6 +7,7 @@ NO_PIC=
WARNS?= 2
CFLAGS+=${PICFLAG} -fvisibility=hidden -DVISIBILITY_HIDDEN
+CFLAGS+=-I${.CURDIR}/../../contrib/libcxxrt
.if ${MACHINE_CPUARCH} == "amd64"
CRTARCH=x86_64
@@ -14,7 +15,7 @@ CRTARCH=x86_64
CRTARCH=${MACHINE_CPUARCH}
.endif
-CRTSRC=${.CURDIR}/../../contrib/compiler-rt/lib
+CRTSRC=${.CURDIR}/../../contrib/compiler-rt/lib/builtins
.PATH: ${CRTSRC}/${CRTARCH} ${CRTSRC}
@@ -24,6 +25,7 @@ SRCF= absvdi2 \
addvdi3 \
addvsi3 \
addvti3 \
+ apple_versioning \
ashldi3 \
ashlti3 \
ashrdi3 \
@@ -34,8 +36,6 @@ SRCF= absvdi2 \
clzti2 \
cmpdi2 \
cmpti2 \
- comparedf2 \
- comparesf2 \
ctzdi2 \
ctzsi2 \
ctzti2 \
@@ -67,18 +67,22 @@ SRCF= absvdi2 \
fixxfti \
floatdidf \
floatdisf \
+ floatditf \
floatdixf \
+ floatsitf \
floattidf \
floattisf \
floattixf \
floatundidf \
floatundisf \
+ floatunditf \
floatundixf \
floatunsidf \
floatunsisf \
floatuntidf \
floatuntisf \
floatuntixf \
+ gcc_personality_v0 \
int_util \
lshrdi3 \
lshrti3 \
@@ -94,6 +98,7 @@ SRCF= absvdi2 \
mulvdi3 \
mulvsi3 \
mulvti3 \
+ multc3 \
mulxc3 \
negdf2 \
negdi2 \
@@ -126,6 +131,26 @@ SRCF= absvdi2 \
umoddi3 \
umodti3
+# 128-bit quad precision long double support, only used on arm64
+.if ${MACHINE_CPUARCH} == "aarch64"
+SRCF+= addtf3 \
+ comparetf2 \
+ divtf3 \
+ extenddftf2 \
+ extendsftf2 \
+ fixtfdi \
+ fixtfsi \
+ fixtfti \
+ fixunstfdi \
+ fixunstfsi \
+ fixunstfti \
+ floatunsitf \
+ multf3 \
+ subtf3 \
+ trunctfdf2 \
+ trunctfsf2
+.endif
+
# These are already shipped by libc.a on arm and mips
.if ${MACHINE_CPUARCH} != "arm" && ${MACHINE_CPUARCH} != "mips"
SRCF+= adddf3 \
@@ -144,6 +169,11 @@ SRCF+= adddf3 \
truncdfsf2
.endif
+.if ${MACHINE_CPUARCH} != "arm"
+SRCF+= comparedf2 \
+ comparesf2
+.endif
+
.if ${MACHINE_CPUARCH} != "mips"
SRCF+= divsi3 \
modsi3 \
@@ -174,14 +204,22 @@ SRCS+= ${file}.c
.endfor
.if ${MACHINE_CPUARCH} == "arm"
-SRCS+= aeabi_idivmod.S \
+SRCS+= aeabi_div0.c \
+ aeabi_idivmod.S \
aeabi_ldivmod.S \
aeabi_memcmp.S \
aeabi_memcpy.S \
aeabi_memmove.S \
aeabi_memset.S \
aeabi_uidivmod.S \
- aeabi_uldivmod.S
+ aeabi_uldivmod.S \
+ bswapdi2.S \
+ bswapsi2.S \
+ switch16.S \
+ switch32.S \
+ switch8.S \
+ switchu8.S \
+ sync_synchronize.S
.endif
.if ${MK_INSTALLLIB} != "no"
diff --git a/lib/libcrypt/tests/Makefile b/lib/libcrypt/tests/Makefile
index 20993e2..6f98b53a 100644
--- a/lib/libcrypt/tests/Makefile
+++ b/lib/libcrypt/tests/Makefile
@@ -7,7 +7,6 @@ TESTSDIR= ${TESTSBASE}/lib/libcrypt
ATF_TESTS_C= crypt_tests
CFLAGS+= -I${.CURDIR:H}
-DPADD+= ${LIBCRYPT}
-LDADD+= -lcrypt
+LIBADD= crypt
.include <bsd.test.mk>
diff --git a/lib/libcuse/Makefile b/lib/libcuse/Makefile
index 2d1ded5..a232fa2 100644
--- a/lib/libcuse/Makefile
+++ b/lib/libcuse/Makefile
@@ -30,14 +30,12 @@ SHLIB_MINOR= 0
SRCS= cuse_lib.c
INCS= cuse.h
MAN= cuse.3
-PTHREAD_LIBS?= -lpthread
CFLAGS+= -D_GNU_SOURCE
.if defined(HAVE_DEBUG)
CFLAGS+= -g
CFLAGS+= -DHAVE_DEBUG
.endif
-DPADD+= ${LIBPTHREAD}
-LDADD+= ${PTHREAD_LIBS}
+LIBADD= pthread
MLINKS=
MLINKS+= cuse.3 cuse_alloc_unit_number.3
diff --git a/lib/libcxxrt/Makefile.depend.host b/lib/libcxxrt/Makefile.depend.host
new file mode 100644
index 0000000..8dc8a74
--- /dev/null
+++ b/lib/libcxxrt/Makefile.depend.host
@@ -0,0 +1,13 @@
+# Autogenerated - do NOT edit!
+
+DEP_RELDIR := ${_PARSEDIR:S,${SRCTOP}/,,}
+
+DIRDEPS = \
+ usr.bin/clang/clang \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif
diff --git a/lib/libdevctl/Makefile b/lib/libdevctl/Makefile
new file mode 100644
index 0000000..74687ec
--- /dev/null
+++ b/lib/libdevctl/Makefile
@@ -0,0 +1,8 @@
+# $FreeBSD$
+
+LIB= devctl
+SRCS= devctl.c
+INCS= devctl.h
+MAN= devctl.3
+
+.include <bsd.lib.mk>
diff --git a/lib/libdevctl/devctl.3 b/lib/libdevctl/devctl.3
new file mode 100644
index 0000000..be869f9
--- /dev/null
+++ b/lib/libdevctl/devctl.3
@@ -0,0 +1,295 @@
+.\"
+.\" Copyright (c) 2014 John Baldwin <jhb@FreeBSD.org>
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd December 26, 2014
+.Dt DEVCTL 3
+.Os
+.Sh NAME
+.Nm devctl ,
+.Nm devctl_attach ,
+.Nm devctl_detach ,
+.Nm devctl_disable ,
+.Nm devctl_enable ,
+.Nm devctl_resume ,
+.Nm devctl_suspend
+.Nd device control library
+.Sh LIBRARY
+.Lb libdevctl
+.Sh SYNOPSIS
+.In devctl.h
+.Ft int
+.Fn devctl_attach "const char *device"
+.Ft int
+.Fn devctl_detach "const char *device" "bool force"
+.Ft int
+.Fn devctl_disable "const char *device" "bool force_detach"
+.Ft int
+.Fn devctl_enable "const char *device"
+.Ft int
+.Fn devctl_resume "const char *device"
+.Ft int
+.Fn devctl_suspend "const char *device"
+.Ft int
+.Fn devctl_set_driver "const char *device" "const char *driver" "bool force"
+.Sh DESCRIPTION
+The
+.Nm
+library adjusts the state of devices in the kernel's internal device
+hierarchy.
+Each control operation accepts a
+.Fa device
+argument that identifies the device to adjust.
+The
+.Fa device
+may be specified as either the name of an existing device or as a
+bus-specific address.
+The following bus-specific address formats are currently supported:
+.Bl -tag -offset indent
+.It Sy pci Ns Fa domain Ns : Ns Fa bus Ns : Ns Fa slot Ns : Ns Fa function
+A PCI device with the specified
+.Fa domain ,
+.Fa bus ,
+.Fa slot ,
+and
+.Fa function .
+.It Sy pci Ns Fa bus Ns : Ns Fa slot Ns : Ns Fa function
+A PCI device in domain zero with the specified
+.Fa bus ,
+.Fa slot ,
+and
+.Fa function .
+.It Fa handle
+A device with an ACPI handle of
+.Fa handle .
+The handle must be specified as an absolute path and must begin with a
+.Dq \e .
+.El
+.Pp
+The
+.Fn devctl_attach
+function probes a device and attaches a suitable device driver if one is
+found.
+.Pp
+The
+.Fn devctl_detach
+function detaches a device from its current device driver.
+The device is left detached until either a new driver for its parent
+bus is loaded or the device is explicitly probed via
+.Fn devctl_attach .
+If
+.Fa force
+is true,
+the current device driver will be detached even if the device is busy.
+.Pp
+The
+.Fn devctl_disable
+function disables a device.
+If the device is currently attached to a device driver,
+the device driver will be detached from the device,
+but the device will retain its current name.
+If
+.Fa force_detach
+is true,
+the current device driver will be detached even if the device is busy.
+The device will remain disabled and detached until it is explicitly enabled
+via
+.Fn devctl_enable .
+.Pp
+The
+.Fn devctl_enable
+function re-enables a disabled device.
+The device will probe and attach if a suitable device driver is found.
+.Pp
+The
+.Fn devctl_suspend
+function suspends a device.
+This may include placing the device in a reduced power state,
+but any device driver currently attached to the device will remain attached.
+.Pp
+The
+.Fn devctl_resume
+function resumes a suspended device to a fully working state.
+.Pp
+The
+.Fn devctl_set_driver
+function attaches a device driver named
+.Fa driver
+to a device.
+If the device is already attached and
+.Fa force
+is false,
+the request will fail.
+If the device is already attached and
+.Fa force
+is true,
+the device will be detached from its current device driver before it is
+attached to the new device driver.
+.Sh RETURN VALUES
+.Rv -std devctl_attach devctl_detach devctl_disable devctl_enable \
+devctl_suspend devctl_resume devctl_set_driver
+.Sh ERRORS
+In addition to specific errors noted below,
+all of the
+.Nm
+functions may fail for any of the errors described in
+.Xr open 2
+as well as:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+The device name is too long.
+.It Bq Er ENOENT
+No existing device matches the specified name or location.
+.It Bq Er EPERM
+The current process is not permitted to adjust the state of
+.Fa device .
+.El
+.Pp
+The
+.Fn devctl_attach
+function may fail if:
+.Bl -tag -width Er
+.It Bq Er EBUSY
+The device is already attached.
+.It Bq Er ENOMEM
+An internal memory allocation request failed.
+.It Bq Er ENXIO
+The device is disabled.
+.It Bq Er ENXIO
+No suitable driver for the device could be found,
+or the driver failed to attach.
+.El
+.Pp
+The
+.Fn devctl_detach
+function may fail if:
+.Bl -tag -width Er
+.It Bq Er EBUSY
+The current device driver for
+.Fa device
+is busy and cannot detach at this time.
+Note that some drivers may return this even if
+.Fa force
+is true.
+.It Bq Er ENXIO
+The device is not attached to a driver.
+.It Bq Er ENXIO
+The current device driver for
+.Fa device
+does not support detaching.
+.El
+.Pp
+The
+.Fn devctl_enable
+function may fail if:
+.Bl -tag -width Er
+.It Bq Er EBUSY
+The device is already enabled.
+.It Bq Er ENOMEM
+An internal memory allocation request failed.
+.It Bq Er ENXIO
+No suitable driver for the device could be found,
+or the driver failed to attach.
+.El
+.Pp
+The
+.Fn devctl_disable
+function may fail if:
+.Bl -tag -width Er
+.It Bq Er EBUSY
+The current device driver for
+.Fa device
+is busy and cannot detach at this time.
+Note that some drivers may return this even if
+.Fa force_detach
+is true.
+.It Bq Er ENXIO
+The device is already disabled.
+.It Bq Er ENXIO
+The current device driver for
+.Fa device
+does not support detaching.
+.El
+.Pp
+The
+.Fn devctl_suspend
+function may fail if:
+.Bl -tag -width Er
+.It Bq Er EBUSY
+The device is already suspended.
+.It Bq Er EINVAL
+The device to be suspended is the root bus device.
+.El
+.Pp
+The
+.Fn devctl_resume
+function may fail if:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+The device is not suspended.
+.It Bq Er EINVAL
+The device to be resumed is the root bus device.
+.El
+.Pp
+The
+.Fn devctl_set_driver
+function may fail if:
+.Bl -tag -width Er
+.It Bq Er EBUSY
+The device is currently attached to a device driver and
+.Fa force
+is false.
+.It Bq Er EBUSY
+The current device driver for
+.Fa device
+is busy and cannot detach at this time.
+.It Bq Er EFAULT
+The
+.Fa driver
+argument points outside the process' allocated address space.
+.It Bq Er ENOENT
+No device driver with the requested name exists.
+.It Bq Er ENOMEM
+An internal memory allocation request failed.
+.It Bq Er ENXIO
+The device is disabled.
+.It Bq Er ENXIO
+The new device driver failed to attach.
+.El
+.Sh SEE ALSO
+.Xr devinfo 3 ,
+.Xr devstat 3 ,
+.Xr devctl 8
+.Sh HISTORY
+The
+.Nm
+library first appeared in
+.Fx 11.0 .
+.Sh BUGS
+If a device is suspended individually via
+.Fn devctl_suspend
+and the entire machine is subsequently suspended,
+the device will be resumed when the machine resumes.
diff --git a/lib/libdevctl/devctl.c b/lib/libdevctl/devctl.c
new file mode 100644
index 0000000..7be431e
--- /dev/null
+++ b/lib/libdevctl/devctl.c
@@ -0,0 +1,124 @@
+/*-
+ * Copyright (c) 2014 John Baldwin <jhb@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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/bus.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <string.h>
+#include "devctl.h"
+
+static int
+devctl_request(u_long cmd, struct devreq *req)
+{
+ static int devctl2_fd = -1;
+
+ if (devctl2_fd == -1) {
+ devctl2_fd = open("/dev/devctl2", O_RDONLY);
+ if (devctl2_fd == -1)
+ return (-1);
+ }
+ return (ioctl(devctl2_fd, cmd, req));
+}
+
+static int
+devctl_simple_request(u_long cmd, const char *name, int flags)
+{
+ struct devreq req;
+
+ memset(&req, 0, sizeof(req));
+ if (strlcpy(req.dr_name, name, sizeof(req.dr_name)) >=
+ sizeof(req.dr_name)) {
+ errno = EINVAL;
+ return (-1);
+ }
+ req.dr_flags = flags;
+ return (devctl_request(cmd, &req));
+}
+
+int
+devctl_attach(const char *device)
+{
+
+ return (devctl_simple_request(DEV_ATTACH, device, 0));
+}
+
+int
+devctl_detach(const char *device, bool force)
+{
+
+ return (devctl_simple_request(DEV_DETACH, device, force ?
+ DEVF_FORCE_DETACH : 0));
+}
+
+int
+devctl_enable(const char *device)
+{
+
+ return (devctl_simple_request(DEV_ENABLE, device, 0));
+}
+
+int
+devctl_disable(const char *device, bool force_detach)
+{
+
+ return (devctl_simple_request(DEV_DISABLE, device, force_detach ?
+ DEVF_FORCE_DETACH : 0));
+}
+
+int
+devctl_suspend(const char *device)
+{
+
+ return (devctl_simple_request(DEV_SUSPEND, device, 0));
+}
+
+int
+devctl_resume(const char *device)
+{
+
+ return (devctl_simple_request(DEV_RESUME, device, 0));
+}
+
+int
+devctl_set_driver(const char *device, const char *driver, bool force)
+{
+ struct devreq req;
+
+ memset(&req, 0, sizeof(req));
+ if (strlcpy(req.dr_name, device, sizeof(req.dr_name)) >=
+ sizeof(req.dr_name)) {
+ errno = EINVAL;
+ return (-1);
+ }
+ req.dr_data = __DECONST(char *, driver);
+ if (force)
+ req.dr_flags |= DEVF_SET_DRIVER_DETACH;
+ return (devctl_request(DEV_SET_DRIVER, &req));
+}
diff --git a/lib/libdevctl/devctl.h b/lib/libdevctl/devctl.h
new file mode 100644
index 0000000..f773b11
--- /dev/null
+++ b/lib/libdevctl/devctl.h
@@ -0,0 +1,42 @@
+/*-
+ * Copyright (c) 2014 John Baldwin <jhb@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$
+ */
+
+#ifndef __DEVCTL_H__
+#define __DEVCTL_H__
+
+#include <stdbool.h>
+
+int devctl_attach(const char *device);
+int devctl_detach(const char *device, bool force);
+int devctl_enable(const char *device);
+int devctl_disable(const char *device, bool force_detach);
+int devctl_suspend(const char *device);
+int devctl_resume(const char *device);
+int devctl_set_driver(const char *device, const char *driver, bool force);
+
+#endif /* !__DEVCTL_H__ */
diff --git a/lib/libdevinfo/devinfo.h b/lib/libdevinfo/devinfo.h
index c8990a6..b0b8cec 100644
--- a/lib/libdevinfo/devinfo.h
+++ b/lib/libdevinfo/devinfo.h
@@ -50,7 +50,7 @@ struct devinfo_dev {
char *dd_location; /* Where bus thinks dev at */
uint32_t dd_devflags; /* API flags */
uint16_t dd_flags; /* internal dev flags */
- devinfo_state_t dd_state; /* attacement state of dev */
+ devinfo_state_t dd_state; /* attachment state of dev */
};
struct devinfo_rman {
diff --git a/lib/libdevstat/Makefile b/lib/libdevstat/Makefile
index aeb07b9..dcda3c2 100644
--- a/lib/libdevstat/Makefile
+++ b/lib/libdevstat/Makefile
@@ -7,8 +7,7 @@ SHLIB_MAJOR= 7
SRCS= devstat.c
INCS= devstat.h
-DPADD= ${LIBKVM}
-LDADD= -lkvm
+LIBADD= kvm
MAN= devstat.3
diff --git a/lib/libdevstat/devstat.c b/lib/libdevstat/devstat.c
index ade8738..d52332b 100644
--- a/lib/libdevstat/devstat.c
+++ b/lib/libdevstat/devstat.c
@@ -1487,22 +1487,9 @@ devstat_compute_statistics(struct devstat *current, struct devstat *previous,
*destld = 0.0;
break;
/*
- * This calculation is somewhat bogus. It simply divides
- * the elapsed time by the total number of transactions
- * completed. While that does give the caller a good
- * picture of the average rate of transaction completion,
- * it doesn't necessarily give the caller a good view of
- * how long transactions took to complete on average.
- * Those two numbers will be different for a device that
- * can handle more than one transaction at a time. e.g.
- * SCSI disks doing tagged queueing.
- *
- * The only way to accurately determine the real average
- * time per transaction would be to compute and store the
- * time on a per-transaction basis. That currently isn't
- * done in the kernel, and would only be desireable if it
- * could be implemented in a somewhat non-intrusive and high
- * performance way.
+ * Some devstat callers update the duration and some don't.
+ * So this will only be accurate if they provide the
+ * duration.
*/
case DSM_MS_PER_TRANSACTION:
if (totaltransfers > 0) {
@@ -1512,11 +1499,6 @@ devstat_compute_statistics(struct devstat *current, struct devstat *previous,
} else
*destld = 0.0;
break;
- /*
- * As above, these next two really only give the average
- * rate of completion for read and write transactions, not
- * the average time the transaction took to complete.
- */
case DSM_MS_PER_TRANSACTION_READ:
if (totaltransfersread > 0) {
*destld = totaldurationread;
diff --git a/lib/libdpv/Makefile b/lib/libdpv/Makefile
index 8096cc9..f2dc481 100644
--- a/lib/libdpv/Makefile
+++ b/lib/libdpv/Makefile
@@ -6,8 +6,7 @@ INCS= dpv.h
MAN= dpv.3
MLINKS= dpv.3 dpv_free.3
-DPADD= ${LIBDIALOG} ${LIBFIGPAR} ${LIBNCURSESW} ${LIBUTIL}
-LDADD= -ldialog -lfigpar -lncursesw -lutil
+LIBADD= dialog figpar util ncursesw
SRCS= dialog_util.c dialogrc.c dprompt.c dpv.c status.c util.c
diff --git a/lib/libdpv/Makefile.depend b/lib/libdpv/Makefile.depend
new file mode 100644
index 0000000..c6e5e45
--- /dev/null
+++ b/lib/libdpv/Makefile.depend
@@ -0,0 +1,25 @@
+# Autogenerated - do NOT edit!
+
+DEP_RELDIR := ${_PARSEDIR:S,${SRCTOP}/,,}
+
+DIRDEPS = \
+ gnu/lib/csu \
+ gnu/lib/libdialog \
+ gnu/lib/libgcc \
+ include \
+ include/xlocale \
+ lib/${CSU_DIR} \
+ lib/libc \
+ lib/libcompiler_rt \
+ lib/libfigpar \
+ lib/libutil \
+ lib/msun \
+ lib/ncurses/ncursesw \
+ usr.bin/xinstall.host \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif
diff --git a/lib/libdpv/dpv.3 b/lib/libdpv/dpv.3
index 8c04ac3..d16e649 100644
--- a/lib/libdpv/dpv.3
+++ b/lib/libdpv/dpv.3
@@ -435,8 +435,8 @@ or desired values.
.El
.Sh SEE ALSO
.Xr dialog 1 ,
-.Xr dialog 3 ,
-.Xr Xdialog 1
+.Xr Xdialog 1 ,
+.Xr dialog 3
.Sh HISTORY
The
.Nm
@@ -502,7 +502,7 @@ This does not effect
.Xr Xdialog 1 ,
which renders the color escape sequences as plain text.
See
-.Do Li
+.Do
embedded "\\Z" sequences
.Dc
in
diff --git a/lib/libdwarf/Makefile b/lib/libdwarf/Makefile
index 9d4df83..590aab3 100644
--- a/lib/libdwarf/Makefile
+++ b/lib/libdwarf/Makefile
@@ -46,6 +46,7 @@ SRCS= \
dwarf_pubtypes.c \
dwarf_ranges.c \
dwarf_reloc.c \
+ dwarf_sections.c \
dwarf_seterror.c \
dwarf_str.c \
dwarf_types.c \
@@ -96,8 +97,7 @@ sys/elf32.h sys/elf64.h sys/elf_common.h: ${.CURDIR}/../../sys/${.TARGET}
mkdir -p ${.OBJDIR}/sys
ln -sf ${.CURDIR}/../../sys/${.TARGET} ${.TARGET}
-LDADD+= -lelf
-DPADD+= ${LIBELF}
+LIBADD+= elf
SHLIB_MAJOR= 4
@@ -131,6 +131,7 @@ MAN= dwarf.3 \
dwarf_add_weakname.3 \
dwarf_attr.3 \
dwarf_attrlist.3 \
+ dwarf_attroffset.3 \
dwarf_attrval_signed.3 \
dwarf_child.3 \
dwarf_dealloc.3 \
@@ -170,6 +171,7 @@ MAN= dwarf.3 \
dwarf_get_cie_info.3 \
dwarf_get_cie_of_fde.3 \
dwarf_get_cu_die_offset.3 \
+ dwarf_get_die_infotypes_flag.3 \
dwarf_get_elf.3 \
dwarf_get_fde_at_pc.3 \
dwarf_get_fde_info_for_all_regs.3 \
@@ -191,6 +193,7 @@ MAN= dwarf.3 \
dwarf_get_relocation_info.3 \
dwarf_get_relocation_info_count.3 \
dwarf_get_section_bytes.3 \
+ dwarf_get_section_max_offsets.3 \
dwarf_get_str.3 \
dwarf_get_types.3 \
dwarf_get_vars.3 \
@@ -208,6 +211,7 @@ MAN= dwarf.3 \
dwarf_new_expr.3 \
dwarf_new_fde.3 \
dwarf_next_cu_header.3 \
+ dwarf_next_types_section.3 \
dwarf_object_init.3 \
dwarf_producer_init.3 \
dwarf_producer_set_isa.3 \
@@ -236,7 +240,9 @@ MLINKS+= \
dwarf_attrval_signed.3 dwarf_attrval_string.3 \
dwarf_attrval_signed.3 dwarf_attrval_unsigned.3 \
dwarf_child.3 dwarf_offdie.3 \
+ dwarf_child.3 dwarf_offdie_b.3 \
dwarf_child.3 dwarf_siblingof.3 \
+ dwarf_child.3 dwarf_siblingof_b.3 \
dwarf_dealloc.3 dwarf_fde_cie_list_dealloc.3 \
dwarf_dealloc.3 dwarf_funcs_dealloc.3 \
dwarf_dealloc.3 dwarf_globals_dealloc.3 \
@@ -250,6 +256,7 @@ MLINKS+= \
dwarf_dieoffset.3 dwarf_die_CU_offset.3 \
dwarf_dieoffset.3 dwarf_die_CU_offset_range.3 \
dwarf_dieoffset.3 dwarf_get_cu_die_offset_given_cu_header_offset.3 \
+ dwarf_dieoffset.3 dwarf_get_cu_die_offset_given_cu_header_offset_b.3 \
dwarf_finish.3 dwarf_object_finish.3 \
dwarf_formref.3 dwarf_global_formref.3 \
dwarf_formudata.3 dwarf_formsdata.3 \
@@ -289,6 +296,7 @@ MLINKS+= \
dwarf_get_pubtypes.3 dwarf_pubtype_name_offsets.3 \
dwarf_get_pubtypes.3 dwarf_pubtypename.3 \
dwarf_get_ranges.3 dwarf_get_ranges_a.3 \
+ dwarf_get_section_max_offsets.3 dwarf_get_section_max_offsets_b.3 \
dwarf_get_types.3 dwarf_type_die_offset.3 \
dwarf_get_types.3 dwarf_type_cu_offset.3 \
dwarf_get_types.3 dwarf_type_name_offsets.3 \
@@ -307,6 +315,7 @@ MLINKS+= \
dwarf_highpc.3 dwarf_bitoffset.3 \
dwarf_highpc.3 dwarf_bitsize.3 \
dwarf_highpc.3 dwarf_bytesize.3 \
+ dwarf_highpc.3 dwarf_highpc_b.3 \
dwarf_highpc.3 dwarf_lowpc.3 \
dwarf_highpc.3 dwarf_srclang.3 \
dwarf_lineno.3 dwarf_lineaddr.3 \
@@ -318,6 +327,9 @@ MLINKS+= \
dwarf_lineno.3 dwarf_line_srcfileno.3 \
dwarf_loclist.3 dwarf_loclist_n.3 \
dwarf_loclist_from_expr.3 dwarf_loclist_from_expr_a.3 \
+ dwarf_loclist_from_expr.3 dwarf_loclist_from_expr_b.3 \
+ dwarf_next_cu_header.3 dwarf_next_cu_header_b.3 \
+ dwarf_next_cu_header.3 dwarf_next_cu_header_c.3 \
dwarf_producer_init.3 dwarf_producer_init_b.3 \
dwarf_seterrarg.3 dwarf_seterrhand.3 \
dwarf_set_frame_cfa_value.3 dwarf_set_frame_rule_initial_value.3 \
diff --git a/lib/libedit/Makefile b/lib/libedit/Makefile
index df86778..8a97ce0 100644
--- a/lib/libedit/Makefile
+++ b/lib/libedit/Makefile
@@ -7,11 +7,10 @@ SHLIB_MAJOR= 7
SHLIBDIR?= /lib
OSRCS= chared.c common.c el.c emacs.c fcns.c filecomplete.c help.c \
- hist.c key.c map.c \
- parse.c prompt.c read.c refresh.c search.c sig.c term.c tty.c vi.c
+ hist.c keymacro.c map.c chartype.c \
+ parse.c prompt.c read.c refresh.c search.c sig.c terminal.c tty.c vi.c
-DPADD= ${LIBNCURSESW}
-LDADD= -lncursesw
+LIBADD= ncursesw
MAN= editline.3 editrc.5
@@ -35,7 +34,10 @@ CLEANFILES+= common.h editline.c emacs.h fcns.c fcns.h help.c help.h vi.h
INCS= histedit.h
-CFLAGS+= -I. -I${.CURDIR} -I${.CURDIR}/edit
+OSRCS+= eln.c
+SRCS+= tokenizern.c historyn.c
+CLEANFILES+= tokenizern.c historyn.c
+CFLAGS+= -I. -I${.CURDIR} -I${.CURDIR}/edit -DWIDECHAR
CFLAGS+= #-DDEBUG_TTY -DDEBUG_KEY -DDEBUG_READ -DDEBUG -DDEBUG_REFRESH
CFLAGS+= #-DDEBUG_PASTE -DDEBUG_EDIT
@@ -66,6 +68,12 @@ help.h: ${ASRC} makelist
editline.c: ${OSRCS}
sh ${.CURDIR}/makelist -e ${.ALLSRC:T} > ${.TARGET}
+tokenizern.c: makelist Makefile
+ sh ${.CURDIR}/makelist -n tokenizer.c > ${.TARGET}
+
+historyn.c: makelist Makefile
+ sh ${.CURDIR}/makelist -n history.c > ${.TARGET}
+
# minimal dependency to make "make depend" optional
editline.o editline.po editline.So editline.ln: \
common.h emacs.h fcns.c fcns.h help.c help.h vi.h
diff --git a/lib/libedit/Makefile.depend b/lib/libedit/Makefile.depend
index 918d492..8a034af 100644
--- a/lib/libedit/Makefile.depend
+++ b/lib/libedit/Makefile.depend
@@ -43,6 +43,9 @@ editline.po: fcns.h
editline.po: help.c
editline.po: help.h
editline.po: vi.h
+historyn.So: historyn.c
+historyn.o: historyn.c
+historyn.po: historyn.c
readline.So: common.h
readline.So: emacs.h
readline.So: fcns.h
@@ -58,4 +61,7 @@ readline.po: emacs.h
readline.po: fcns.h
readline.po: help.h
readline.po: vi.h
+tokenizern.So: tokenizern.c
+tokenizern.o: tokenizern.c
+tokenizern.po: tokenizern.c
.endif
diff --git a/lib/libedit/TEST/rl1.c b/lib/libedit/TEST/rl1.c
new file mode 100644
index 0000000..79050cc
--- /dev/null
+++ b/lib/libedit/TEST/rl1.c
@@ -0,0 +1,53 @@
+/* $NetBSD: rl1.c,v 1.1 2010/09/16 20:08:51 christos Exp $ */
+
+/*-
+ * Copyright (c) 2010 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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>
+#if !defined(lint)
+__RCSID("$NetBSD: rl1.c,v 1.1 2010/09/16 20:08:51 christos Exp $");
+#endif /* not lint */
+__FBSDID("$FreeBSD$");
+
+/*
+ * test.c: A little test program
+ */
+#include <stdio.h>
+#include <readline/readline.h>
+
+int
+main(int argc, char *argv[])
+{
+ char *p;
+ while ((p = readline("hi$")) != NULL) {
+ add_history(p);
+ printf("%d %s\n", history_length, p);
+ }
+ return 0;
+}
diff --git a/lib/libedit/TEST/tc1.c b/lib/libedit/TEST/tc1.c
index a60aa75..1969973 100644
--- a/lib/libedit/TEST/tc1.c
+++ b/lib/libedit/TEST/tc1.c
@@ -1,3 +1,5 @@
+/* $NetBSD: tc1.c,v 1.6 2014/06/18 20:12:15 christos Exp $ */
+
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -30,22 +32,24 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
+#include "config.h"
#ifndef lint
__COPYRIGHT("@(#) Copyright (c) 1992, 1993\n\
The Regents of the University of California. All rights reserved.\n");
#endif /* not lint */
#if !defined(lint) && !defined(SCCSID)
+#if 0
static char sccsid[] = "@(#)test.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: tc1.c,v 1.6 2014/06/18 20:12:15 christos Exp $");
+#endif
#endif /* not lint && not SCCSID */
-__RCSID("$NetBSD: test.c,v 1.3 2009/07/17 12:25:52 christos Exp $");
__FBSDID("$FreeBSD$");
/*
* test.c: A little test program
*/
-#include "sys.h"
#include <stdio.h>
#include <string.h>
#include <signal.h>
@@ -54,6 +58,7 @@ __FBSDID("$FreeBSD$");
#include <stdlib.h>
#include <unistd.h>
#include <dirent.h>
+#include <locale.h>
#include "histedit.h"
@@ -68,7 +73,7 @@ static void sig(int);
static char *
prompt(EditLine *el)
{
- static char a[] = "\1\e[7m\1Edit$\1\e[0m\1 ";
+ static char a[] = "\1\033[7m\1Edit$\1\033[0m\1 ";
static char b[] = "Edit> ";
return (continuation ? b : a);
@@ -88,6 +93,7 @@ complete(EditLine *el, int ch)
const char* ptr;
const LineInfo *lf = el_line(el);
int len;
+ int res = CC_ERROR;
/*
* Find the last word
@@ -101,16 +107,16 @@ complete(EditLine *el, int ch)
if (len > strlen(dp->d_name))
continue;
if (strncmp(dp->d_name, ptr, len) == 0) {
- closedir(dd);
if (el_insertstr(el, &dp->d_name[len]) == -1)
- return (CC_ERROR);
+ res = CC_ERROR;
else
- return (CC_REFRESH);
+ res = CC_REFRESH;
+ break;
}
}
closedir(dd);
- return (CC_ERROR);
+ return res;
}
int
@@ -127,6 +133,7 @@ main(int argc, char *argv[])
History *hist;
HistEvent ev;
+ (void) setlocale(LC_CTYPE, "");
(void) signal(SIGINT, sig);
(void) signal(SIGQUIT, sig);
(void) signal(SIGHUP, sig);
diff --git a/lib/libedit/TEST/wtc1.c b/lib/libedit/TEST/wtc1.c
new file mode 100644
index 0000000..ec5574b
--- /dev/null
+++ b/lib/libedit/TEST/wtc1.c
@@ -0,0 +1,281 @@
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <stdio.h>
+#include <string.h>
+#include <signal.h>
+#include <sys/wait.h>
+#include <err.h>
+#include <ctype.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <limits.h>
+#include <locale.h>
+
+#include "../histedit.h"
+
+
+static int continuation;
+volatile sig_atomic_t gotsig;
+static const char hfile[] = ".whistory";
+
+static wchar_t *
+prompt(EditLine *el)
+{
+ static wchar_t a[] = L"\1\033[7m\1Edit$\1\033[0m\1 ";
+ static wchar_t b[] = L"Edit> ";
+
+ return continuation ? b : a;
+}
+
+
+static void
+sig(int i)
+{
+ gotsig = i;
+}
+
+const char *
+my_wcstombs(const wchar_t *wstr)
+{
+ static struct {
+ char *str;
+ int len;
+ } buf;
+
+ int needed = wcstombs(0, wstr, 0) + 1;
+ if (needed > buf.len) {
+ buf.str = malloc(needed);
+ buf.len = needed;
+ }
+ wcstombs(buf.str, wstr, needed);
+ buf.str[needed - 1] = 0;
+
+ return buf.str;
+}
+
+
+static unsigned char
+complete(EditLine *el, int ch)
+{
+ DIR *dd = opendir(".");
+ struct dirent *dp;
+ const wchar_t *ptr;
+ char *buf, *bptr;
+ const LineInfoW *lf = el_wline(el);
+ int len, mblen, i;
+ unsigned char res = 0;
+ wchar_t dir[1024];
+
+ /* Find the last word */
+ for (ptr = lf->cursor -1; !iswspace(*ptr) && ptr > lf->buffer; --ptr)
+ continue;
+ len = lf->cursor - ++ptr;
+
+ /* Convert last word to multibyte encoding, so we can compare to it */
+ wctomb(NULL, 0); /* Reset shift state */
+ mblen = MB_LEN_MAX * len + 1;
+ buf = bptr = malloc(mblen);
+ if (buf == NULL)
+ err(1, "malloc");
+ for (i = 0; i < len; ++i) {
+ /* Note: really should test for -1 return from wctomb */
+ bptr += wctomb(bptr, ptr[i]);
+ }
+ *bptr = 0; /* Terminate multibyte string */
+ mblen = bptr - buf;
+
+ /* Scan directory for matching name */
+ for (dp = readdir(dd); dp != NULL; dp = readdir(dd)) {
+ if (mblen > strlen(dp->d_name))
+ continue;
+ if (strncmp(dp->d_name, buf, mblen) == 0) {
+ mbstowcs(dir, &dp->d_name[mblen],
+ sizeof(dir) / sizeof(*dir));
+ if (el_winsertstr(el, dir) == -1)
+ res = CC_ERROR;
+ else
+ res = CC_REFRESH;
+ break;
+ }
+ }
+
+ closedir(dd);
+ free(buf);
+ return res;
+}
+
+
+int
+main(int argc, char *argv[])
+{
+ EditLine *el = NULL;
+ int numc, ncontinuation;
+ const wchar_t *line;
+ TokenizerW *tok;
+ HistoryW *hist;
+ HistEventW ev;
+#ifdef DEBUG
+ int i;
+#endif
+
+ setlocale(LC_ALL, "");
+
+ (void)signal(SIGINT, sig);
+ (void)signal(SIGQUIT, sig);
+ (void)signal(SIGHUP, sig);
+ (void)signal(SIGTERM, sig);
+
+ hist = history_winit(); /* Init built-in history */
+ history_w(hist, &ev, H_SETSIZE, 100); /* Remember 100 events */
+ history_w(hist, &ev, H_LOAD, hfile);
+
+ tok = tok_winit(NULL); /* Init the tokenizer */
+
+ el = el_init(argv[0], stdin, stdout, stderr);
+
+ el_wset(el, EL_EDITOR, L"vi"); /* Default editor is vi */
+ el_wset(el, EL_SIGNAL, 1); /* Handle signals gracefully */
+ el_wset(el, EL_PROMPT_ESC, prompt, '\1'); /* Set the prompt function */
+
+ el_wset(el, EL_HIST, history_w, hist); /* FIXME - history_w? */
+
+ /* Add a user-defined function */
+ el_wset(el, EL_ADDFN, L"ed-complete", L"Complete argument", complete);
+
+ /* Bind <tab> to it */
+ el_wset(el, EL_BIND, L"^I", L"ed-complete", NULL);
+
+ /*
+ * Bind j, k in vi command mode to previous and next line, instead
+ * of previous and next history.
+ */
+ el_wset(el, EL_BIND, L"-a", L"k", L"ed-prev-line", NULL);
+ el_wset(el, EL_BIND, L"-a", L"j", L"ed-next-line", NULL);
+
+ /* Source the user's defaults file. */
+ el_source(el, NULL);
+
+ while((line = el_wgets(el, &numc)) != NULL && numc != 0) {
+ int ac, cc, co, rc;
+ const wchar_t **av;
+
+ const LineInfoW *li;
+ li = el_wline(el);
+
+#ifdef DEBUG
+ (void)fwprintf(stderr, L"==> got %d %ls", numc, line);
+ (void)fwprintf(stderr, L" > li `%.*ls_%.*ls'\n",
+ (li->cursor - li->buffer), li->buffer,
+ (li->lastchar - 1 - li->cursor),
+ (li->cursor >= li->lastchar) ? L"" : li->cursor);
+#endif
+
+ if (gotsig) {
+ (void)fprintf(stderr, "Got signal %d.\n", (int)gotsig);
+ gotsig = 0;
+ el_reset(el);
+ }
+
+ if(!continuation && numc == 1)
+ continue; /* Only got a linefeed */
+
+ ac = cc = co = 0;
+ ncontinuation = tok_wline(tok, li, &ac, &av, &cc, &co);
+ if (ncontinuation < 0) {
+ (void) fprintf(stderr, "Internal error\n");
+ continuation = 0;
+ continue;
+ }
+
+#ifdef DEBUG
+ (void)fprintf(stderr, " > nc %d ac %d cc %d co %d\n",
+ ncontinuation, ac, cc, co);
+#endif
+ history_w(hist, &ev, continuation ? H_APPEND : H_ENTER, line);
+
+ continuation = ncontinuation;
+ ncontinuation = 0;
+ if(continuation)
+ continue;
+
+#ifdef DEBUG
+ for (i = 0; i < ac; ++i) {
+ (void)fwprintf(stderr, L" > arg# %2d ", i);
+ if (i != cc)
+ (void)fwprintf(stderr, L"`%ls'\n", av[i]);
+ else
+ (void)fwprintf(stderr, L"`%.*ls_%ls'\n",
+ co, av[i], av[i] + co);
+ }
+#endif
+
+ if (wcscmp (av[0], L"history") == 0) {
+ switch(ac) {
+ case 1:
+ for(rc = history_w(hist, &ev, H_LAST);
+ rc != -1;
+ rc = history_w(hist, &ev, H_PREV))
+ (void)fwprintf(stdout, L"%4d %ls",
+ ev.num, ev.str);
+ break;
+ case 2:
+ if (wcscmp(av[1], L"clear") == 0)
+ history_w(hist, &ev, H_CLEAR);
+ else
+ goto badhist;
+ break;
+ case 3:
+ if (wcscmp(av[1], L"load") == 0)
+ history_w(hist, &ev, H_LOAD,
+ my_wcstombs(av[2]));
+ else if (wcscmp(av[1], L"save") == 0)
+ history_w(hist, &ev, H_SAVE,
+ my_wcstombs(av[2]));
+ else
+ goto badhist;
+ break;
+ badhist:
+ default:
+ (void)fprintf(stderr,
+ "Bad history arguments\n");
+ break;
+ }
+ } else if (el_wparse(el, ac, av) == -1) {
+ switch (fork()) {
+ case 0: {
+ Tokenizer *ntok = tok_init(NULL);
+ int nargc;
+ const char **nav;
+ tok_str(ntok, my_wcstombs(line), &nargc, &nav);
+ execvp(nav[0],(char **)nav);
+ perror(nav[0]);
+ _exit(1);
+ /* NOTREACHED */
+ break;
+ }
+ case -1:
+ perror("fork");
+ break;
+ default:
+ if (wait(&rc) == -1)
+ perror("wait");
+ (void)fprintf(stderr, "Exit %x\n", rc);
+ break;
+ }
+ }
+
+ tok_wreset(tok);
+ }
+
+ el_end(el);
+ tok_wend(tok);
+ history_w(hist, &ev, H_SAVE, hfile);
+ history_wend(hist);
+
+ fprintf(stdout, "\n");
+ return 0;
+}
+
+
diff --git a/lib/libedit/chared.c b/lib/libedit/chared.c
index 6a4f3f6..2b57051 100644
--- a/lib/libedit/chared.c
+++ b/lib/libedit/chared.c
@@ -1,3 +1,5 @@
+/* $NetBSD: chared.c,v 1.40 2014/06/18 18:12:28 christos Exp $ */
+
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -28,12 +30,15 @@
* 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.
- *
- * $NetBSD: chared.c,v 1.27 2009/02/15 21:55:23 christos Exp $
*/
+#include "config.h"
#if !defined(lint) && !defined(SCCSID)
+#if 0
static char sccsid[] = "@(#)chared.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: chared.c,v 1.40 2014/06/18 18:12:28 christos Exp $");
+#endif
#endif /* not lint && not SCCSID */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
@@ -41,12 +46,10 @@ __FBSDID("$FreeBSD$");
/*
* chared.c: Character editor utilities
*/
-#include "sys.h"
-
#include <stdlib.h>
#include "el.h"
-private void ch__clearmacro(EditLine *);
+private void ch__clearmacro (EditLine *);
/* value to leave unused in line buffer */
#define EL_LEAVE 2
@@ -62,10 +65,10 @@ cv_undo(EditLine *el)
size_t size;
/* Save entire line for undo */
- size = el->el_line.lastchar - el->el_line.buffer;
- vu->len = size;
+ size = (size_t)(el->el_line.lastchar - el->el_line.buffer);
+ vu->len = (ssize_t)size;
vu->cursor = (int)(el->el_line.cursor - el->el_line.buffer);
- memcpy(vu->buf, el->el_line.buffer, size);
+ (void)memcpy(vu->buf, el->el_line.buffer, size * sizeof(*vu->buf));
/* save command info for redo */
r->count = el->el_state.doingarg ? el->el_state.argument : 0;
@@ -79,11 +82,11 @@ cv_undo(EditLine *el)
* Save yank/delete data for paste
*/
protected void
-cv_yank(EditLine *el, const char *ptr, int size)
+cv_yank(EditLine *el, const Char *ptr, int size)
{
c_kill_t *k = &el->el_chared.c_kill;
- memcpy(k->buf, ptr, (size_t)size);
+ (void)memcpy(k->buf, ptr, (size_t)size * sizeof(*k->buf));
k->last = k->buf + size;
}
@@ -94,7 +97,7 @@ cv_yank(EditLine *el, const char *ptr, int size)
protected void
c_insert(EditLine *el, int num)
{
- char *cp;
+ Char *cp;
if (el->el_line.lastchar + num >= el->el_line.limit) {
if (!ch_enlargebufs(el, (size_t)num))
@@ -126,7 +129,7 @@ c_delafter(EditLine *el, int num)
}
if (num > 0) {
- char *cp;
+ Char *cp;
for (cp = el->el_line.cursor; cp <= el->el_line.lastchar; cp++)
*cp = cp[num];
@@ -142,7 +145,7 @@ c_delafter(EditLine *el, int num)
protected void
c_delafter1(EditLine *el)
{
- char *cp;
+ Char *cp;
for (cp = el->el_line.cursor; cp <= el->el_line.lastchar; cp++)
*cp = cp[1];
@@ -167,7 +170,7 @@ c_delbefore(EditLine *el, int num)
}
if (num > 0) {
- char *cp;
+ Char *cp;
for (cp = el->el_line.cursor - num;
cp <= el->el_line.lastchar;
@@ -185,7 +188,7 @@ c_delbefore(EditLine *el, int num)
protected void
c_delbefore1(EditLine *el)
{
- char *cp;
+ Char *cp;
for (cp = el->el_line.cursor - 1; cp <= el->el_line.lastchar; cp++)
*cp = cp[1];
@@ -198,9 +201,9 @@ c_delbefore1(EditLine *el)
* Return if p is part of a word according to emacs
*/
protected int
-ce__isword(int p)
+ce__isword(Int p)
{
- return (isalnum(p) || strchr("*?_-.[]~=", p) != NULL);
+ return Isalnum(p) || Strchr(STR("*?_-.[]~="), p) != NULL;
}
@@ -208,11 +211,11 @@ ce__isword(int p)
* Return if p is part of a word according to vi
*/
protected int
-cv__isword(int p)
+cv__isword(Int p)
{
- if (isalnum(p) || p == '_')
+ if (Isalnum(p) || p == '_')
return 1;
- if (isgraph(p))
+ if (Isgraph(p))
return 2;
return 0;
}
@@ -222,24 +225,24 @@ cv__isword(int p)
* Return if p is part of a big word according to vi
*/
protected int
-cv__isWord(int p)
+cv__isWord(Int p)
{
- return (!isspace(p));
+ return !Isspace(p);
}
/* c__prev_word():
* Find the previous word
*/
-protected char *
-c__prev_word(char *p, char *low, int n, int (*wtest)(int))
+protected Char *
+c__prev_word(Char *p, Char *low, int n, int (*wtest)(Int))
{
p--;
while (n--) {
- while ((p >= low) && !(*wtest)((unsigned char) *p))
+ while ((p >= low) && !(*wtest)(*p))
p--;
- while ((p >= low) && (*wtest)((unsigned char) *p))
+ while ((p >= low) && (*wtest)(*p))
p--;
}
@@ -248,117 +251,83 @@ c__prev_word(char *p, char *low, int n, int (*wtest)(int))
if (p < low)
p = low;
/* cp now points where we want it */
- return (p);
+ return p;
}
/* c__next_word():
* Find the next word
*/
-protected char *
-c__next_word(char *p, char *high, int n, int (*wtest)(int))
+protected Char *
+c__next_word(Char *p, Char *high, int n, int (*wtest)(Int))
{
while (n--) {
- while ((p < high) && !(*wtest)((unsigned char) *p))
+ while ((p < high) && !(*wtest)(*p))
p++;
- while ((p < high) && (*wtest)((unsigned char) *p))
+ while ((p < high) && (*wtest)(*p))
p++;
}
if (p > high)
p = high;
/* p now points where we want it */
- return (p);
+ return p;
}
/* cv_next_word():
* Find the next word vi style
*/
-protected char *
-cv_next_word(EditLine *el, char *p, char *high, int n, int (*wtest)(int))
+protected Char *
+cv_next_word(EditLine *el, Char *p, Char *high, int n, int (*wtest)(Int))
{
int test;
while (n--) {
- test = (*wtest)((unsigned char) *p);
- while ((p < high) && (*wtest)((unsigned char) *p) == test)
+ test = (*wtest)(*p);
+ while ((p < high) && (*wtest)(*p) == test)
p++;
/*
* vi historically deletes with cw only the word preserving the
* trailing whitespace! This is not what 'w' does..
*/
if (n || el->el_chared.c_vcmd.action != (DELETE|INSERT))
- while ((p < high) && isspace((unsigned char) *p))
+ while ((p < high) && Isspace(*p))
p++;
}
/* p now points where we want it */
if (p > high)
- return (high);
+ return high;
else
- return (p);
+ return p;
}
/* cv_prev_word():
* Find the previous word vi style
*/
-protected char *
-cv_prev_word(char *p, char *low, int n, int (*wtest)(int))
+protected Char *
+cv_prev_word(Char *p, Char *low, int n, int (*wtest)(Int))
{
int test;
p--;
while (n--) {
- while ((p > low) && isspace((unsigned char) *p))
+ while ((p > low) && Isspace(*p))
p--;
- test = (*wtest)((unsigned char) *p);
- while ((p >= low) && (*wtest)((unsigned char) *p) == test)
+ test = (*wtest)(*p);
+ while ((p >= low) && (*wtest)(*p) == test)
p--;
}
p++;
/* p now points where we want it */
if (p < low)
- return (low);
+ return low;
else
- return (p);
+ return p;
}
-#ifdef notdef
-/* c__number():
- * Ignore character p points to, return number appearing after that.
- * A '$' by itself means a big number; "$-" is for negative; '^' means 1.
- * Return p pointing to last char used.
- */
-protected char *
-c__number(
- char *p, /* character position */
- int *num, /* Return value */
- int dval) /* dval is the number to subtract from like $-3 */
-{
- int i;
- int sign = 1;
-
- if (*++p == '^') {
- *num = 1;
- return (p);
- }
- if (*p == '$') {
- if (*++p != '-') {
- *num = 0x7fffffff; /* Handle $ */
- return (--p);
- }
- sign = -1; /* Handle $- */
- ++p;
- }
- for (i = 0; isdigit((unsigned char) *p); i = 10 * i + *p++ - '0')
- continue;
- *num = (sign < 0 ? dval - i : i);
- return (--p);
-}
-#endif
-
/* cv_delfini():
* Finish vi delete action
*/
@@ -397,48 +366,26 @@ cv_delfini(EditLine *el)
}
-#ifdef notdef
-/* ce__endword():
- * Go to the end of this word according to emacs
- */
-protected char *
-ce__endword(char *p, char *high, int n)
-{
- p++;
-
- while (n--) {
- while ((p < high) && isspace((unsigned char) *p))
- p++;
- while ((p < high) && !isspace((unsigned char) *p))
- p++;
- }
-
- p--;
- return (p);
-}
-#endif
-
-
/* cv__endword():
* Go to the end of this word according to vi
*/
-protected char *
-cv__endword(char *p, char *high, int n, int (*wtest)(int))
+protected Char *
+cv__endword(Char *p, Char *high, int n, int (*wtest)(Int))
{
int test;
p++;
while (n--) {
- while ((p < high) && isspace((unsigned char) *p))
+ while ((p < high) && Isspace(*p))
p++;
- test = (*wtest)((unsigned char) *p);
- while ((p < high) && (*wtest)((unsigned char) *p) == test)
+ test = (*wtest)(*p);
+ while ((p < high) && (*wtest)(*p) == test)
p++;
}
p--;
- return (p);
+ return p;
}
/* ch_init():
@@ -449,24 +396,29 @@ ch_init(EditLine *el)
{
c_macro_t *ma = &el->el_chared.c_macro;
- el->el_line.buffer = (char *) el_malloc(EL_BUFSIZ);
+ el->el_line.buffer = el_malloc(EL_BUFSIZ *
+ sizeof(*el->el_line.buffer));
if (el->el_line.buffer == NULL)
- return (-1);
+ return -1;
- (void) memset(el->el_line.buffer, 0, EL_BUFSIZ);
+ (void) memset(el->el_line.buffer, 0, EL_BUFSIZ *
+ sizeof(*el->el_line.buffer));
el->el_line.cursor = el->el_line.buffer;
el->el_line.lastchar = el->el_line.buffer;
el->el_line.limit = &el->el_line.buffer[EL_BUFSIZ - EL_LEAVE];
- el->el_chared.c_undo.buf = (char *) el_malloc(EL_BUFSIZ);
+ el->el_chared.c_undo.buf = el_malloc(EL_BUFSIZ *
+ sizeof(*el->el_chared.c_undo.buf));
if (el->el_chared.c_undo.buf == NULL)
- return (-1);
- (void) memset(el->el_chared.c_undo.buf, 0, EL_BUFSIZ);
+ return -1;
+ (void) memset(el->el_chared.c_undo.buf, 0, EL_BUFSIZ *
+ sizeof(*el->el_chared.c_undo.buf));
el->el_chared.c_undo.len = -1;
el->el_chared.c_undo.cursor = 0;
- el->el_chared.c_redo.buf = (char *) el_malloc(EL_BUFSIZ);
+ el->el_chared.c_redo.buf = el_malloc(EL_BUFSIZ *
+ sizeof(*el->el_chared.c_redo.buf));
if (el->el_chared.c_redo.buf == NULL)
- return (-1);
+ return -1;
el->el_chared.c_redo.pos = el->el_chared.c_redo.buf;
el->el_chared.c_redo.lim = el->el_chared.c_redo.buf + EL_BUFSIZ;
el->el_chared.c_redo.cmd = ED_UNASSIGNED;
@@ -474,12 +426,18 @@ ch_init(EditLine *el)
el->el_chared.c_vcmd.action = NOP;
el->el_chared.c_vcmd.pos = el->el_line.buffer;
- el->el_chared.c_kill.buf = (char *) el_malloc(EL_BUFSIZ);
+ el->el_chared.c_kill.buf = el_malloc(EL_BUFSIZ *
+ sizeof(*el->el_chared.c_kill.buf));
if (el->el_chared.c_kill.buf == NULL)
- return (-1);
- (void) memset(el->el_chared.c_kill.buf, 0, EL_BUFSIZ);
+ return -1;
+ (void) memset(el->el_chared.c_kill.buf, 0, EL_BUFSIZ *
+ sizeof(*el->el_chared.c_kill.buf));
el->el_chared.c_kill.mark = el->el_line.buffer;
el->el_chared.c_kill.last = el->el_chared.c_kill.buf;
+ el->el_chared.c_resizefun = NULL;
+ el->el_chared.c_resizearg = NULL;
+ el->el_chared.c_aliasfun = NULL;
+ el->el_chared.c_aliasarg = NULL;
el->el_map.current = el->el_map.key;
@@ -491,10 +449,10 @@ ch_init(EditLine *el)
ma->level = -1;
ma->offset = 0;
- ma->macro = (char **) el_malloc(EL_MAXMACRO * sizeof(char *));
+ ma->macro = el_malloc(EL_MAXMACRO * sizeof(*ma->macro));
if (ma->macro == NULL)
- return (-1);
- return (0);
+ return -1;
+ return 0;
}
/* ch_reset():
@@ -533,7 +491,7 @@ ch__clearmacro(EditLine *el)
{
c_macro_t *ma = &el->el_chared.c_macro;
while (ma->level >= 0)
- el_free((ptr_t)ma->macro[ma->level--]);
+ el_free(ma->macro[ma->level--]);
}
/* ch_enlargebufs():
@@ -544,9 +502,9 @@ protected int
ch_enlargebufs(EditLine *el, size_t addlen)
{
size_t sz, newsz;
- char *newbuffer, *oldbuf, *oldkbuf;
+ Char *newbuffer, *oldbuf, *oldkbuf;
- sz = el->el_line.limit - el->el_line.buffer + EL_LEAVE;
+ sz = (size_t)(el->el_line.limit - el->el_line.buffer + EL_LEAVE);
newsz = sz * 2;
/*
* If newly required length is longer than current buffer, we need
@@ -560,12 +518,12 @@ ch_enlargebufs(EditLine *el, size_t addlen)
/*
* Reallocate line buffer.
*/
- newbuffer = el_realloc(el->el_line.buffer, newsz);
+ newbuffer = el_realloc(el->el_line.buffer, newsz * sizeof(*newbuffer));
if (!newbuffer)
return 0;
/* zero the newly added memory, leave old data in */
- (void) memset(&newbuffer[sz], 0, newsz - sz);
+ (void) memset(&newbuffer[sz], 0, (newsz - sz) * sizeof(*newbuffer));
oldbuf = el->el_line.buffer;
@@ -578,12 +536,13 @@ ch_enlargebufs(EditLine *el, size_t addlen)
/*
* Reallocate kill buffer.
*/
- newbuffer = el_realloc(el->el_chared.c_kill.buf, newsz);
+ newbuffer = el_realloc(el->el_chared.c_kill.buf, newsz *
+ sizeof(*newbuffer));
if (!newbuffer)
return 0;
/* zero the newly added memory, leave old data in */
- (void) memset(&newbuffer[sz], 0, newsz - sz);
+ (void) memset(&newbuffer[sz], 0, (newsz - sz) * sizeof(*newbuffer));
oldkbuf = el->el_chared.c_kill.buf;
@@ -596,15 +555,17 @@ ch_enlargebufs(EditLine *el, size_t addlen)
/*
* Reallocate undo buffer.
*/
- newbuffer = el_realloc(el->el_chared.c_undo.buf, newsz);
+ newbuffer = el_realloc(el->el_chared.c_undo.buf,
+ newsz * sizeof(*newbuffer));
if (!newbuffer)
return 0;
/* zero the newly added memory, leave old data in */
- (void) memset(&newbuffer[sz], 0, newsz - sz);
+ (void) memset(&newbuffer[sz], 0, (newsz - sz) * sizeof(*newbuffer));
el->el_chared.c_undo.buf = newbuffer;
- newbuffer = el_realloc(el->el_chared.c_redo.buf, newsz);
+ newbuffer = el_realloc(el->el_chared.c_redo.buf,
+ newsz * sizeof(*newbuffer));
if (!newbuffer)
return 0;
el->el_chared.c_redo.pos = newbuffer +
@@ -618,6 +579,8 @@ ch_enlargebufs(EditLine *el, size_t addlen)
/* Safe to set enlarged buffer size */
el->el_line.limit = &el->el_line.buffer[newsz - EL_LEAVE];
+ if (el->el_chared.c_resizefun)
+ (*el->el_chared.c_resizefun)(el, el->el_chared.c_resizearg);
return 1;
}
@@ -627,20 +590,20 @@ ch_enlargebufs(EditLine *el, size_t addlen)
protected void
ch_end(EditLine *el)
{
- el_free((ptr_t) el->el_line.buffer);
+ el_free(el->el_line.buffer);
el->el_line.buffer = NULL;
el->el_line.limit = NULL;
- el_free((ptr_t) el->el_chared.c_undo.buf);
+ el_free(el->el_chared.c_undo.buf);
el->el_chared.c_undo.buf = NULL;
- el_free((ptr_t) el->el_chared.c_redo.buf);
+ el_free(el->el_chared.c_redo.buf);
el->el_chared.c_redo.buf = NULL;
el->el_chared.c_redo.pos = NULL;
el->el_chared.c_redo.lim = NULL;
el->el_chared.c_redo.cmd = ED_UNASSIGNED;
- el_free((ptr_t) el->el_chared.c_kill.buf);
+ el_free(el->el_chared.c_kill.buf);
el->el_chared.c_kill.buf = NULL;
ch_reset(el, 1);
- el_free((ptr_t) el->el_chared.c_macro.macro);
+ el_free(el->el_chared.c_macro.macro);
el->el_chared.c_macro.macro = NULL;
}
@@ -649,21 +612,21 @@ ch_end(EditLine *el)
* Insert string at cursorI
*/
public int
-el_insertstr(EditLine *el, const char *s)
+FUN(el,insertstr)(EditLine *el, const Char *s)
{
size_t len;
- if ((len = strlen(s)) == 0)
- return (-1);
+ if (s == NULL || (len = Strlen(s)) == 0)
+ return -1;
if (el->el_line.lastchar + len >= el->el_line.limit) {
if (!ch_enlargebufs(el, len))
- return (-1);
+ return -1;
}
c_insert(el, (int)len);
while (*s)
*el->el_line.cursor++ = *s++;
- return (0);
+ return 0;
}
@@ -685,19 +648,38 @@ el_deletestr(EditLine *el, int n)
el->el_line.cursor = el->el_line.buffer;
}
+/* el_cursor():
+ * Move the cursor to the left or the right of the current position
+ */
+public int
+el_cursor(EditLine *el, int n)
+{
+ if (n == 0)
+ goto out;
+
+ el->el_line.cursor += n;
+
+ if (el->el_line.cursor < el->el_line.buffer)
+ el->el_line.cursor = el->el_line.buffer;
+ if (el->el_line.cursor > el->el_line.lastchar)
+ el->el_line.cursor = el->el_line.lastchar;
+out:
+ return (int)(el->el_line.cursor - el->el_line.buffer);
+}
+
/* c_gets():
* Get a string
*/
protected int
-c_gets(EditLine *el, char *buf, const char *prompt)
+c_gets(EditLine *el, Char *buf, const Char *prompt)
{
- char ch;
+ Char ch;
ssize_t len;
- char *cp = el->el_line.buffer;
+ Char *cp = el->el_line.buffer;
if (prompt) {
- len = strlen(prompt);
- memcpy(cp, prompt, (size_t)len);
+ len = (ssize_t)Strlen(prompt);
+ (void)memcpy(cp, prompt, (size_t)len * sizeof(*cp));
cp += len;
}
len = 0;
@@ -708,7 +690,7 @@ c_gets(EditLine *el, char *buf, const char *prompt)
el->el_line.lastchar = cp + 1;
re_refresh(el);
- if (el_getc(el, &ch) != 1) {
+ if (FUN(el,getc)(el, &ch) != 1) {
ed_end_of_file(el, 0);
len = -1;
break;
@@ -716,8 +698,8 @@ c_gets(EditLine *el, char *buf, const char *prompt)
switch (ch) {
- case '\010': /* Delete and backspace */
- case '\177':
+ case 0010: /* Delete and backspace */
+ case 0177:
if (len == 0) {
len = -1;
break;
@@ -725,15 +707,15 @@ c_gets(EditLine *el, char *buf, const char *prompt)
cp--;
continue;
- case '\033': /* ESC */
+ case 0033: /* ESC */
case '\r': /* Newline */
case '\n':
buf[len] = ch;
break;
default:
- if (len >= EL_BUFSIZ - 16)
- term_beep(el);
+ if (len >= (ssize_t)(EL_BUFSIZ - 16))
+ terminal_beep(el);
else {
buf[len++] = ch;
*cp++ = ch;
@@ -756,13 +738,13 @@ c_gets(EditLine *el, char *buf, const char *prompt)
protected int
c_hpos(EditLine *el)
{
- char *ptr;
+ Char *ptr;
/*
* Find how many characters till the beginning of this line.
*/
if (el->el_line.cursor == el->el_line.buffer)
- return (0);
+ return 0;
else {
for (ptr = el->el_line.cursor - 1;
ptr >= el->el_line.buffer && *ptr != '\n';
@@ -771,3 +753,19 @@ c_hpos(EditLine *el)
return (int)(el->el_line.cursor - ptr - 1);
}
}
+
+protected int
+ch_resizefun(EditLine *el, el_zfunc_t f, void *a)
+{
+ el->el_chared.c_resizefun = f;
+ el->el_chared.c_resizearg = a;
+ return 0;
+}
+
+protected int
+ch_aliasfun(EditLine *el, el_afunc_t f, void *a)
+{
+ el->el_chared.c_aliasfun = f;
+ el->el_chared.c_aliasarg = a;
+ return 0;
+}
diff --git a/lib/libedit/chared.h b/lib/libedit/chared.h
index 153fceb..909adac 100644
--- a/lib/libedit/chared.h
+++ b/lib/libedit/chared.h
@@ -1,3 +1,5 @@
+/* $NetBSD: chared.h,v 1.22 2014/06/18 18:12:28 christos Exp $ */
+
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -30,7 +32,6 @@
* SUCH DAMAGE.
*
* @(#)chared.h 8.1 (Berkeley) 6/4/93
- * $NetBSD: chared.h,v 1.18 2009/02/15 21:55:23 christos Exp $
* $FreeBSD$
*/
@@ -63,7 +64,7 @@
typedef struct c_macro_t {
int level;
int offset;
- char **macro;
+ Char **macro;
} c_macro_t;
/*
@@ -72,16 +73,16 @@ typedef struct c_macro_t {
typedef struct c_undo_t {
ssize_t len; /* length of saved line */
int cursor; /* position of saved cursor */
- char *buf; /* full saved text */
+ Char *buf; /* full saved text */
} c_undo_t;
/* redo for vi */
typedef struct c_redo_t {
- char *buf; /* redo insert key sequence */
- char *pos;
- char *lim;
+ Char *buf; /* redo insert key sequence */
+ Char *pos;
+ Char *lim;
el_action_t cmd; /* command to redo */
- char ch; /* char that invoked it */
+ Char ch; /* char that invoked it */
int count;
int action; /* from cv_action() */
} c_redo_t;
@@ -91,18 +92,21 @@ typedef struct c_redo_t {
*/
typedef struct c_vcmd_t {
int action;
- char *pos;
+ Char *pos;
} c_vcmd_t;
/*
* Kill buffer for emacs
*/
typedef struct c_kill_t {
- char *buf;
- char *last;
- char *mark;
+ Char *buf;
+ Char *last;
+ Char *mark;
} c_kill_t;
+typedef void (*el_zfunc_t)(EditLine *, void *);
+typedef const char *(*el_afunc_t)(void *, const char *);
+
/*
* Note that we use both data structures because the user can bind
* commands from both editors!
@@ -113,13 +117,16 @@ typedef struct el_chared_t {
c_redo_t c_redo;
c_vcmd_t c_vcmd;
c_macro_t c_macro;
+ el_zfunc_t c_resizefun;
+ el_afunc_t c_aliasfun;
+ void * c_resizearg;
+ void * c_aliasarg;
} el_chared_t;
#define STRQQ "\"\""
#define isglob(a) (strchr("*[]?", (a)) != NULL)
-#define isword(a) (isprint(a))
#define NOP 0x00
#define DELETE 0x01
@@ -140,27 +147,29 @@ typedef struct el_chared_t {
#include "fcns.h"
-protected int cv__isword(int);
-protected int cv__isWord(int);
+protected int cv__isword(Int);
+protected int cv__isWord(Int);
protected void cv_delfini(EditLine *);
-protected char *cv__endword(char *, char *, int, int (*)(int));
-protected int ce__isword(int);
+protected Char *cv__endword(Char *, Char *, int, int (*)(Int));
+protected int ce__isword(Int);
protected void cv_undo(EditLine *);
-protected void cv_yank(EditLine *, const char *, int);
-protected char *cv_next_word(EditLine*, char *, char *, int, int (*)(int));
-protected char *cv_prev_word(char *, char *, int, int (*)(int));
-protected char *c__next_word(char *, char *, int, int (*)(int));
-protected char *c__prev_word(char *, char *, int, int (*)(int));
+protected void cv_yank(EditLine *, const Char *, int);
+protected Char *cv_next_word(EditLine*, Char *, Char *, int, int (*)(Int));
+protected Char *cv_prev_word(Char *, Char *, int, int (*)(Int));
+protected Char *c__next_word(Char *, Char *, int, int (*)(Int));
+protected Char *c__prev_word(Char *, Char *, int, int (*)(Int));
protected void c_insert(EditLine *, int);
protected void c_delbefore(EditLine *, int);
protected void c_delbefore1(EditLine *);
protected void c_delafter(EditLine *, int);
protected void c_delafter1(EditLine *);
-protected int c_gets(EditLine *, char *, const char *);
+protected int c_gets(EditLine *, Char *, const Char *);
protected int c_hpos(EditLine *);
protected int ch_init(EditLine *);
protected void ch_reset(EditLine *, int);
+protected int ch_resizefun(EditLine *, el_zfunc_t, void *);
+protected int ch_aliasfun(EditLine *, el_afunc_t, void *);
protected int ch_enlargebufs(EditLine *, size_t);
protected void ch_end(EditLine *);
diff --git a/lib/libedit/chartype.c b/lib/libedit/chartype.c
new file mode 100644
index 0000000..c240c8c
--- /dev/null
+++ b/lib/libedit/chartype.c
@@ -0,0 +1,360 @@
+/* $NetBSD: chartype.c,v 1.12 2015/02/22 02:16:19 christos Exp $ */
+
+/*-
+ * Copyright (c) 2009 The NetBSD Foundation, Inc.
+ * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ */
+
+/*
+ * chartype.c: character classification and meta information
+ */
+#include "config.h"
+#if !defined(lint) && !defined(SCCSID)
+__RCSID("$NetBSD: chartype.c,v 1.12 2015/02/22 02:16:19 christos Exp $");
+#endif /* not lint && not SCCSID */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include "el.h"
+#include <stdlib.h>
+
+#define CT_BUFSIZ ((size_t)1024)
+
+#ifdef WIDECHAR
+protected int
+ct_conv_cbuff_resize(ct_buffer_t *conv, size_t csize)
+{
+ void *p;
+
+ if (csize <= conv->csize)
+ return 0;
+
+ conv->csize = csize;
+
+ p = el_realloc(conv->cbuff, conv->csize * sizeof(*conv->cbuff));
+ if (p == NULL) {
+ conv->csize = 0;
+ el_free(conv->cbuff);
+ conv->cbuff = NULL;
+ return -1;
+ }
+ conv->cbuff = p;
+ return 0;
+}
+
+protected int
+ct_conv_wbuff_resize(ct_buffer_t *conv, size_t wsize)
+{
+ void *p;
+
+ if (wsize <= conv->wsize)
+ return 0;
+
+ conv->wsize = wsize;
+
+ p = el_realloc(conv->wbuff, conv->wsize * sizeof(*conv->wbuff));
+ if (p == NULL) {
+ conv->wsize = 0;
+ el_free(conv->wbuff);
+ conv->wbuff = NULL;
+ return -1;
+ }
+ conv->wbuff = p;
+ return 0;
+}
+
+
+public char *
+ct_encode_string(const Char *s, ct_buffer_t *conv)
+{
+ char *dst;
+ ssize_t used;
+
+ if (!s)
+ return NULL;
+
+ dst = conv->cbuff;
+ for (;;) {
+ used = (ssize_t)(dst - conv->cbuff);
+ if ((conv->csize - (size_t)used) < 5) {
+ if (ct_conv_cbuff_resize(conv,
+ conv->csize + CT_BUFSIZ) == -1)
+ return NULL;
+ dst = conv->cbuff + used;
+ }
+ if (!*s)
+ break;
+ used = ct_encode_char(dst, (size_t)5, *s);
+ if (used == -1) /* failed to encode, need more buffer space */
+ abort();
+ ++s;
+ dst += used;
+ }
+ *dst = '\0';
+ return conv->cbuff;
+}
+
+public Char *
+ct_decode_string(const char *s, ct_buffer_t *conv)
+{
+ size_t len;
+
+ if (!s)
+ return NULL;
+
+ len = ct_mbstowcs(NULL, s, (size_t)0);
+ if (len == (size_t)-1)
+ return NULL;
+
+ if (conv->wsize < ++len)
+ if (ct_conv_wbuff_resize(conv, len + CT_BUFSIZ) == -1)
+ return NULL;
+
+ ct_mbstowcs(conv->wbuff, s, conv->wsize);
+ return conv->wbuff;
+}
+
+
+protected Char **
+ct_decode_argv(int argc, const char *argv[], ct_buffer_t *conv)
+{
+ size_t bufspace;
+ int i;
+ Char *p;
+ Char **wargv;
+ ssize_t bytes;
+
+ /* Make sure we have enough space in the conversion buffer to store all
+ * the argv strings. */
+ for (i = 0, bufspace = 0; i < argc; ++i)
+ bufspace += argv[i] ? strlen(argv[i]) + 1 : 0;
+ if (conv->wsize < ++bufspace)
+ if (ct_conv_wbuff_resize(conv, bufspace + CT_BUFSIZ) == -1)
+ return NULL;
+
+ wargv = el_malloc((size_t)argc * sizeof(*wargv));
+
+ for (i = 0, p = conv->wbuff; i < argc; ++i) {
+ if (!argv[i]) { /* don't pass null pointers to mbstowcs */
+ wargv[i] = NULL;
+ continue;
+ } else {
+ wargv[i] = p;
+ bytes = (ssize_t)mbstowcs(p, argv[i], bufspace);
+ }
+ if (bytes == -1) {
+ el_free(wargv);
+ return NULL;
+ } else
+ bytes++; /* include '\0' in the count */
+ bufspace -= (size_t)bytes;
+ p += bytes;
+ }
+
+ return wargv;
+}
+
+
+protected size_t
+ct_enc_width(Char c)
+{
+ /* UTF-8 encoding specific values */
+ if (c < 0x80)
+ return 1;
+ else if (c < 0x0800)
+ return 2;
+ else if (c < 0x10000)
+ return 3;
+ else if (c < 0x110000)
+ return 4;
+ else
+ return 0; /* not a valid codepoint */
+}
+
+protected ssize_t
+ct_encode_char(char *dst, size_t len, Char c)
+{
+ ssize_t l = 0;
+ if (len < ct_enc_width(c))
+ return -1;
+ l = ct_wctomb(dst, c);
+
+ if (l < 0) {
+ ct_wctomb_reset;
+ l = 0;
+ }
+ return l;
+}
+#endif
+
+protected const Char *
+ct_visual_string(const Char *s)
+{
+ static Char *buff = NULL;
+ static size_t buffsize = 0;
+ void *p;
+ Char *dst;
+ ssize_t used = 0;
+
+ if (!s)
+ return NULL;
+ if (!buff) {
+ buffsize = CT_BUFSIZ;
+ buff = el_malloc(buffsize * sizeof(*buff));
+ }
+ dst = buff;
+ while (*s) {
+ used = ct_visual_char(dst, buffsize - (size_t)(dst - buff), *s);
+ if (used == -1) { /* failed to encode, need more buffer space */
+ used = dst - buff;
+ buffsize += CT_BUFSIZ;
+ p = el_realloc(buff, buffsize * sizeof(*buff));
+ if (p == NULL)
+ goto out;
+ buff = p;
+ dst = buff + used;
+ /* don't increment s here - we want to retry it! */
+ }
+ else
+ ++s;
+ dst += used;
+ }
+ if (dst >= (buff + buffsize)) { /* sigh */
+ buffsize += 1;
+ p = el_realloc(buff, buffsize * sizeof(*buff));
+ if (p == NULL)
+ goto out;
+ buff = p;
+ dst = buff + buffsize - 1;
+ }
+ *dst = 0;
+ return buff;
+out:
+ el_free(buff);
+ buffsize = 0;
+ return NULL;
+}
+
+
+
+protected int
+ct_visual_width(Char c)
+{
+ int t = ct_chr_class(c);
+ switch (t) {
+ case CHTYPE_ASCIICTL:
+ return 2; /* ^@ ^? etc. */
+ case CHTYPE_TAB:
+ return 1; /* Hmm, this really need to be handled outside! */
+ case CHTYPE_NL:
+ return 0; /* Should this be 1 instead? */
+#ifdef WIDECHAR
+ case CHTYPE_PRINT:
+ return wcwidth(c);
+ case CHTYPE_NONPRINT:
+ if (c > 0xffff) /* prefer standard 4-byte display over 5-byte */
+ return 8; /* \U+12345 */
+ else
+ return 7; /* \U+1234 */
+#else
+ case CHTYPE_PRINT:
+ return 1;
+ case CHTYPE_NONPRINT:
+ return 4; /* \123 */
+#endif
+ default:
+ return 0; /* should not happen */
+ }
+}
+
+
+protected ssize_t
+ct_visual_char(Char *dst, size_t len, Char c)
+{
+ int t = ct_chr_class(c);
+ switch (t) {
+ case CHTYPE_TAB:
+ case CHTYPE_NL:
+ case CHTYPE_ASCIICTL:
+ if (len < 2)
+ return -1; /* insufficient space */
+ *dst++ = '^';
+ if (c == '\177')
+ *dst = '?'; /* DEL -> ^? */
+ else
+ *dst = c | 0100; /* uncontrolify it */
+ return 2;
+ case CHTYPE_PRINT:
+ if (len < 1)
+ return -1; /* insufficient space */
+ *dst = c;
+ return 1;
+ case CHTYPE_NONPRINT:
+ /* we only use single-width glyphs for display,
+ * so this is right */
+ if ((ssize_t)len < ct_visual_width(c))
+ return -1; /* insufficient space */
+#ifdef WIDECHAR
+ *dst++ = '\\';
+ *dst++ = 'U';
+ *dst++ = '+';
+#define tohexdigit(v) "0123456789ABCDEF"[v]
+ if (c > 0xffff) /* prefer standard 4-byte display over 5-byte */
+ *dst++ = tohexdigit(((unsigned int) c >> 16) & 0xf);
+ *dst++ = tohexdigit(((unsigned int) c >> 12) & 0xf);
+ *dst++ = tohexdigit(((unsigned int) c >> 8) & 0xf);
+ *dst++ = tohexdigit(((unsigned int) c >> 4) & 0xf);
+ *dst = tohexdigit(((unsigned int) c ) & 0xf);
+ return c > 0xffff ? 8 : 7;
+#else
+ *dst++ = '\\';
+#define tooctaldigit(v) ((v) + '0')
+ *dst++ = tooctaldigit(((unsigned int) c >> 6) & 0x7);
+ *dst++ = tooctaldigit(((unsigned int) c >> 3) & 0x7);
+ *dst++ = tooctaldigit(((unsigned int) c ) & 0x7);
+#endif
+ /*FALLTHROUGH*/
+ /* these two should be handled outside this function */
+ default: /* we should never hit the default */
+ return 0;
+ }
+}
+
+
+
+
+protected int
+ct_chr_class(Char c)
+{
+ if (c == '\t')
+ return CHTYPE_TAB;
+ else if (c == '\n')
+ return CHTYPE_NL;
+ else if (IsASCII(c) && Iscntrl(c))
+ return CHTYPE_ASCIICTL;
+ else if (Isprint(c))
+ return CHTYPE_PRINT;
+ else
+ return CHTYPE_NONPRINT;
+}
diff --git a/lib/libedit/chartype.h b/lib/libedit/chartype.h
index c8b2b14..17ca5f3 100644
--- a/lib/libedit/chartype.h
+++ b/lib/libedit/chartype.h
@@ -1,4 +1,4 @@
-/* $NetBSD: chartype.h,v 1.6 2010/04/20 02:01:13 christos Exp $ */
+/* $NetBSD: chartype.h,v 1.15 2015/05/17 13:14:41 christos Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -39,7 +39,7 @@
* supports non-BMP code points without requiring UTF-16, but nothing
* seems to actually advertise this properly, despite Unicode 3.1 having
* been around since 2001... */
-#if !defined(__NetBSD__) && !defined(__sun) && !(defined(__APPLE__) && defined(__MACH__))
+#if !defined(__NetBSD__) && !defined(__sun) && !(defined(__APPLE__) && defined(__MACH__)) && !defined(__OpenBSD__) && !defined(__FreeBSD__)
#ifndef __STDC_ISO_10646__
/* In many places it is assumed that the first 127 code points are ASCII
* compatible, so ensure wchar_t indeed does ISO 10646 and not some other
@@ -56,7 +56,7 @@
#endif
#define ct_mbtowc mbtowc
-#define ct_mbtowc_reset mbtowc(0,0,0)
+#define ct_mbtowc_reset mbtowc(0,0,(size_t)0)
#define ct_wctomb wctomb
#define ct_wctomb_reset wctomb(0,0)
#define ct_wcstombs wcstombs
@@ -67,6 +67,7 @@
#define FUN(prefix,rest) prefix ## _w ## rest
#define FUNW(type) type ## _w
#define TYPE(type) type ## W
+#define FCHAR "%lc"
#define FSTR "%ls"
#define STR(x) L ## x
#define UC(c) c
@@ -100,7 +101,12 @@
#define Strtol(p,e,b) wcstol(p,e,b)
-#define Width(c) wcwidth(c)
+static inline int
+Width(wchar_t c)
+{
+ int w = wcwidth(c);
+ return w < 0 ? 0 : w;
+}
#else /* NARROW */
@@ -116,6 +122,7 @@
#define FUN(prefix,rest) prefix ## _ ## rest
#define FUNW(type) type
#define TYPE(type) type
+#define FCHAR "%c"
#define FSTR "%s"
#define STR(x) x
#define UC(c) (unsigned char)(c)
@@ -167,11 +174,11 @@ typedef struct ct_buffer_t {
} ct_buffer_t;
#define ct_encode_string __ct_encode_string
-/* Encode a wide character string and return the UTF-8 encoded result. */
+/* Encode a wide-character string and return the UTF-8 encoded result. */
public char *ct_encode_string(const Char *, ct_buffer_t *);
#define ct_decode_string __ct_decode_string
-/* Decode a (multi)?byte string and return the wide character string result. */
+/* Decode a (multi)?byte string and return the wide-character string result. */
public Char *ct_decode_string(const char *, ct_buffer_t *);
/* Decode a (multi)?byte argv string array.
@@ -179,7 +186,8 @@ public Char *ct_decode_string(const char *, ct_buffer_t *);
protected Char **ct_decode_argv(int, const char *[], ct_buffer_t *);
/* Resizes the conversion buffer(s) if needed. */
-protected void ct_conv_buff_resize(ct_buffer_t *, size_t, size_t);
+protected int ct_conv_cbuff_resize(ct_buffer_t *, size_t);
+protected int ct_conv_wbuff_resize(ct_buffer_t *, size_t);
protected ssize_t ct_encode_char(char *, size_t, Char);
protected size_t ct_enc_width(Char);
@@ -189,7 +197,8 @@ protected size_t ct_enc_width(Char);
#define ct_encode_string(s, b) (s)
#define ct_decode_string(s, b) (s)
#define ct_decode_argv(l, s, b) (s)
-#define ct_conv_buff_resize(b, os, ns)
+#define ct_conv_cbuff_resize(b, s) ((s) == (0))
+#define ct_conv_wbuff_resize(b, s) ((s) == (0))
#define ct_encode_char(d, l, s) (*d = s, 1)
#define ct_free_argv(s)
#endif
@@ -201,7 +210,7 @@ protected size_t ct_enc_width(Char);
/* The maximum buffer size to hold the most unwieldly visual representation,
* in this case \U+nnnnn. */
-#define VISUAL_WIDTH_MAX 8
+#define VISUAL_WIDTH_MAX ((size_t)8)
/* The terminal is thought of in terms of X columns by Y lines. In the cases
* where a wide character takes up more than one column, the adjacent
diff --git a/lib/libedit/common.c b/lib/libedit/common.c
index 64490c9..fc09a9b 100644
--- a/lib/libedit/common.c
+++ b/lib/libedit/common.c
@@ -1,3 +1,5 @@
+/* $NetBSD: common.c,v 1.29 2012/03/24 20:08:43 christos Exp $ */
+
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -28,12 +30,15 @@
* 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.
- *
- * $NetBSD: common.c,v 1.23 2009/02/27 04:18:45 msaitoh Exp $
*/
+#include "config.h"
#if !defined(lint) && !defined(SCCSID)
+#if 0
static char sccsid[] = "@(#)common.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: common.c,v 1.29 2012/03/24 20:08:43 christos Exp $");
+#endif
#endif /* not lint && not SCCSID */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
@@ -41,7 +46,6 @@ __FBSDID("$FreeBSD$");
/*
* common.c: Common Editor functions
*/
-#include "sys.h"
#include "el.h"
/* ed_end_of_file():
@@ -50,12 +54,12 @@ __FBSDID("$FreeBSD$");
*/
protected el_action_t
/*ARGSUSED*/
-ed_end_of_file(EditLine *el, int c __unused)
+ed_end_of_file(EditLine *el, Int c __attribute__((__unused__)))
{
re_goto_bottom(el);
*el->el_line.lastchar = '\0';
- return (CC_EOF);
+ return CC_EOF;
}
@@ -64,12 +68,12 @@ ed_end_of_file(EditLine *el, int c __unused)
* Insert a character [bound to all insert keys]
*/
protected el_action_t
-ed_insert(EditLine *el, int c)
+ed_insert(EditLine *el, Int c)
{
int count = el->el_state.argument;
if (c == '\0')
- return (CC_ERROR);
+ return CC_ERROR;
if (el->el_line.lastchar + el->el_state.argument >=
el->el_line.limit) {
@@ -97,7 +101,7 @@ ed_insert(EditLine *el, int c)
if (el->el_state.inputmode == MODE_REPLACE_1)
return vi_command_mode(el, 0);
- return (CC_NORM);
+ return CC_NORM;
}
@@ -107,12 +111,12 @@ ed_insert(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-ed_delete_prev_word(EditLine *el, int c __unused)
+ed_delete_prev_word(EditLine *el, Int c __attribute__((__unused__)))
{
- char *cp, *p, *kp;
+ Char *cp, *p, *kp;
if (el->el_line.cursor == el->el_line.buffer)
- return (CC_ERROR);
+ return CC_ERROR;
cp = c__prev_word(el->el_line.cursor, el->el_line.buffer,
el->el_state.argument, ce__isword);
@@ -125,7 +129,7 @@ ed_delete_prev_word(EditLine *el, int c __unused)
el->el_line.cursor = cp;
if (el->el_line.cursor < el->el_line.buffer)
el->el_line.cursor = el->el_line.buffer; /* bounds check */
- return (CC_REFRESH);
+ return CC_REFRESH;
}
@@ -135,9 +139,9 @@ ed_delete_prev_word(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-ed_delete_next_char(EditLine *el, int c)
+ed_delete_next_char(EditLine *el, Int c __attribute__((__unused__)))
{
-#ifdef notdef /* XXX */
+#ifdef DEBUG_EDIT
#define EL el->el_line
(void) fprintf(el->el_errlfile,
"\nD(b: %x(%s) c: %x(%s) last: %x(%s) limit: %x(%s)\n",
@@ -150,21 +154,21 @@ ed_delete_next_char(EditLine *el, int c)
if (el->el_line.cursor == el->el_line.buffer) {
/* if I'm also at the beginning */
#ifdef KSHVI
- return (CC_ERROR);
+ return CC_ERROR;
#else
/* then do an EOF */
- term_writechar(el, c);
- return (CC_EOF);
+ terminal_writec(el, c);
+ return CC_EOF;
#endif
} else {
#ifdef KSHVI
el->el_line.cursor--;
#else
- return (CC_ERROR);
+ return CC_ERROR;
#endif
}
} else
- return (CC_ERROR);
+ return CC_ERROR;
}
c_delafter(el, el->el_state.argument); /* delete after dot */
if (el->el_map.type == MAP_VI &&
@@ -172,7 +176,7 @@ ed_delete_next_char(EditLine *el, int c)
el->el_line.cursor > el->el_line.buffer)
/* bounds check */
el->el_line.cursor = el->el_line.lastchar - 1;
- return (CC_REFRESH);
+ return CC_REFRESH;
}
@@ -182,9 +186,9 @@ ed_delete_next_char(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-ed_kill_line(EditLine *el, int c __unused)
+ed_kill_line(EditLine *el, Int c __attribute__((__unused__)))
{
- char *kp, *cp;
+ Char *kp, *cp;
cp = el->el_line.cursor;
kp = el->el_chared.c_kill.buf;
@@ -193,7 +197,7 @@ ed_kill_line(EditLine *el, int c __unused)
el->el_chared.c_kill.last = kp;
/* zap! -- delete to end */
el->el_line.lastchar = el->el_line.cursor;
- return (CC_REFRESH);
+ return CC_REFRESH;
}
@@ -203,17 +207,20 @@ ed_kill_line(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-ed_move_to_end(EditLine *el, int c __unused)
+ed_move_to_end(EditLine *el, Int c __attribute__((__unused__)))
{
el->el_line.cursor = el->el_line.lastchar;
if (el->el_map.type == MAP_VI) {
if (el->el_chared.c_vcmd.action != NOP) {
cv_delfini(el);
- return (CC_REFRESH);
+ return CC_REFRESH;
}
+#ifdef VI_MOVE
+ el->el_line.cursor--;
+#endif
}
- return (CC_CURSOR);
+ return CC_CURSOR;
}
@@ -223,21 +230,21 @@ ed_move_to_end(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-ed_move_to_beg(EditLine *el, int c __unused)
+ed_move_to_beg(EditLine *el, Int c __attribute__((__unused__)))
{
el->el_line.cursor = el->el_line.buffer;
if (el->el_map.type == MAP_VI) {
/* We want FIRST non space character */
- while (isspace((unsigned char) *el->el_line.cursor))
+ while (Isspace(*el->el_line.cursor))
el->el_line.cursor++;
if (el->el_chared.c_vcmd.action != NOP) {
cv_delfini(el);
- return (CC_REFRESH);
+ return CC_REFRESH;
}
}
- return (CC_CURSOR);
+ return CC_CURSOR;
}
@@ -246,12 +253,12 @@ ed_move_to_beg(EditLine *el, int c __unused)
* [^T] [^T]
*/
protected el_action_t
-ed_transpose_chars(EditLine *el, int c)
+ed_transpose_chars(EditLine *el, Int c)
{
if (el->el_line.cursor < el->el_line.lastchar) {
if (el->el_line.lastchar <= &el->el_line.buffer[1])
- return (CC_ERROR);
+ return CC_ERROR;
else
el->el_line.cursor++;
}
@@ -260,9 +267,9 @@ ed_transpose_chars(EditLine *el, int c)
c = el->el_line.cursor[-2];
el->el_line.cursor[-2] = el->el_line.cursor[-1];
el->el_line.cursor[-1] = c;
- return (CC_REFRESH);
+ return CC_REFRESH;
} else
- return (CC_ERROR);
+ return CC_ERROR;
}
@@ -272,15 +279,15 @@ ed_transpose_chars(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-ed_next_char(EditLine *el, int c __unused)
+ed_next_char(EditLine *el, Int c __attribute__((__unused__)))
{
- char *lim = el->el_line.lastchar;
+ Char *lim = el->el_line.lastchar;
if (el->el_line.cursor >= lim ||
(el->el_line.cursor == lim - 1 &&
el->el_map.type == MAP_VI &&
el->el_chared.c_vcmd.action == NOP))
- return (CC_ERROR);
+ return CC_ERROR;
el->el_line.cursor += el->el_state.argument;
if (el->el_line.cursor > lim)
@@ -289,9 +296,9 @@ ed_next_char(EditLine *el, int c __unused)
if (el->el_map.type == MAP_VI)
if (el->el_chared.c_vcmd.action != NOP) {
cv_delfini(el);
- return (CC_REFRESH);
+ return CC_REFRESH;
}
- return (CC_CURSOR);
+ return CC_CURSOR;
}
@@ -301,11 +308,11 @@ ed_next_char(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-ed_prev_word(EditLine *el, int c __unused)
+ed_prev_word(EditLine *el, Int c __attribute__((__unused__)))
{
if (el->el_line.cursor == el->el_line.buffer)
- return (CC_ERROR);
+ return CC_ERROR;
el->el_line.cursor = c__prev_word(el->el_line.cursor,
el->el_line.buffer,
@@ -315,9 +322,9 @@ ed_prev_word(EditLine *el, int c __unused)
if (el->el_map.type == MAP_VI)
if (el->el_chared.c_vcmd.action != NOP) {
cv_delfini(el);
- return (CC_REFRESH);
+ return CC_REFRESH;
}
- return (CC_CURSOR);
+ return CC_CURSOR;
}
@@ -327,7 +334,7 @@ ed_prev_word(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-ed_prev_char(EditLine *el, int c __unused)
+ed_prev_char(EditLine *el, Int c __attribute__((__unused__)))
{
if (el->el_line.cursor > el->el_line.buffer) {
@@ -338,11 +345,11 @@ ed_prev_char(EditLine *el, int c __unused)
if (el->el_map.type == MAP_VI)
if (el->el_chared.c_vcmd.action != NOP) {
cv_delfini(el);
- return (CC_REFRESH);
+ return CC_REFRESH;
}
- return (CC_CURSOR);
+ return CC_CURSOR;
} else
- return (CC_ERROR);
+ return CC_ERROR;
}
@@ -351,19 +358,19 @@ ed_prev_char(EditLine *el, int c __unused)
* [^V] [^V]
*/
protected el_action_t
-ed_quoted_insert(EditLine *el, int c)
+ed_quoted_insert(EditLine *el, Int c)
{
int num;
- char tc;
+ Char tc;
tty_quotemode(el);
- num = el_getc(el, &tc);
- c = (unsigned char) tc;
+ num = FUN(el,getc)(el, &tc);
+ c = tc;
tty_noquotemode(el);
if (num == 1)
- return (ed_insert(el, c));
+ return ed_insert(el, c);
else
- return (ed_end_of_file(el, 0));
+ return ed_end_of_file(el, 0);
}
@@ -371,11 +378,11 @@ ed_quoted_insert(EditLine *el, int c)
* Adds to argument or enters a digit
*/
protected el_action_t
-ed_digit(EditLine *el, int c)
+ed_digit(EditLine *el, Int c)
{
- if (!isdigit((unsigned char) c))
- return (CC_ERROR);
+ if (!Isdigit(c))
+ return CC_ERROR;
if (el->el_state.doingarg) {
/* if doing an arg, add this in... */
@@ -383,11 +390,11 @@ ed_digit(EditLine *el, int c)
el->el_state.argument = c - '0';
else {
if (el->el_state.argument > 1000000)
- return (CC_ERROR);
+ return CC_ERROR;
el->el_state.argument =
(el->el_state.argument * 10) + (c - '0');
}
- return (CC_ARGHACK);
+ return CC_ARGHACK;
}
return ed_insert(el, c);
@@ -399,22 +406,22 @@ ed_digit(EditLine *el, int c)
* For ESC-n
*/
protected el_action_t
-ed_argument_digit(EditLine *el, int c)
+ed_argument_digit(EditLine *el, Int c)
{
- if (!isdigit((unsigned char) c))
- return (CC_ERROR);
+ if (!Isdigit(c))
+ return CC_ERROR;
if (el->el_state.doingarg) {
if (el->el_state.argument > 1000000)
- return (CC_ERROR);
+ return CC_ERROR;
el->el_state.argument = (el->el_state.argument * 10) +
(c - '0');
} else { /* else starting an argument */
el->el_state.argument = c - '0';
el->el_state.doingarg = 1;
}
- return (CC_ARGHACK);
+ return CC_ARGHACK;
}
@@ -424,10 +431,11 @@ ed_argument_digit(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-ed_unassigned(EditLine *el, int c __unused)
+ed_unassigned(EditLine *el __attribute__((__unused__)),
+ Int c __attribute__((__unused__)))
{
- return (CC_ERROR);
+ return CC_ERROR;
}
@@ -441,11 +449,11 @@ ed_unassigned(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-ed_tty_sigint(EditLine *el __unused,
- int c __unused)
+ed_tty_sigint(EditLine *el __attribute__((__unused__)),
+ Int c __attribute__((__unused__)))
{
- return (CC_NORM);
+ return CC_NORM;
}
@@ -455,11 +463,11 @@ ed_tty_sigint(EditLine *el __unused,
*/
protected el_action_t
/*ARGSUSED*/
-ed_tty_dsusp(EditLine *el __unused,
- int c __unused)
+ed_tty_dsusp(EditLine *el __attribute__((__unused__)),
+ Int c __attribute__((__unused__)))
{
- return (CC_NORM);
+ return CC_NORM;
}
@@ -469,11 +477,11 @@ ed_tty_dsusp(EditLine *el __unused,
*/
protected el_action_t
/*ARGSUSED*/
-ed_tty_flush_output(EditLine *el __unused,
- int c __unused)
+ed_tty_flush_output(EditLine *el __attribute__((__unused__)),
+ Int c __attribute__((__unused__)))
{
- return (CC_NORM);
+ return CC_NORM;
}
@@ -483,11 +491,11 @@ ed_tty_flush_output(EditLine *el __unused,
*/
protected el_action_t
/*ARGSUSED*/
-ed_tty_sigquit(EditLine *el __unused,
- int c __unused)
+ed_tty_sigquit(EditLine *el __attribute__((__unused__)),
+ Int c __attribute__((__unused__)))
{
- return (CC_NORM);
+ return CC_NORM;
}
@@ -497,11 +505,11 @@ ed_tty_sigquit(EditLine *el __unused,
*/
protected el_action_t
/*ARGSUSED*/
-ed_tty_sigtstp(EditLine *el __unused,
- int c __unused)
+ed_tty_sigtstp(EditLine *el __attribute__((__unused__)),
+ Int c __attribute__((__unused__)))
{
- return (CC_NORM);
+ return CC_NORM;
}
@@ -511,11 +519,11 @@ ed_tty_sigtstp(EditLine *el __unused,
*/
protected el_action_t
/*ARGSUSED*/
-ed_tty_stop_output(EditLine *el __unused,
- int c __unused)
+ed_tty_stop_output(EditLine *el __attribute__((__unused__)),
+ Int c __attribute__((__unused__)))
{
- return (CC_NORM);
+ return CC_NORM;
}
@@ -525,11 +533,11 @@ ed_tty_stop_output(EditLine *el __unused,
*/
protected el_action_t
/*ARGSUSED*/
-ed_tty_start_output(EditLine *el __unused,
- int c __unused)
+ed_tty_start_output(EditLine *el __attribute__((__unused__)),
+ Int c __attribute__((__unused__)))
{
- return (CC_NORM);
+ return CC_NORM;
}
@@ -539,13 +547,13 @@ ed_tty_start_output(EditLine *el __unused,
*/
protected el_action_t
/*ARGSUSED*/
-ed_newline(EditLine *el, int c __unused)
+ed_newline(EditLine *el, Int c __attribute__((__unused__)))
{
re_goto_bottom(el);
*el->el_line.lastchar++ = '\n';
*el->el_line.lastchar = '\0';
- return (CC_NEWLINE);
+ return CC_NEWLINE;
}
@@ -555,17 +563,17 @@ ed_newline(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-ed_delete_prev_char(EditLine *el, int c __unused)
+ed_delete_prev_char(EditLine *el, Int c __attribute__((__unused__)))
{
if (el->el_line.cursor <= el->el_line.buffer)
- return (CC_ERROR);
+ return CC_ERROR;
c_delbefore(el, el->el_state.argument);
el->el_line.cursor -= el->el_state.argument;
if (el->el_line.cursor < el->el_line.buffer)
el->el_line.cursor = el->el_line.buffer;
- return (CC_REFRESH);
+ return CC_REFRESH;
}
@@ -575,12 +583,12 @@ ed_delete_prev_char(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-ed_clear_screen(EditLine *el, int c __unused)
+ed_clear_screen(EditLine *el, Int c __attribute__((__unused__)))
{
- term_clear_screen(el); /* clear the whole real screen */
+ terminal_clear_screen(el); /* clear the whole real screen */
re_clear_display(el); /* reset everything */
- return (CC_REFRESH);
+ return CC_REFRESH;
}
@@ -590,11 +598,11 @@ ed_clear_screen(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-ed_redisplay(EditLine *el __unused,
- int c __unused)
+ed_redisplay(EditLine *el __attribute__((__unused__)),
+ Int c __attribute__((__unused__)))
{
- return (CC_REDISPLAY);
+ return CC_REDISPLAY;
}
@@ -604,11 +612,11 @@ ed_redisplay(EditLine *el __unused,
*/
protected el_action_t
/*ARGSUSED*/
-ed_start_over(EditLine *el, int c __unused)
+ed_start_over(EditLine *el, Int c __attribute__((__unused__)))
{
ch_reset(el, 0);
- return (CC_REFRESH);
+ return CC_REFRESH;
}
@@ -618,11 +626,11 @@ ed_start_over(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-ed_sequence_lead_in(EditLine *el __unused,
- int c __unused)
+ed_sequence_lead_in(EditLine *el __attribute__((__unused__)),
+ Int c __attribute__((__unused__)))
{
- return (CC_NORM);
+ return CC_NORM;
}
@@ -632,7 +640,7 @@ ed_sequence_lead_in(EditLine *el __unused,
*/
protected el_action_t
/*ARGSUSED*/
-ed_prev_history(EditLine *el, int c __unused)
+ed_prev_history(EditLine *el, Int c __attribute__((__unused__)))
{
char beep = 0;
int sv_event = el->el_history.eventno;
@@ -642,7 +650,7 @@ ed_prev_history(EditLine *el, int c __unused)
if (el->el_history.eventno == 0) { /* save the current buffer
* away */
- (void) strncpy(el->el_history.buf, el->el_line.buffer,
+ (void) Strncpy(el->el_history.buf, el->el_line.buffer,
EL_BUFSIZ);
el->el_history.last = el->el_history.buf +
(el->el_line.lastchar - el->el_line.buffer);
@@ -652,7 +660,7 @@ ed_prev_history(EditLine *el, int c __unused)
if (hist_get(el) == CC_ERROR) {
if (el->el_map.type == MAP_VI) {
el->el_history.eventno = sv_event;
- return CC_ERROR;
+
}
beep = 1;
/* el->el_history.eventno was fixed by first call */
@@ -670,7 +678,7 @@ ed_prev_history(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-ed_next_history(EditLine *el, int c __unused)
+ed_next_history(EditLine *el, Int c __attribute__((__unused__)))
{
el_action_t beep = CC_REFRESH, rval;
@@ -697,9 +705,9 @@ ed_next_history(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-ed_search_prev_history(EditLine *el, int c __unused)
+ed_search_prev_history(EditLine *el, Int c __attribute__((__unused__)))
{
- const char *hp;
+ const Char *hp;
int h;
bool_t found = 0;
@@ -712,20 +720,20 @@ ed_search_prev_history(EditLine *el, int c __unused)
"e_prev_search_hist(): eventno < 0;\n");
#endif
el->el_history.eventno = 0;
- return (CC_ERROR);
+ return CC_ERROR;
}
if (el->el_history.eventno == 0) {
- (void) strncpy(el->el_history.buf, el->el_line.buffer,
+ (void) Strncpy(el->el_history.buf, el->el_line.buffer,
EL_BUFSIZ);
el->el_history.last = el->el_history.buf +
(el->el_line.lastchar - el->el_line.buffer);
}
if (el->el_history.ref == NULL)
- return (CC_ERROR);
+ return CC_ERROR;
hp = HIST_FIRST(el);
if (hp == NULL)
- return (CC_ERROR);
+ return CC_ERROR;
c_setpat(el); /* Set search pattern !! */
@@ -736,7 +744,7 @@ ed_search_prev_history(EditLine *el, int c __unused)
#ifdef SDEBUG
(void) fprintf(el->el_errfile, "Comparing with \"%s\"\n", hp);
#endif
- if ((strncmp(hp, el->el_line.buffer, (size_t)
+ if ((Strncmp(hp, el->el_line.buffer, (size_t)
(el->el_line.lastchar - el->el_line.buffer)) ||
hp[el->el_line.lastchar - el->el_line.buffer]) &&
c_hmatch(el, hp)) {
@@ -751,11 +759,11 @@ ed_search_prev_history(EditLine *el, int c __unused)
#ifdef SDEBUG
(void) fprintf(el->el_errfile, "not found\n");
#endif
- return (CC_ERROR);
+ return CC_ERROR;
}
el->el_history.eventno = h;
- return (hist_get(el));
+ return hist_get(el);
}
@@ -765,9 +773,9 @@ ed_search_prev_history(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-ed_search_next_history(EditLine *el, int c __unused)
+ed_search_next_history(EditLine *el, Int c __attribute__((__unused__)))
{
- const char *hp;
+ const Char *hp;
int h;
bool_t found = 0;
@@ -776,14 +784,14 @@ ed_search_next_history(EditLine *el, int c __unused)
*el->el_line.lastchar = '\0'; /* just in case */
if (el->el_history.eventno == 0)
- return (CC_ERROR);
+ return CC_ERROR;
if (el->el_history.ref == NULL)
- return (CC_ERROR);
+ return CC_ERROR;
hp = HIST_FIRST(el);
if (hp == NULL)
- return (CC_ERROR);
+ return CC_ERROR;
c_setpat(el); /* Set search pattern !! */
@@ -791,7 +799,7 @@ ed_search_next_history(EditLine *el, int c __unused)
#ifdef SDEBUG
(void) fprintf(el->el_errfile, "Comparing with \"%s\"\n", hp);
#endif
- if ((strncmp(hp, el->el_line.buffer, (size_t)
+ if ((Strncmp(hp, el->el_line.buffer, (size_t)
(el->el_line.lastchar - el->el_line.buffer)) ||
hp[el->el_line.lastchar - el->el_line.buffer]) &&
c_hmatch(el, hp))
@@ -804,12 +812,12 @@ ed_search_next_history(EditLine *el, int c __unused)
#ifdef SDEBUG
(void) fprintf(el->el_errfile, "not found\n");
#endif
- return (CC_ERROR);
+ return CC_ERROR;
}
}
el->el_history.eventno = found;
- return (hist_get(el));
+ return hist_get(el);
}
@@ -819,9 +827,9 @@ ed_search_next_history(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-ed_prev_line(EditLine *el, int c __unused)
+ed_prev_line(EditLine *el, Int c __attribute__((__unused__)))
{
- char *ptr;
+ Char *ptr;
int nchars = c_hpos(el);
/*
@@ -835,7 +843,7 @@ ed_prev_line(EditLine *el, int c __unused)
break;
if (el->el_state.argument > 0)
- return (CC_ERROR);
+ return CC_ERROR;
/*
* Move to the beginning of the line
@@ -852,7 +860,7 @@ ed_prev_line(EditLine *el, int c __unused)
continue;
el->el_line.cursor = ptr;
- return (CC_CURSOR);
+ return CC_CURSOR;
}
@@ -862,9 +870,9 @@ ed_prev_line(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-ed_next_line(EditLine *el, int c __unused)
+ed_next_line(EditLine *el, Int c __attribute__((__unused__)))
{
- char *ptr;
+ Char *ptr;
int nchars = c_hpos(el);
/*
@@ -875,7 +883,7 @@ ed_next_line(EditLine *el, int c __unused)
break;
if (el->el_state.argument > 0)
- return (CC_ERROR);
+ return CC_ERROR;
/*
* Move to the character requested
@@ -886,7 +894,7 @@ ed_next_line(EditLine *el, int c __unused)
continue;
el->el_line.cursor = ptr;
- return (CC_CURSOR);
+ return CC_CURSOR;
}
@@ -896,16 +904,16 @@ ed_next_line(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-ed_command(EditLine *el, int c __unused)
+ed_command(EditLine *el, Int c __attribute__((__unused__)))
{
- char tmpbuf[EL_BUFSIZ];
+ Char tmpbuf[EL_BUFSIZ];
int tmplen;
- tmplen = c_gets(el, tmpbuf, "\n: ");
- term__putc(el, '\n');
+ tmplen = c_gets(el, tmpbuf, STR("\n: "));
+ terminal__putc(el, '\n');
if (tmplen < 0 || (tmpbuf[tmplen] = 0, parse_line(el, tmpbuf)) == -1)
- term_beep(el);
+ terminal_beep(el);
el->el_map.current = el->el_map.key;
re_clear_display(el);
diff --git a/lib/libedit/config.h b/lib/libedit/config.h
new file mode 100644
index 0000000..526869f
--- /dev/null
+++ b/lib/libedit/config.h
@@ -0,0 +1,290 @@
+/* $FreeBSD$ */
+/* config.h. Generated from config.h.in by configure. */
+/* config.h.in. Generated from configure.ac by autoheader. */
+
+/* Define to 1 if the `closedir' function returns void instead of `int'. */
+/* #undef CLOSEDIR_VOID */
+
+/* Define to 1 if you have the <curses.h> header file. */
+#define HAVE_CURSES_H 1
+
+/* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'.
+ */
+#define HAVE_DIRENT_H 1
+
+/* Define to 1 if you have the <dlfcn.h> header file. */
+#define HAVE_DLFCN_H 1
+
+/* Define to 1 if you have the `endpwent' function. */
+#define HAVE_ENDPWENT 1
+
+/* Define to 1 if you have the <fcntl.h> header file. */
+#define HAVE_FCNTL_H 1
+
+/* Define to 1 if you have the `fgetln' function. */
+#define HAVE_FGETLN 1
+
+/* Define to 1 if you have the `fork' function. */
+#define HAVE_FORK 1
+
+/* Define to 1 if you have getpwnam_r and getpwuid_r that are draft POSIX.1
+ versions. */
+/* #undef HAVE_GETPW_R_DRAFT */
+
+/* Define to 1 if you have getpwnam_r and getpwuid_r that are POSIX.1
+ compatible. */
+#define HAVE_GETPW_R_POSIX 1
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#define HAVE_INTTYPES_H 1
+
+/* Define to 1 if you have the `isascii' function. */
+#define HAVE_ISASCII 1
+
+/* Define to 1 if you have the `issetugid' function. */
+#define HAVE_ISSETUGID 1
+
+/* Define to 1 if you have the `curses' library (-lcurses). */
+/* #undef HAVE_LIBCURSES */
+
+/* Define to 1 if you have the `ncurses' library (-lncurses). */
+#define HAVE_LIBNCURSES 1
+
+/* Define to 1 if you have the `termcap' library (-ltermcap). */
+/* #undef HAVE_LIBTERMCAP */
+
+/* Define to 1 if you have the `terminfo' library (-lterminfo). */
+/* #undef HAVE_LIBTERMINFO */
+
+/* Define to 1 if you have the `termlib' library (-ltermlib). */
+/* #undef HAVE_LIBTERMLIB */
+
+/* Define to 1 if you have the <limits.h> header file. */
+#define HAVE_LIMITS_H 1
+
+/* Define to 1 if you have the <malloc.h> header file. */
+#define HAVE_MALLOC_H 1
+
+/* Define to 1 if you have the `memchr' function. */
+#define HAVE_MEMCHR 1
+
+/* Define to 1 if you have the <memory.h> header file. */
+#define HAVE_MEMORY_H 1
+
+/* Define to 1 if you have the `memset' function. */
+#define HAVE_MEMSET 1
+
+/* Define to 1 if you have the <ncurses.h> header file. */
+#define HAVE_NCURSES_H 1
+
+/* Define to 1 if you have the <ndir.h> header file, and it defines `DIR'. */
+/* #undef HAVE_NDIR_H */
+
+/* Define to 1 if you have the `regcomp' function. */
+#define HAVE_REGCOMP 1
+
+/* Define to 1 if you have the `re_comp' function. */
+/* #undef HAVE_RE_COMP */
+
+/* Define to 1 if `stat' has the bug that it succeeds when given the
+ zero-length file name argument. */
+/* #undef HAVE_STAT_EMPTY_STRING_BUG */
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#define HAVE_STDINT_H 1
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#define HAVE_STDLIB_H 1
+
+/* Define to 1 if you have the `strcasecmp' function. */
+#define HAVE_STRCASECMP 1
+
+/* Define to 1 if you have the `strchr' function. */
+#define HAVE_STRCHR 1
+
+/* Define to 1 if you have the `strcspn' function. */
+#define HAVE_STRCSPN 1
+
+/* Define to 1 if you have the `strdup' function. */
+#define HAVE_STRDUP 1
+
+/* Define to 1 if you have the `strerror' function. */
+#define HAVE_STRERROR 1
+
+/* Define to 1 if you have the <strings.h> header file. */
+#define HAVE_STRINGS_H 1
+
+/* Define to 1 if you have the <string.h> header file. */
+#define HAVE_STRING_H 1
+
+/* Define to 1 if you have the `strlcat' function. */
+#define HAVE_STRLCAT 1
+
+/* Define to 1 if you have the `strlcpy' function. */
+#define HAVE_STRLCPY 1
+
+/* Define to 1 if you have the `strrchr' function. */
+#define HAVE_STRRCHR 1
+
+/* Define to 1 if you have the `strstr' function. */
+#define HAVE_STRSTR 1
+
+/* Define to 1 if you have the `strtol' function. */
+#define HAVE_STRTOL 1
+
+/* Define to 1 if struct dirent has member d_namlen */
+#define HAVE_STRUCT_DIRENT_D_NAMLEN 1
+
+/* Define to 1 if you have the `strunvis' function. */
+#define HAVE_STRUNVIS 1
+
+/* Define to 1 if you have the `strvis' function. */
+#define HAVE_STRVIS 1
+
+/* Define to 1 if you have the <sys/cdefs.h> header file. */
+#define HAVE_SYS_CDEFS_H 1
+
+/* Define to 1 if you have the <sys/dir.h> header file, and it defines `DIR'.
+ */
+/* #undef HAVE_SYS_DIR_H */
+
+/* Define to 1 if you have the <sys/ioctl.h> header file. */
+#define HAVE_SYS_IOCTL_H 1
+
+/* Define to 1 if you have the <sys/ndir.h> header file, and it defines `DIR'.
+ */
+/* #undef HAVE_SYS_NDIR_H */
+
+/* Define to 1 if you have the <sys/param.h> header file. */
+#define HAVE_SYS_PARAM_H 1
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#define HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#define HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
+#define HAVE_SYS_WAIT_H 1
+
+/* Define to 1 if you have the <termcap.h> header file. */
+#define HAVE_TERMCAP_H 1
+
+/* Define to 1 if you have the <term.h> header file. */
+#define HAVE_TERM_H 1
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#define HAVE_UNISTD_H 1
+
+/* Define to 1 if the system has the type `u_int32_t'. */
+#define HAVE_U_INT32_T 1
+
+/* Define to 1 if you have the `vfork' function. */
+#define HAVE_VFORK 1
+
+/* Define to 1 if you have the <vfork.h> header file. */
+/* #undef HAVE_VFORK_H */
+
+/* Define to 1 if you have the `vis' function. */
+#define HAVE_VIS 1
+
+/* Define to 1 if you have the `wcsdup' function. */
+#define HAVE_WCSDUP 1
+
+/* Define to 1 if `fork' works. */
+#define HAVE_WORKING_FORK 1
+
+/* Define to 1 if `vfork' works. */
+#define HAVE_WORKING_VFORK 1
+
+/* Define to 1 if `lstat' dereferences a symlink specified with a trailing
+ slash. */
+#define LSTAT_FOLLOWS_SLASHED_SYMLINK 1
+
+/* Define to the sub-directory in which libtool stores uninstalled libraries.
+ */
+#define LT_OBJDIR ".libs/"
+
+/* Name of package */
+#define PACKAGE "libedit-20110729"
+
+/* Define to the address where bug reports for this package should be sent. */
+#define PACKAGE_BUGREPORT ""
+
+/* Define to the full name of this package. */
+#define PACKAGE_NAME "libedit"
+
+/* Define to the full name and version of this package. */
+#define PACKAGE_STRING "libedit 3.0"
+
+/* Define to the one symbol short name of this package. */
+#define PACKAGE_TARNAME "libedit-20110729"
+
+/* Define to the home page for this package. */
+#define PACKAGE_URL ""
+
+/* Define to the version of this package. */
+#define PACKAGE_VERSION "3.0"
+
+/* Define as the return type of signal handlers (`int' or `void'). */
+#define RETSIGTYPE void
+
+/* Define to 1 if you have the ANSI C header files. */
+#define STDC_HEADERS 1
+
+/* Enable extensions on AIX 3, Interix. */
+#ifndef _ALL_SOURCE
+# define _ALL_SOURCE 1
+#endif
+/* Enable GNU extensions on systems that have them. */
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE 1
+#endif
+/* Enable threading extensions on Solaris. */
+#ifndef _POSIX_PTHREAD_SEMANTICS
+# define _POSIX_PTHREAD_SEMANTICS 1
+#endif
+/* Enable extensions on HP NonStop. */
+#ifndef _TANDEM_SOURCE
+# define _TANDEM_SOURCE 1
+#endif
+/* Enable general extensions on Solaris. */
+#ifndef __EXTENSIONS__
+# define __EXTENSIONS__ 1
+#endif
+
+
+/* Version number of package */
+#define VERSION "3.0"
+
+/* Define to 1 if you want wide-character code */
+/* #undef WIDECHAR */
+
+/* Define to 1 if on MINIX. */
+/* #undef _MINIX */
+
+/* Define to 2 if the system does not provide POSIX.1 features except with
+ this defined. */
+/* #undef _POSIX_1_SOURCE */
+
+/* Define to 1 if you need to in order for `stat' and other things to work. */
+/* #undef _POSIX_SOURCE */
+
+/* Define to empty if `const' does not conform to ANSI C. */
+/* #undef const */
+
+/* Define to `int' if <sys/types.h> does not define. */
+/* #undef pid_t */
+
+/* Define to `unsigned int' if <sys/types.h> does not define. */
+/* #undef size_t */
+
+/* Define as `fork' if `vfork' does not work. */
+/* #undef vfork */
+
+
+#include "sys.h"
+#undef SCCSID
+#undef LIBC_SCCS
+#undef lint
+#undef SIZE_T_MAX
diff --git a/lib/libedit/edit/readline/readline.h b/lib/libedit/edit/readline/readline.h
index 5b9c39d..4371457 100644
--- a/lib/libedit/edit/readline/readline.h
+++ b/lib/libedit/edit/readline/readline.h
@@ -1,4 +1,4 @@
-/* $NetBSD: readline.h,v 1.31 2010/08/04 20:29:18 christos Exp $ */
+/* $NetBSD: readline.h,v 1.34 2013/05/28 00:10:34 christos Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -111,6 +111,7 @@ extern char *rl_basic_word_break_characters;
extern char *rl_completer_word_break_characters;
extern char *rl_completer_quote_characters;
extern Function *rl_completion_entry_function;
+extern char *(*rl_completion_word_break_hook)(void);
extern CPPFunction *rl_attempted_completion_function;
extern int rl_attempted_completion_over;
extern int rl_completion_type;
@@ -126,6 +127,8 @@ extern char *rl_prompt;
/*
* The following is not implemented
*/
+extern int rl_catch_signals;
+extern int rl_catch_sigwinch;
extern KEYMAP_ENTRY_ARRAY emacs_standard_keymap,
emacs_meta_keymap,
emacs_ctlx_keymap;
@@ -153,7 +156,6 @@ int where_history(void);
HIST_ENTRY *current_history(void);
HIST_ENTRY *history_get(int);
HIST_ENTRY *remove_history(int);
-/*###152 [lint] syntax error 'histdata_t' [249]%%%*/
HIST_ENTRY *replace_history_entry(int, const char *, histdata_t);
int history_total_bytes(void);
int history_set_pos(int);
@@ -200,6 +202,7 @@ void rl_get_screen_size(int *, int *);
void rl_set_screen_size(int, int);
char *rl_filename_completion_function (const char *, int);
int _rl_abort_internal(void);
+int _rl_qsort_string_compare(char **, char **);
char **rl_completion_matches(const char *, rl_compentry_func_t *);
void rl_forced_update_display(void);
int rl_set_prompt(const char *);
diff --git a/lib/libedit/editline.3 b/lib/libedit/editline.3
index df7cd87..1e0ff5d 100644
--- a/lib/libedit/editline.3
+++ b/lib/libedit/editline.3
@@ -1,6 +1,6 @@
-.\" $NetBSD: editline.3,v 1.70 2009/07/05 21:55:24 perry Exp $
+.\" $NetBSD: editline.3,v 1.84 2014/12/25 13:39:41 wiz Exp $
.\"
-.\" Copyright (c) 1997-2003 The NetBSD Foundation, Inc.
+.\" Copyright (c) 1997-2014 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This file was contributed to The NetBSD Foundation by Luke Mewburn.
@@ -28,33 +28,52 @@
.\"
.\" $FreeBSD$
.\"
-.Dd July 5, 2009
+.Dd December 25, 2014
.Dt EDITLINE 3
.Os
.Sh NAME
.Nm editline ,
.Nm el_init ,
+.Nm el_init_fd ,
.Nm el_end ,
.Nm el_reset ,
.Nm el_gets ,
+.Nm el_wgets ,
.Nm el_getc ,
+.Nm el_wgetc ,
.Nm el_push ,
+.Nm el_wpush ,
.Nm el_parse ,
+.Nm el_wparse ,
.Nm el_set ,
+.Nm el_wset ,
.Nm el_get ,
+.Nm el_wget ,
.Nm el_source ,
.Nm el_resize ,
+.Nm el_cursor ,
.Nm el_line ,
+.Nm el_wline ,
.Nm el_insertstr ,
+.Nm el_winsertstr ,
.Nm el_deletestr ,
+.Nm el_wdeletestr ,
.Nm history_init ,
+.Nm history_winit ,
.Nm history_end ,
+.Nm history_wend ,
.Nm history ,
+.Nm history_w ,
.Nm tok_init ,
+.Nm tok_winit ,
.Nm tok_end ,
+.Nm tok_wend ,
.Nm tok_reset ,
+.Nm tok_wreset ,
.Nm tok_line ,
+.Nm tok_wline ,
.Nm tok_str
+.Nm tok_wstr
.Nd line editor, history and tokenization functions
.Sh LIBRARY
.Lb libedit
@@ -62,51 +81,86 @@
.In histedit.h
.Ft EditLine *
.Fn el_init "const char *prog" "FILE *fin" "FILE *fout" "FILE *ferr"
+.Ft EditLine *
+.Fn el_init_fd "const char *prog" "FILE *fin" "FILE *fout" "FILE *ferr" "int fdin" "int fdout" "int fderr"
.Ft void
.Fn el_end "EditLine *e"
.Ft void
.Fn el_reset "EditLine *e"
.Ft const char *
.Fn el_gets "EditLine *e" "int *count"
+.Ft const wchar_t *
+.Fn el_wgets "EditLine *e" "int *count"
.Ft int
.Fn el_getc "EditLine *e" "char *ch"
+.Ft int
+.Fn el_wgetc "EditLine *e" "wchar_t *ch"
+.Ft void
+.Fn el_push "EditLine *e" "const char *str"
.Ft void
-.Fn el_push "EditLine *e" "char *str"
+.Fn el_wpush "EditLine *e" "const wchar_t *str"
.Ft int
.Fn el_parse "EditLine *e" "int argc" "const char *argv[]"
.Ft int
+.Fn el_wparse "EditLine *e" "int argc" "const wchar_t *argv[]"
+.Ft int
.Fn el_set "EditLine *e" "int op" "..."
.Ft int
+.Fn el_wset "EditLine *e" "int op" "..."
+.Ft int
.Fn el_get "EditLine *e" "int op" "..."
.Ft int
+.Fn el_wget "EditLine *e" "int op" "..."
+.Ft int
.Fn el_source "EditLine *e" "const char *file"
.Ft void
.Fn el_resize "EditLine *e"
+.Fn int
+.Fn el_cursor "EditLine *e" "int count"
.Ft const LineInfo *
.Fn el_line "EditLine *e"
+.Ft const LineInfoW *
+.Fn el_wline "EditLine *e"
.Ft int
.Fn el_insertstr "EditLine *e" "const char *str"
+.Ft int
+.Fn el_winsertstr "EditLine *e" "const wchar_t *str"
.Ft void
.Fn el_deletestr "EditLine *e" "int count"
+.Ft void
+.Fn el_wdeletestr "EditLine *e" "int count"
.Ft History *
.Fn history_init
+.Ft HistoryW *
+.Fn history_winit
.Ft void
.Fn history_end "History *h"
+.Ft void
+.Fn history_wend "HistoryW *h"
.Ft int
.Fn history "History *h" "HistEvent *ev" "int op" "..."
+.Ft int
+.Fn history_w "HistoryW *h" "HistEventW *ev" "int op" "..."
.Ft Tokenizer *
.Fn tok_init "const char *IFS"
+.Ft TokenizerW *
+.Fn tok_winit "const wchar_t *IFS"
.Ft void
.Fn tok_end "Tokenizer *t"
.Ft void
+.Fn tok_wend "TokenizerW *t"
+.Ft void
.Fn tok_reset "Tokenizer *t"
+.Ft void
+.Fn tok_wreset "TokenizerW *t"
.Ft int
-.Fo tok_line
-.Fa "Tokenizer *t" "const LineInfo *li" "int *argc" "const char **argv[]"
-.Fa "int *cursorc" "int *cursoro"
-.Fc
+.Fn tok_line "Tokenizer *t" "const LineInfo *li" "int *argc" "const char **argv[]" "int *cursorc" "int *cursoro"
+.Ft int
+.Fn tok_wline "TokenizerW *t" "const LineInfoW *li" "int *argc" "const wchar_t **argv[]" "int *cursorc" "int *cursoro"
.Ft int
.Fn tok_str "Tokenizer *t" "const char *str" "int *argc" "const char **argv[]"
+.Ft int
+.Fn tok_wstr "TokenizerW *t" "const wchar_t *str" "int *argc" "const wchar_t **argv[]"
.Sh DESCRIPTION
The
.Nm
@@ -126,14 +180,21 @@ The line editing functions use a common data structure,
.Fa EditLine ,
which is created by
.Fn el_init
+or
+.Fn el_init_fd
and freed by
.Fn el_end .
.Pp
+The wide-character functions behave the same way as their narrow
+counterparts.
+.Pp
The following functions are available:
.Bl -tag -width 4n
.It Fn el_init
Initialise the line editor, and return a data structure
-to be used by all other line editing functions.
+to be used by all other line editing functions, or
+.Dv NULL
+on failure.
.Fa prog
is the name of the invoking program, used when reading the
.Xr editrc 5
@@ -146,11 +207,20 @@ are the input, output, and error streams (respectively) to use.
In this documentation, references to
.Dq the tty
are actually to this input/output stream combination.
+.It Fn el_init_fd
+Like
+.Fn el_init
+but allows specifying file descriptors for the
+.Xr stdio 3
+corresponding streams, in case those were created with
+.Xr funopen 3 .
.It Fn el_end
Clean up and finish with
.Fa e ,
assumed to have been created with
-.Fn el_init .
+.Fn el_init
+or
+.Fn el_init_fd .
.It Fn el_reset
Reset the tty and the parser.
This should be called after an error which may have upset the tty's
@@ -174,7 +244,10 @@ and must be copied if the data is to be retained.
Read a character from the tty.
.Fa ch
is modified to contain the character read.
-Returns the number of characters read if successful, \-1 otherwise.
+Returns the number of characters read if successful, \-1 otherwise,
+in which case
+.Dv errno
+can be inspected for the cause.
.It Fn el_push
Pushes
.Fa str
@@ -196,7 +269,7 @@ to execute builtin
.Nm
commands.
If the command is prefixed with
-.Dq prog:
+.Dq prog :
then
.Fn el_parse
will only execute the command if
@@ -209,7 +282,7 @@ The return value is
\-1 if the command is unknown,
0 if there was no error or
.Dq prog
-did not match, or
+didn't match, or
1 if the command returned an error.
Refer to
.Xr editrc 5
@@ -221,6 +294,7 @@ parameters.
.Fa op
determines which parameter to set, and each operation has its
own parameter list.
+Returns 0 on success, \-1 on failure.
.Pp
The following values for
.Fa op
@@ -385,6 +459,14 @@ check this
(using
.Fn el_get )
to determine if editing should be enabled or not.
+.It Dv EL_UNBUFFERED , Fa "int flag"
+If
+.Fa flag
+is zero,
+unbuffered mode is disabled (the default).
+In unbuffered mode,
+.Fn el_gets
+will return immediately after processing a single character.
.It Dv EL_GETCFN , Fa "int (*f)(EditLine *, char *c)"
Define the character reading function as
.Fa f ,
@@ -396,7 +478,7 @@ and
.Fn el_getc .
The builtin function can be set or restored with the special function
name
-.Dv EL_BUILTIN_GETCFN .
+.Dq Dv EL_BUILTIN_GETCFN .
.It Dv EL_CLIENTDATA , Fa "void *data"
Register
.Fa data
@@ -454,7 +536,7 @@ If
is not
.Dv NULL ,
return the start/stop literal prompt character in it.
-.It Dv EL_EDITOR , Fa "const char *"
+.It Dv EL_EDITOR , Fa "const char **"
Return the name of the editor, which will be one of
.Dq emacs
or
@@ -478,7 +560,7 @@ above).
Return non-zero if editing is enabled.
.It Dv EL_GETCFN , Fa "int (**f)(EditLine *, char *)"
Return a pointer to the function that read characters, which is equal to
-.Dv EL_BUILTIN_GETCFN
+.Dq Dv EL_BUILTIN_GETCFN
in the case of the default builtin function.
.It Dv EL_CLIENTDATA , Fa "void **data"
Retrieve
@@ -487,10 +569,7 @@ previously registered with the corresponding
.Fn el_set
call.
.It Dv EL_UNBUFFERED , Fa "int"
-Sets or clears unbuffered mode.
-In this mode,
-.Fn el_gets
-will return immediately after processing a single character.
+Return non-zero if unbuffered mode is enabled.
.It Dv EL_PREP_TERM , Fa "int"
Sets or clears terminal editing mode.
.It Dv EL_GETFP , Fa "int fd", Fa "FILE **fp"
@@ -531,6 +610,8 @@ Refer to
.Xr editrc 5
for details on the format of
.Fa file .
+.Fn el_source
+returns 0 on success and \-1 on error.
.It Fn el_resize
Must be called if the terminal size changes.
If
@@ -538,9 +619,14 @@ If
has been set with
.Fn el_set ,
then this is done automatically.
-Otherwise, it is the responsibility of the application to call
+Otherwise, it's the responsibility of the application to call
.Fn el_resize
on the appropriate occasions.
+.It Fn el_cursor
+Move the cursor to the right (if positive) or to the left (if negative)
+.Fa count
+characters.
+Returns the resulting offset of the cursor from the beginning of the line.
.It Fn el_line
Return the editing information for the current line in a
.Fa LineInfo
@@ -568,7 +654,7 @@ Insert
into the line at the cursor.
Returns \-1 if
.Fa str
-is empty or will not fit, and 0 otherwise.
+is empty or won't fit, and 0 otherwise.
.It Fn el_deletestr
Delete
.Fa count
@@ -586,7 +672,9 @@ The following functions are available:
.Bl -tag -width 4n
.It Fn history_init
Initialise the history list, and return a data structure
-to be used by all other history list functions.
+to be used by all other history list functions, or
+.Dv NULL
+on failure.
.It Fn history_end
Clean up and finish with
.Fa h ,
@@ -623,7 +711,7 @@ 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.
+is the argument given to a function when it's invoked.
.It Dv H_FIRST
Return the first element in the history.
.It Dv H_LAST
@@ -655,12 +743,12 @@ as a new element to the history, and, if necessary,
removing the oldest entry to keep the list to the created size.
If
.Dv H_SETUNIQUE
-was has been called with a non-zero arguments, the element
+has been called with a non-zero argument, the element
will not be entered into the history if its contents match
the ones of the current history element.
If the element is entered
.Fn history
-returns 1, if it is ignored as a duplicate returns 0.
+returns 1; if it is ignored as a duplicate returns 0.
Finally
.Fn history
returns \-1 if an error occurred.
@@ -682,9 +770,11 @@ Load the history list stored in
.It Dv H_SAVE , Fa "const char *file"
Save the history list to
.Fa file .
-.It Dv H_SAVE_FP , Fa "FILE*"
+.It Dv H_SAVE_FP , Fa "FILE *fp"
Save the history list to the opened
-.Fa FILE* .
+.Ft FILE
+pointer
+.Fa fp .
.It Dv H_SETUNIQUE , Fa "int unique"
Set flag that adjacent identical event strings should not be entered
into the history.
@@ -701,9 +791,8 @@ The caller is responsible for free'ing the string in the returned
.Fa HistEvent .
.El
.Pp
-The
.Fn history
-function returns \*[Ge] 0 if the operation
+returns \*[Gt]= 0 if the operation
.Fa op
succeeds.
Otherwise, \-1 is returned and
@@ -747,7 +836,7 @@ and before a new line is to be tokenized.
.It Fn tok_line
Tokenize
.Fa li ,
-if successful, modify
+If successful, modify:
.Fa argv
to contain the words,
.Fa argc
@@ -774,12 +863,14 @@ and
.Aq newline .
A positive exit code indicates that another line should be read
and tokenization attempted again.
+.
.It Fn tok_str
A simpler form of
.Fn tok_line ;
.Fa str
is a NUL terminated string to tokenize.
.El
+.
.\"XXX.Sh EXAMPLES
.\"XXX: provide some examples
.Sh SEE ALSO
@@ -796,10 +887,9 @@ library first appeared in
.Dv CC_REDISPLAY
appeared in
.Nx 1.3 .
-.Dv CC_REFRESH_BEEP
-and
+.Dv CC_REFRESH_BEEP ,
.Dv EL_EDITMODE
-appeared in
+and the readline emulation appeared in
.Nx 1.4 .
.Dv EL_RPROMPT
appeared in
@@ -817,6 +907,10 @@ wrote this manual and implemented
.Dv EL_EDITMODE ,
and
.Dv EL_RPROMPT .
+.An Jaromir Dolecek
+implemented the readline emulation.
+.An Johny Mattsson
+implemented wide-character support.
.Sh BUGS
At this time, it is the responsibility of the caller to
check the result of the
diff --git a/lib/libedit/editrc.5 b/lib/libedit/editrc.5
index 6e04ea1..139f573 100644
--- a/lib/libedit/editrc.5
+++ b/lib/libedit/editrc.5
@@ -1,4 +1,4 @@
-.\" $NetBSD: editrc.5,v 1.24 2009/04/11 22:17:52 wiz Exp $
+.\" $NetBSD: editrc.5,v 1.29 2014/12/25 13:39:41 wiz Exp $
.\"
.\" Copyright (c) 1997-2000 The NetBSD Foundation, Inc.
.\" All rights reserved.
@@ -28,7 +28,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd October 18, 2003
+.Dd December 25, 2014
.Dt EDITRC 5
.Os
.Sh NAME
@@ -44,7 +44,8 @@ file defines various settings to be used by the
library.
.Pp
The format of each line is:
-.Dl [prog:]command [arg [...]]
+.Pp
+.Dl [prog:]command [arg ...]
.Pp
.Ar command
is one of the
@@ -105,16 +106,12 @@ to
.Ar key .
Options include:
.Bl -tag -width 4n
-.It Fl e
-Bind all keys to the standard GNU Emacs-like bindings.
-.It Fl v
-Bind all keys to the standard
-.Xr vi 1 Ns -like
-bindings.
.It Fl a
List or change key bindings in the
.Xr vi 1
mode alternate (command mode) key map.
+.It Fl e
+Bind all keys to the standard GNU Emacs-like bindings.
.It Fl k
.Ar key
is interpreted as a symbolic arrow key name, which may be one of
@@ -136,6 +133,10 @@ Bound keys in
.Ar command
are themselves reinterpreted, and this continues for ten levels of
interpretation.
+.It Fl v
+Bind all keys to the standard
+.Xr vi 1 Ns -like
+bindings.
.El
.Pp
.Ar command
@@ -150,8 +151,10 @@ can contain control characters of the form
.Sm off
.Sq No ^ Ar character
.Sm on
-(e.g.\&
-.Sq ^A ) ,
+.Po
+e.g.\&
+.Sq ^A
+.Pc ,
and the following backslashed escape sequences:
.Pp
.Bl -tag -compact -offset indent -width 4n
@@ -186,7 +189,7 @@ and
.Sq ^ .
.It Ic echotc Oo Fl sv Oc Ar arg Ar ...
Exercise terminal capabilities given in
-.Ar arg Ar ... .
+.Ar arg ... .
If
.Ar arg
is
@@ -194,7 +197,8 @@ is
.Sq cols ,
.Sq lines ,
.Sq rows ,
-.Sq meta or
+.Sq meta ,
+or
.Sq tabs ,
the value of that capability is printed, with
.Dq yes
@@ -207,7 +211,7 @@ returns an empty string for non-existent capabilities, rather than
causing an error.
.Fl v
causes messages to be verbose.
-.It Ic edit Op Cm on | off
+.It Ic edit Op Li on | Li off
Enable or disable the
.Nm editline
functionality in a program.
@@ -229,9 +233,6 @@ is non zero, only keep unique history entries.
If
.Dv n
is zero, then keep all entries (the default).
-.It Ic telltc
-List the values of all the terminal capabilities (see
-.Xr termcap 5 ) .
.It Ic settc Ar cap Ar val
Set the terminal capability
.Ar cap
@@ -262,9 +263,13 @@ set of tty modes respectively; defaulting to
Without other arguments,
.Ic setty
lists the modes in the chosen set which are fixed on
-.Pq Sq +mode
+.Po
+.Sq +mode
+.Pc
or off
-.Pq Sq -mode .
+.Po
+.Sq -mode
+.Pc .
.Fl a
lists all tty modes in the chosen set regardless of the setting.
With
@@ -286,6 +291,9 @@ If
is empty
then the character is set to
.Dv _POSIX_VDISABLE .
+.It Ic telltc
+List the values of all the terminal capabilities (see
+.Xr termcap 5 ) .
.El
.Sh EDITOR COMMANDS
The following editor commands are available for use in key bindings:
@@ -295,11 +303,11 @@ The following editor commands are available for use in key bindings:
Vi paste previous deletion to the right of the cursor.
.It Ic vi-paste-prev
Vi paste previous deletion to the left of the cursor.
-.It Ic vi-prev-space-word
+.It Ic vi-prev-big-word
Vi move to the previous space delimited word.
.It Ic vi-prev-word
Vi move to the previous word.
-.It Ic vi-next-space-word
+.It Ic vi-next-big-word
Vi move to the next space delimited word.
.It Ic vi-next-word
Vi move to the next word.
@@ -327,9 +335,9 @@ Vi enter insert mode after the cursor.
Vi enter insert mode at end of line.
.It Ic vi-delete-meta
Vi delete prefix command.
-.It Ic vi-end-word
+.It Ic vi-end-big-word
Vi move to the end of the current space delimited word.
-.It Ic vi-to-end-word
+.It Ic vi-end-word
Vi move to the end of the current word.
.It Ic vi-undo
Vi undo last change.
@@ -363,6 +371,28 @@ Vi move up to the character specified previous.
Vi repeat current character search in the same search direction.
.It Ic vi-repeat-prev-char
Vi repeat current character search in the opposite search direction.
+.It Ic vi-match
+Vi go to matching () {} or [].
+.It Ic vi-undo-line
+Vi undo all changes to line.
+.It Ic vi-to-column
+Vi go to specified column.
+.It Ic vi-yank-end
+Vi yank to end of line.
+.It Ic vi-yank
+Vi yank.
+.It Ic vi-comment-out
+Vi comment out current command.
+.It Ic vi-alias
+Vi include shell alias.
+.It Ic vi-to-history-line
+Vi go to specified history file line..
+.It Ic vi-histedit
+Vi edit history line with vi.
+.It Ic vi-history-word
+Vi append word from previous input line.
+.It Ic vi-redo
+Vi redo last non-motion command.
.It Ic em-delete-or-list
Delete character under cursor or list completions if at end of line.
.It Ic em-delete-next-word
diff --git a/lib/libedit/el.c b/lib/libedit/el.c
index d6cfb2d..57ea6e5 100644
--- a/lib/libedit/el.c
+++ b/lib/libedit/el.c
@@ -1,3 +1,5 @@
+/* $NetBSD: el.c,v 1.73 2014/06/18 18:12:28 christos Exp $ */
+
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -28,12 +30,15 @@
* 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.
- *
- * $NetBSD: el.c,v 1.55 2009/07/25 21:19:23 christos Exp $
*/
+#include "config.h"
#if !defined(lint) && !defined(SCCSID)
+#if 0
static char sccsid[] = "@(#)el.c 8.2 (Berkeley) 1/3/94";
+#else
+__RCSID("$NetBSD: el.c,v 1.73 2014/06/18 18:12:28 christos Exp $");
+#endif
#endif /* not lint && not SCCSID */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
@@ -41,29 +46,34 @@ __FBSDID("$FreeBSD$");
/*
* el.c: EditLine interface functions
*/
-#include "sys.h"
-
#include <sys/types.h>
#include <sys/param.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <ctype.h>
+#include <locale.h>
+#include <langinfo.h>
#include "el.h"
-#define HAVE_ISSETUGID
-
/* el_init():
* Initialize editline and set default parameters.
*/
public EditLine *
el_init(const char *prog, FILE *fin, FILE *fout, FILE *ferr)
{
+ return el_init_fd(prog, fin, fout, ferr, fileno(fin), fileno(fout),
+ fileno(ferr));
+}
- EditLine *el = (EditLine *) el_malloc(sizeof(EditLine));
+public EditLine *
+el_init_fd(const char *prog, FILE *fin, FILE *fout, FILE *ferr,
+ int fdin, int fdout, int fderr)
+{
+ EditLine *el = el_malloc(sizeof(*el));
if (el == NULL)
- return (NULL);
+ return NULL;
memset(el, 0, sizeof(EditLine));
@@ -71,9 +81,12 @@ el_init(const char *prog, FILE *fin, FILE *fout, FILE *ferr)
el->el_outfile = fout;
el->el_errfile = ferr;
- el->el_infd = fileno(fin);
+ el->el_infd = fdin;
+ el->el_outfd = fdout;
+ el->el_errfd = fderr;
- if ((el->el_prog = el_strdup(prog)) == NULL) {
+ el->el_prog = Strdup(ct_decode_string(prog, &el->el_scratch));
+ if (el->el_prog == NULL) {
el_free(el);
return NULL;
}
@@ -82,13 +95,19 @@ el_init(const char *prog, FILE *fin, FILE *fout, FILE *ferr)
* Initialize all the modules. Order is important!!!
*/
el->el_flags = 0;
+#ifdef WIDECHAR
+ if (setlocale(LC_CTYPE, NULL) != NULL){
+ if (strcmp(nl_langinfo(CODESET), "UTF-8") == 0)
+ el->el_flags |= CHARSET_IS_UTF8;
+ }
+#endif
- if (term_init(el) == -1) {
+ if (terminal_init(el) == -1) {
el_free(el->el_prog);
el_free(el);
return NULL;
}
- (void) key_init(el);
+ (void) keymacro_init(el);
(void) map_init(el);
if (tty_init(el) == -1)
el->el_flags |= NO_TTY;
@@ -99,7 +118,7 @@ el_init(const char *prog, FILE *fin, FILE *fout, FILE *ferr)
(void) sig_init(el);
(void) read_init(el);
- return (el);
+ return el;
}
@@ -115,8 +134,8 @@ el_end(EditLine *el)
el_reset(el);
- term_end(el);
- key_end(el);
+ terminal_end(el);
+ keymacro_end(el);
map_end(el);
tty_end(el);
ch_end(el);
@@ -125,8 +144,14 @@ el_end(EditLine *el)
prompt_end(el);
sig_end(el);
- el_free((ptr_t) el->el_prog);
- el_free((ptr_t) el);
+ el_free(el->el_prog);
+#ifdef WIDECHAR
+ el_free(el->el_scratch.cbuff);
+ el_free(el->el_scratch.wbuff);
+ el_free(el->el_lgcyconv.cbuff);
+ el_free(el->el_lgcyconv.wbuff);
+#endif
+ el_free(el);
}
@@ -146,13 +171,13 @@ el_reset(EditLine *el)
* set the editline parameters
*/
public int
-el_set(EditLine *el, int op, ...)
+FUN(el,set)(EditLine *el, int op, ...)
{
va_list ap;
int rv = 0;
if (el == NULL)
- return (-1);
+ return -1;
va_start(ap, op);
switch (op) {
@@ -160,25 +185,39 @@ el_set(EditLine *el, int op, ...)
case EL_RPROMPT: {
el_pfunc_t p = va_arg(ap, el_pfunc_t);
- rv = prompt_set(el, p, 0, op);
+ rv = prompt_set(el, p, 0, op, 1);
+ break;
+ }
+
+ case EL_RESIZE: {
+ el_zfunc_t p = va_arg(ap, el_zfunc_t);
+ void *arg = va_arg(ap, void *);
+ rv = ch_resizefun(el, p, arg);
+ break;
+ }
+
+ case EL_ALIAS_TEXT: {
+ el_afunc_t p = va_arg(ap, el_afunc_t);
+ void *arg = va_arg(ap, void *);
+ rv = ch_aliasfun(el, p, arg);
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);
+ int c = va_arg(ap, int);
- rv = prompt_set(el, p, c, op);
+ rv = prompt_set(el, p, c, op, 1);
break;
}
case EL_TERMINAL:
- rv = term_set(el, va_arg(ap, char *));
+ rv = terminal_set(el, va_arg(ap, char *));
break;
case EL_EDITOR:
- rv = map_set_editor(el, va_arg(ap, char *));
+ rv = map_set_editor(el, va_arg(ap, Char *));
break;
case EL_SIGNAL:
@@ -191,40 +230,39 @@ el_set(EditLine *el, int op, ...)
case EL_BIND:
case EL_TELLTC:
case EL_SETTC:
- case EL_GETTC:
case EL_ECHOTC:
case EL_SETTY:
{
- const char *argv[20];
+ const Char *argv[20];
int i;
- for (i = 1; i < 20; i++)
- if ((argv[i] = va_arg(ap, char *)) == NULL)
+ for (i = 1; i < (int)__arraycount(argv); i++)
+ if ((argv[i] = va_arg(ap, Char *)) == NULL)
break;
switch (op) {
case EL_BIND:
- argv[0] = "bind";
+ argv[0] = STR("bind");
rv = map_bind(el, i, argv);
break;
case EL_TELLTC:
- argv[0] = "telltc";
- rv = term_telltc(el, i, argv);
+ argv[0] = STR("telltc");
+ rv = terminal_telltc(el, i, argv);
break;
case EL_SETTC:
- argv[0] = "settc";
- rv = term_settc(el, i, argv);
+ argv[0] = STR("settc");
+ rv = terminal_settc(el, i, argv);
break;
case EL_ECHOTC:
- argv[0] = "echotc";
- rv = term_echotc(el, i, argv);
+ argv[0] = STR("echotc");
+ rv = terminal_echotc(el, i, argv);
break;
case EL_SETTY:
- argv[0] = "setty";
+ argv[0] = STR("setty");
rv = tty_stty(el, i, argv);
break;
@@ -238,8 +276,8 @@ el_set(EditLine *el, int op, ...)
case EL_ADDFN:
{
- char *name = va_arg(ap, char *);
- char *help = va_arg(ap, char *);
+ Char *name = va_arg(ap, Char *);
+ Char *help = va_arg(ap, Char *);
el_func_t func = va_arg(ap, el_func_t);
rv = map_addfunc(el, name, help, func);
@@ -249,9 +287,11 @@ el_set(EditLine *el, int op, ...)
case EL_HIST:
{
hist_fun_t func = va_arg(ap, hist_fun_t);
- ptr_t ptr = va_arg(ap, char *);
+ void *ptr = va_arg(ap, void *);
rv = hist_set(el, func, ptr);
+ if (!(el->el_flags & CHARSET_IS_UTF8))
+ el->el_flags &= ~NARROW_HISTORY;
break;
}
@@ -267,6 +307,7 @@ el_set(EditLine *el, int op, ...)
{
el_rfunc_t rc = va_arg(ap, el_rfunc_t);
rv = el_read_setfn(el, rc);
+ el->el_flags &= ~NARROW_READ;
break;
}
@@ -311,9 +352,11 @@ el_set(EditLine *el, int op, ...)
break;
case 1:
el->el_outfile = fp;
+ el->el_outfd = fileno(fp);
break;
case 2:
el->el_errfile = fp;
+ el->el_errfd = fileno(fp);
break;
default:
rv = -1;
@@ -325,7 +368,7 @@ el_set(EditLine *el, int op, ...)
case EL_REFRESH:
re_clear_display(el);
re_refresh(el);
- term__flush(el);
+ terminal__flush(el);
break;
default:
@@ -334,7 +377,7 @@ el_set(EditLine *el, int op, ...)
}
va_end(ap);
- return (rv);
+ return rv;
}
@@ -342,7 +385,7 @@ el_set(EditLine *el, int op, ...)
* retrieve the editline parameters
*/
public int
-el_get(EditLine *el, int op, ...)
+FUN(el,get)(EditLine *el, int op, ...)
{
va_list ap;
int rv;
@@ -356,14 +399,20 @@ el_get(EditLine *el, int op, ...)
case EL_PROMPT:
case EL_RPROMPT: {
el_pfunc_t *p = va_arg(ap, el_pfunc_t *);
- char *c = va_arg(ap, char *);
+ rv = prompt_get(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, Char *);
rv = prompt_get(el, p, c, op);
break;
}
case EL_EDITOR:
- rv = map_get_editor(el, va_arg(ap, const char **));
+ rv = map_get_editor(el, va_arg(ap, const Char **));
break;
case EL_SIGNAL:
@@ -377,7 +426,7 @@ el_get(EditLine *el, int op, ...)
break;
case EL_TERMINAL:
- term_get(el, va_arg(ap, const char **));
+ terminal_get(el, va_arg(ap, const char **));
rv = 0;
break;
@@ -387,44 +436,15 @@ el_get(EditLine *el, int op, ...)
char *argv[20];
int i;
- for (i = 1; i < (int)(sizeof(argv) / sizeof(argv[0])); i++)
+ for (i = 1; i < (int)__arraycount(argv); i++)
if ((argv[i] = va_arg(ap, char *)) == NULL)
break;
- switch (op) {
- case EL_GETTC:
- argv[0] = name;
- rv = term_gettc(el, i, argv);
- break;
-
- default:
- rv = -1;
- EL_ABORT((el->el_errfile, "Bad op %d\n", op));
- break;
- }
+ argv[0] = name;
+ rv = terminal_gettc(el, i, argv);
break;
}
-#if 0 /* XXX */
- case EL_ADDFN:
- {
- char *name = va_arg(ap, char *);
- char *help = va_arg(ap, char *);
- el_func_t func = va_arg(ap, el_func_t);
-
- rv = map_addfunc(el, name, help, func);
- break;
- }
-
- case EL_HIST:
- {
- hist_fun_t func = va_arg(ap, hist_fun_t);
- ptr_t ptr = va_arg(ap, char *);
- rv = hist_set(el, func, ptr);
- }
- break;
-#endif /* XXX */
-
case EL_GETCFN:
*va_arg(ap, el_rfunc_t *) = el_read_getfn(el);
rv = 0;
@@ -436,7 +456,7 @@ el_get(EditLine *el, int op, ...)
break;
case EL_UNBUFFERED:
- *va_arg(ap, int *) = (!(el->el_flags & UNBUFFERED));
+ *va_arg(ap, int *) = (el->el_flags & UNBUFFERED) != 0;
rv = 0;
break;
@@ -470,18 +490,18 @@ el_get(EditLine *el, int op, ...)
}
va_end(ap);
- return (rv);
+ return rv;
}
/* el_line():
* Return editing info
*/
-public const LineInfo *
-el_line(EditLine *el)
+public const TYPE(LineInfo) *
+FUN(el,line)(EditLine *el)
{
- return (const LineInfo *) (void *) &el->el_line;
+ return (const TYPE(LineInfo) *)(void *)&el->el_line;
}
@@ -494,23 +514,24 @@ el_source(EditLine *el, const char *fname)
FILE *fp;
size_t len;
char *ptr;
-#ifdef HAVE_ISSETUGID
- char path[MAXPATHLEN];
-#endif
+ char *path = NULL;
+ const Char *dptr;
+ int error = 0;
fp = NULL;
if (fname == NULL) {
#ifdef HAVE_ISSETUGID
static const char elpath[] = "/.editrc";
+ size_t plen = sizeof(elpath);
if (issetugid())
- return (-1);
+ return -1;
if ((ptr = getenv("HOME")) == NULL)
- return (-1);
- if (strlcpy(path, ptr, sizeof(path)) >= sizeof(path))
- return (-1);
- if (strlcat(path, elpath, sizeof(path)) >= sizeof(path))
- return (-1);
+ return -1;
+ plen += strlen(ptr);
+ if ((path = el_malloc(plen * sizeof(*path))) == NULL)
+ return -1;
+ (void)snprintf(path, plen, "%s%s", ptr, elpath);
fname = path;
#else
/*
@@ -518,33 +539,37 @@ el_source(EditLine *el, const char *fname)
* to keep from inadvertently opening up the user to a security
* hole.
*/
- return (-1);
+ return -1;
#endif
}
if (fp == NULL)
fp = fopen(fname, "r");
- if (fp == NULL)
- return (-1);
+ if (fp == NULL) {
+ el_free(path);
+ return -1;
+ }
while ((ptr = fgetln(fp, &len)) != NULL) {
- if (len > 0 && ptr[len - 1] == '\n')
+ if (*ptr == '\n')
+ continue; /* Empty line. */
+ dptr = ct_decode_string(ptr, &el->el_scratch);
+ if (!dptr)
+ continue;
+ if (len > 0 && dptr[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 == '#')
+ while (*dptr != '\0' && Isspace(*dptr))
+ dptr++;
+ if (*dptr == '#')
continue; /* ignore, this is a comment line */
-
- if (parse_line(el, ptr) == -1) {
- (void) fclose(fp);
- return (-1);
- }
+ if ((error = parse_line(el, dptr)) == -1)
+ break;
}
+ el_free(path);
(void) fclose(fp);
- return (0);
+ return error;
}
@@ -562,8 +587,8 @@ el_resize(EditLine *el)
(void) sigprocmask(SIG_BLOCK, &nset, &oset);
/* get the correct window size */
- if (term_get_size(el, &lins, &cols))
- term_change_size(el, lins, cols);
+ if (terminal_get_size(el, &lins, &cols))
+ terminal_change_size(el, lins, cols);
(void) sigprocmask(SIG_SETMASK, &oset, NULL);
}
@@ -576,7 +601,7 @@ public void
el_beep(EditLine *el)
{
- term_beep(el);
+ terminal_beep(el);
}
@@ -585,24 +610,25 @@ el_beep(EditLine *el)
*/
protected int
/*ARGSUSED*/
-el_editmode(EditLine *el, int argc, const char **argv)
+el_editmode(EditLine *el, int argc, const Char **argv)
{
- const char *how;
+ const Char *how;
if (argv == NULL || argc != 2 || argv[1] == NULL)
- return (-1);
+ return -1;
how = argv[1];
- if (strcmp(how, "on") == 0) {
+ if (Strcmp(how, STR("on")) == 0) {
el->el_flags &= ~EDIT_DISABLED;
tty_rawmode(el);
- } else if (strcmp(how, "off") == 0) {
+ } else if (Strcmp(how, STR("off")) == 0) {
tty_cookedmode(el);
el->el_flags |= EDIT_DISABLED;
}
else {
- (void) fprintf(el->el_errfile, "edit: Bad value `%s'.\n", how);
- return (-1);
+ (void) fprintf(el->el_errfile, "edit: Bad value `" FSTR "'.\n",
+ how);
+ return -1;
}
- return (0);
+ return 0;
}
diff --git a/lib/libedit/el.h b/lib/libedit/el.h
index 67d01ff..ed3d2ef 100644
--- a/lib/libedit/el.h
+++ b/lib/libedit/el.h
@@ -1,3 +1,5 @@
+/* $NetBSD: el.h,v 1.25 2011/07/29 23:44:44 christos Exp $ */
+
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -30,7 +32,6 @@
* SUCH DAMAGE.
*
* @(#)el.h 8.1 (Berkeley) 6/4/93
- * $NetBSD: el.h,v 1.17 2006/12/15 22:13:33 christos Exp $
* $FreeBSD$
*/
@@ -46,15 +47,21 @@
#define VIDEFAULT
#define ANCHOR
+#include "histedit.h"
+#include "chartype.h"
#include <stdio.h>
#include <sys/types.h>
-#define EL_BUFSIZ 1024 /* Maximum line size */
+#define EL_BUFSIZ ((size_t)1024) /* Maximum line size */
#define HANDLE_SIGNALS 0x01
#define NO_TTY 0x02
#define EDIT_DISABLED 0x04
#define UNBUFFERED 0x08
+#define CHARSET_IS_UTF8 0x10
+#define IGNORE_EXTCHARS 0x20 /* Ignore characters read > 0xff */
+#define NARROW_HISTORY 0x40
+#define NARROW_READ 0x80
typedef int bool_t; /* True or not */
@@ -66,10 +73,10 @@ typedef struct coord_t { /* Position on the screen */
} coord_t;
typedef struct el_line_t {
- char *buffer; /* Input line */
- char *cursor; /* Cursor position */
- char *lastchar; /* Last character */
- const char *limit; /* Max position */
+ Char *buffer; /* Input line */
+ Char *cursor; /* Cursor position */
+ Char *lastchar; /* Last character */
+ const Char *limit; /* Max position */
} el_line_t;
/*
@@ -82,21 +89,20 @@ typedef struct el_state_t {
int metanext; /* Is the next char a meta char */
el_action_t lastcmd; /* Previous command */
el_action_t thiscmd; /* this command */
- char thisch; /* char that generated it */
+ Char thisch; /* char that generated it */
} el_state_t;
/*
* Until we come up with something better...
*/
-#define el_strdup(a) strdup(a)
#define el_malloc(a) malloc(a)
#define el_realloc(a,b) realloc(a, b)
#define el_free(a) free(a)
#include "tty.h"
#include "prompt.h"
-#include "key.h"
-#include "term.h"
+#include "keymacro.h"
+#include "terminal.h"
#include "refresh.h"
#include "chared.h"
#include "common.h"
@@ -109,34 +115,41 @@ typedef struct el_state_t {
#include "read.h"
struct editline {
- char *el_prog; /* the program name */
+ Char *el_prog; /* the program name */
FILE *el_infile; /* Stdio stuff */
FILE *el_outfile; /* Stdio stuff */
FILE *el_errfile; /* Stdio stuff */
int el_infd; /* Input file descriptor */
+ int el_outfd; /* Output file descriptor */
+ int el_errfd; /* Error 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 */
+ Char **el_display; /* Real screen image = what is there */
+ Char **el_vdisplay; /* Virtual screen image = what we see */
void *el_data; /* Client data */
el_line_t el_line; /* The current line information */
el_state_t el_state; /* Current editor state */
- el_term_t el_term; /* Terminal dependent stuff */
+ el_terminal_t el_terminal; /* Terminal dependent stuff */
el_tty_t el_tty; /* Tty dependent stuff */
el_refresh_t el_refresh; /* Refresh stuff */
el_prompt_t el_prompt; /* Prompt stuff */
el_prompt_t el_rprompt; /* Prompt stuff */
el_chared_t el_chared; /* Characted editor stuff */
el_map_t el_map; /* Key mapping stuff */
- el_key_t el_key; /* Key binding stuff */
+ el_keymacro_t el_keymacro; /* Key binding stuff */
el_history_t el_history; /* History stuff */
el_search_t el_search; /* Search stuff */
el_signal_t el_signal; /* Signal handling stuff */
el_read_t el_read; /* Character reading stuff */
+#ifdef WIDECHAR
+ ct_buffer_t el_scratch; /* Scratch conversion buffer */
+ ct_buffer_t el_lgcyconv; /* Buffer for legacy wrappers */
+ LineInfo el_lgcylinfo; /* Legacy LineInfo buffer */
+#endif
};
-protected int el_editmode(EditLine *, int, const char **);
+protected int el_editmode(EditLine *, int, const Char **);
#ifdef DEBUG
#define EL_ABORT(a) do { \
diff --git a/lib/libedit/eln.c b/lib/libedit/eln.c
new file mode 100644
index 0000000..013aa3e
--- /dev/null
+++ b/lib/libedit/eln.c
@@ -0,0 +1,401 @@
+/* $NetBSD: eln.c,v 1.19 2015/05/18 15:07:04 christos Exp $ */
+
+/*-
+ * Copyright (c) 2009 The NetBSD Foundation, Inc.
+ * 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. 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
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION 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 "config.h"
+#if !defined(lint) && !defined(SCCSID)
+__RCSID("$NetBSD: eln.c,v 1.19 2015/05/18 15:07:04 christos Exp $");
+#endif /* not lint && not SCCSID */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include "histedit.h"
+#include "el.h"
+#include "read.h"
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+public int
+el_getc(EditLine *el, char *cp)
+{
+ int num_read;
+ wchar_t wc = 0;
+
+ if (!(el->el_flags & CHARSET_IS_UTF8))
+ el->el_flags |= IGNORE_EXTCHARS;
+ num_read = el_wgetc (el, &wc);
+ if (!(el->el_flags & CHARSET_IS_UTF8))
+ el->el_flags &= ~IGNORE_EXTCHARS;
+
+ if (num_read > 0)
+ *cp = (char)wc;
+ return num_read;
+}
+
+
+public void
+el_push(EditLine *el, const char *str)
+{
+ /* Using multibyte->wide string decoding works fine under single-byte
+ * character sets too, and Does The Right Thing. */
+ el_wpush(el, ct_decode_string(str, &el->el_lgcyconv));
+}
+
+
+public const char *
+el_gets(EditLine *el, int *nread)
+{
+ const wchar_t *tmp;
+
+ if (!(el->el_flags & CHARSET_IS_UTF8))
+ el->el_flags |= IGNORE_EXTCHARS;
+ tmp = el_wgets(el, nread);
+ if (tmp != NULL) {
+ size_t nwread = 0;
+ for (int i = 0; i < *nread; i++)
+ nwread += ct_enc_width(tmp[i]);
+ *nread = (int)nwread;
+ }
+ if (!(el->el_flags & CHARSET_IS_UTF8))
+ el->el_flags &= ~IGNORE_EXTCHARS;
+ return ct_encode_string(tmp, &el->el_lgcyconv);
+}
+
+
+public int
+el_parse(EditLine *el, int argc, const char *argv[])
+{
+ int ret;
+ const wchar_t **wargv;
+
+ wargv = (const wchar_t **)
+ ct_decode_argv(argc, argv, &el->el_lgcyconv);
+ if (!wargv)
+ return -1;
+ ret = el_wparse(el, argc, wargv);
+ ct_free_argv(wargv);
+
+ return ret;
+}
+
+
+public int
+el_set(EditLine *el, int op, ...)
+{
+ va_list ap;
+ int ret;
+
+ if (!el)
+ return -1;
+ va_start(ap, op);
+
+ switch (op) {
+ case EL_PROMPT: /* el_pfunc_t */
+ case EL_RPROMPT: {
+ el_pfunc_t p = va_arg(ap, el_pfunc_t);
+ ret = prompt_set(el, p, 0, op, 0);
+ break;
+ }
+
+ case EL_RESIZE: {
+ el_zfunc_t p = va_arg(ap, el_zfunc_t);
+ void *arg = va_arg(ap, void *);
+ ret = ch_resizefun(el, p, arg);
+ break;
+ }
+
+ case EL_ALIAS_TEXT: {
+ el_afunc_t p = va_arg(ap, el_afunc_t);
+ void *arg = va_arg(ap, void *);
+ ret = ch_aliasfun(el, p, arg);
+ break;
+ }
+
+ case EL_PROMPT_ESC:
+ case EL_RPROMPT_ESC: {
+ el_pfunc_t p = va_arg(ap, el_pfunc_t);
+ int c = va_arg(ap, int);
+
+ ret = prompt_set(el, p, c, op, 0);
+ break;
+ }
+
+ case EL_TERMINAL: /* const char * */
+ ret = el_wset(el, op, va_arg(ap, char *));
+ break;
+
+ case EL_EDITOR: /* const wchar_t * */
+ ret = el_wset(el, op, ct_decode_string(va_arg(ap, char *),
+ &el->el_lgcyconv));
+ break;
+
+ case EL_SIGNAL: /* int */
+ case EL_EDITMODE:
+ case EL_UNBUFFERED:
+ case EL_PREP_TERM:
+ ret = el_wset(el, op, va_arg(ap, int));
+ break;
+
+ case EL_BIND: /* const char * list -> const wchar_t * list */
+ case EL_TELLTC:
+ case EL_SETTC:
+ case EL_ECHOTC:
+ case EL_SETTY: {
+ const char *argv[20];
+ int i;
+ const wchar_t **wargv;
+ for (i = 1; i < (int)__arraycount(argv) - 1; ++i)
+ if ((argv[i] = va_arg(ap, const char *)) == NULL)
+ break;
+ argv[0] = argv[i] = NULL;
+ wargv = (const wchar_t **)
+ ct_decode_argv(i + 1, argv, &el->el_lgcyconv);
+ if (!wargv) {
+ ret = -1;
+ goto out;
+ }
+ /*
+ * AFAIK we can't portably pass through our new wargv to
+ * el_wset(), so we have to reimplement the body of
+ * el_wset() for these ops.
+ */
+ switch (op) {
+ case EL_BIND:
+ wargv[0] = STR("bind");
+ ret = map_bind(el, i, wargv);
+ break;
+ case EL_TELLTC:
+ wargv[0] = STR("telltc");
+ ret = terminal_telltc(el, i, wargv);
+ break;
+ case EL_SETTC:
+ wargv[0] = STR("settc");
+ ret = terminal_settc(el, i, wargv);
+ break;
+ case EL_ECHOTC:
+ wargv[0] = STR("echotc");
+ ret = terminal_echotc(el, i, wargv);
+ break;
+ case EL_SETTY:
+ wargv[0] = STR("setty");
+ ret = tty_stty(el, i, wargv);
+ break;
+ default:
+ ret = -1;
+ }
+ ct_free_argv(wargv);
+ break;
+ }
+
+ /* XXX: do we need to change el_func_t too? */
+ case EL_ADDFN: { /* const char *, const char *, el_func_t */
+ const char *args[2];
+ el_func_t func;
+ wchar_t **wargv;
+
+ args[0] = va_arg(ap, const char *);
+ args[1] = va_arg(ap, const char *);
+ func = va_arg(ap, el_func_t);
+
+ wargv = ct_decode_argv(2, args, &el->el_lgcyconv);
+ if (!wargv) {
+ ret = -1;
+ goto out;
+ }
+ // XXX: The two strdup's leak
+ ret = map_addfunc(el, Strdup(wargv[0]), Strdup(wargv[1]),
+ func);
+ ct_free_argv(wargv);
+ break;
+ }
+ case EL_HIST: { /* hist_fun_t, const char * */
+ hist_fun_t fun = va_arg(ap, hist_fun_t);
+ void *ptr = va_arg(ap, void *);
+ ret = hist_set(el, fun, ptr);
+ el->el_flags |= NARROW_HISTORY;
+ break;
+ }
+
+ /* XXX: do we need to change el_rfunc_t? */
+ case EL_GETCFN: /* el_rfunc_t */
+ ret = el_wset(el, op, va_arg(ap, el_rfunc_t));
+ el->el_flags |= NARROW_READ;
+ break;
+
+ case EL_CLIENTDATA: /* void * */
+ ret = el_wset(el, op, va_arg(ap, void *));
+ break;
+
+ case EL_SETFP: { /* int, FILE * */
+ int what = va_arg(ap, int);
+ FILE *fp = va_arg(ap, FILE *);
+ ret = el_wset(el, op, what, fp);
+ break;
+ }
+
+ case EL_REFRESH:
+ re_clear_display(el);
+ re_refresh(el);
+ terminal__flush(el);
+ ret = 0;
+ break;
+
+ default:
+ ret = -1;
+ break;
+ }
+
+out:
+ va_end(ap);
+ return ret;
+}
+
+
+public int
+el_get(EditLine *el, int op, ...)
+{
+ va_list ap;
+ int ret;
+
+ if (!el)
+ return -1;
+
+ va_start(ap, op);
+
+ switch (op) {
+ case EL_PROMPT: /* el_pfunc_t * */
+ case EL_RPROMPT: {
+ el_pfunc_t *p = va_arg(ap, el_pfunc_t *);
+ ret = prompt_get(el, p, 0, op);
+ break;
+ }
+
+ case EL_PROMPT_ESC: /* el_pfunc_t *, char **/
+ case EL_RPROMPT_ESC: {
+ el_pfunc_t *p = va_arg(ap, el_pfunc_t *);
+ char *c = va_arg(ap, char *);
+ wchar_t wc = 0;
+ ret = prompt_get(el, p, &wc, op);
+ *c = (char)wc;
+ break;
+ }
+
+ case EL_EDITOR: {
+ const char **p = va_arg(ap, const char **);
+ const wchar_t *pw;
+ ret = el_wget(el, op, &pw);
+ *p = ct_encode_string(pw, &el->el_lgcyconv);
+ if (!el->el_lgcyconv.csize)
+ ret = -1;
+ break;
+ }
+
+ case EL_TERMINAL: /* const char ** */
+ ret = el_wget(el, op, va_arg(ap, const char **));
+ break;
+
+ case EL_SIGNAL: /* int * */
+ case EL_EDITMODE:
+ case EL_UNBUFFERED:
+ case EL_PREP_TERM:
+ ret = el_wget(el, op, va_arg(ap, int *));
+ break;
+
+ case EL_GETTC: {
+ char *argv[20];
+ static char gettc[] = "gettc";
+ int i;
+ for (i = 1; i < (int)__arraycount(argv); ++i)
+ if ((argv[i] = va_arg(ap, char *)) == NULL)
+ break;
+ argv[0] = gettc;
+ ret = terminal_gettc(el, i, argv);
+ break;
+ }
+
+ /* XXX: do we need to change el_rfunc_t? */
+ case EL_GETCFN: /* el_rfunc_t */
+ ret = el_wget(el, op, va_arg(ap, el_rfunc_t *));
+ break;
+
+ case EL_CLIENTDATA: /* void ** */
+ ret = el_wget(el, op, va_arg(ap, void **));
+ break;
+
+ case EL_GETFP: { /* int, FILE ** */
+ int what = va_arg(ap, int);
+ FILE **fpp = va_arg(ap, FILE **);
+ ret = el_wget(el, op, what, fpp);
+ break;
+ }
+
+ default:
+ ret = -1;
+ break;
+ }
+
+ va_end(ap);
+ return ret;
+}
+
+
+const LineInfo *
+el_line(EditLine *el)
+{
+ const LineInfoW *winfo = el_wline(el);
+ LineInfo *info = &el->el_lgcylinfo;
+ size_t offset;
+ const Char *p;
+
+ info->buffer = ct_encode_string(winfo->buffer, &el->el_lgcyconv);
+
+ offset = 0;
+ for (p = winfo->buffer; p < winfo->cursor; p++)
+ offset += ct_enc_width(*p);
+ info->cursor = info->buffer + offset;
+
+ offset = 0;
+ for (p = winfo->buffer; p < winfo->lastchar; p++)
+ offset += ct_enc_width(*p);
+ info->lastchar = info->buffer + offset;
+
+ return info;
+}
+
+
+int
+el_insertstr(EditLine *el, const char *str)
+{
+ return el_winsertstr(el, ct_decode_string(str, &el->el_lgcyconv));
+}
diff --git a/lib/libedit/emacs.c b/lib/libedit/emacs.c
index edcc84b..c1c30d6 100644
--- a/lib/libedit/emacs.c
+++ b/lib/libedit/emacs.c
@@ -1,3 +1,5 @@
+/* $NetBSD: emacs.c,v 1.25 2011/07/29 15:16:33 christos Exp $ */
+
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -28,12 +30,15 @@
* 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.
- *
- * $NetBSD: emacs.c,v 1.22 2009/02/15 21:55:23 christos Exp $
*/
+#include "config.h"
#if !defined(lint) && !defined(SCCSID)
+#if 0
static char sccsid[] = "@(#)emacs.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: emacs.c,v 1.25 2011/07/29 15:16:33 christos Exp $");
+#endif
#endif /* not lint && not SCCSID */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
@@ -41,7 +46,6 @@ __FBSDID("$FreeBSD$");
/*
* emacs.c: Emacs functions
*/
-#include "sys.h"
#include "el.h"
/* em_delete_or_list():
@@ -50,22 +54,22 @@ __FBSDID("$FreeBSD$");
*/
protected el_action_t
/*ARGSUSED*/
-em_delete_or_list(EditLine *el, int c)
+em_delete_or_list(EditLine *el, Int c)
{
if (el->el_line.cursor == el->el_line.lastchar) {
/* if I'm at the end */
if (el->el_line.cursor == el->el_line.buffer) {
/* and the beginning */
- term_writec(el, c); /* then do an EOF */
- return (CC_EOF);
+ terminal_writec(el, c); /* then do an EOF */
+ return CC_EOF;
} else {
/*
* Here we could list completions, but it is an
* error right now
*/
- term_beep(el);
- return (CC_ERROR);
+ terminal_beep(el);
+ return CC_ERROR;
}
} else {
if (el->el_state.doingarg)
@@ -75,7 +79,7 @@ em_delete_or_list(EditLine *el, int c)
if (el->el_line.cursor > el->el_line.lastchar)
el->el_line.cursor = el->el_line.lastchar;
/* bounds check */
- return (CC_REFRESH);
+ return CC_REFRESH;
}
}
@@ -86,12 +90,12 @@ em_delete_or_list(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-em_delete_next_word(EditLine *el, int c __unused)
+em_delete_next_word(EditLine *el, Int c __attribute__((__unused__)))
{
- char *cp, *p, *kp;
+ Char *cp, *p, *kp;
if (el->el_line.cursor == el->el_line.lastchar)
- return (CC_ERROR);
+ return CC_ERROR;
cp = c__next_word(el->el_line.cursor, el->el_line.lastchar,
el->el_state.argument, ce__isword);
@@ -105,7 +109,7 @@ em_delete_next_word(EditLine *el, int c __unused)
if (el->el_line.cursor > el->el_line.lastchar)
el->el_line.cursor = el->el_line.lastchar;
/* bounds check */
- return (CC_REFRESH);
+ return CC_REFRESH;
}
@@ -115,17 +119,17 @@ em_delete_next_word(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-em_yank(EditLine *el, int c __unused)
+em_yank(EditLine *el, Int c __attribute__((__unused__)))
{
- char *kp, *cp;
+ Char *kp, *cp;
if (el->el_chared.c_kill.last == el->el_chared.c_kill.buf)
- return (CC_NORM);
+ return CC_NORM;
if (el->el_line.lastchar +
(el->el_chared.c_kill.last - el->el_chared.c_kill.buf) >=
el->el_line.limit)
- return (CC_ERROR);
+ return CC_ERROR;
el->el_chared.c_kill.mark = el->el_line.cursor;
cp = el->el_line.cursor;
@@ -141,7 +145,7 @@ em_yank(EditLine *el, int c __unused)
if (el->el_state.argument == 1)
el->el_line.cursor = cp;
- return (CC_REFRESH);
+ return CC_REFRESH;
}
@@ -151,9 +155,9 @@ em_yank(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-em_kill_line(EditLine *el, int c __unused)
+em_kill_line(EditLine *el, Int c __attribute__((__unused__)))
{
- char *kp, *cp;
+ Char *kp, *cp;
cp = el->el_line.buffer;
kp = el->el_chared.c_kill.buf;
@@ -163,7 +167,7 @@ em_kill_line(EditLine *el, int c __unused)
/* zap! -- delete all of it */
el->el_line.lastchar = el->el_line.buffer;
el->el_line.cursor = el->el_line.buffer;
- return (CC_REFRESH);
+ return CC_REFRESH;
}
@@ -173,12 +177,12 @@ em_kill_line(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-em_kill_region(EditLine *el, int c __unused)
+em_kill_region(EditLine *el, Int c __attribute__((__unused__)))
{
- char *kp, *cp;
+ Char *kp, *cp;
if (!el->el_chared.c_kill.mark)
- return (CC_ERROR);
+ return CC_ERROR;
if (el->el_chared.c_kill.mark > el->el_line.cursor) {
cp = el->el_line.cursor;
@@ -196,7 +200,7 @@ em_kill_region(EditLine *el, int c __unused)
c_delbefore(el, (int)(cp - el->el_chared.c_kill.mark));
el->el_line.cursor = el->el_chared.c_kill.mark;
}
- return (CC_REFRESH);
+ return CC_REFRESH;
}
@@ -206,12 +210,12 @@ em_kill_region(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-em_copy_region(EditLine *el, int c __unused)
+em_copy_region(EditLine *el, Int c __attribute__((__unused__)))
{
- char *kp, *cp;
+ Char *kp, *cp;
if (!el->el_chared.c_kill.mark)
- return (CC_ERROR);
+ return CC_ERROR;
if (el->el_chared.c_kill.mark > el->el_line.cursor) {
cp = el->el_line.cursor;
@@ -226,7 +230,7 @@ em_copy_region(EditLine *el, int c __unused)
*kp++ = *cp++; /* copy it */
el->el_chared.c_kill.last = kp;
}
- return (CC_NORM);
+ return CC_NORM;
}
@@ -235,7 +239,7 @@ em_copy_region(EditLine *el, int c __unused)
* Gosling emacs transpose chars [^T]
*/
protected el_action_t
-em_gosmacs_transpose(EditLine *el, int c)
+em_gosmacs_transpose(EditLine *el, Int c)
{
if (el->el_line.cursor > &el->el_line.buffer[1]) {
@@ -243,9 +247,9 @@ em_gosmacs_transpose(EditLine *el, int c)
c = el->el_line.cursor[-2];
el->el_line.cursor[-2] = el->el_line.cursor[-1];
el->el_line.cursor[-1] = c;
- return (CC_REFRESH);
+ return CC_REFRESH;
} else
- return (CC_ERROR);
+ return CC_ERROR;
}
@@ -255,10 +259,10 @@ em_gosmacs_transpose(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-em_next_word(EditLine *el, int c __unused)
+em_next_word(EditLine *el, Int c __attribute__((__unused__)))
{
if (el->el_line.cursor == el->el_line.lastchar)
- return (CC_ERROR);
+ return CC_ERROR;
el->el_line.cursor = c__next_word(el->el_line.cursor,
el->el_line.lastchar,
@@ -268,9 +272,9 @@ em_next_word(EditLine *el, int c __unused)
if (el->el_map.type == MAP_VI)
if (el->el_chared.c_vcmd.action != NOP) {
cv_delfini(el);
- return (CC_REFRESH);
+ return CC_REFRESH;
}
- return (CC_CURSOR);
+ return CC_CURSOR;
}
@@ -280,21 +284,21 @@ em_next_word(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-em_upper_case(EditLine *el, int c __unused)
+em_upper_case(EditLine *el, Int c __attribute__((__unused__)))
{
- char *cp, *ep;
+ Char *cp, *ep;
ep = c__next_word(el->el_line.cursor, el->el_line.lastchar,
el->el_state.argument, ce__isword);
for (cp = el->el_line.cursor; cp < ep; cp++)
- if (islower((unsigned char)*cp))
- *cp = toupper((unsigned char)*cp);
+ if (Islower(*cp))
+ *cp = Toupper(*cp);
el->el_line.cursor = ep;
if (el->el_line.cursor > el->el_line.lastchar)
el->el_line.cursor = el->el_line.lastchar;
- return (CC_REFRESH);
+ return CC_REFRESH;
}
@@ -304,29 +308,29 @@ em_upper_case(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-em_capitol_case(EditLine *el, int c __unused)
+em_capitol_case(EditLine *el, Int c __attribute__((__unused__)))
{
- char *cp, *ep;
+ Char *cp, *ep;
ep = c__next_word(el->el_line.cursor, el->el_line.lastchar,
el->el_state.argument, ce__isword);
for (cp = el->el_line.cursor; cp < ep; cp++) {
- if (isalpha((unsigned char)*cp)) {
- if (islower((unsigned char)*cp))
- *cp = toupper((unsigned char)*cp);
+ if (Isalpha(*cp)) {
+ if (Islower(*cp))
+ *cp = Toupper(*cp);
cp++;
break;
}
}
for (; cp < ep; cp++)
- if (isupper((unsigned char)*cp))
- *cp = tolower((unsigned char)*cp);
+ if (Isupper(*cp))
+ *cp = Tolower(*cp);
el->el_line.cursor = ep;
if (el->el_line.cursor > el->el_line.lastchar)
el->el_line.cursor = el->el_line.lastchar;
- return (CC_REFRESH);
+ return CC_REFRESH;
}
@@ -336,21 +340,21 @@ em_capitol_case(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-em_lower_case(EditLine *el, int c __unused)
+em_lower_case(EditLine *el, Int c __attribute__((__unused__)))
{
- char *cp, *ep;
+ Char *cp, *ep;
ep = c__next_word(el->el_line.cursor, el->el_line.lastchar,
el->el_state.argument, ce__isword);
for (cp = el->el_line.cursor; cp < ep; cp++)
- if (isupper((unsigned char)*cp))
- *cp = tolower((unsigned char)*cp);
+ if (Isupper(*cp))
+ *cp = Tolower(*cp);
el->el_line.cursor = ep;
if (el->el_line.cursor > el->el_line.lastchar)
el->el_line.cursor = el->el_line.lastchar;
- return (CC_REFRESH);
+ return CC_REFRESH;
}
@@ -360,11 +364,11 @@ em_lower_case(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-em_set_mark(EditLine *el, int c __unused)
+em_set_mark(EditLine *el, Int c __attribute__((__unused__)))
{
el->el_chared.c_kill.mark = el->el_line.cursor;
- return (CC_NORM);
+ return CC_NORM;
}
@@ -374,14 +378,14 @@ em_set_mark(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-em_exchange_mark(EditLine *el, int c __unused)
+em_exchange_mark(EditLine *el, Int c __attribute__((__unused__)))
{
- char *cp;
+ Char *cp;
cp = el->el_line.cursor;
el->el_line.cursor = el->el_chared.c_kill.mark;
el->el_chared.c_kill.mark = cp;
- return (CC_CURSOR);
+ return CC_CURSOR;
}
@@ -391,14 +395,14 @@ em_exchange_mark(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-em_universal_argument(EditLine *el, int c __unused)
+em_universal_argument(EditLine *el, Int c __attribute__((__unused__)))
{ /* multiply current argument by 4 */
if (el->el_state.argument > 1000000)
- return (CC_ERROR);
+ return CC_ERROR;
el->el_state.doingarg = 1;
el->el_state.argument *= 4;
- return (CC_ARGHACK);
+ return CC_ARGHACK;
}
@@ -408,11 +412,11 @@ em_universal_argument(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-em_meta_next(EditLine *el, int c __unused)
+em_meta_next(EditLine *el, Int c __attribute__((__unused__)))
{
el->el_state.metanext = 1;
- return (CC_ARGHACK);
+ return CC_ARGHACK;
}
@@ -421,12 +425,12 @@ em_meta_next(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-em_toggle_overwrite(EditLine *el, int c __unused)
+em_toggle_overwrite(EditLine *el, Int c __attribute__((__unused__)))
{
el->el_state.inputmode = (el->el_state.inputmode == MODE_INSERT) ?
MODE_REPLACE : MODE_INSERT;
- return (CC_NORM);
+ return CC_NORM;
}
@@ -435,12 +439,12 @@ em_toggle_overwrite(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-em_copy_prev_word(EditLine *el, int c __unused)
+em_copy_prev_word(EditLine *el, Int c __attribute__((__unused__)))
{
- char *cp, *oldc, *dp;
+ Char *cp, *oldc, *dp;
if (el->el_line.cursor == el->el_line.buffer)
- return (CC_ERROR);
+ return CC_ERROR;
oldc = el->el_line.cursor;
/* does a bounds check */
@@ -453,7 +457,7 @@ em_copy_prev_word(EditLine *el, int c __unused)
el->el_line.cursor = dp;/* put cursor at end */
- return (CC_REFRESH);
+ return CC_REFRESH;
}
@@ -462,11 +466,11 @@ em_copy_prev_word(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-em_inc_search_next(EditLine *el, int c __unused)
+em_inc_search_next(EditLine *el, Int c __attribute__((__unused__)))
{
el->el_search.patlen = 0;
- return (ce_inc_search(el, ED_SEARCH_NEXT_HISTORY));
+ return ce_inc_search(el, ED_SEARCH_NEXT_HISTORY);
}
@@ -475,11 +479,11 @@ em_inc_search_next(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-em_inc_search_prev(EditLine *el, int c __unused)
+em_inc_search_prev(EditLine *el, Int c __attribute__((__unused__)))
{
el->el_search.patlen = 0;
- return (ce_inc_search(el, ED_SEARCH_PREV_HISTORY));
+ return ce_inc_search(el, ED_SEARCH_PREV_HISTORY);
}
@@ -489,11 +493,11 @@ em_inc_search_prev(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-em_delete_prev_char(EditLine *el, int c __unused)
+em_delete_prev_char(EditLine *el, Int c __attribute__((__unused__)))
{
if (el->el_line.cursor <= el->el_line.buffer)
- return (CC_ERROR);
+ return CC_ERROR;
if (el->el_state.doingarg)
c_delbefore(el, el->el_state.argument);
@@ -502,5 +506,5 @@ em_delete_prev_char(EditLine *el, int c __unused)
el->el_line.cursor -= el->el_state.argument;
if (el->el_line.cursor < el->el_line.buffer)
el->el_line.cursor = el->el_line.buffer;
- return (CC_REFRESH);
+ return CC_REFRESH;
}
diff --git a/lib/libedit/filecomplete.c b/lib/libedit/filecomplete.c
index bf0d759..10d44e4 100644
--- a/lib/libedit/filecomplete.c
+++ b/lib/libedit/filecomplete.c
@@ -1,3 +1,5 @@
+/* $NetBSD: filecomplete.c,v 1.34 2014/10/18 15:07:02 riz Exp $ */
+
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
* All rights reserved.
@@ -25,10 +27,12 @@
* 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.
- *
- * $NetBSD: filecomplete.c,v 1.19 2010/06/01 18:20:26 christos Exp $
*/
+#include "config.h"
+#if !defined(lint) && !defined(SCCSID)
+__RCSID("$NetBSD: filecomplete.c,v 1.34 2014/10/18 15:07:02 riz Exp $");
+#endif /* not lint && not SCCSID */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
@@ -44,16 +48,16 @@ __FBSDID("$FreeBSD$");
#include <limits.h>
#include <errno.h>
#include <fcntl.h>
-#include <vis.h>
+
#include "el.h"
#include "fcns.h" /* for EL_NUM_FCNS */
#include "histedit.h"
#include "filecomplete.h"
-static char break_chars[] = { ' ', '\t', '\n', '"', '\\', '\'', '`',
- '>', '<', '=', ';', '|', '&', '{', '(', '\0' };
+static const Char break_chars[] = { ' ', '\t', '\n', '"', '\\', '\'', '`', '@',
+ '$', '>', '<', '=', ';', '|', '&', '{', '(', '\0' };
/* Tilde is deliberately omitted here, we treat it specially. */
-static char extra_quote_chars[] = { ')', '}', '*', '?', '[', '$', '\0' };
+static const Char extra_quote_chars[] = { ')', '}', '*', '?', '[', '$', '\0' };
/********************************/
@@ -64,18 +68,21 @@ static char extra_quote_chars[] = { ')', '}', '*', '?', '[', '$', '\0' };
* if ``user'' isn't valid user name or ``txt'' doesn't start
* w/ '~', returns pointer to strdup()ed copy of ``txt''
*
- * it's callers's responsibility to free() returned string
+ * it's the caller's responsibility to free() the returned string
*/
char *
fn_tilde_expand(const char *txt)
{
- struct passwd pwres, *pass;
+#if defined(HAVE_GETPW_R_POSIX) || defined(HAVE_GETPW_R_DRAFT)
+ struct passwd pwres;
+ char pwbuf[1024];
+#endif
+ struct passwd *pass;
char *temp;
size_t len = 0;
- char pwbuf[1024];
if (txt[0] != '~')
- return (strdup(txt));
+ return strdup(txt);
temp = strchr(txt + 1, '/');
if (temp == NULL) {
@@ -83,34 +90,49 @@ fn_tilde_expand(const char *txt)
if (temp == NULL)
return NULL;
} else {
- len = temp - txt + 1; /* text until string after slash */
- temp = malloc(len);
+ /* text until string after slash */
+ len = (size_t)(temp - txt + 1);
+ temp = el_malloc(len * sizeof(*temp));
if (temp == NULL)
return NULL;
(void)strncpy(temp, txt + 1, len - 2);
temp[len - 2] = '\0';
}
if (temp[0] == 0) {
- if (getpwuid_r(getuid(), &pwres, pwbuf, sizeof(pwbuf), &pass) != 0)
- pass = NULL;
+#ifdef HAVE_GETPW_R_POSIX
+ if (getpwuid_r(getuid(), &pwres, pwbuf, sizeof(pwbuf),
+ &pass) != 0)
+ pass = NULL;
+#elif HAVE_GETPW_R_DRAFT
+ pass = getpwuid_r(getuid(), &pwres, pwbuf, sizeof(pwbuf));
+#else
+ pass = getpwuid(getuid());
+#endif
} else {
+#ifdef HAVE_GETPW_R_POSIX
if (getpwnam_r(temp, &pwres, pwbuf, sizeof(pwbuf), &pass) != 0)
pass = NULL;
+#elif HAVE_GETPW_R_DRAFT
+ pass = getpwnam_r(temp, &pwres, pwbuf, sizeof(pwbuf));
+#else
+ pass = getpwnam(temp);
+#endif
}
- free(temp); /* value no more needed */
+ el_free(temp); /* value no more needed */
if (pass == NULL)
- return (strdup(txt));
+ return strdup(txt);
- /* update pointer txt to point at string immediately following */
+ /* update pointer txt to point at string immedially following */
/* first slash */
txt += len;
- temp = malloc(strlen(pass->pw_dir) + 1 + strlen(txt) + 1);
+ len = strlen(pass->pw_dir) + 1 + strlen(txt) + 1;
+ temp = el_malloc(len * sizeof(*temp));
if (temp == NULL)
return NULL;
- (void)sprintf(temp, "%s/%s", pass->pw_dir, txt);
+ (void)snprintf(temp, len, "%s/%s", pass->pw_dir, txt);
- return (temp);
+ return temp;
}
@@ -119,7 +141,7 @@ fn_tilde_expand(const char *txt)
* such file can be found
* value of ``state'' is ignored
*
- * it's caller's responsibility to free returned string
+ * it's the caller's responsibility to free the returned string
*/
char *
fn_filename_completion_function(const char *text, int state)
@@ -136,19 +158,21 @@ fn_filename_completion_function(const char *text, int state)
if (temp) {
char *nptr;
temp++;
- nptr = realloc(filename, strlen(temp) + 1);
+ nptr = el_realloc(filename, (strlen(temp) + 1) *
+ sizeof(*nptr));
if (nptr == NULL) {
- free(filename);
+ el_free(filename);
filename = NULL;
return NULL;
}
filename = nptr;
(void)strcpy(filename, temp);
- len = temp - text; /* including last slash */
+ len = (size_t)(temp - text); /* including last slash */
- nptr = realloc(dirname, len + 1);
+ nptr = el_realloc(dirname, (len + 1) *
+ sizeof(*nptr));
if (nptr == NULL) {
- free(dirname);
+ el_free(dirname);
dirname = NULL;
return NULL;
}
@@ -156,7 +180,7 @@ fn_filename_completion_function(const char *text, int state)
(void)strncpy(dirname, text, len);
dirname[len] = '\0';
} else {
- free(filename);
+ el_free(filename);
if (*text == 0)
filename = NULL;
else {
@@ -164,7 +188,7 @@ fn_filename_completion_function(const char *text, int state)
if (filename == NULL)
return NULL;
}
- free(dirname);
+ el_free(dirname);
dirname = NULL;
}
@@ -175,7 +199,7 @@ fn_filename_completion_function(const char *text, int state)
/* support for ``~user'' syntax */
- free(dirpath);
+ el_free(dirpath);
dirpath = NULL;
if (dirname == NULL) {
if ((dirname = strdup("")) == NULL)
@@ -191,7 +215,7 @@ fn_filename_completion_function(const char *text, int state)
dir = opendir(dirpath);
if (!dir)
- return (NULL); /* cannot open the directory */
+ return NULL; /* cannot open the directory */
/* will be used in cycle */
filename_len = filename ? strlen(filename) : 0;
@@ -208,26 +232,36 @@ fn_filename_completion_function(const char *text, int state)
/* otherwise, get first entry where first */
/* filename_len characters are equal */
if (entry->d_name[0] == filename[0]
+#if HAVE_STRUCT_DIRENT_D_NAMLEN
&& entry->d_namlen >= filename_len
+#else
+ && strlen(entry->d_name) >= filename_len
+#endif
&& strncmp(entry->d_name, filename,
filename_len) == 0)
break;
}
if (entry) { /* match found */
+
+#if HAVE_STRUCT_DIRENT_D_NAMLEN
len = entry->d_namlen;
+#else
+ len = strlen(entry->d_name);
+#endif
- temp = malloc(strlen(dirname) + len + 1);
+ len = strlen(dirname) + len + 1;
+ temp = el_malloc(len * sizeof(*temp));
if (temp == NULL)
return NULL;
- (void)sprintf(temp, "%s%s", dirname, entry->d_name);
+ (void)snprintf(temp, len, "%s%s", dirname, entry->d_name);
} else {
(void)closedir(dir);
dir = NULL;
temp = NULL;
}
- return (temp);
+ return temp;
}
@@ -244,11 +278,9 @@ append_char_function(const char *name)
rs = "/";
out:
if (expname)
- free(expname);
+ el_free(expname);
return rs;
}
-
-
/*
* returns list of completions for text given
* non-static for readline.
@@ -269,10 +301,10 @@ completion_matches(const char *text, char *(*genfunc)(const char *, int))
char **nmatch_list;
while (matches + 3 >= match_list_len)
match_list_len <<= 1;
- nmatch_list = realloc(match_list,
- match_list_len * sizeof(char *));
+ nmatch_list = el_realloc(match_list,
+ match_list_len * sizeof(*nmatch_list));
if (nmatch_list == NULL) {
- free(match_list);
+ el_free(match_list);
return NULL;
}
match_list = nmatch_list;
@@ -295,9 +327,9 @@ completion_matches(const char *text, char *(*genfunc)(const char *, int))
max_equal = i;
}
- retstr = malloc(max_equal + 1);
+ retstr = el_malloc((max_equal + 1) * sizeof(*retstr));
if (retstr == NULL) {
- free(match_list);
+ el_free(match_list);
return NULL;
}
(void)strncpy(retstr, match_list[1], max_equal);
@@ -305,12 +337,11 @@ completion_matches(const char *text, char *(*genfunc)(const char *, int))
match_list[0] = retstr;
/* add NULL as last pointer to the array */
- match_list[matches + 1] = (char *) NULL;
+ match_list[matches + 1] = NULL;
- return (match_list);
+ return match_list;
}
-
/*
* Sort function for qsort(). Just wrapper around strcasecmp().
*/
@@ -323,47 +354,53 @@ _fn_qsort_string_compare(const void *i1, const void *i2)
return strcasecmp(s1, s2);
}
-
/*
* Display list of strings in columnar format on readline's output stream.
- * 'matches' is list of strings, 'len' is number of strings in 'matches',
- * 'max' is maximum length of string in 'matches'.
+ * 'matches' is list of strings, 'num' is number of strings in 'matches',
+ * 'width' is maximum length of string in 'matches'.
+ *
+ * matches[0] is not one of the match strings, but it is counted in
+ * num, so the strings are matches[1] *through* matches[num-1].
*/
void
-fn_display_match_list(EditLine *el, char **matches, size_t len, size_t max)
+fn_display_match_list (EditLine *el, char **matches, size_t num, size_t width)
{
- size_t i, idx, limit, count;
- int screenwidth = el->el_term.t_size.h;
+ size_t line, lines, col, cols, thisguy;
+ int screenwidth = el->el_terminal.t_size.h;
+
+ /* Ignore matches[0]. Avoid 1-based array logic below. */
+ matches++;
+ num--;
+
+ /*
+ * Find out how many entries can be put on one line; count
+ * with one space between strings the same way it's printed.
+ */
+ cols = (size_t)screenwidth / (width + 1);
+ if (cols == 0)
+ cols = 1;
+
+ /* how many lines of output, rounded up */
+ lines = (num + cols - 1) / cols;
+
+ /* Sort the items. */
+ qsort(matches, num, sizeof(char *), _fn_qsort_string_compare);
/*
- * Find out how many entries can be put on one line, count
- * with two spaces between strings.
+ * On the ith line print elements i, i+lines, i+lines*2, etc.
*/
- limit = screenwidth / (max + 2);
- if (limit == 0)
- limit = 1;
-
- /* how many lines of output */
- count = len / limit;
- if (count * limit < len)
- count++;
-
- /* Sort the items if they are not already sorted. */
- qsort(&matches[1], len, sizeof(char *), _fn_qsort_string_compare);
-
- idx = 1;
- for(; count > 0; count--) {
- int more = limit > 0 && matches[0];
- for(i = 0; more; idx++) {
- more = ++i < limit && matches[idx + 1];
- (void)fprintf(el->el_outfile, "%-*s%s", (int)max,
- matches[idx], more ? " " : "");
+ for (line = 0; line < lines; line++) {
+ for (col = 0; col < cols; col++) {
+ thisguy = line + col * lines;
+ if (thisguy >= num)
+ break;
+ (void)fprintf(el->el_outfile, "%s%-*s",
+ col == 0 ? "" : " ", (int)width, matches[thisguy]);
}
(void)fprintf(el->el_outfile, "\n");
}
}
-
/*
* Complete the word at or before point,
* 'what_to_do' says what to do with the completion.
@@ -380,18 +417,18 @@ int
fn_complete(EditLine *el,
char *(*complet_func)(const char *, int),
char **(*attempted_completion_function)(const char *, int, int),
- const char *word_break, const char *special_prefixes,
+ const Char *word_break, const Char *special_prefixes,
const char *(*app_func)(const char *), size_t query_items,
int *completion_type, int *over, int *point, int *end,
- const char *(*find_word_start_func)(const char *, const char *),
- char *(*dequoting_func)(const char *),
+ const Char *(*find_word_start_func)(const Char *, const Char *),
+ Char *(*dequoting_func)(const Char *),
char *(*quoting_func)(const char *))
{
- const LineInfo *li;
- char *temp;
- char *dequoted_temp;
- char **matches;
- const char *ctemp;
+ const TYPE(LineInfo) *li;
+ Char *temp;
+ Char *dequoted_temp;
+ char **matches;
+ const Char *ctemp;
size_t len;
int what_to_do = '\t';
int retval = CC_NORM;
@@ -409,26 +446,20 @@ fn_complete(EditLine *el,
app_func = append_char_function;
/* We now look backwards for the start of a filename/variable word */
- li = el_line(el);
+ li = FUN(el,line)(el);
if (find_word_start_func)
ctemp = find_word_start_func(li->buffer, li->cursor);
else {
ctemp = li->cursor;
while (ctemp > li->buffer
- && !strchr(word_break, ctemp[-1])
- && (!special_prefixes || !strchr(special_prefixes, ctemp[-1]) ) )
+ && !Strchr(word_break, ctemp[-1])
+ && (!special_prefixes || !Strchr(special_prefixes, ctemp[-1]) ) )
ctemp--;
}
- len = li->cursor - ctemp;
-#if defined(__SSP__) || defined(__SSP_ALL__)
- temp = malloc(sizeof(*temp) * (len + 1));
- if (temp == NULL)
- return retval;
-#else
- temp = alloca(sizeof(*temp) * (len + 1));
-#endif
- (void)strncpy(temp, ctemp, len);
+ len = (size_t)(li->cursor - ctemp);
+ temp = el_malloc((len + 1) * sizeof(*temp));
+ (void)Strncpy(temp, ctemp, len);
temp[len] = '\0';
if (dequoting_func) {
@@ -447,13 +478,17 @@ fn_complete(EditLine *el,
if (attempted_completion_function) {
int cur_off = (int)(li->cursor - li->buffer);
- matches = (*attempted_completion_function) (dequoted_temp ? dequoted_temp : temp,
- (int)(cur_off - len), cur_off);
+ matches = (*attempted_completion_function)(
+ ct_encode_string(dequoted_temp ? dequoted_temp : temp,
+ &el->el_scratch),
+ cur_off - (int)len, cur_off);
} else
matches = 0;
if (!attempted_completion_function ||
(over != NULL && !*over && !matches))
- matches = completion_matches(dequoted_temp ? dequoted_temp : temp, complet_func);
+ matches = completion_matches(
+ ct_encode_string(dequoted_temp ? dequoted_temp : temp,
+ &el->el_scratch), complet_func);
if (over != NULL)
*over = 0;
@@ -475,23 +510,25 @@ fn_complete(EditLine *el,
goto free_matches;
} else
quoted_match = NULL;
-
el_deletestr(el, (int) len);
- el_insertstr(el, quoted_match ? quoted_match : matches[0]);
-
- free(quoted_match);
+ FUN(el,insertstr)(el,
+ ct_decode_string(quoted_match ? quoted_match :
+ matches[0] , &el->el_scratch));
}
if (what_to_do == '?')
goto display_matches;
- if (matches[2] == NULL && strcmp(matches[0], matches[1]) == 0) {
+ if (matches[2] == NULL &&
+ (matches[1] == NULL || strcmp(matches[0], matches[1]) == 0)) {
/*
* We found exact match. Add a space after
* it, unless we do filename completion and the
* object is a directory.
*/
- el_insertstr(el, (*app_func)(matches[0]));
+ FUN(el,insertstr)(el,
+ ct_decode_string((*app_func)(matches[0]),
+ &el->el_scratch));
} else if (what_to_do == '!') {
display_matches:
/*
@@ -504,7 +541,8 @@ fn_complete(EditLine *el,
if (match_len > maxlen)
maxlen = match_len;
}
- matches_num = i - 1;
+ /* matches[1] through matches[i-1] are available */
+ matches_num = (size_t)(i - 1);
/* newline to get on next line from command line */
(void)fprintf(el->el_outfile, "\n");
@@ -523,9 +561,17 @@ fn_complete(EditLine *el,
(void)fprintf(el->el_outfile, "\n");
}
- if (match_display)
- fn_display_match_list(el, matches, matches_num,
- maxlen);
+ if (match_display) {
+ /*
+ * Interface of this function requires the
+ * strings be matches[1..num-1] for compat.
+ * We have matches_num strings not counting
+ * the prefix in matches[0], so we need to
+ * add 1 to matches_num for the call.
+ */
+ fn_display_match_list(el, matches,
+ matches_num+1, maxlen);
+ }
retval = CC_REDISPLAY;
} else if (matches[0][0]) {
/*
@@ -544,18 +590,15 @@ fn_complete(EditLine *el,
free_matches:
/* free elements of array and the array itself */
for (i = 0; matches[i]; i++)
- free(matches[i]);
- free(matches);
+ el_free(matches[i]);
+ el_free(matches);
matches = NULL;
}
free(dequoted_temp);
-#if defined(__SSP__) || defined(__SSP_ALL__)
- free(temp);
-#endif
+ el_free(temp);
return retval;
}
-
/*
* el-compatible wrapper around rl_complete; needed for key binding
*/
@@ -564,30 +607,26 @@ unsigned char
_el_fn_complete(EditLine *el, int ch __attribute__((__unused__)))
{
return (unsigned char)fn_complete(el, NULL, NULL,
- break_chars, NULL, NULL, 100,
+ break_chars, NULL, NULL, (size_t)100,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL);
}
-
-static const char *
-sh_find_word_start(const char *buffer, const char *cursor)
+static const Char *
+sh_find_word_start(const Char *buffer, const Char *cursor)
{
- const char *word_start = buffer;
+ const Char *word_start = buffer;
while (buffer < cursor) {
if (*buffer == '\\')
buffer++;
- else if (strchr(break_chars, *buffer))
+ else if (Strchr(break_chars, *buffer))
word_start = buffer + 1;
-
buffer++;
}
-
return word_start;
}
-
static char *
sh_quote(const char *str)
{
@@ -595,24 +634,20 @@ sh_quote(const char *str)
int extra_len = 0;
char *quoted_str, *dst;
- if (*str == '-' || *str == '+')
- extra_len += 2;
- for (src = str; *src != '\0'; src++)
- if (strchr(break_chars, *src) ||
- strchr(extra_quote_chars, *src))
+ for (src = str; *src != '\0'; src++)
+ if (Strchr(break_chars, *src) ||
+ Strchr(extra_quote_chars, *src))
extra_len++;
quoted_str = malloc(sizeof(*quoted_str) *
- (strlen(str) + extra_len + 1));
+ (strlen(str) + extra_len + 1));
if (quoted_str == NULL)
return NULL;
dst = quoted_str;
- if (*str == '-' || *str == '+')
- *dst++ = '.', *dst++ = '/';
for (src = str; *src != '\0'; src++) {
- if (strchr(break_chars, *src) ||
- strchr(extra_quote_chars, *src))
+ if (Strchr(break_chars, *src) ||
+ Strchr(extra_quote_chars, *src))
*dst++ = '\\';
*dst++ = *src;
}
@@ -621,14 +656,13 @@ sh_quote(const char *str)
return quoted_str;
}
-
-static char *
-sh_dequote(const char *str)
+static Char *
+sh_dequote(const Char *str)
{
- char *dequoted_str, *dst;
+ Char *dequoted_str, *dst;
/* save extra space to replace \~ with ./~ */
- dequoted_str = malloc(sizeof(*dequoted_str) * (strlen(str) + 1 + 1));
+ dequoted_str = malloc(sizeof(*dequoted_str) * (Strlen(str) + 1 + 1));
if (dequoted_str == NULL)
return NULL;
@@ -652,7 +686,6 @@ sh_dequote(const char *str)
return dequoted_str;
}
-
/*
* completion function using sh quoting rules; for key binding
*/
diff --git a/lib/libedit/filecomplete.h b/lib/libedit/filecomplete.h
index 215cf7d..3666686 100644
--- a/lib/libedit/filecomplete.h
+++ b/lib/libedit/filecomplete.h
@@ -1,3 +1,5 @@
+/* $NetBSD: filecomplete.h,v 1.9 2009/12/30 22:37:40 christos Exp $ */
+
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
* All rights reserved.
@@ -26,7 +28,6 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
- * $NetBSD: filecomplete.h,v 1.8 2009/02/16 00:15:45 christos Exp $
* $FreeBSD$
*/
#ifndef _FILECOMPLETE_H_
@@ -35,10 +36,10 @@
int fn_complete(EditLine *,
char *(*)(const char *, int),
char **(*)(const char *, int, int),
- const char *, const char *, const char *(*)(const char *), size_t,
+ const Char *, const Char *, const char *(*)(const char *), size_t,
int *, int *, int *, int *,
- const char *(*)(const char *, const char *),
- char *(*)(const char *),
+ const Char *(*)(const Char *, const Char *),
+ Char *(*)(const Char *),
char *(*)(const char *));
void fn_display_match_list(EditLine *, char **, size_t, size_t);
diff --git a/lib/libedit/hist.c b/lib/libedit/hist.c
index 601e102..66cfd312 100644
--- a/lib/libedit/hist.c
+++ b/lib/libedit/hist.c
@@ -1,3 +1,5 @@
+/* $NetBSD: hist.c,v 1.20 2011/07/29 15:16:33 christos Exp $ */
+
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -28,12 +30,15 @@
* 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.
- *
- * $NetBSD: hist.c,v 1.15 2003/11/01 23:36:39 christos Exp $
*/
+#include "config.h"
#if !defined(lint) && !defined(SCCSID)
+#if 0
static char sccsid[] = "@(#)hist.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: hist.c,v 1.20 2011/07/29 15:16:33 christos Exp $");
+#endif
#endif /* not lint && not SCCSID */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
@@ -41,7 +46,6 @@ __FBSDID("$FreeBSD$");
/*
* hist.c: History access functions
*/
-#include "sys.h"
#include <stdlib.h>
#include "el.h"
@@ -54,12 +58,12 @@ hist_init(EditLine *el)
el->el_history.fun = NULL;
el->el_history.ref = NULL;
- el->el_history.buf = (char *) el_malloc(EL_BUFSIZ);
+ el->el_history.buf = el_malloc(EL_BUFSIZ * sizeof(*el->el_history.buf));
el->el_history.sz = EL_BUFSIZ;
if (el->el_history.buf == NULL)
- return (-1);
+ return -1;
el->el_history.last = el->el_history.buf;
- return (0);
+ return 0;
}
@@ -70,7 +74,7 @@ protected void
hist_end(EditLine *el)
{
- el_free((ptr_t) el->el_history.buf);
+ el_free(el->el_history.buf);
el->el_history.buf = NULL;
}
@@ -79,12 +83,12 @@ hist_end(EditLine *el)
* Set new history interface
*/
protected int
-hist_set(EditLine *el, hist_fun_t fun, ptr_t ptr)
+hist_set(EditLine *el, hist_fun_t fun, void *ptr)
{
el->el_history.ref = ptr;
el->el_history.fun = fun;
- return (0);
+ return 0;
}
@@ -95,11 +99,11 @@ hist_set(EditLine *el, hist_fun_t fun, ptr_t ptr)
protected el_action_t
hist_get(EditLine *el)
{
- const char *hp;
+ const Char *hp;
int h;
if (el->el_history.eventno == 0) { /* if really the current line */
- (void) strncpy(el->el_line.buffer, el->el_history.buf,
+ (void) Strncpy(el->el_line.buffer, el->el_history.buf,
el->el_history.sz);
el->el_line.lastchar = el->el_line.buffer +
(el->el_history.last - el->el_history.buf);
@@ -111,24 +115,25 @@ hist_get(EditLine *el)
#endif /* KSHVI */
el->el_line.cursor = el->el_line.lastchar;
- return (CC_REFRESH);
+ return CC_REFRESH;
}
if (el->el_history.ref == NULL)
- return (CC_ERROR);
+ return CC_ERROR;
hp = HIST_FIRST(el);
if (hp == NULL)
- return (CC_ERROR);
+ return CC_ERROR;
for (h = 1; h < el->el_history.eventno; h++)
if ((hp = HIST_NEXT(el)) == NULL) {
el->el_history.eventno = h;
- return (CC_ERROR);
+ return CC_ERROR;
}
- (void) strlcpy(el->el_line.buffer, hp,
+ (void) Strncpy(el->el_line.buffer, hp,
(size_t)(el->el_line.limit - el->el_line.buffer));
- el->el_line.lastchar = el->el_line.buffer + strlen(el->el_line.buffer);
+ el->el_line.buffer[el->el_line.limit - el->el_line.buffer - 1] = '\0';
+ el->el_line.lastchar = el->el_line.buffer + Strlen(el->el_line.buffer);
if (el->el_line.lastchar > el->el_line.buffer
&& el->el_line.lastchar[-1] == '\n')
@@ -143,7 +148,7 @@ hist_get(EditLine *el)
#endif /* KSHVI */
el->el_line.cursor = el->el_line.lastchar;
- return (CC_REFRESH);
+ return CC_REFRESH;
}
@@ -151,34 +156,34 @@ hist_get(EditLine *el)
* process a history command
*/
protected int
-hist_command(EditLine *el, int argc, const char **argv)
+hist_command(EditLine *el, int argc, const Char **argv)
{
- const char *str;
+ const Char *str;
int num;
- HistEvent ev;
+ TYPE(HistEvent) ev;
if (el->el_history.ref == NULL)
- return (-1);
+ return -1;
- if (argc == 1 || strcmp(argv[1], "list") == 0) {
+ if (argc == 1 || Strcmp(argv[1], STR("list")) == 0) {
/* List history entries */
for (str = HIST_LAST(el); str != NULL; str = HIST_PREV(el))
(void) fprintf(el->el_outfile, "%d %s",
- el->el_history.ev.num, str);
- return (0);
+ el->el_history.ev.num, ct_encode_string(str, &el->el_scratch));
+ return 0;
}
if (argc != 3)
- return (-1);
+ return -1;
- num = (int)strtol(argv[2], NULL, 0);
+ num = (int)Strtol(argv[2], NULL, 0);
- if (strcmp(argv[1], "size") == 0)
- return history(el->el_history.ref, &ev, H_SETSIZE, num);
+ if (Strcmp(argv[1], STR("size")) == 0)
+ return FUNW(history)(el->el_history.ref, &ev, H_SETSIZE, num);
- if (strcmp(argv[1], "unique") == 0)
- return history(el->el_history.ref, &ev, H_SETUNIQUE, num);
+ if (Strcmp(argv[1], STR("unique")) == 0)
+ return FUNW(history)(el->el_history.ref, &ev, H_SETUNIQUE, num);
return -1;
}
@@ -191,13 +196,13 @@ protected int
/*ARGSUSED*/
hist_enlargebuf(EditLine *el, size_t oldsz, size_t newsz)
{
- char *newbuf;
+ Char *newbuf;
- newbuf = realloc(el->el_history.buf, newsz);
+ newbuf = el_realloc(el->el_history.buf, newsz * sizeof(*newbuf));
if (!newbuf)
return 0;
- (void) memset(&newbuf[oldsz], '\0', newsz - oldsz);
+ (void) memset(&newbuf[oldsz], '\0', (newsz - oldsz) * sizeof(*newbuf));
el->el_history.last = newbuf +
(el->el_history.last - el->el_history.buf);
@@ -206,3 +211,15 @@ hist_enlargebuf(EditLine *el, size_t oldsz, size_t newsz)
return 1;
}
+
+#ifdef WIDECHAR
+protected wchar_t *
+hist_convert(EditLine *el, int fn, void *arg)
+{
+ HistEventW ev;
+ if ((*(el)->el_history.fun)((el)->el_history.ref, &ev, fn, arg) == -1)
+ return NULL;
+ return ct_decode_string((const char *)(const void *)ev.str,
+ &el->el_scratch);
+}
+#endif
diff --git a/lib/libedit/hist.h b/lib/libedit/hist.h
index 4ddedcc..1cd7d9d 100644
--- a/lib/libedit/hist.h
+++ b/lib/libedit/hist.h
@@ -1,3 +1,5 @@
+/* $NetBSD: hist.h,v 1.14 2014/05/11 01:05:17 christos Exp $ */
+
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -30,7 +32,6 @@
* SUCH DAMAGE.
*
* @(#)hist.h 8.1 (Berkeley) 6/4/93
- * $NetBSD: hist.h,v 1.10 2003/08/07 16:44:31 agc Exp $
* $FreeBSD$
*/
@@ -42,21 +43,29 @@
#include "histedit.h"
-typedef int (*hist_fun_t)(ptr_t, HistEvent *, int, ...);
+typedef int (*hist_fun_t)(void *, TYPE(HistEvent) *, int, ...);
typedef struct el_history_t {
- char *buf; /* The history buffer */
+ Char *buf; /* The history buffer */
size_t sz; /* Size of history buffer */
- char *last; /* The last character */
+ Char *last; /* The last character */
int eventno; /* Event we are looking for */
- ptr_t ref; /* Argument for history fcns */
+ void * ref; /* Argument for history fcns */
hist_fun_t fun; /* Event access */
- HistEvent ev; /* Event cookie */
+ TYPE(HistEvent) ev; /* Event cookie */
} el_history_t;
-#define HIST_FUN(el, fn, arg) \
+#define HIST_FUN_INTERNAL(el, fn, arg) \
((((*(el)->el_history.fun) ((el)->el_history.ref, &(el)->el_history.ev, \
fn, arg)) == -1) ? NULL : (el)->el_history.ev.str)
+#ifdef WIDECHAR
+#define HIST_FUN(el, fn, arg) \
+ (((el)->el_flags & NARROW_HISTORY) ? hist_convert(el, fn, arg) : \
+ HIST_FUN_INTERNAL(el, fn, arg))
+#else
+#define HIST_FUN(el, fn, arg) HIST_FUN_INTERNAL(el, fn, arg)
+#endif
+
#define HIST_NEXT(el) HIST_FUN(el, H_NEXT, NULL)
#define HIST_FIRST(el) HIST_FUN(el, H_FIRST, NULL)
@@ -70,8 +79,11 @@ typedef struct el_history_t {
protected int hist_init(EditLine *);
protected void hist_end(EditLine *);
protected el_action_t hist_get(EditLine *);
-protected int hist_set(EditLine *, hist_fun_t, ptr_t);
-protected int hist_command(EditLine *, int, const char **);
+protected int hist_set(EditLine *, hist_fun_t, void *);
+protected int hist_command(EditLine *, int, const Char **);
protected int hist_enlargebuf(EditLine *, size_t, size_t);
+#ifdef WIDECHAR
+protected wchar_t *hist_convert(EditLine *, int, void *);
+#endif
#endif /* _h_el_hist */
diff --git a/lib/libedit/histedit.h b/lib/libedit/histedit.h
index 7cc5246..bed186e 100644
--- a/lib/libedit/histedit.h
+++ b/lib/libedit/histedit.h
@@ -1,3 +1,5 @@
+/* $NetBSD: histedit.h,v 1.53 2014/06/18 18:12:28 christos Exp $ */
+
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -30,7 +32,6 @@
* SUCH DAMAGE.
*
* @(#)histedit.h 8.2 (Berkeley) 1/3/94
- * $NetBSD: histedit.h,v 1.41 2009/09/07 21:24:33 christos Exp $
* $FreeBSD$
*/
@@ -40,10 +41,12 @@
#ifndef _HISTEDIT_H_
#define _HISTEDIT_H_
+#define LIBEDIT_MAJOR 2
+#define LIBEDIT_MINOR 11
+
#include <sys/types.h>
#include <stdio.h>
-__BEGIN_DECLS
#ifdef __cplusplus
extern "C" {
#endif
@@ -82,6 +85,8 @@ typedef struct lineinfo {
* Initialization, cleanup, and resetting
*/
EditLine *el_init(const char *, FILE *, FILE *, FILE *);
+EditLine *el_init_fd(const char *, FILE *, FILE *, FILE *,
+ int, int, int);
void el_end(EditLine *);
void el_reset(EditLine *);
@@ -113,32 +118,47 @@ unsigned char _el_fn_sh_complete(EditLine *, int);
/*
* el_set/el_get parameters
+ *
+ * When using el_wset/el_wget (as opposed to el_set/el_get):
+ * Char is wchar_t, otherwise it is char.
+ * prompt_func is el_wpfunc_t, otherwise it is el_pfunc_t .
+
+ * Prompt function prototypes are:
+ * typedef char *(*el_pfunct_t) (EditLine *);
+ * typedef wchar_t *(*el_wpfunct_t) (EditLine *);
+ *
+ * For operations that support set or set/get, the argument types listed are for
+ * the "set" operation. For "get", each listed type must be a pointer.
+ * E.g. EL_EDITMODE takes an int when set, but an int* when get.
+ *
+ * Operations that only support "get" have the correct argument types listed.
*/
-#define EL_PROMPT 0 /* , el_pfunc_t); */
-#define EL_TERMINAL 1 /* , const char *); */
-#define EL_EDITOR 2 /* , const char *); */
-#define EL_SIGNAL 3 /* , int); */
-#define EL_BIND 4 /* , const char *, ..., NULL); */
-#define EL_TELLTC 5 /* , const char *, ..., NULL); */
-#define EL_SETTC 6 /* , const char *, ..., NULL); */
-#define EL_ECHOTC 7 /* , const char *, ..., NULL); */
-#define EL_SETTY 8 /* , const char *, ..., NULL); */
-#define EL_ADDFN 9 /* , const char *, const char * */
- /* , el_func_t); */
-#define EL_HIST 10 /* , hist_fun_t, const char *); */
-#define EL_EDITMODE 11 /* , int); */
-#define EL_RPROMPT 12 /* , el_pfunc_t); */
-#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_GETTC 17 /* , const char *, ..., NULL); */
-#define EL_GETFP 18 /* , int, FILE **); */
-#define EL_SETFP 19 /* , int, FILE *); */
+#define EL_PROMPT 0 /* , prompt_func); set/get */
+#define EL_TERMINAL 1 /* , const char *); set/get */
+#define EL_EDITOR 2 /* , const Char *); set/get */
+#define EL_SIGNAL 3 /* , int); set/get */
+#define EL_BIND 4 /* , const Char *, ..., NULL); set */
+#define EL_TELLTC 5 /* , const Char *, ..., NULL); set */
+#define EL_SETTC 6 /* , const Char *, ..., NULL); set */
+#define EL_ECHOTC 7 /* , const Char *, ..., NULL); set */
+#define EL_SETTY 8 /* , const Char *, ..., NULL); set */
+#define EL_ADDFN 9 /* , const Char *, const Char, set */
+ /* el_func_t); */
+#define EL_HIST 10 /* , hist_fun_t, const void *); set */
+#define EL_EDITMODE 11 /* , int); set/get */
+#define EL_RPROMPT 12 /* , prompt_func); set/get */
+#define EL_GETCFN 13 /* , el_rfunc_t); set/get */
+#define EL_CLIENTDATA 14 /* , void *); set/get */
+#define EL_UNBUFFERED 15 /* , int); set/get */
+#define EL_PREP_TERM 16 /* , int); set */
+#define EL_GETTC 17 /* , const Char *, ..., NULL); get */
+#define EL_GETFP 18 /* , int, FILE **); get */
+#define EL_SETFP 19 /* , int, FILE *); set */
#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 */
#define EL_RESIZE 23 /* , el_zfunc_t, void *); set */
+#define EL_ALIAS_TEXT 24 /* , el_afunc_t, void *); set */
#define EL_BUILTIN_GETCFN (NULL)
@@ -183,7 +203,6 @@ int history(History *, HistEvent *, int, ...);
#define H_FUNC 0 /* , UTSL */
#define H_SETSIZE 1 /* , const int); */
-#define H_EVENT 1 /* , const int); */
#define H_GETSIZE 2 /* , void); */
#define H_FIRST 3 /* , void); */
#define H_LAST 4 /* , void); */
@@ -191,12 +210,12 @@ int history(History *, HistEvent *, int, ...);
#define H_NEXT 6 /* , void); */
#define H_CURR 8 /* , const int); */
#define H_SET 7 /* , int); */
-#define H_ADD 9 /* , const char *); */
-#define H_ENTER 10 /* , const char *); */
-#define H_APPEND 11 /* , const char *); */
+#define H_ADD 9 /* , const wchar_t *); */
+#define H_ENTER 10 /* , const wchar_t *); */
+#define H_APPEND 11 /* , const wchar_t *); */
#define H_END 12 /* , void); */
-#define H_NEXT_STR 13 /* , const char *); */
-#define H_PREV_STR 14 /* , const char *); */
+#define H_NEXT_STR 13 /* , const wchar_t *); */
+#define H_PREV_STR 14 /* , const wchar_t *); */
#define H_NEXT_EVENT 15 /* , const int); */
#define H_PREV_EVENT 16 /* , const int); */
#define H_LOAD 17 /* , const char *); */
@@ -208,7 +227,8 @@ int history(History *, HistEvent *, int, ...);
#define H_NEXT_EVDATA 23 /* , const int, histdata_t *); */
#define H_DELDATA 24 /* , int, histdata_t *);*/
#define H_REPLACE 25 /* , const char *, histdata_t); */
-#define H_SAVE_FP 26 /* , FILE*); */
+#define H_SAVE_FP 26 /* , FILE *); */
+
/*
@@ -228,7 +248,75 @@ int tok_line(Tokenizer *, const LineInfo *,
int tok_str(Tokenizer *, const char *,
int *, const char ***);
-__END_DECLS
+/*
+ * Begin Wide Character Support
+ */
+#ifdef __linux__
+/* Apparently we need _GNU_SOURCE defined to get access to wcsdup on Linux */
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+#endif
+
+#include <wchar.h>
+#include <wctype.h>
+
+/*
+ * Wide character versions
+ */
+
+/*
+ * ==== Editing ====
+ */
+typedef struct lineinfow {
+ const wchar_t *buffer;
+ const wchar_t *cursor;
+ const wchar_t *lastchar;
+} LineInfoW;
+
+const wchar_t *el_wgets(EditLine *, int *);
+int el_wgetc(EditLine *, wchar_t *);
+void el_wpush(EditLine *, const wchar_t *);
+
+int el_wparse(EditLine *, int, const wchar_t **);
+
+int el_wset(EditLine *, int, ...);
+int el_wget(EditLine *, int, ...);
+
+int el_cursor(EditLine *, int);
+const LineInfoW *el_wline(EditLine *);
+int el_winsertstr(EditLine *, const wchar_t *);
+#define el_wdeletestr el_deletestr
+
+/*
+ * ==== History ====
+ */
+typedef struct histeventW {
+ int num;
+ const wchar_t *str;
+} HistEventW;
+
+typedef struct historyW HistoryW;
+
+HistoryW * history_winit(void);
+void history_wend(HistoryW *);
+
+int history_w(HistoryW *, HistEventW *, int, ...);
+
+/*
+ * ==== Tokenization ====
+ */
+typedef struct tokenizerW TokenizerW;
+
+/* Wide character tokenizer support */
+TokenizerW *tok_winit(const wchar_t *);
+void tok_wend(TokenizerW *);
+void tok_wreset(TokenizerW *);
+int tok_wline(TokenizerW *, const LineInfoW *,
+ int *, const wchar_t ***, int *, int *);
+int tok_wstr(TokenizerW *, const wchar_t *,
+ int *, const wchar_t ***);
+
#ifdef __cplusplus
}
#endif
diff --git a/lib/libedit/history.c b/lib/libedit/history.c
index cd86977..6e225e9 100644
--- a/lib/libedit/history.c
+++ b/lib/libedit/history.c
@@ -1,3 +1,5 @@
+/* $NetBSD: history.c,v 1.47 2014/05/11 01:05:17 christos Exp $ */
+
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -28,21 +30,22 @@
* 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.
- *
- * $NetBSD: history.c,v 1.34 2009/09/07 21:24:33 christos Exp $
*/
+#include "config.h"
#if !defined(lint) && !defined(SCCSID)
+#if 0
static char sccsid[] = "@(#)history.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: history.c,v 1.47 2014/05/11 01:05:17 christos Exp $");
+#endif
#endif /* not lint && not SCCSID */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
/*
- * hist.c: History access functions
+ * hist.c: TYPE(History) access functions
*/
-#include "sys.h"
-
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
@@ -52,14 +55,15 @@ __FBSDID("$FreeBSD$");
static const char hist_cookie[] = "_HiStOrY_V2_\n";
#include "histedit.h"
+#include "chartype.h"
-typedef int (*history_gfun_t)(ptr_t, HistEvent *);
-typedef int (*history_efun_t)(ptr_t, HistEvent *, const char *);
-typedef void (*history_vfun_t)(ptr_t, HistEvent *);
-typedef int (*history_sfun_t)(ptr_t, HistEvent *, const int);
+typedef int (*history_gfun_t)(void *, TYPE(HistEvent) *);
+typedef int (*history_efun_t)(void *, TYPE(HistEvent) *, const Char *);
+typedef void (*history_vfun_t)(void *, TYPE(HistEvent) *);
+typedef int (*history_sfun_t)(void *, TYPE(HistEvent) *, const int);
-struct history {
- ptr_t h_ref; /* Argument for history fcns */
+struct TYPE(history) {
+ void *h_ref; /* Argument for history fcns */
int h_ent; /* Last entry point for history */
history_gfun_t h_first; /* Get the first element */
history_gfun_t h_next; /* Get the next element */
@@ -84,30 +88,30 @@ struct history {
#define HADD(h, ev, str) (*(h)->h_add)((h)->h_ref, ev, str)
#define HDEL(h, ev, n) (*(h)->h_del)((h)->h_ref, ev, n)
-#define h_strdup(a) strdup(a)
+#define h_strdup(a) Strdup(a)
#define h_malloc(a) malloc(a)
#define h_realloc(a, b) realloc((a), (b))
#define h_free(a) free(a)
typedef struct {
int num;
- char *str;
+ Char *str;
} HistEventPrivate;
-private int history_setsize(History *, HistEvent *, int);
-private int history_getsize(History *, HistEvent *);
-private int history_setunique(History *, HistEvent *, int);
-private int history_getunique(History *, HistEvent *);
-private int history_set_fun(History *, History *);
-private int history_load(History *, const char *);
-private int history_save(History *, const char *);
-private int history_save_fp(History *, FILE*);
-private int history_prev_event(History *, HistEvent *, int);
-private int history_next_event(History *, HistEvent *, int);
-private int history_next_string(History *, HistEvent *, const char *);
-private int history_prev_string(History *, HistEvent *, const char *);
+private int history_setsize(TYPE(History) *, TYPE(HistEvent) *, int);
+private int history_getsize(TYPE(History) *, TYPE(HistEvent) *);
+private int history_setunique(TYPE(History) *, TYPE(HistEvent) *, int);
+private int history_getunique(TYPE(History) *, TYPE(HistEvent) *);
+private int history_set_fun(TYPE(History) *, TYPE(History) *);
+private int history_load(TYPE(History) *, const char *);
+private int history_save(TYPE(History) *, const char *);
+private int history_save_fp(TYPE(History) *, FILE *);
+private int history_prev_event(TYPE(History) *, TYPE(HistEvent) *, int);
+private int history_next_event(TYPE(History) *, TYPE(HistEvent) *, int);
+private int history_next_string(TYPE(History) *, TYPE(HistEvent) *, const Char *);
+private int history_prev_string(TYPE(History) *, TYPE(HistEvent) *, const Char *);
/***********************************************************************/
@@ -116,7 +120,7 @@ private int history_prev_string(History *, HistEvent *, const char *);
* Builtin- history implementation
*/
typedef struct hentry_t {
- HistEvent ev; /* What we return */
+ TYPE(HistEvent) ev; /* What we return */
void *data; /* data */
struct hentry_t *next; /* Next entry */
struct hentry_t *prev; /* Previous entry */
@@ -128,27 +132,27 @@ typedef struct history_t {
int max; /* Maximum number of events */
int cur; /* Current number of events */
int eventid; /* For generation of unique event id */
- int flags; /* History flags */
+ int flags; /* TYPE(History) flags */
#define H_UNIQUE 1 /* Store only unique elements */
} history_t;
-private int history_def_next(ptr_t, HistEvent *);
-private int history_def_first(ptr_t, HistEvent *);
-private int history_def_prev(ptr_t, HistEvent *);
-private int history_def_last(ptr_t, HistEvent *);
-private int history_def_curr(ptr_t, HistEvent *);
-private int history_def_set(ptr_t, HistEvent *, const int);
-private void history_def_clear(ptr_t, HistEvent *);
-private int history_def_enter(ptr_t, HistEvent *, const char *);
-private int history_def_add(ptr_t, HistEvent *, const char *);
-private int history_def_del(ptr_t, HistEvent *, const int);
+private int history_def_next(void *, TYPE(HistEvent) *);
+private int history_def_first(void *, TYPE(HistEvent) *);
+private int history_def_prev(void *, TYPE(HistEvent) *);
+private int history_def_last(void *, TYPE(HistEvent) *);
+private int history_def_curr(void *, TYPE(HistEvent) *);
+private int history_def_set(void *, TYPE(HistEvent) *, const int);
+private void history_def_clear(void *, TYPE(HistEvent) *);
+private int history_def_enter(void *, TYPE(HistEvent) *, const Char *);
+private int history_def_add(void *, TYPE(HistEvent) *, const Char *);
+private int history_def_del(void *, TYPE(HistEvent) *, const int);
-private int history_def_init(ptr_t *, HistEvent *, int);
-private int history_def_insert(history_t *, HistEvent *, const char *);
-private void history_def_delete(history_t *, HistEvent *, hentry_t *);
+private int history_def_init(void **, TYPE(HistEvent) *, int);
+private int history_def_insert(history_t *, TYPE(HistEvent) *, const Char *);
+private void history_def_delete(history_t *, TYPE(HistEvent) *, hentry_t *);
-private int history_deldata_nth(history_t *, HistEvent *, int, void **);
-private int history_set_nth(ptr_t, HistEvent *, int);
+private int history_deldata_nth(history_t *, TYPE(HistEvent) *, int, void **);
+private int history_set_nth(void *, TYPE(HistEvent) *, int);
#define history_def_setsize(p, num)(void) (((history_t *)p)->max = (num))
#define history_def_getsize(p) (((history_t *)p)->cur)
@@ -166,23 +170,23 @@ private int history_set_nth(ptr_t, HistEvent *, int);
}
/* error messages */
-static const char *const he_errlist[] = {
- "OK",
- "unknown error",
- "malloc() failed",
- "first event not found",
- "last event not found",
- "empty list",
- "no next event",
- "no previous event",
- "current event is invalid",
- "event not found",
- "can't read history from file",
- "can't write history",
- "required parameter(s) not supplied",
- "history size negative",
- "function not allowed with other history-functions-set the default",
- "bad parameters"
+static const Char *const he_errlist[] = {
+ STR("OK"),
+ STR("unknown error"),
+ STR("malloc() failed"),
+ STR("first event not found"),
+ STR("last event not found"),
+ STR("empty list"),
+ STR("no next event"),
+ STR("no previous event"),
+ STR("current event is invalid"),
+ STR("event not found"),
+ STR("can't read history from file"),
+ STR("can't write history"),
+ STR("required parameter(s) not supplied"),
+ STR("history size negative"),
+ STR("function not allowed with other history-functions-set the default"),
+ STR("bad parameters")
};
/* error codes */
#define _HE_OK 0
@@ -206,7 +210,7 @@ static const char *const he_errlist[] = {
* Default function to return the first event in the history.
*/
private int
-history_def_first(ptr_t p, HistEvent *ev)
+history_def_first(void *p, TYPE(HistEvent) *ev)
{
history_t *h = (history_t *) p;
@@ -215,10 +219,10 @@ history_def_first(ptr_t p, HistEvent *ev)
*ev = h->cursor->ev;
else {
he_seterrev(ev, _HE_FIRST_NOTFOUND);
- return (-1);
+ return -1;
}
- return (0);
+ return 0;
}
@@ -226,7 +230,7 @@ history_def_first(ptr_t p, HistEvent *ev)
* Default function to return the last event in the history.
*/
private int
-history_def_last(ptr_t p, HistEvent *ev)
+history_def_last(void *p, TYPE(HistEvent) *ev)
{
history_t *h = (history_t *) p;
@@ -235,10 +239,10 @@ history_def_last(ptr_t p, HistEvent *ev)
*ev = h->cursor->ev;
else {
he_seterrev(ev, _HE_LAST_NOTFOUND);
- return (-1);
+ return -1;
}
- return (0);
+ return 0;
}
@@ -246,24 +250,24 @@ history_def_last(ptr_t p, HistEvent *ev)
* Default function to return the next event in the history.
*/
private int
-history_def_next(ptr_t p, HistEvent *ev)
+history_def_next(void *p, TYPE(HistEvent) *ev)
{
history_t *h = (history_t *) p;
if (h->cursor == &h->list) {
he_seterrev(ev, _HE_EMPTY_LIST);
- return (-1);
+ return -1;
}
if (h->cursor->next == &h->list) {
he_seterrev(ev, _HE_END_REACHED);
- return (-1);
+ return -1;
}
h->cursor = h->cursor->next;
*ev = h->cursor->ev;
- return (0);
+ return 0;
}
@@ -271,25 +275,25 @@ history_def_next(ptr_t p, HistEvent *ev)
* Default function to return the previous event in the history.
*/
private int
-history_def_prev(ptr_t p, HistEvent *ev)
+history_def_prev(void *p, TYPE(HistEvent) *ev)
{
history_t *h = (history_t *) p;
if (h->cursor == &h->list) {
he_seterrev(ev,
(h->cur > 0) ? _HE_END_REACHED : _HE_EMPTY_LIST);
- return (-1);
+ return -1;
}
if (h->cursor->prev == &h->list) {
he_seterrev(ev, _HE_START_REACHED);
- return (-1);
+ return -1;
}
h->cursor = h->cursor->prev;
*ev = h->cursor->ev;
- return (0);
+ return 0;
}
@@ -297,7 +301,7 @@ history_def_prev(ptr_t p, HistEvent *ev)
* Default function to return the current event in the history.
*/
private int
-history_def_curr(ptr_t p, HistEvent *ev)
+history_def_curr(void *p, TYPE(HistEvent) *ev)
{
history_t *h = (history_t *) p;
@@ -306,10 +310,10 @@ history_def_curr(ptr_t p, HistEvent *ev)
else {
he_seterrev(ev,
(h->cur > 0) ? _HE_CURR_INVALID : _HE_EMPTY_LIST);
- return (-1);
+ return -1;
}
- return (0);
+ return 0;
}
@@ -318,13 +322,13 @@ history_def_curr(ptr_t p, HistEvent *ev)
* given one.
*/
private int
-history_def_set(ptr_t p, HistEvent *ev, const int n)
+history_def_set(void *p, TYPE(HistEvent) *ev, const int n)
{
history_t *h = (history_t *) p;
if (h->cur == 0) {
he_seterrev(ev, _HE_EMPTY_LIST);
- return (-1);
+ return -1;
}
if (h->cursor == &h->list || h->cursor->ev.num != n) {
for (h->cursor = h->list.next; h->cursor != &h->list;
@@ -334,9 +338,9 @@ history_def_set(ptr_t p, HistEvent *ev, const int n)
}
if (h->cursor == &h->list) {
he_seterrev(ev, _HE_NOT_FOUND);
- return (-1);
+ return -1;
}
- return (0);
+ return 0;
}
@@ -345,13 +349,13 @@ history_def_set(ptr_t p, HistEvent *ev, const int n)
* n-th one.
*/
private int
-history_set_nth(ptr_t p, HistEvent *ev, int n)
+history_set_nth(void *p, TYPE(HistEvent) *ev, int n)
{
history_t *h = (history_t *) p;
if (h->cur == 0) {
he_seterrev(ev, _HE_EMPTY_LIST);
- return (-1);
+ return -1;
}
for (h->cursor = h->list.prev; h->cursor != &h->list;
h->cursor = h->cursor->prev)
@@ -359,9 +363,9 @@ history_set_nth(ptr_t p, HistEvent *ev, int n)
break;
if (h->cursor == &h->list) {
he_seterrev(ev, _HE_NOT_FOUND);
- return (-1);
+ return -1;
}
- return (0);
+ return 0;
}
@@ -369,45 +373,46 @@ history_set_nth(ptr_t p, HistEvent *ev, int n)
* Append string to element
*/
private int
-history_def_add(ptr_t p, HistEvent *ev, const char *str)
+history_def_add(void *p, TYPE(HistEvent) *ev, const Char *str)
{
history_t *h = (history_t *) p;
size_t len;
- char *s;
+ Char *s;
HistEventPrivate *evp = (void *)&h->cursor->ev;
if (h->cursor == &h->list)
- return (history_def_enter(p, ev, str));
- len = strlen(evp->str) + strlen(str) + 1;
- s = (char *) h_malloc(len);
+ return history_def_enter(p, ev, str);
+ len = Strlen(evp->str) + Strlen(str) + 1;
+ s = h_malloc(len * sizeof(*s));
if (s == NULL) {
he_seterrev(ev, _HE_MALLOC_FAILED);
- return (-1);
+ return -1;
}
- (void) strlcpy(s, h->cursor->ev.str, len);
- (void) strlcat(s, str, len);
- h_free((ptr_t)evp->str);
+ (void) Strncpy(s, h->cursor->ev.str, len);
+ s[len - 1] = '\0';
+ (void) Strncat(s, str, len - Strlen(s) - 1);
+ h_free(evp->str);
evp->str = s;
*ev = h->cursor->ev;
- return (0);
+ return 0;
}
private int
-history_deldata_nth(history_t *h, HistEvent *ev,
+history_deldata_nth(history_t *h, TYPE(HistEvent) *ev,
int num, void **data)
{
if (history_set_nth(h, ev, num) != 0)
- return (-1);
+ 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);
+ 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);
+ return 0;
}
@@ -416,16 +421,16 @@ history_deldata_nth(history_t *h, HistEvent *ev,
*/
/* ARGSUSED */
private int
-history_def_del(ptr_t p, HistEvent *ev __unused,
+history_def_del(void *p, TYPE(HistEvent) *ev __attribute__((__unused__)),
const int num)
{
history_t *h = (history_t *) p;
if (history_def_set(h, ev, num) != 0)
- return (-1);
- ev->str = strdup(h->cursor->ev.str);
+ return -1;
+ ev->str = Strdup(h->cursor->ev.str);
ev->num = h->cursor->ev.num;
history_def_delete(h, ev, h->cursor);
- return (0);
+ return 0;
}
@@ -435,7 +440,7 @@ history_def_del(ptr_t p, HistEvent *ev __unused,
/* ARGSUSED */
private void
history_def_delete(history_t *h,
- HistEvent *ev __unused, hentry_t *hp)
+ TYPE(HistEvent) *ev __attribute__((__unused__)), hentry_t *hp)
{
HistEventPrivate *evp = (void *)&hp->ev;
if (hp == &h->list)
@@ -447,7 +452,7 @@ history_def_delete(history_t *h,
}
hp->prev->next = hp->next;
hp->next->prev = hp->prev;
- h_free((ptr_t) evp->str);
+ h_free(evp->str);
h_free(hp);
h->cur--;
}
@@ -457,29 +462,31 @@ history_def_delete(history_t *h,
* Insert element with string str in the h list
*/
private int
-history_def_insert(history_t *h, HistEvent *ev, const char *str)
+history_def_insert(history_t *h, TYPE(HistEvent) *ev, const Char *str)
{
+ hentry_t *c;
- h->cursor = (hentry_t *) h_malloc(sizeof(hentry_t));
- if (h->cursor == NULL)
+ c = h_malloc(sizeof(*c));
+ if (c == NULL)
goto oomem;
- if ((h->cursor->ev.str = h_strdup(str)) == NULL) {
- h_free((ptr_t)h->cursor);
+ if ((c->ev.str = h_strdup(str)) == NULL) {
+ h_free(c);
goto oomem;
}
- h->cursor->data = NULL;
- h->cursor->ev.num = ++h->eventid;
- h->cursor->next = h->list.next;
- h->cursor->prev = &h->list;
- h->list.next->prev = h->cursor;
- h->list.next = h->cursor;
+ c->data = NULL;
+ c->ev.num = ++h->eventid;
+ c->next = h->list.next;
+ c->prev = &h->list;
+ h->list.next->prev = c;
+ h->list.next = c;
h->cur++;
+ h->cursor = c;
- *ev = h->cursor->ev;
- return (0);
+ *ev = c->ev;
+ return 0;
oomem:
he_seterrev(ev, _HE_MALLOC_FAILED);
- return (-1);
+ return -1;
}
@@ -487,16 +494,16 @@ oomem:
* Default function to enter an item in the history
*/
private int
-history_def_enter(ptr_t p, HistEvent *ev, const char *str)
+history_def_enter(void *p, TYPE(HistEvent) *ev, const Char *str)
{
history_t *h = (history_t *) p;
if ((h->flags & H_UNIQUE) != 0 && h->list.next != &h->list &&
- strcmp(h->list.next->ev.str, str) == 0)
- return (0);
+ Strcmp(h->list.next->ev.str, str) == 0)
+ return 0;
if (history_def_insert(h, ev, str) == -1)
- return (-1); /* error, keep error message */
+ return -1; /* error, keep error message */
/*
* Always keep at least one entry.
@@ -505,7 +512,7 @@ history_def_enter(ptr_t p, HistEvent *ev, const char *str)
while (h->cur > h->max && h->cur > 0)
history_def_delete(h, ev, h->list.prev);
- return (1);
+ return 1;
}
@@ -514,9 +521,9 @@ history_def_enter(ptr_t p, HistEvent *ev, const char *str)
*/
/* ARGSUSED */
private int
-history_def_init(ptr_t *p, HistEvent *ev __unused, int n)
+history_def_init(void **p, TYPE(HistEvent) *ev __attribute__((__unused__)), int n)
{
- history_t *h = (history_t *) h_malloc(sizeof(history_t));
+ history_t *h = (history_t *) h_malloc(sizeof(*h));
if (h == NULL)
return -1;
@@ -530,7 +537,7 @@ history_def_init(ptr_t *p, HistEvent *ev __unused, int n)
h->list.ev.num = 0;
h->cursor = &h->list;
h->flags = 0;
- *p = (ptr_t) h;
+ *p = h;
return 0;
}
@@ -539,12 +546,13 @@ history_def_init(ptr_t *p, HistEvent *ev __unused, int n)
* Default history cleanup function
*/
private void
-history_def_clear(ptr_t p, HistEvent *ev)
+history_def_clear(void *p, TYPE(HistEvent) *ev)
{
history_t *h = (history_t *) p;
while (h->list.prev != &h->list)
history_def_delete(h, ev, h->list.prev);
+ h->cursor = &h->list;
h->eventid = 0;
h->cur = 0;
}
@@ -557,16 +565,16 @@ history_def_clear(ptr_t p, HistEvent *ev)
/* history_init():
* Initialization function.
*/
-public History *
-history_init(void)
+public TYPE(History) *
+FUN(history,init)(void)
{
- HistEvent ev;
- History *h = (History *) h_malloc(sizeof(History));
+ TYPE(HistEvent) ev;
+ TYPE(History) *h = (TYPE(History) *) h_malloc(sizeof(*h));
if (h == NULL)
return NULL;
if (history_def_init(&h->h_ref, &ev, 0) == -1) {
- h_free((ptr_t)h);
+ h_free(h);
return NULL;
}
h->h_ent = -1;
@@ -581,7 +589,7 @@ history_init(void)
h->h_add = history_def_add;
h->h_del = history_def_del;
- return (h);
+ return h;
}
@@ -589,9 +597,9 @@ history_init(void)
* clean up history;
*/
public void
-history_end(History *h)
+FUN(history,end)(TYPE(History) *h)
{
- HistEvent ev;
+ TYPE(HistEvent) ev;
if (h->h_next == history_def_next)
history_def_clear(h->h_ref, &ev);
@@ -605,19 +613,19 @@ history_end(History *h)
* Set history number of events
*/
private int
-history_setsize(History *h, HistEvent *ev, int num)
+history_setsize(TYPE(History) *h, TYPE(HistEvent) *ev, int num)
{
if (h->h_next != history_def_next) {
he_seterrev(ev, _HE_NOT_ALLOWED);
- return (-1);
+ return -1;
}
if (num < 0) {
he_seterrev(ev, _HE_BAD_PARAM);
- return (-1);
+ return -1;
}
history_def_setsize(h->h_ref, num);
- return (0);
+ return 0;
}
@@ -625,18 +633,18 @@ history_setsize(History *h, HistEvent *ev, int num)
* Get number of events currently in history
*/
private int
-history_getsize(History *h, HistEvent *ev)
+history_getsize(TYPE(History) *h, TYPE(HistEvent) *ev)
{
if (h->h_next != history_def_next) {
he_seterrev(ev, _HE_NOT_ALLOWED);
- return (-1);
+ return -1;
}
ev->num = history_def_getsize(h->h_ref);
if (ev->num < -1) {
he_seterrev(ev, _HE_SIZE_NEGATIVE);
- return (-1);
+ return -1;
}
- return (0);
+ return 0;
}
@@ -644,15 +652,15 @@ history_getsize(History *h, HistEvent *ev)
* Set if adjacent equal events should not be entered in history.
*/
private int
-history_setunique(History *h, HistEvent *ev, int uni)
+history_setunique(TYPE(History) *h, TYPE(HistEvent) *ev, int uni)
{
if (h->h_next != history_def_next) {
he_seterrev(ev, _HE_NOT_ALLOWED);
- return (-1);
+ return -1;
}
history_def_setunique(h->h_ref, uni);
- return (0);
+ return 0;
}
@@ -660,14 +668,14 @@ history_setunique(History *h, HistEvent *ev, int uni)
* Get if adjacent equal events should not be entered in history.
*/
private int
-history_getunique(History *h, HistEvent *ev)
+history_getunique(TYPE(History) *h, TYPE(HistEvent) *ev)
{
if (h->h_next != history_def_next) {
he_seterrev(ev, _HE_NOT_ALLOWED);
- return (-1);
+ return -1;
}
ev->num = history_def_getunique(h->h_ref);
- return (0);
+ return 0;
}
@@ -675,16 +683,17 @@ history_getunique(History *h, HistEvent *ev)
* Set history functions
*/
private int
-history_set_fun(History *h, History *nh)
+history_set_fun(TYPE(History) *h, TYPE(History) *nh)
{
- HistEvent ev;
+ TYPE(HistEvent) ev;
if (nh->h_first == NULL || nh->h_next == NULL || nh->h_last == NULL ||
nh->h_prev == NULL || nh->h_curr == NULL || nh->h_set == NULL ||
nh->h_enter == NULL || nh->h_add == NULL || nh->h_clear == NULL ||
nh->h_del == NULL || nh->h_ref == NULL) {
if (h->h_next != history_def_next) {
- history_def_init(&h->h_ref, &ev, 0);
+ if (history_def_init(&h->h_ref, &ev, 0) == -1)
+ return -1;
h->h_first = history_def_first;
h->h_next = history_def_next;
h->h_last = history_def_last;
@@ -696,7 +705,7 @@ history_set_fun(History *h, History *nh)
h->h_add = history_def_add;
h->h_del = history_def_del;
}
- return (-1);
+ return -1;
}
if (h->h_next == history_def_next)
history_def_clear(h->h_ref, &ev);
@@ -713,25 +722,28 @@ history_set_fun(History *h, History *nh)
h->h_add = nh->h_add;
h->h_del = nh->h_del;
- return (0);
+ return 0;
}
/* history_load():
- * History load function
+ * TYPE(History) load function
*/
private int
-history_load(History *h, const char *fname)
+history_load(TYPE(History) *h, const char *fname)
{
FILE *fp;
char *line;
size_t sz, max_size;
char *ptr;
int i = -1;
- HistEvent ev;
+ TYPE(HistEvent) ev;
+#ifdef WIDECHAR
+ static ct_buffer_t conv;
+#endif
if ((fp = fopen(fname, "r")) == NULL)
- return (i);
+ return i;
if ((line = fgetln(fp, &sz)) == NULL)
goto done;
@@ -739,7 +751,7 @@ history_load(History *h, const char *fname)
if (strncmp(line, hist_cookie, sz) != 0)
goto done;
- ptr = h_malloc(max_size = 1024);
+ ptr = h_malloc((max_size = 1024) * sizeof(*ptr));
if (ptr == NULL)
goto done;
for (i = 0; (line = fgetln(fp, &sz)) != NULL; i++) {
@@ -752,8 +764,8 @@ history_load(History *h, const char *fname)
if (max_size < sz) {
char *nptr;
- max_size = (sz + 1024) & ~1023;
- nptr = h_realloc(ptr, max_size);
+ max_size = (sz + 1024) & (size_t)~1023;
+ nptr = h_realloc(ptr, max_size * sizeof(*ptr));
if (nptr == NULL) {
i = -1;
goto oomem;
@@ -762,77 +774,82 @@ history_load(History *h, const char *fname)
}
(void) strunvis(ptr, line);
line[sz] = c;
- if (HENTER(h, &ev, ptr) == -1) {
+ if (HENTER(h, &ev, ct_decode_string(ptr, &conv)) == -1) {
i = -1;
goto oomem;
}
}
oomem:
- h_free((ptr_t)ptr);
+ h_free(ptr);
done:
(void) fclose(fp);
- return (i);
+ return i;
}
+
/* history_save_fp():
- * History save with open FILE*
+ * TYPE(History) save function
*/
-private int history_save_fp(History *h, FILE* fp)
+private int
+history_save_fp(TYPE(History) *h, FILE *fp)
{
- HistEvent ev;
+ TYPE(HistEvent) ev;
int i = -1, retval;
size_t len, max_size;
char *ptr;
+ const char *str;
+#ifdef WIDECHAR
+ static ct_buffer_t conv;
+#endif
if (fchmod(fileno(fp), S_IRUSR|S_IWUSR) == -1)
goto done;
if (fputs(hist_cookie, fp) == EOF)
goto done;
- ptr = h_malloc(max_size = 1024);
+ ptr = h_malloc((max_size = 1024) * sizeof(*ptr));
if (ptr == NULL)
goto done;
for (i = 0, retval = HLAST(h, &ev);
retval != -1;
retval = HPREV(h, &ev), i++) {
- len = strlen(ev.str) * 4;
+ str = ct_encode_string(ev.str, &conv);
+ len = strlen(str) * 4;
if (len >= max_size) {
char *nptr;
- max_size = (len + 1024) & ~1023;
- nptr = h_realloc(ptr, max_size);
+ max_size = (len + 1024) & (size_t)~1023;
+ nptr = h_realloc(ptr, max_size * sizeof(*ptr));
if (nptr == NULL) {
i = -1;
goto oomem;
}
ptr = nptr;
}
- (void) strvis(ptr, ev.str, VIS_WHITE);
+ (void) strvis(ptr, str, VIS_WHITE);
(void) fprintf(fp, "%s\n", ptr);
}
oomem:
- h_free((ptr_t)ptr);
+ h_free(ptr);
done:
- return (i);
-
+ return i;
}
/* history_save():
- * History save function
+ * History save function
*/
private int
-history_save(History *h, const char *fname)
+history_save(TYPE(History) *h, const char *fname)
{
- FILE *fp;
- int i;
+ FILE *fp;
+ int i;
- if ((fp = fopen(fname, "w")) == NULL)
- return (-1);
+ if ((fp = fopen(fname, "w")) == NULL)
+ return -1;
- i = history_save_fp(h, fp);
+ i = history_save_fp(h, fp);
-done:
- (void) fclose(fp);
- return (i);
+ (void) fclose(fp);
+ return i;
}
@@ -840,33 +857,33 @@ done:
* Find the previous event, with number given
*/
private int
-history_prev_event(History *h, HistEvent *ev, int num)
+history_prev_event(TYPE(History) *h, TYPE(HistEvent) *ev, int num)
{
int retval;
for (retval = HCURR(h, ev); retval != -1; retval = HPREV(h, ev))
if (ev->num == num)
- return (0);
+ return 0;
he_seterrev(ev, _HE_NOT_FOUND);
- return (-1);
+ return -1;
}
private int
-history_next_evdata(History *h, HistEvent *ev, int num, void **d)
+history_next_evdata(TYPE(History) *h, TYPE(HistEvent) *ev, int num, void **d)
{
int retval;
for (retval = HCURR(h, ev); retval != -1; retval = HPREV(h, ev))
- if (num-- <= 0) {
+ if (ev->num == num) {
if (d)
*d = ((history_t *)h->h_ref)->cursor->data;
- return (0);
+ return 0;
}
he_seterrev(ev, _HE_NOT_FOUND);
- return (-1);
+ return -1;
}
@@ -874,16 +891,16 @@ history_next_evdata(History *h, HistEvent *ev, int num, void **d)
* Find the next event, with number given
*/
private int
-history_next_event(History *h, HistEvent *ev, int num)
+history_next_event(TYPE(History) *h, TYPE(HistEvent) *ev, int num)
{
int retval;
for (retval = HCURR(h, ev); retval != -1; retval = HNEXT(h, ev))
if (ev->num == num)
- return (0);
+ return 0;
he_seterrev(ev, _HE_NOT_FOUND);
- return (-1);
+ return -1;
}
@@ -891,17 +908,17 @@ history_next_event(History *h, HistEvent *ev, int num)
* Find the previous event beginning with string
*/
private int
-history_prev_string(History *h, HistEvent *ev, const char *str)
+history_prev_string(TYPE(History) *h, TYPE(HistEvent) *ev, const Char *str)
{
- size_t len = strlen(str);
+ size_t len = Strlen(str);
int retval;
for (retval = HCURR(h, ev); retval != -1; retval = HNEXT(h, ev))
- if (strncmp(str, ev->str, len) == 0)
- return (0);
+ if (Strncmp(str, ev->str, len) == 0)
+ return 0;
he_seterrev(ev, _HE_NOT_FOUND);
- return (-1);
+ return -1;
}
@@ -909,17 +926,17 @@ history_prev_string(History *h, HistEvent *ev, const char *str)
* Find the next event beginning with string
*/
private int
-history_next_string(History *h, HistEvent *ev, const char *str)
+history_next_string(TYPE(History) *h, TYPE(HistEvent) *ev, const Char *str)
{
- size_t len = strlen(str);
+ size_t len = Strlen(str);
int retval;
for (retval = HCURR(h, ev); retval != -1; retval = HPREV(h, ev))
- if (strncmp(str, ev->str, len) == 0)
- return (0);
+ if (Strncmp(str, ev->str, len) == 0)
+ return 0;
he_seterrev(ev, _HE_NOT_FOUND);
- return (-1);
+ return -1;
}
@@ -927,10 +944,10 @@ history_next_string(History *h, HistEvent *ev, const char *str)
* User interface to history functions.
*/
int
-history(History *h, HistEvent *ev, int fun, ...)
+FUNW(history)(TYPE(History) *h, TYPE(HistEvent) *ev, int fun, ...)
{
va_list va;
- const char *str;
+ const Char *str;
int retval;
va_start(va, fun);
@@ -955,7 +972,7 @@ history(History *h, HistEvent *ev, int fun, ...)
break;
case H_ADD:
- str = va_arg(va, const char *);
+ str = va_arg(va, const Char *);
retval = HADD(h, ev, str);
break;
@@ -964,13 +981,13 @@ history(History *h, HistEvent *ev, int fun, ...)
break;
case H_ENTER:
- str = va_arg(va, const char *);
+ str = va_arg(va, const Char *);
if ((retval = HENTER(h, ev, str)) != -1)
h->h_ent = ev->num;
break;
case H_APPEND:
- str = va_arg(va, const char *);
+ str = va_arg(va, const Char *);
if ((retval = HSET(h, ev, h->h_ent)) != -1)
retval = HADD(h, ev, str);
break;
@@ -1017,9 +1034,9 @@ history(History *h, HistEvent *ev, int fun, ...)
break;
case H_SAVE_FP:
- retval = history_save_fp(h, va_arg(va, FILE*));
+ retval = history_save_fp(h, va_arg(va, FILE *));
if (retval == -1)
- he_seterrev(ev, _HE_HIST_WRITE);
+ he_seterrev(ev, _HE_HIST_WRITE);
break;
case H_PREV_EVENT:
@@ -1031,18 +1048,18 @@ history(History *h, HistEvent *ev, int fun, ...)
break;
case H_PREV_STR:
- retval = history_prev_string(h, ev, va_arg(va, const char *));
+ retval = history_prev_string(h, ev, va_arg(va, const Char *));
break;
case H_NEXT_STR:
- retval = history_next_string(h, ev, va_arg(va, const char *));
+ retval = history_next_string(h, ev, va_arg(va, const Char *));
break;
case H_FUNC:
{
- History hf;
+ TYPE(History) hf;
- hf.h_ref = va_arg(va, ptr_t);
+ hf.h_ref = va_arg(va, void *);
h->h_ent = -1;
hf.h_first = va_arg(va, history_gfun_t);
hf.h_next = va_arg(va, history_gfun_t);
@@ -1061,7 +1078,7 @@ history(History *h, HistEvent *ev, int fun, ...)
}
case H_END:
- history_end(h);
+ FUN(history,end)(h);
retval = 0;
break;
@@ -1083,10 +1100,10 @@ history(History *h, HistEvent *ev, int fun, ...)
case H_REPLACE: /* only use after H_NEXT_EVDATA */
{
- const char *line = va_arg(va, const char *);
+ const Char *line = va_arg(va, const Char *);
void *d = va_arg(va, void *);
- const char *s;
- if(!line || !(s = strdup(line))) {
+ const Char *s;
+ if(!line || !(s = Strdup(line))) {
retval = -1;
break;
}
diff --git a/lib/libedit/key.c b/lib/libedit/keymacro.c
index 5a0b779..1a1bdd5 100644
--- a/lib/libedit/key.c
+++ b/lib/libedit/keymacro.c
@@ -1,3 +1,5 @@
+/* $NetBSD: keymacro.c,v 1.7 2011/08/16 16:25:15 christos Exp $ */
+
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -28,31 +30,35 @@
* 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.
- *
- * $NetBSD: key.c,v 1.20 2009/02/15 21:55:23 christos Exp $
*/
+#include "config.h"
#if !defined(lint) && !defined(SCCSID)
+#if 0
static char sccsid[] = "@(#)key.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: keymacro.c,v 1.7 2011/08/16 16:25:15 christos Exp $");
+#endif
#endif /* not lint && not SCCSID */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
/*
- * key.c: This module contains the procedures for maintaining
- * the extended-key map.
+ * keymacro.c: This module contains the procedures for maintaining
+ * the extended-key map.
*
* An extended-key (key) is a sequence of keystrokes introduced
* with a sequence introducer and consisting of an arbitrary
- * number of characters. This module maintains a map (the el->el_key.map)
+ * number of characters. This module maintains a map (the
+ * el->el_keymacro.map)
* to convert these extended-key sequences into input strs
* (XK_STR), editor functions (XK_CMD), or unix commands (XK_EXE).
*
* Warning:
* If key is a substr of some other keys, then the longer
* keys are lost!! That is, if the keys "abcd" and "abcef"
- * are in el->el_key.map, adding the key "abc" will cause the first two
- * definitions to be lost.
+ * are in el->el_keymacro.map, adding the key "abc" will cause
+ * the first two definitions to be lost.
*
* Restrictions:
* -------------
@@ -65,102 +71,104 @@ __FBSDID("$FreeBSD$");
#include "el.h"
/*
- * The Nodes of the el->el_key.map. The el->el_key.map is a linked list
- * of these node elements
+ * The Nodes of the el->el_keymacro.map. The el->el_keymacro.map is a
+ * linked list of these node elements
*/
-struct key_node_t {
- char ch; /* single character of key */
- int type; /* node type */
- key_value_t val; /* command code or pointer to str, */
+struct keymacro_node_t {
+ Char ch; /* single character of key */
+ int type; /* node type */
+ keymacro_value_t val; /* command code or pointer to str, */
/* if this is a leaf */
- struct key_node_t *next; /* ptr to next char of this key */
- struct key_node_t *sibling; /* ptr to another key with same prefix*/
+ struct keymacro_node_t *next; /* ptr to next char of this key */
+ struct keymacro_node_t *sibling;/* ptr to another key with same prefix*/
};
-private int node_trav(EditLine *, key_node_t *, char *,
- key_value_t *);
-private int node__try(EditLine *, key_node_t *, const char *,
- key_value_t *, int);
-private key_node_t *node__get(int);
-private void node__free(key_node_t *);
-private void node__put(EditLine *, key_node_t *);
-private int node__delete(EditLine *, key_node_t **, const char *);
-private int node_lookup(EditLine *, const char *, key_node_t *,
- size_t);
-private int node_enum(EditLine *, key_node_t *, size_t);
+private int node_trav(EditLine *, keymacro_node_t *, Char *,
+ keymacro_value_t *);
+private int node__try(EditLine *, keymacro_node_t *, const Char *,
+ keymacro_value_t *, int);
+private keymacro_node_t *node__get(Int);
+private void node__free(keymacro_node_t *);
+private void node__put(EditLine *, keymacro_node_t *);
+private int node__delete(EditLine *, keymacro_node_t **,
+ const Char *);
+private int node_lookup(EditLine *, const Char *,
+ keymacro_node_t *, size_t);
+private int node_enum(EditLine *, keymacro_node_t *, size_t);
#define KEY_BUFSIZ EL_BUFSIZ
-/* key_init():
+/* keymacro_init():
* Initialize the key maps
*/
protected int
-key_init(EditLine *el)
+keymacro_init(EditLine *el)
{
- el->el_key.buf = (char *) el_malloc(KEY_BUFSIZ);
- if (el->el_key.buf == NULL)
- return (-1);
- el->el_key.map = NULL;
- key_reset(el);
- return (0);
+ el->el_keymacro.buf = el_malloc(KEY_BUFSIZ *
+ sizeof(*el->el_keymacro.buf));
+ if (el->el_keymacro.buf == NULL)
+ return -1;
+ el->el_keymacro.map = NULL;
+ keymacro_reset(el);
+ return 0;
}
-/* key_end():
+/* keymacro_end():
* Free the key maps
*/
protected void
-key_end(EditLine *el)
+keymacro_end(EditLine *el)
{
- el_free((ptr_t) el->el_key.buf);
- el->el_key.buf = NULL;
- node__free(el->el_key.map);
+ el_free(el->el_keymacro.buf);
+ el->el_keymacro.buf = NULL;
+ node__free(el->el_keymacro.map);
}
-/* key_map_cmd():
+/* keymacro_map_cmd():
* Associate cmd with a key value
*/
-protected key_value_t *
-key_map_cmd(EditLine *el, int cmd)
+protected keymacro_value_t *
+keymacro_map_cmd(EditLine *el, int cmd)
{
- el->el_key.val.cmd = (el_action_t) cmd;
- return (&el->el_key.val);
+ el->el_keymacro.val.cmd = (el_action_t) cmd;
+ return &el->el_keymacro.val;
}
-/* key_map_str():
+/* keymacro_map_str():
* Associate str with a key value
*/
-protected key_value_t *
-key_map_str(EditLine *el, char *str)
+protected keymacro_value_t *
+keymacro_map_str(EditLine *el, Char *str)
{
- el->el_key.val.str = str;
- return (&el->el_key.val);
+ el->el_keymacro.val.str = str;
+ return &el->el_keymacro.val;
}
-/* key_reset():
- * Takes all nodes on el->el_key.map and puts them on free list. Then
- * initializes el->el_key.map with arrow keys
+/* keymacro_reset():
+ * Takes all nodes on el->el_keymacro.map and puts them on free list.
+ * Then initializes el->el_keymacro.map with arrow keys
* [Always bind the ansi arrow keys?]
*/
protected void
-key_reset(EditLine *el)
+keymacro_reset(EditLine *el)
{
- node__put(el, el->el_key.map);
- el->el_key.map = NULL;
+ node__put(el, el->el_keymacro.map);
+ el->el_keymacro.map = NULL;
return;
}
-/* key_get():
- * Calls the recursive function with entry point el->el_key.map
+/* keymacro_get():
+ * Calls the recursive function with entry point el->el_keymacro.map
* Looks up *ch in map and then reads characters until a
* complete match is found or a mismatch occurs. Returns the
* type of the match found (XK_STR, XK_CMD, or XK_EXE).
@@ -168,98 +176,101 @@ key_reset(EditLine *el)
* The last character read is returned in *ch.
*/
protected int
-key_get(EditLine *el, char *ch, key_value_t *val)
+keymacro_get(EditLine *el, Char *ch, keymacro_value_t *val)
{
- return (node_trav(el, el->el_key.map, ch, val));
+ return node_trav(el, el->el_keymacro.map, ch, val);
}
-/* key_add():
- * Adds key to the el->el_key.map and associates the value in val with it.
- * If key is already is in el->el_key.map, the new code is applied to the
- * existing key. Ntype specifies if code is a command, an
- * out str or a unix command.
+/* keymacro_add():
+ * Adds key to the el->el_keymacro.map and associates the value in
+ * val with it. If key is already is in el->el_keymacro.map, the new
+ * code is applied to the existing key. Ntype specifies if code is a
+ * command, an out str or a unix command.
*/
protected void
-key_add(EditLine *el, const char *key, key_value_t *val, int ntype)
+keymacro_add(EditLine *el, const Char *key, keymacro_value_t *val, int ntype)
{
if (key[0] == '\0') {
(void) fprintf(el->el_errfile,
- "key_add: Null extended-key not allowed.\n");
+ "keymacro_add: Null extended-key not allowed.\n");
return;
}
if (ntype == XK_CMD && val->cmd == ED_SEQUENCE_LEAD_IN) {
(void) fprintf(el->el_errfile,
- "key_add: sequence-lead-in command not allowed\n");
+ "keymacro_add: sequence-lead-in command not allowed\n");
return;
}
- if (el->el_key.map == NULL)
+ if (el->el_keymacro.map == NULL)
/* tree is initially empty. Set up new node to match key[0] */
- el->el_key.map = node__get(key[0]);
+ el->el_keymacro.map = node__get(key[0]);
/* it is properly initialized */
- /* Now recurse through el->el_key.map */
- (void) node__try(el, el->el_key.map, key, val, ntype);
+ /* Now recurse through el->el_keymacro.map */
+ (void) node__try(el, el->el_keymacro.map, key, val, ntype);
return;
}
-/* key_clear():
+/* keymacro_clear():
*
*/
protected void
-key_clear(EditLine *el, el_action_t *map, const char *in)
+keymacro_clear(EditLine *el, el_action_t *map, const Char *in)
{
-
+#ifdef WIDECHAR
+ if (*in > N_KEYS) /* can't be in the map */
+ return;
+#endif
if ((map[(unsigned char)*in] == ED_SEQUENCE_LEAD_IN) &&
((map == el->el_map.key &&
el->el_map.alt[(unsigned char)*in] != ED_SEQUENCE_LEAD_IN) ||
(map == el->el_map.alt &&
el->el_map.key[(unsigned char)*in] != ED_SEQUENCE_LEAD_IN)))
- (void) key_delete(el, in);
+ (void) keymacro_delete(el, in);
}
-/* key_delete():
+/* keymacro_delete():
* Delete the key and all longer keys staring with key, if
* they exists.
*/
protected int
-key_delete(EditLine *el, const char *key)
+keymacro_delete(EditLine *el, const Char *key)
{
if (key[0] == '\0') {
(void) fprintf(el->el_errfile,
- "key_delete: Null extended-key not allowed.\n");
- return (-1);
+ "keymacro_delete: Null extended-key not allowed.\n");
+ return -1;
}
- if (el->el_key.map == NULL)
- return (0);
+ if (el->el_keymacro.map == NULL)
+ return 0;
- (void) node__delete(el, &el->el_key.map, key);
- return (0);
+ (void) node__delete(el, &el->el_keymacro.map, key);
+ return 0;
}
-/* key_print():
+/* keymacro_print():
* Print the binding associated with key key.
- * Print entire el->el_key.map if null
+ * Print entire el->el_keymacro.map if null
*/
protected void
-key_print(EditLine *el, const char *key)
+keymacro_print(EditLine *el, const Char *key)
{
- /* do nothing if el->el_key.map is empty and null key specified */
- if (el->el_key.map == NULL && *key == 0)
+ /* do nothing if el->el_keymacro.map is empty and null key specified */
+ if (el->el_keymacro.map == NULL && *key == 0)
return;
- el->el_key.buf[0] = '"';
- if (node_lookup(el, key, el->el_key.map, 1) <= -1)
+ el->el_keymacro.buf[0] = '"';
+ if (node_lookup(el, key, el->el_keymacro.map, (size_t)1) <= -1)
/* key is not bound */
- (void) fprintf(el->el_errfile, "Unbound extended key \"%s\"\n",
- key);
+ (void) fprintf(el->el_errfile, "Unbound extended key \"" FSTR
+ "\"\n", key);
return;
}
@@ -269,34 +280,34 @@ key_print(EditLine *el, const char *key)
* found. May read in more characters.
*/
private int
-node_trav(EditLine *el, key_node_t *ptr, char *ch, key_value_t *val)
+node_trav(EditLine *el, keymacro_node_t *ptr, Char *ch, keymacro_value_t *val)
{
if (ptr->ch == *ch) {
/* match found */
if (ptr->next) {
/* key not complete so get next char */
- if (el_getc(el, ch) != 1) { /* if EOF or error */
+ if (FUN(el,getc)(el, ch) != 1) {/* if EOF or error */
val->cmd = ED_END_OF_FILE;
- return (XK_CMD);
+ return XK_CMD;
/* PWP: Pretend we just read an end-of-file */
}
- return (node_trav(el, ptr->next, ch, val));
+ return node_trav(el, ptr->next, ch, val);
} else {
*val = ptr->val;
if (ptr->type != XK_CMD)
*ch = '\0';
- return (ptr->type);
+ return ptr->type;
}
} else {
/* no match found here */
if (ptr->sibling) {
/* try next sibling */
- return (node_trav(el, ptr->sibling, ch, val));
+ return node_trav(el, ptr->sibling, ch, val);
} else {
/* no next sibling -- mismatch */
val->str = NULL;
- return (XK_STR);
+ return XK_STR;
}
}
}
@@ -306,11 +317,12 @@ node_trav(EditLine *el, key_node_t *ptr, char *ch, key_value_t *val)
* Find a node that matches *str or allocate a new one
*/
private int
-node__try(EditLine *el, key_node_t *ptr, const char *str, key_value_t *val, int ntype)
+node__try(EditLine *el, keymacro_node_t *ptr, const Char *str,
+ keymacro_value_t *val, int ntype)
{
if (ptr->ch != *str) {
- key_node_t *xm;
+ keymacro_node_t *xm;
for (xm = ptr; xm->sibling != NULL; xm = xm->sibling)
if (xm->sibling->ch == *str)
@@ -333,7 +345,7 @@ node__try(EditLine *el, key_node_t *ptr, const char *str, key_value_t *val, int
case XK_STR:
case XK_EXE:
if (ptr->val.str)
- el_free((ptr_t) ptr->val.str);
+ el_free(ptr->val.str);
break;
default:
EL_ABORT((el->el_errfile, "Bad XK_ type %d\n",
@@ -347,7 +359,7 @@ node__try(EditLine *el, key_node_t *ptr, const char *str, key_value_t *val, int
break;
case XK_STR:
case XK_EXE:
- if ((ptr->val.str = el_strdup(val->str)) == NULL)
+ if ((ptr->val.str = Strdup(val->str)) == NULL)
return -1;
break;
default:
@@ -360,7 +372,7 @@ node__try(EditLine *el, key_node_t *ptr, const char *str, key_value_t *val, int
ptr->next = node__get(*str); /* setup new node */
(void) node__try(el, ptr->next, str, val, ntype);
}
- return (0);
+ return 0;
}
@@ -368,21 +380,21 @@ node__try(EditLine *el, key_node_t *ptr, const char *str, key_value_t *val, int
* Delete node that matches str
*/
private int
-node__delete(EditLine *el, key_node_t **inptr, const char *str)
+node__delete(EditLine *el, keymacro_node_t **inptr, const Char *str)
{
- key_node_t *ptr;
- key_node_t *prev_ptr = NULL;
+ keymacro_node_t *ptr;
+ keymacro_node_t *prev_ptr = NULL;
ptr = *inptr;
if (ptr->ch != *str) {
- key_node_t *xm;
+ keymacro_node_t *xm;
for (xm = ptr; xm->sibling != NULL; xm = xm->sibling)
if (xm->sibling->ch == *str)
break;
if (xm->sibling == NULL)
- return (0);
+ return 0;
prev_ptr = xm;
ptr = xm->sibling;
}
@@ -394,20 +406,20 @@ node__delete(EditLine *el, key_node_t **inptr, const char *str)
prev_ptr->sibling = ptr->sibling;
ptr->sibling = NULL;
node__put(el, ptr);
- return (1);
+ return 1;
} else if (ptr->next != NULL &&
node__delete(el, &ptr->next, str) == 1) {
if (ptr->next != NULL)
- return (0);
+ return 0;
if (prev_ptr == NULL)
*inptr = ptr->sibling;
else
prev_ptr->sibling = ptr->sibling;
ptr->sibling = NULL;
node__put(el, ptr);
- return (1);
+ return 1;
} else {
- return (0);
+ return 0;
}
}
@@ -416,7 +428,7 @@ node__delete(EditLine *el, key_node_t **inptr, const char *str)
* Puts a tree of nodes onto free list using free(3).
*/
private void
-node__put(EditLine *el, key_node_t *ptr)
+node__put(EditLine *el, keymacro_node_t *ptr)
{
if (ptr == NULL)
return;
@@ -434,25 +446,25 @@ node__put(EditLine *el, key_node_t *ptr)
case XK_EXE:
case XK_STR:
if (ptr->val.str != NULL)
- el_free((ptr_t) ptr->val.str);
+ el_free(ptr->val.str);
break;
default:
EL_ABORT((el->el_errfile, "Bad XK_ type %d\n", ptr->type));
break;
}
- el_free((ptr_t) ptr);
+ el_free(ptr);
}
/* node__get():
- * Returns pointer to a key_node_t for ch.
+ * Returns pointer to a keymacro_node_t for ch.
*/
-private key_node_t *
-node__get(int ch)
+private keymacro_node_t *
+node__get(Int ch)
{
- key_node_t *ptr;
+ keymacro_node_t *ptr;
- ptr = (key_node_t *) el_malloc((size_t) sizeof(key_node_t));
+ ptr = el_malloc(sizeof(*ptr));
if (ptr == NULL)
return NULL;
ptr->ch = ch;
@@ -460,17 +472,17 @@ node__get(int ch)
ptr->val.str = NULL;
ptr->next = NULL;
ptr->sibling = NULL;
- return (ptr);
+ return ptr;
}
private void
-node__free(key_node_t *k)
+node__free(keymacro_node_t *k)
{
if (k == NULL)
return;
node__free(k->sibling);
node__free(k->next);
- el_free((ptr_t) k);
+ el_free(k);
}
/* node_lookup():
@@ -478,38 +490,40 @@ node__free(key_node_t *k)
* Print if last node
*/
private int
-node_lookup(EditLine *el, const char *str, key_node_t *ptr, size_t cnt)
+node_lookup(EditLine *el, const Char *str, keymacro_node_t *ptr, size_t cnt)
{
- size_t ncnt;
+ ssize_t used;
if (ptr == NULL)
- return (-1); /* cannot have null ptr */
+ return -1; /* cannot have null ptr */
- if (*str == 0) {
+ if (!str || *str == 0) {
/* no more chars in str. node_enum from here. */
(void) node_enum(el, ptr, cnt);
- return (0);
+ return 0;
} else {
- /* If match put this char into el->el_key.buf. Recurse */
+ /* If match put this char into el->el_keymacro.buf. Recurse */
if (ptr->ch == *str) {
/* match found */
- ncnt = key__decode_char(el->el_key.buf,
- (size_t)KEY_BUFSIZ, cnt,
- (unsigned char) ptr->ch);
+ used = ct_visual_char(el->el_keymacro.buf + cnt,
+ KEY_BUFSIZ - cnt, ptr->ch);
+ if (used == -1)
+ return -1; /* ran out of buffer space */
if (ptr->next != NULL)
/* not yet at leaf */
return (node_lookup(el, str + 1, ptr->next,
- ncnt + 1));
+ (size_t)used + cnt));
else {
/* next node is null so key should be complete */
if (str[1] == 0) {
- el->el_key.buf[ncnt + 1] = '"';
- el->el_key.buf[ncnt + 2] = '\0';
- key_kprint(el, el->el_key.buf,
+ size_t px = cnt + (size_t)used;
+ el->el_keymacro.buf[px] = '"';
+ el->el_keymacro.buf[px + 1] = '\0';
+ keymacro_kprint(el, el->el_keymacro.buf,
&ptr->val, ptr->type);
- return (0);
+ return 0;
} else
- return (-1);
+ return -1;
/* mismatch -- str still has chars */
}
} else {
@@ -518,7 +532,7 @@ node_lookup(EditLine *el, const char *str, key_node_t *ptr, size_t cnt)
return (node_lookup(el, str, ptr->sibling,
cnt));
else
- return (-1);
+ return -1;
}
}
}
@@ -528,49 +542,50 @@ node_lookup(EditLine *el, const char *str, key_node_t *ptr, size_t cnt)
* Traverse the node printing the characters it is bound in buffer
*/
private int
-node_enum(EditLine *el, key_node_t *ptr, size_t cnt)
+node_enum(EditLine *el, keymacro_node_t *ptr, size_t cnt)
{
- size_t ncnt;
+ ssize_t used;
if (cnt >= KEY_BUFSIZ - 5) { /* buffer too small */
- el->el_key.buf[++cnt] = '"';
- el->el_key.buf[++cnt] = '\0';
+ el->el_keymacro.buf[++cnt] = '"';
+ el->el_keymacro.buf[++cnt] = '\0';
(void) fprintf(el->el_errfile,
"Some extended keys too long for internal print buffer");
- (void) fprintf(el->el_errfile, " \"%s...\"\n", el->el_key.buf);
- return (0);
+ (void) fprintf(el->el_errfile, " \"" FSTR "...\"\n",
+ el->el_keymacro.buf);
+ return 0;
}
if (ptr == NULL) {
#ifdef DEBUG_EDIT
(void) fprintf(el->el_errfile,
"node_enum: BUG!! Null ptr passed\n!");
#endif
- return (-1);
+ return -1;
}
/* put this char at end of str */
- ncnt = key__decode_char(el->el_key.buf, (size_t)KEY_BUFSIZ, cnt,
- (unsigned char)ptr->ch);
+ used = ct_visual_char(el->el_keymacro.buf + cnt, KEY_BUFSIZ - cnt,
+ ptr->ch);
if (ptr->next == NULL) {
/* print this key and function */
- el->el_key.buf[ncnt + 1] = '"';
- el->el_key.buf[ncnt + 2] = '\0';
- key_kprint(el, el->el_key.buf, &ptr->val, ptr->type);
+ el->el_keymacro.buf[cnt + (size_t)used ] = '"';
+ el->el_keymacro.buf[cnt + (size_t)used + 1] = '\0';
+ keymacro_kprint(el, el->el_keymacro.buf, &ptr->val, ptr->type);
} else
- (void) node_enum(el, ptr->next, ncnt + 1);
+ (void) node_enum(el, ptr->next, cnt + (size_t)used);
/* go to sibling if there is one */
if (ptr->sibling)
(void) node_enum(el, ptr->sibling, cnt);
- return (0);
+ return 0;
}
-/* key_kprint():
+/* keymacro_kprint():
* Print the specified key and its associated
* function specified by val
*/
protected void
-key_kprint(EditLine *el, const char *key, key_value_t *val, int ntype)
+keymacro_kprint(EditLine *el, const Char *key, keymacro_value_t *val, int ntype)
{
el_bindings_t *fp;
char unparsbuf[EL_BUFSIZ];
@@ -580,16 +595,19 @@ key_kprint(EditLine *el, const char *key, key_value_t *val, int ntype)
switch (ntype) {
case XK_STR:
case XK_EXE:
- (void) key__decode_str(val->str, unparsbuf,
+ (void) keymacro__decode_str(val->str, unparsbuf,
sizeof(unparsbuf),
ntype == XK_STR ? "\"\"" : "[]");
- (void) fprintf(el->el_outfile, fmt, key, unparsbuf);
+ (void) fprintf(el->el_outfile, fmt,
+ ct_encode_string(key, &el->el_scratch), unparsbuf);
break;
case XK_CMD:
for (fp = el->el_map.help; fp->name; fp++)
if (val->cmd == fp->func) {
+ ct_wcstombs(unparsbuf, fp->name, sizeof(unparsbuf));
+ unparsbuf[sizeof(unparsbuf) -1] = '\0';
(void) fprintf(el->el_outfile, fmt,
- key, fp->name);
+ ct_encode_string(key, &el->el_scratch), unparsbuf);
break;
}
#ifdef DEBUG_KEY
@@ -604,7 +622,8 @@ key_kprint(EditLine *el, const char *key, key_value_t *val, int ntype)
break;
}
else
- (void) fprintf(el->el_outfile, fmt, key, "no input");
+ (void) fprintf(el->el_outfile, fmt, ct_encode_string(key,
+ &el->el_scratch), "no input");
}
@@ -613,54 +632,14 @@ key_kprint(EditLine *el, const char *key, key_value_t *val, int ntype)
*b++ = c; \
else \
b++
-/* key__decode_char():
- * Put a printable form of char in buf.
- */
-protected size_t
-key__decode_char(char *buf, size_t cnt, size_t off, int ch)
-{
- char *sb = buf + off;
- char *eb = buf + cnt;
- char *b = sb;
-
- ch = (unsigned char)ch;
- if (ch == 0) {
- ADDC('^');
- ADDC('@');
- return (int)(b - sb);
- }
- if (iscntrl(ch)) {
- ADDC('^');
- if (ch == '\177')
- ADDC('?');
- else
- ADDC(toascii(ch) | 0100);
- } else if (ch == '^') {
- ADDC('\\');
- ADDC('^');
- } else if (ch == '\\') {
- ADDC('\\');
- ADDC('\\');
- } else if (ch == ' ' || (isprint(ch) && !isspace(ch))) {
- ADDC(ch);
- } else {
- ADDC('\\');
- ADDC((((unsigned int) ch >> 6) & 7) + '0');
- ADDC((((unsigned int) ch >> 3) & 7) + '0');
- ADDC((ch & 7) + '0');
- }
- return (size_t)(b - sb);
-}
-
-
-/* key__decode_str():
+/* keymacro__decode_str():
* Make a printable version of the ey
*/
protected size_t
-key__decode_str(const char *str, char *buf, size_t len, const char *sep)
+keymacro__decode_str(const Char *str, char *buf, size_t len, const char *sep)
{
char *b = buf, *eb = b + len;
- const char *p;
+ const Char *p;
b = buf;
if (sep[0] != '\0') {
@@ -669,36 +648,24 @@ key__decode_str(const char *str, char *buf, size_t len, const char *sep)
if (*str == '\0') {
ADDC('^');
ADDC('@');
- if (sep[0] != '\0' && sep[1] != '\0') {
- ADDC(sep[1]);
- }
- goto done;
+ goto add_endsep;
}
for (p = str; *p != 0; p++) {
- if (iscntrl((unsigned char) *p)) {
- ADDC('^');
- if (*p == '\177') {
- ADDC('?');
- } else {
- ADDC(toascii(*p) | 0100);
- }
- } else if (*p == '^' || *p == '\\') {
- ADDC('\\');
- ADDC(*p);
- } else if (*p == ' ' || (isprint((unsigned char) *p) &&
- !isspace((unsigned char) *p))) {
- ADDC(*p);
- } else {
- ADDC('\\');
- ADDC((((unsigned int) *p >> 6) & 7) + '0');
- ADDC((((unsigned int) *p >> 3) & 7) + '0');
- ADDC((*p & 7) + '0');
+ Char dbuf[VISUAL_WIDTH_MAX];
+ Char *p2 = dbuf;
+ ssize_t l = ct_visual_char(dbuf, VISUAL_WIDTH_MAX, *p);
+ while (l-- > 0) {
+ ssize_t n = ct_encode_char(b, (size_t)(eb - b), *p2++);
+ if (n == -1) /* ran out of space */
+ goto add_endsep;
+ else
+ b += n;
}
}
+add_endsep:
if (sep[0] != '\0' && sep[1] != '\0') {
ADDC(sep[1]);
}
-done:
ADDC('\0');
if ((size_t)(b - buf) >= len)
buf[len - 1] = '\0';
diff --git a/lib/libedit/key.h b/lib/libedit/keymacro.h
index 1997adc..57a7a5d 100644
--- a/lib/libedit/key.h
+++ b/lib/libedit/keymacro.h
@@ -1,3 +1,5 @@
+/* $NetBSD: keymacro.h,v 1.2 2011/07/28 03:44:36 christos Exp $ */
+
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -30,54 +32,46 @@
* SUCH DAMAGE.
*
* @(#)key.h 8.1 (Berkeley) 6/4/93
- * $NetBSD: key.h,v 1.10 2006/03/23 20:22:51 christos Exp $
* $FreeBSD$
*/
/*
- * el.key.h: Key macro header
+ * el.keymacro.h: Key macro header
*/
-#ifndef _h_el_key
-#define _h_el_key
+#ifndef _h_el_keymacro
+#define _h_el_keymacro
-typedef union key_value_t {
+typedef union keymacro_value_t {
el_action_t cmd; /* If it is a command the # */
- char *str; /* If it is a string... */
-} key_value_t;
+ Char *str; /* If it is a string... */
+} keymacro_value_t;
-typedef struct key_node_t key_node_t;
+typedef struct keymacro_node_t keymacro_node_t;
-typedef struct el_key_t {
- char *buf; /* Key print buffer */
- key_node_t *map; /* Key map */
- key_value_t val; /* Local conversion buffer */
-} el_key_t;
+typedef struct el_keymacromacro_t {
+ Char *buf; /* Key print buffer */
+ keymacro_node_t *map; /* Key map */
+ keymacro_value_t val; /* Local conversion buffer */
+} el_keymacro_t;
#define XK_CMD 0
#define XK_STR 1
#define XK_NOD 2
#define XK_EXE 3
-#include <term.h>
-
-#undef key_end
-#undef key_clear
-#undef key_print
-
-protected int key_init(EditLine *);
-protected void key_end(EditLine *);
-protected key_value_t *key_map_cmd(EditLine *, int);
-protected key_value_t *key_map_str(EditLine *, char *);
-protected void key_reset(EditLine *);
-protected int key_get(EditLine *, char *, key_value_t *);
-protected void key_add(EditLine *, const char *, key_value_t *, int);
-protected void key_clear(EditLine *, el_action_t *, const char *);
-protected int key_delete(EditLine *, const char *);
-protected void key_print(EditLine *, const char *);
-protected void key_kprint(EditLine *, const char *, key_value_t *,
+protected int keymacro_init(EditLine *);
+protected void keymacro_end(EditLine *);
+protected keymacro_value_t *keymacro_map_cmd(EditLine *, int);
+protected keymacro_value_t *keymacro_map_str(EditLine *, Char *);
+protected void keymacro_reset(EditLine *);
+protected int keymacro_get(EditLine *, Char *, keymacro_value_t *);
+protected void keymacro_add(EditLine *, const Char *, keymacro_value_t *, int);
+protected void keymacro_clear(EditLine *, el_action_t *, const Char *);
+protected int keymacro_delete(EditLine *, const Char *);
+protected void keymacro_print(EditLine *, const Char *);
+protected void keymacro_kprint(EditLine *, const Char *, keymacro_value_t *,
int);
-protected size_t key__decode_str(const char *, char *, size_t,
+protected size_t keymacro__decode_str(const Char *, char *, size_t,
const char *);
-protected size_t key__decode_char(char *, size_t, size_t, int);
-#endif /* _h_el_key */
+#endif /* _h_el_keymacro */
diff --git a/lib/libedit/makelist b/lib/libedit/makelist
index 6bb2476..ec3292f 100644
--- a/lib/libedit/makelist
+++ b/lib/libedit/makelist
@@ -1,6 +1,6 @@
#!/bin/sh -
-# $NetBSD: makelist,v 1.11 2005/10/22 16:45:03 christos Exp $
# $FreeBSD$
+# $NetBSD: makelist,v 1.18 2012/03/21 05:34:54 matt Exp $
#
# Copyright (c) 1992, 1993
# The Regents of the University of California. All rights reserved.
@@ -37,7 +37,7 @@
# makelist.sh: Automatically generate header files...
AWK=awk
-USAGE="usage: $0 -h|-e|-fc|-fh|-bc|-bh|-m <filenames>"
+USAGE="Usage: $0 -n|-h|-e|-fc|-fh|-bc|-bh|-m <filenames>"
if [ "x$1" = "x" ]
then
@@ -54,6 +54,15 @@ case $FLAG in
# generate foo.h file from foo.c
#
+-n)
+ cat << _EOF
+#include "config.h"
+#undef WIDECHAR
+#define NARROWCHAR
+#include "${FILES}"
+_EOF
+ ;;
+
-h)
set - `echo $FILES | sed -e 's/\\./_/g'`
hdr="_h_`basename $1`"
@@ -70,7 +79,7 @@ case $FLAG in
# XXX: need a space between name and prototype so that -fc and -fh
# parsing is much easier
#
- printf("protected el_action_t\t%s (EditLine *, int);\n", name);
+ printf("protected el_action_t\t%s (EditLine *, Int);\n", name);
}
}
END {
@@ -84,7 +93,8 @@ case $FLAG in
cat $FILES | $AWK '
BEGIN {
printf("/* Automatically generated file, do not edit */\n");
- printf("#include \"sys.h\"\n#include \"el.h\"\n");
+ printf("#include \"config.h\"\n#include \"el.h\"\n");
+ printf("#include \"chartype.h\"\n");
printf("private const struct el_bindings_t el_func_help[] = {\n");
low = "abcdefghijklmnopqrstuvwxyz_";
high = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_";
@@ -105,22 +115,22 @@ case $FLAG in
fname = fname s;
}
- printf(" { %-30.30s %-30.30s\n","\"" fname "\",", uname ",");
+ printf(" { %-30.30s %-30.30s\n","STR(\"" fname "\"),", uname ",");
ok = 1;
}
}
/^ \*/ {
if (ok) {
- printf(" \"");
+ printf(" STR(\"");
for (i = 2; i < NF; i++)
printf("%s ", $i);
- printf("%s\" },\n", $i);
+ printf("%s\") },\n", $i);
ok = 0;
}
}
END {
printf("};\n");
- printf("\nprotected const el_bindings_t* help__get()");
+ printf("\nprotected const el_bindings_t* help__get(void)");
printf("{ return el_func_help; }\n");
}'
;;
@@ -141,7 +151,7 @@ case $FLAG in
#
-fh)
cat $FILES | $AWK '/el_action_t/ { print $3 }' | \
- sort | LC_ALL=C tr '[:lower:]' '[:upper:]' | $AWK '
+ sort | tr '[:lower:]' '[:upper:]' | $AWK '
BEGIN {
printf("/* Automatically generated file, do not edit */\n");
printf("#ifndef _h_fcns_c\n#define _h_fcns_c\n");
@@ -153,7 +163,7 @@ case $FLAG in
END {
printf("#define\t%-30.30s\t%3d\n", "EL_NUM_FCNS", count);
- printf("typedef el_action_t (*el_func_t)(EditLine *, int);");
+ printf("typedef el_action_t (*el_func_t)(EditLine *, Int);");
printf("\nprotected const el_func_t* func__get(void);\n");
printf("#endif /* _h_fcns_c */\n");
}'
@@ -165,7 +175,7 @@ case $FLAG in
cat $FILES | $AWK '/el_action_t/ { print $3 }' | sort | $AWK '
BEGIN {
printf("/* Automatically generated file, do not edit */\n");
- printf("#include \"sys.h\"\n#include \"el.h\"\n");
+ printf("#include \"config.h\"\n#include \"el.h\"\n");
printf("private const el_func_t el_func[] = {");
maxlen = 80;
needn = 1;
@@ -186,7 +196,7 @@ case $FLAG in
}
END {
printf("\n};\n");
- printf("\nprotected const el_func_t* func__get() { return el_func; }\n");
+ printf("\nprotected const el_func_t* func__get(void) { return el_func; }\n");
}'
;;
diff --git a/lib/libedit/map.c b/lib/libedit/map.c
index c70904a..03bb3d8 100644
--- a/lib/libedit/map.c
+++ b/lib/libedit/map.c
@@ -1,3 +1,5 @@
+/* $NetBSD: map.c,v 1.35 2015/05/14 10:44:15 christos Exp $ */
+
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -28,12 +30,15 @@
* 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.
- *
- * $NetBSD: map.c,v 1.24 2006/04/09 01:36:51 christos Exp $
*/
+#include "config.h"
#if !defined(lint) && !defined(SCCSID)
+#if 0
static char sccsid[] = "@(#)map.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: map.c,v 1.35 2015/05/14 10:44:15 christos Exp $");
+#endif
#endif /* not lint && not SCCSID */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
@@ -41,14 +46,11 @@ __FBSDID("$FreeBSD$");
/*
* map.c: Editor function definitions
*/
-#include "sys.h"
#include <stdlib.h>
#include "el.h"
-#define N_KEYS 256
-
-private void map_print_key(EditLine *, el_action_t *, const char *);
-private void map_print_some_keys(EditLine *, el_action_t *, int, int);
+private void map_print_key(EditLine *, el_action_t *, const Char *);
+private void map_print_some_keys(EditLine *, el_action_t *, Int, Int);
private void map_print_all_keys(EditLine *);
private void map_init_nls(EditLine *);
private void map_init_meta(EditLine *);
@@ -903,26 +905,25 @@ map_init(EditLine *el)
EL_ABORT((el->errfile, "Vi insert map incorrect\n"));
#endif
- el->el_map.alt = (el_action_t *)el_malloc(sizeof(el_action_t) * N_KEYS);
+ el->el_map.alt = el_malloc(sizeof(*el->el_map.alt) * N_KEYS);
if (el->el_map.alt == NULL)
- return (-1);
- el->el_map.key = (el_action_t *)el_malloc(sizeof(el_action_t) * N_KEYS);
+ return -1;
+ el->el_map.key = el_malloc(sizeof(*el->el_map.key) * N_KEYS);
if (el->el_map.key == NULL)
- return (-1);
+ return -1;
el->el_map.emacs = el_map_emacs;
el->el_map.vic = el_map_vi_command;
el->el_map.vii = el_map_vi_insert;
- el->el_map.help = (el_bindings_t *) el_malloc(sizeof(el_bindings_t) *
- EL_NUM_FCNS);
+ el->el_map.help = el_malloc(sizeof(*el->el_map.help) * EL_NUM_FCNS);
if (el->el_map.help == NULL)
- return (-1);
+ return -1;
(void) memcpy(el->el_map.help, help__get(),
- sizeof(el_bindings_t) * EL_NUM_FCNS);
- el->el_map.func = (el_func_t *)el_malloc(sizeof(el_func_t) *
- EL_NUM_FCNS);
+ sizeof(*el->el_map.help) * EL_NUM_FCNS);
+ el->el_map.func = el_malloc(sizeof(*el->el_map.func) * EL_NUM_FCNS);
if (el->el_map.func == NULL)
- return (-1);
- memcpy(el->el_map.func, func__get(), sizeof(el_func_t) * EL_NUM_FCNS);
+ return -1;
+ memcpy(el->el_map.func, func__get(), sizeof(*el->el_map.func)
+ * EL_NUM_FCNS);
el->el_map.nfunc = EL_NUM_FCNS;
#ifdef VIDEFAULT
@@ -930,7 +931,7 @@ map_init(EditLine *el)
#else
map_init_emacs(el);
#endif /* VIDEFAULT */
- return (0);
+ return 0;
}
@@ -941,16 +942,16 @@ protected void
map_end(EditLine *el)
{
- el_free((ptr_t) el->el_map.alt);
+ el_free(el->el_map.alt);
el->el_map.alt = NULL;
- el_free((ptr_t) el->el_map.key);
+ el_free(el->el_map.key);
el->el_map.key = NULL;
el->el_map.emacs = NULL;
el->el_map.vic = NULL;
el->el_map.vii = NULL;
- el_free((ptr_t) el->el_map.help);
+ el_free(el->el_map.help);
el->el_map.help = NULL;
- el_free((ptr_t) el->el_map.func);
+ el_free(el->el_map.func);
el->el_map.func = NULL;
}
@@ -966,7 +967,7 @@ map_init_nls(EditLine *el)
el_action_t *map = el->el_map.key;
for (i = 0200; i <= 0377; i++)
- if (isprint(i))
+ if (Isprint(i))
map[i] = ED_INSERT;
}
@@ -977,7 +978,7 @@ map_init_nls(EditLine *el)
private void
map_init_meta(EditLine *el)
{
- char buf[3];
+ Char buf[3];
int i;
el_action_t *map = el->el_map.key;
el_action_t *alt = el->el_map.alt;
@@ -995,7 +996,7 @@ map_init_meta(EditLine *el)
} else
map = alt;
}
- buf[0] = (char) i;
+ buf[0] = (Char) i;
buf[2] = 0;
for (i = 0200; i <= 0377; i++)
switch (map[i]) {
@@ -1005,7 +1006,7 @@ map_init_meta(EditLine *el)
break;
default:
buf[1] = i & 0177;
- key_add(el, buf, key_map_cmd(el, (int) map[i]), XK_CMD);
+ keymacro_add(el, buf, keymacro_map_cmd(el, (int) map[i]), XK_CMD);
break;
}
map[(int) buf[0]] = ED_SEQUENCE_LEAD_IN;
@@ -1027,7 +1028,7 @@ map_init_vi(EditLine *el)
el->el_map.type = MAP_VI;
el->el_map.current = el->el_map.key;
- key_reset(el);
+ keymacro_reset(el);
for (i = 0; i < N_KEYS; i++) {
key[i] = vii[i];
@@ -1038,7 +1039,7 @@ map_init_vi(EditLine *el)
map_init_nls(el);
tty_bind_char(el, 1);
- term_bind_arrow(el);
+ terminal_bind_arrow(el);
}
@@ -1049,14 +1050,14 @@ protected void
map_init_emacs(EditLine *el)
{
int i;
- char buf[3];
+ Char buf[3];
el_action_t *key = el->el_map.key;
el_action_t *alt = el->el_map.alt;
const el_action_t *emacs = el->el_map.emacs;
el->el_map.type = MAP_EMACS;
el->el_map.current = el->el_map.key;
- key_reset(el);
+ keymacro_reset(el);
for (i = 0; i < N_KEYS; i++) {
key[i] = emacs[i];
@@ -1069,10 +1070,10 @@ map_init_emacs(EditLine *el)
buf[0] = CONTROL('X');
buf[1] = CONTROL('X');
buf[2] = 0;
- key_add(el, buf, key_map_cmd(el, EM_EXCHANGE_MARK), XK_CMD);
+ keymacro_add(el, buf, keymacro_map_cmd(el, EM_EXCHANGE_MARK), XK_CMD);
tty_bind_char(el, 1);
- term_bind_arrow(el);
+ terminal_bind_arrow(el);
}
@@ -1080,18 +1081,18 @@ map_init_emacs(EditLine *el)
* Set the editor
*/
protected int
-map_set_editor(EditLine *el, char *editor)
+map_set_editor(EditLine *el, Char *editor)
{
- if (strcmp(editor, "emacs") == 0) {
+ if (Strcmp(editor, STR("emacs")) == 0) {
map_init_emacs(el);
- return (0);
+ return 0;
}
- if (strcmp(editor, "vi") == 0) {
+ if (Strcmp(editor, STR("vi")) == 0) {
map_init_vi(el);
- return (0);
+ return 0;
}
- return (-1);
+ return -1;
}
@@ -1099,20 +1100,20 @@ map_set_editor(EditLine *el, char *editor)
* Retrieve the editor
*/
protected int
-map_get_editor(EditLine *el, const char **editor)
+map_get_editor(EditLine *el, const Char **editor)
{
if (editor == NULL)
- return (-1);
+ return -1;
switch (el->el_map.type) {
case MAP_EMACS:
- *editor = "emacs";
- return (0);
+ *editor = STR("emacs");
+ return 0;
case MAP_VI:
- *editor = "vi";
- return (0);
+ *editor = STR("vi");
+ return 0;
}
- return (-1);
+ return -1;
}
@@ -1120,22 +1121,22 @@ map_get_editor(EditLine *el, const char **editor)
* Print the function description for 1 key
*/
private void
-map_print_key(EditLine *el, el_action_t *map, const char *in)
+map_print_key(EditLine *el, el_action_t *map, const Char *in)
{
char outbuf[EL_BUFSIZ];
el_bindings_t *bp, *ep;
if (in[0] == '\0' || in[1] == '\0') {
- (void) key__decode_str(in, outbuf, sizeof(outbuf), "");
+ (void) keymacro__decode_str(in, outbuf, sizeof(outbuf), "");
ep = &el->el_map.help[el->el_map.nfunc];
for (bp = el->el_map.help; bp < ep; bp++)
if (bp->func == map[(unsigned char) *in]) {
(void) fprintf(el->el_outfile,
- "%s\t->\t%s\n", outbuf, bp->name);
+ "%s\t->\t" FSTR "\n", outbuf, bp->name);
return;
}
} else
- key_print(el, in);
+ keymacro_print(el, in);
}
@@ -1143,10 +1144,10 @@ map_print_key(EditLine *el, el_action_t *map, const char *in)
* Print keys from first to last
*/
private void
-map_print_some_keys(EditLine *el, el_action_t *map, int first, int last)
+map_print_some_keys(EditLine *el, el_action_t *map, Int first, Int last)
{
el_bindings_t *bp, *ep;
- char firstbuf[2], lastbuf[2];
+ Char firstbuf[2], lastbuf[2];
char unparsbuf[EL_BUFSIZ], extrabuf[EL_BUFSIZ];
firstbuf[0] = first;
@@ -1155,7 +1156,7 @@ map_print_some_keys(EditLine *el, el_action_t *map, int first, int last)
lastbuf[1] = 0;
if (map[first] == ED_UNASSIGNED) {
if (first == last) {
- (void) key__decode_str(firstbuf, unparsbuf,
+ (void) keymacro__decode_str(firstbuf, unparsbuf,
sizeof(unparsbuf), STRQQ);
(void) fprintf(el->el_outfile,
"%-15s-> is undefined\n", unparsbuf);
@@ -1166,17 +1167,17 @@ map_print_some_keys(EditLine *el, el_action_t *map, int first, int last)
for (bp = el->el_map.help; bp < ep; bp++) {
if (bp->func == map[first]) {
if (first == last) {
- (void) key__decode_str(firstbuf, unparsbuf,
+ (void) keymacro__decode_str(firstbuf, unparsbuf,
sizeof(unparsbuf), STRQQ);
- (void) fprintf(el->el_outfile, "%-15s-> %s\n",
+ (void) fprintf(el->el_outfile, "%-15s-> " FSTR "\n",
unparsbuf, bp->name);
} else {
- (void) key__decode_str(firstbuf, unparsbuf,
+ (void) keymacro__decode_str(firstbuf, unparsbuf,
sizeof(unparsbuf), STRQQ);
- (void) key__decode_str(lastbuf, extrabuf,
+ (void) keymacro__decode_str(lastbuf, extrabuf,
sizeof(extrabuf), STRQQ);
(void) fprintf(el->el_outfile,
- "%-4s to %-7s-> %s\n",
+ "%-4s to %-7s-> " FSTR "\n",
unparsbuf, extrabuf, bp->name);
}
return;
@@ -1184,14 +1185,14 @@ map_print_some_keys(EditLine *el, el_action_t *map, int first, int last)
}
#ifdef MAP_DEBUG
if (map == el->el_map.key) {
- (void) key__decode_str(firstbuf, unparsbuf,
+ (void) keymacro__decode_str(firstbuf, unparsbuf,
sizeof(unparsbuf), STRQQ);
(void) fprintf(el->el_outfile,
"BUG!!! %s isn't bound to anything.\n", unparsbuf);
(void) fprintf(el->el_outfile, "el->el_map.key[%d] == %d\n",
first, el->el_map.key[first]);
} else {
- (void) key__decode_str(firstbuf, unparsbuf,
+ (void) keymacro__decode_str(firstbuf, unparsbuf,
sizeof(unparsbuf), STRQQ);
(void) fprintf(el->el_outfile,
"BUG!!! %s isn't bound to anything.\n", unparsbuf);
@@ -1232,9 +1233,9 @@ map_print_all_keys(EditLine *el)
map_print_some_keys(el, el->el_map.alt, prev, i - 1);
(void) fprintf(el->el_outfile, "Multi-character bindings\n");
- key_print(el, "");
+ keymacro_print(el, STR(""));
(void) fprintf(el->el_outfile, "Arrow key bindings\n");
- term_print_arrow(el, "");
+ terminal_print_arrow(el, STR(""));
}
@@ -1242,21 +1243,21 @@ map_print_all_keys(EditLine *el)
* Add/remove/change bindings
*/
protected int
-map_bind(EditLine *el, int argc, const char **argv)
+map_bind(EditLine *el, int argc, const Char **argv)
{
el_action_t *map;
int ntype, rem;
- const char *p;
- char inbuf[EL_BUFSIZ];
- char outbuf[EL_BUFSIZ];
- const char *in = NULL;
- char *out;
+ const Char *p;
+ Char inbuf[EL_BUFSIZ];
+ Char outbuf[EL_BUFSIZ];
+ const Char *in = NULL;
+ Char *out;
el_bindings_t *bp, *ep;
int cmd;
int key;
if (argv == NULL)
- return (-1);
+ return -1;
map = el->el_map.key;
ntype = XK_CMD;
@@ -1286,63 +1287,63 @@ map_bind(EditLine *el, int argc, const char **argv)
case 'v':
map_init_vi(el);
- return (0);
+ return 0;
case 'e':
map_init_emacs(el);
- return (0);
+ return 0;
case 'l':
ep = &el->el_map.help[el->el_map.nfunc];
for (bp = el->el_map.help; bp < ep; bp++)
(void) fprintf(el->el_outfile,
- "%s\n\t%s\n",
+ "" FSTR "\n\t" FSTR "\n",
bp->name, bp->description);
- return (0);
+ return 0;
default:
(void) fprintf(el->el_errfile,
- "%s: Invalid switch `%c'.\n",
- argv[0], p[1]);
+ "" FSTR ": Invalid switch `" FCHAR "'.\n",
+ argv[0], (Int)p[1]);
}
else
break;
if (argv[argc] == NULL) {
map_print_all_keys(el);
- return (0);
+ return 0;
}
if (key)
in = argv[argc++];
else if ((in = parse__string(inbuf, argv[argc++])) == NULL) {
(void) fprintf(el->el_errfile,
- "%s: Invalid \\ or ^ in instring.\n",
+ "" FSTR ": Invalid \\ or ^ in instring.\n",
argv[0]);
- return (-1);
+ return -1;
}
if (rem) {
if (key) {
- (void) term_clear_arrow(el, in);
- return (-1);
+ (void) terminal_clear_arrow(el, in);
+ return -1;
}
if (in[1])
- (void) key_delete(el, in);
+ (void) keymacro_delete(el, in);
else if (map[(unsigned char) *in] == ED_SEQUENCE_LEAD_IN)
- (void) key_delete(el, in);
+ (void) keymacro_delete(el, in);
else
map[(unsigned char) *in] = ED_UNASSIGNED;
- return (0);
+ return 0;
}
if (argv[argc] == NULL) {
if (key)
- term_print_arrow(el, in);
+ terminal_print_arrow(el, in);
else
map_print_key(el, map, in);
- return (0);
+ return 0;
}
#ifdef notyet
if (argv[argc + 1] != NULL) {
- bindkey_usage();
- return (-1);
+ bindkeymacro_usage();
+ return -1;
}
#endif
@@ -1351,40 +1352,42 @@ map_bind(EditLine *el, int argc, const char **argv)
case XK_EXE:
if ((out = parse__string(outbuf, argv[argc])) == NULL) {
(void) fprintf(el->el_errfile,
- "%s: Invalid \\ or ^ in outstring.\n", argv[0]);
- return (-1);
+ "" FSTR ": Invalid \\ or ^ in outstring.\n", argv[0]);
+ return -1;
}
if (key)
- term_set_arrow(el, in, key_map_str(el, out), ntype);
+ terminal_set_arrow(el, in, keymacro_map_str(el, out), ntype);
else
- key_add(el, in, key_map_str(el, out), ntype);
+ keymacro_add(el, in, keymacro_map_str(el, out), ntype);
map[(unsigned char) *in] = ED_SEQUENCE_LEAD_IN;
break;
case XK_CMD:
if ((cmd = parse_cmd(el, argv[argc])) == -1) {
(void) fprintf(el->el_errfile,
- "%s: Invalid command `%s'.\n", argv[0], argv[argc]);
- return (-1);
+ "" FSTR ": Invalid command `" FSTR "'.\n",
+ argv[0], argv[argc]);
+ return -1;
}
if (key)
- term_set_arrow(el, in, key_map_cmd(el, cmd), ntype);
+ terminal_set_arrow(el, in, keymacro_map_cmd(el, cmd), ntype);
else {
if (in[1]) {
- key_add(el, in, key_map_cmd(el, cmd), ntype);
+ keymacro_add(el, in, keymacro_map_cmd(el, cmd), ntype);
map[(unsigned char) *in] = ED_SEQUENCE_LEAD_IN;
} else {
- key_clear(el, map, in);
- map[(unsigned char) *in] = cmd;
+ keymacro_clear(el, map, in);
+ map[(unsigned char) *in] = (el_action_t)cmd;
}
}
break;
+ /* coverity[dead_error_begin] */
default:
EL_ABORT((el->el_errfile, "Bad XK_ type %d\n", ntype));
break;
}
- return (0);
+ return 0;
}
@@ -1392,29 +1395,30 @@ map_bind(EditLine *el, int argc, const char **argv)
* add a user defined function
*/
protected int
-map_addfunc(EditLine *el, const char *name, const char *help, el_func_t func)
+map_addfunc(EditLine *el, const Char *name, const Char *help, el_func_t func)
{
void *p;
- int nf = el->el_map.nfunc + 1;
+ size_t nf = el->el_map.nfunc + 1;
if (name == NULL || help == NULL || func == NULL)
- return (-1);
+ return -1;
- if ((p = el_realloc(el->el_map.func, nf * sizeof(el_func_t))) == NULL)
- return (-1);
- el->el_map.func = (el_func_t *) p;
- if ((p = el_realloc(el->el_map.help, nf * sizeof(el_bindings_t)))
+ if ((p = el_realloc(el->el_map.func, nf *
+ sizeof(*el->el_map.func))) == NULL)
+ return -1;
+ el->el_map.func = p;
+ if ((p = el_realloc(el->el_map.help, nf * sizeof(*el->el_map.help)))
== NULL)
- return (-1);
- el->el_map.help = (el_bindings_t *) p;
+ return -1;
+ el->el_map.help = p;
- nf = el->el_map.nfunc;
+ nf = (size_t)el->el_map.nfunc;
el->el_map.func[nf] = func;
el->el_map.help[nf].name = name;
- el->el_map.help[nf].func = nf;
+ el->el_map.help[nf].func = (int)nf;
el->el_map.help[nf].description = help;
el->el_map.nfunc++;
- return (0);
+ return 0;
}
diff --git a/lib/libedit/map.h b/lib/libedit/map.h
index a76d872..0380297 100644
--- a/lib/libedit/map.h
+++ b/lib/libedit/map.h
@@ -1,3 +1,5 @@
+/* $NetBSD: map.h,v 1.10 2014/07/06 18:15:34 christos Exp $ */
+
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -30,7 +32,6 @@
* SUCH DAMAGE.
*
* @(#)map.h 8.1 (Berkeley) 6/4/93
- * $NetBSD: map.h,v 1.8 2003/08/07 16:44:32 agc Exp $
* $FreeBSD$
*/
@@ -41,9 +42,9 @@
#define _h_el_map
typedef struct el_bindings_t { /* for the "bind" shell command */
- const char *name; /* function name for bind command */
+ const Char *name; /* function name for bind command */
int func; /* function numeric value */
- const char *description; /* description of function */
+ const Char *description; /* description of function */
} el_bindings_t;
@@ -57,19 +58,21 @@ typedef struct el_map_t {
int type; /* Emacs or vi */
el_bindings_t *help; /* The help for the editor functions */
el_func_t *func; /* List of available functions */
- int nfunc; /* The number of functions/help items */
+ size_t nfunc; /* The number of functions/help items */
} el_map_t;
#define MAP_EMACS 0
#define MAP_VI 1
-protected int map_bind(EditLine *, int, const char **);
+#define N_KEYS 256
+
+protected int map_bind(EditLine *, int, const Char **);
protected int map_init(EditLine *);
protected void map_end(EditLine *);
protected void map_init_vi(EditLine *);
protected void map_init_emacs(EditLine *);
-protected int map_set_editor(EditLine *, char *);
-protected int map_get_editor(EditLine *, const char **);
-protected int map_addfunc(EditLine *, const char *, const char *, el_func_t);
+protected int map_set_editor(EditLine *, Char *);
+protected int map_get_editor(EditLine *, const Char **);
+protected int map_addfunc(EditLine *, const Char *, const Char *, el_func_t);
#endif /* _h_el_map */
diff --git a/lib/libedit/parse.c b/lib/libedit/parse.c
index 0ffe51d..1c19cc7 100644
--- a/lib/libedit/parse.c
+++ b/lib/libedit/parse.c
@@ -1,3 +1,5 @@
+/* $NetBSD: parse.c,v 1.27 2014/07/06 18:15:34 christos Exp $ */
+
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -28,12 +30,15 @@
* 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.
- *
- * $NetBSD: parse.c,v 1.22 2005/05/29 04:58:15 lukem Exp $
*/
+#include "config.h"
#if !defined(lint) && !defined(SCCSID)
+#if 0
static char sccsid[] = "@(#)parse.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: parse.c,v 1.27 2014/07/06 18:15:34 christos Exp $");
+#endif
#endif /* not lint && not SCCSID */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
@@ -51,22 +56,21 @@ __FBSDID("$FreeBSD$");
* settc
* setty
*/
-#include "sys.h"
#include "el.h"
#include <stdlib.h>
private const struct {
- const char *name;
- int (*func)(EditLine *, int, const char **);
+ const Char *name;
+ int (*func)(EditLine *, int, const Char **);
} cmds[] = {
- { "bind", map_bind },
- { "echotc", term_echotc },
- { "edit", el_editmode },
- { "history", hist_command },
- { "telltc", term_telltc },
- { "settc", term_settc },
- { "setty", tty_stty },
- { NULL, NULL }
+ { STR("bind"), map_bind },
+ { STR("echotc"), terminal_echotc },
+ { STR("edit"), el_editmode },
+ { STR("history"), hist_command },
+ { STR("telltc"), terminal_telltc },
+ { STR("settc"), terminal_settc },
+ { STR("setty"), tty_stty },
+ { NULL, NULL }
};
@@ -74,17 +78,17 @@ private const struct {
* Parse a line and dispatch it
*/
protected int
-parse_line(EditLine *el, const char *line)
+parse_line(EditLine *el, const Char *line)
{
- const char **argv;
+ const Char **argv;
int argc;
- Tokenizer *tok;
+ TYPE(Tokenizer) *tok;
- tok = tok_init(NULL);
- tok_str(tok, line, &argc, &argv);
- argc = el_parse(el, argc, argv);
- tok_end(tok);
- return (argc);
+ tok = FUN(tok,init)(NULL);
+ FUN(tok,str)(tok, line, &argc, &argv);
+ argc = FUN(el,parse)(el, argc, argv);
+ FUN(tok,end)(tok);
+ return argc;
}
@@ -92,57 +96,57 @@ parse_line(EditLine *el, const char *line)
* Command dispatcher
*/
public int
-el_parse(EditLine *el, int argc, const char *argv[])
+FUN(el,parse)(EditLine *el, int argc, const Char *argv[])
{
- const char *ptr;
+ const Char *ptr;
int i;
if (argc < 1)
- return (-1);
- ptr = strchr(argv[0], ':');
+ return -1;
+ ptr = Strchr(argv[0], ':');
if (ptr != NULL) {
- char *tprog;
+ Char *tprog;
size_t l;
if (ptr == argv[0])
- return (0);
- l = ptr - argv[0] - 1;
- tprog = (char *) el_malloc(l + 1);
+ return 0;
+ l = (size_t)(ptr - argv[0] - 1);
+ tprog = el_malloc((l + 1) * sizeof(*tprog));
if (tprog == NULL)
- return (0);
- (void) strncpy(tprog, argv[0], l);
+ return 0;
+ (void) Strncpy(tprog, argv[0], l);
tprog[l] = '\0';
ptr++;
- l = el_match(el->el_prog, tprog);
+ l = (size_t)el_match(el->el_prog, tprog);
el_free(tprog);
if (!l)
- return (0);
+ return 0;
} else
ptr = argv[0];
for (i = 0; cmds[i].name != NULL; i++)
- if (strcmp(cmds[i].name, ptr) == 0) {
+ if (Strcmp(cmds[i].name, ptr) == 0) {
i = (*cmds[i].func) (el, argc, argv);
- return (-i);
+ return -i;
}
- return (-1);
+ return -1;
}
/* parse__escape():
- * Parse a string of the form ^<char> \<odigit> \<char> and return
+ * Parse a string of the form ^<char> \<odigit> \<char> \U+xxxx and return
* the appropriate character or -1 if the escape is not valid
*/
protected int
-parse__escape(const char **ptr)
+parse__escape(const Char **ptr)
{
- const char *p;
- int c;
+ const Char *p;
+ Int c;
p = *ptr;
if (p[1] == 0)
- return (-1);
+ return -1;
if (*p == '\\') {
p++;
@@ -171,6 +175,28 @@ parse__escape(const char **ptr)
case 'e':
c = '\033'; /* Escape */
break;
+ case 'U': /* Unicode \U+xxxx or \U+xxxxx format */
+ {
+ int i;
+ const Char hex[] = STR("0123456789ABCDEF");
+ const Char *h;
+ ++p;
+ if (*p++ != '+')
+ return -1;
+ c = 0;
+ for (i = 0; i < 5; ++i) {
+ h = Strchr(hex, *p++);
+ if (!h && i < 4)
+ return -1;
+ else if (h)
+ c = (c << 4) | ((int)(h - hex));
+ else
+ --p;
+ }
+ if (c > 0x10FFFF) /* outside valid character range */
+ return -1;
+ break;
+ }
case '0':
case '1':
case '2':
@@ -190,8 +216,8 @@ parse__escape(const char **ptr)
}
c = (c << 3) | (ch - '0');
}
- if ((c & 0xffffff00) != 0)
- return (-1);
+ if ((c & (wint_t)0xffffff00) != (wint_t)0)
+ return -1;
--p;
break;
}
@@ -205,28 +231,28 @@ parse__escape(const char **ptr)
} else
c = *p;
*ptr = ++p;
- return ((unsigned char)c);
+ return c;
}
/* parse__string():
* Parse the escapes from in and put the raw string out
*/
-protected char *
-parse__string(char *out, const char *in)
+protected Char *
+parse__string(Char *out, const Char *in)
{
- char *rv = out;
+ Char *rv = out;
int n;
for (;;)
switch (*in) {
case '\0':
*out = '\0';
- return (rv);
+ return rv;
case '\\':
case '^':
if ((n = parse__escape(&in)) == -1)
- return (NULL);
+ return NULL;
*out++ = n;
break;
@@ -250,12 +276,13 @@ parse__string(char *out, const char *in)
* or -1 if one is not found
*/
protected int
-parse_cmd(EditLine *el, const char *cmd)
+parse_cmd(EditLine *el, const Char *cmd)
{
- el_bindings_t *b;
+ el_bindings_t *b = el->el_map.help;
+ size_t i;
- for (b = el->el_map.help; b->name != NULL; b++)
- if (strcmp(b->name, cmd) == 0)
- return (b->func);
- return (-1);
+ for (i = 0; i < el->el_map.nfunc; i++)
+ if (Strcmp(b[i].name, cmd) == 0)
+ return b[i].func;
+ return -1;
}
diff --git a/lib/libedit/parse.h b/lib/libedit/parse.h
index cca4abf..9d8c934 100644
--- a/lib/libedit/parse.h
+++ b/lib/libedit/parse.h
@@ -1,3 +1,5 @@
+/* $NetBSD: parse.h,v 1.7 2009/12/30 22:37:40 christos Exp $ */
+
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -30,7 +32,6 @@
* SUCH DAMAGE.
*
* @(#)parse.h 8.1 (Berkeley) 6/4/93
- * $NetBSD: parse.h,v 1.6 2005/05/29 04:58:15 lukem Exp $
* $FreeBSD$
*/
@@ -40,9 +41,9 @@
#ifndef _h_el_parse
#define _h_el_parse
-protected int parse_line(EditLine *, const char *);
-protected int parse__escape(const char **);
-protected char *parse__string(char *, const char *);
-protected int parse_cmd(EditLine *, const char *);
+protected int parse_line(EditLine *, const Char *);
+protected int parse__escape(const Char **);
+protected Char *parse__string(Char *, const Char *);
+protected int parse_cmd(EditLine *, const Char *);
#endif /* _h_el_parse */
diff --git a/lib/libedit/prompt.c b/lib/libedit/prompt.c
index 2d37b67..3696d0c 100644
--- a/lib/libedit/prompt.c
+++ b/lib/libedit/prompt.c
@@ -1,3 +1,5 @@
+/* $NetBSD: prompt.c,v 1.20 2011/07/29 15:16:33 christos Exp $ */
+
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -28,12 +30,15 @@
* 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.
- *
- * $NetBSD: prompt.c,v 1.14 2009/03/31 17:38:27 christos Exp $
*/
+#include "config.h"
#if !defined(lint) && !defined(SCCSID)
+#if 0
static char sccsid[] = "@(#)prompt.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: prompt.c,v 1.20 2011/07/29 15:16:33 christos Exp $");
+#endif
#endif /* not lint && not SCCSID */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
@@ -41,50 +46,46 @@ __FBSDID("$FreeBSD$");
/*
* prompt.c: Prompt printing functions
*/
-#include "sys.h"
#include <stdio.h>
#include "el.h"
-private char *prompt_default(EditLine *);
-private char *prompt_default_r(EditLine *);
+private Char *prompt_default(EditLine *);
+private Char *prompt_default_r(EditLine *);
/* prompt_default():
* Just a default prompt, in case the user did not provide one
*/
-private char *
+private Char *
/*ARGSUSED*/
-prompt_default(EditLine *el __unused)
+prompt_default(EditLine *el __attribute__((__unused__)))
{
- static char a[3] = {'?', ' ', '\0'};
+ static Char a[3] = {'?', ' ', '\0'};
- return (a);
+ return a;
}
/* prompt_default_r():
* Just a default rprompt, in case the user did not provide one
*/
-private char *
+private Char *
/*ARGSUSED*/
-prompt_default_r(EditLine *el __unused)
+prompt_default_r(EditLine *el __attribute__((__unused__)))
{
- static char a[1] = {'\0'};
+ static Char a[1] = {'\0'};
- return (a);
+ return a;
}
/* prompt_print():
* Print the prompt and update the prompt position.
- * We use an array of integers in case we want to pass
- * literal escape sequences in the prompt and we want a
- * bit to flag them
*/
protected void
prompt_print(EditLine *el, int op)
{
el_prompt_t *elp;
- char *p;
+ Char *p;
int ignore = 0;
if (op == EL_PROMPT)
@@ -92,13 +93,19 @@ prompt_print(EditLine *el, int op)
else
elp = &el->el_rprompt;
- for (p = (*elp->p_func)(el); *p; p++) {
+ if (elp->p_wide)
+ p = (*elp->p_func)(el);
+ else
+ p = ct_decode_string((char *)(void *)(*elp->p_func)(el),
+ &el->el_scratch);
+
+ for (; *p; p++) {
if (elp->p_ignore == *p) {
ignore = !ignore;
continue;
}
if (ignore)
- term__putc(el, *p);
+ terminal__putc(el, *p);
else
re_putc(el, *p, 1);
}
@@ -132,7 +139,7 @@ prompt_init(EditLine *el)
*/
protected void
/*ARGSUSED*/
-prompt_end(EditLine *el __unused)
+prompt_end(EditLine *el __attribute__((__unused__)))
{
}
@@ -141,7 +148,7 @@ prompt_end(EditLine *el __unused)
* Install a prompt printing function
*/
protected int
-prompt_set(EditLine *el, el_pfunc_t prf, char c, int op)
+prompt_set(EditLine *el, el_pfunc_t prf, Char c, int op, int wide)
{
el_prompt_t *p;
@@ -155,13 +162,15 @@ prompt_set(EditLine *el, el_pfunc_t prf, char c, int op)
p->p_func = prompt_default;
else
p->p_func = prompt_default_r;
- } else
+ } else {
p->p_func = prf;
+ }
p->p_ignore = c;
p->p_pos.v = 0;
p->p_pos.h = 0;
+ p->p_wide = wide;
return 0;
}
@@ -171,7 +180,7 @@ prompt_set(EditLine *el, el_pfunc_t prf, char c, int op)
* Retrieve the prompt printing function
*/
protected int
-prompt_get(EditLine *el, el_pfunc_t *prf, char *c, int op)
+prompt_get(EditLine *el, el_pfunc_t *prf, Char *c, int op)
{
el_prompt_t *p;
@@ -183,8 +192,8 @@ prompt_get(EditLine *el, el_pfunc_t *prf, char *c, int op)
else
p = &el->el_rprompt;
- *prf = el->el_rprompt.p_func;
-
+ if (prf)
+ *prf = p->p_func;
if (c)
*c = p->p_ignore;
diff --git a/lib/libedit/prompt.h b/lib/libedit/prompt.h
index c796d93..260c818 100644
--- a/lib/libedit/prompt.h
+++ b/lib/libedit/prompt.h
@@ -1,3 +1,5 @@
+/* $NetBSD: prompt.h,v 1.10 2009/12/30 22:37:40 christos Exp $ */
+
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -30,7 +32,6 @@
* SUCH DAMAGE.
*
* @(#)prompt.h 8.1 (Berkeley) 6/4/93
- * $NetBSD: prompt.h,v 1.9 2009/03/31 17:38:27 christos Exp $
* $FreeBSD$
*/
@@ -42,18 +43,18 @@
#include "histedit.h"
-typedef char * (*el_pfunc_t)(EditLine*);
+typedef Char *(*el_pfunc_t)(EditLine *);
typedef struct el_prompt_t {
el_pfunc_t p_func; /* Function to return the prompt */
coord_t p_pos; /* position in the line after prompt */
- char p_ignore; /* character to start/end literal
-*/
+ Char p_ignore; /* character to start/end literal */
+ int p_wide;
} el_prompt_t;
protected void prompt_print(EditLine *, int);
-protected int prompt_set(EditLine *, el_pfunc_t, char, int);
-protected int prompt_get(EditLine *, el_pfunc_t *, char *, int);
+protected int prompt_set(EditLine *, el_pfunc_t, Char, int, int);
+protected int prompt_get(EditLine *, el_pfunc_t *, Char *, int);
protected int prompt_init(EditLine *);
protected void prompt_end(EditLine *);
diff --git a/lib/libedit/read.c b/lib/libedit/read.c
index f0b5ef3..9740599 100644
--- a/lib/libedit/read.c
+++ b/lib/libedit/read.c
@@ -1,3 +1,5 @@
+/* $NetBSD: read.c,v 1.71 2014/07/06 18:15:34 christos Exp $ */
+
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -28,12 +30,15 @@
* 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.
- *
- * $NetBSD: read.c,v 1.52 2009/07/22 15:57:00 christos Exp $
*/
+#include "config.h"
#if !defined(lint) && !defined(SCCSID)
+#if 0
static char sccsid[] = "@(#)read.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: read.c,v 1.71 2014/07/06 18:15:34 christos Exp $");
+#endif
#endif /* not lint && not SCCSID */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
@@ -42,19 +47,19 @@ __FBSDID("$FreeBSD$");
* read.c: Clean this junk up! This is horrible code.
* Terminal read functions
*/
-#include "sys.h"
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
+#include <limits.h>
#include "el.h"
-#define OKCMD -1
+#define OKCMD -1 /* must be -1! */
private int read__fixio(int, int);
private int read_preread(EditLine *);
-private int read_char(EditLine *, char *);
-private int read_getcmd(EditLine *, el_action_t *, char *);
+private int read_char(EditLine *, Char *);
+private int read_getcmd(EditLine *, el_action_t *, Char *);
private void read_pop(c_macro_t *);
/* read_init():
@@ -88,7 +93,7 @@ el_read_setfn(EditLine *el, el_rfunc_t rc)
protected el_rfunc_t
el_read_getfn(EditLine *el)
{
- return (el->el_read.read_char == read_char) ?
+ return el->el_read.read_char == read_char ?
EL_BUILTIN_GETCFN : el->el_read.read_char;
}
@@ -121,7 +126,7 @@ read_debug(EditLine *el)
*/
/* ARGSUSED */
private int
-read__fixio(int fd __unused, int e)
+read__fixio(int fd __attribute__((__unused__)), int e)
{
switch (e) {
@@ -130,7 +135,7 @@ read__fixio(int fd __unused, int e)
#ifdef EWOULDBLOCK
case EWOULDBLOCK:
#ifndef TRY_AGAIN
-#define TRY_AGAIN
+#define TRY_AGAIN
#endif
#endif /* EWOULDBLOCK */
@@ -138,7 +143,7 @@ read__fixio(int fd __unused, int e)
#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
case EAGAIN:
#ifndef TRY_AGAIN
-#define TRY_AGAIN
+#define TRY_AGAIN
#endif
#endif /* EWOULDBLOCK && EWOULDBLOCK != EAGAIN */
#endif /* POSIX && EAGAIN */
@@ -147,10 +152,10 @@ read__fixio(int fd __unused, int e)
#ifdef TRY_AGAIN
#if defined(F_SETFL) && defined(O_NDELAY)
if ((e = fcntl(fd, F_GETFL, 0)) == -1)
- return (-1);
+ return -1;
if (fcntl(fd, F_SETFL, e & ~O_NDELAY) == -1)
- return (-1);
+ return -1;
else
e = 1;
#endif /* F_SETFL && O_NDELAY */
@@ -159,21 +164,21 @@ read__fixio(int fd __unused, int e)
{
int zero = 0;
- if (ioctl(fd, FIONBIO, (ioctl_t) & zero) == -1)
- return (-1);
+ if (ioctl(fd, FIONBIO, &zero) == -1)
+ return -1;
else
e = 1;
}
#endif /* FIONBIO */
#endif /* TRY_AGAIN */
- return (e ? 0 : -1);
+ return e ? 0 : -1;
case EINTR:
- return (0);
+ return 0;
default:
- return (-1);
+ return -1;
}
}
@@ -187,10 +192,13 @@ read_preread(EditLine *el)
int chrs = 0;
if (el->el_tty.t_mode == ED_IO)
- return (0);
+ return 0;
+#ifndef WIDECHAR
+/* FIONREAD attempts to buffer up multiple bytes, and to make that work
+ * properly with partial wide/UTF-8 characters would need some careful work. */
#ifdef FIONREAD
- (void) ioctl(el->el_infd, FIONREAD, (ioctl_t) & chrs);
+ (void) ioctl(el->el_infd, FIONREAD, &chrs);
if (chrs > 0) {
char buf[EL_BUFSIZ];
@@ -202,8 +210,8 @@ read_preread(EditLine *el)
}
}
#endif /* FIONREAD */
-
- return (chrs > 0);
+#endif
+ return chrs > 0;
}
@@ -211,35 +219,36 @@ read_preread(EditLine *el)
* Push a macro
*/
public void
-el_push(EditLine *el, const char *str)
+FUN(el,push)(EditLine *el, const Char *str)
{
c_macro_t *ma = &el->el_chared.c_macro;
if (str != NULL && ma->level + 1 < EL_MAXMACRO) {
ma->level++;
- if ((ma->macro[ma->level] = el_strdup(str)) != NULL)
+ if ((ma->macro[ma->level] = Strdup(str)) != NULL)
return;
ma->level--;
}
- term_beep(el);
- term__flush(el);
+ terminal_beep(el);
+ terminal__flush(el);
}
/* read_getcmd():
- * Return next command from the input stream.
+ * Get next command from the input stream, return OKCMD on success.
+ * Character values > 255 are not looked up in the map, but inserted.
*/
private int
-read_getcmd(EditLine *el, el_action_t *cmdnum, char *ch)
+read_getcmd(EditLine *el, el_action_t *cmdnum, Char *ch)
{
el_action_t cmd;
int num;
el->el_errno = 0;
do {
- if ((num = el_getc(el, ch)) != 1) { /* if EOF or error */
+ if ((num = FUN(el,getc)(el, ch)) != 1) {/* if EOF or error */
el->el_errno = num == 0 ? 0 : errno;
- return (num);
+ return 0; /* not OKCMD */
}
#ifdef KANJI
@@ -254,15 +263,20 @@ read_getcmd(EditLine *el, el_action_t *cmdnum, char *ch)
el->el_state.metanext = 0;
*ch |= 0200;
}
- cmd = el->el_map.current[(unsigned char) *ch];
+#ifdef WIDECHAR
+ if (*ch >= N_KEYS)
+ cmd = ED_INSERT;
+ else
+#endif
+ cmd = el->el_map.current[(unsigned char) *ch];
if (cmd == ED_SEQUENCE_LEAD_IN) {
- key_value_t val;
- switch (key_get(el, ch, &val)) {
+ keymacro_value_t val;
+ switch (keymacro_get(el, ch, &val)) {
case XK_CMD:
cmd = val.cmd;
break;
case XK_STR:
- el_push(el, val.str);
+ FUN(el,push)(el, val.str);
break;
#ifdef notyet
case XK_EXE:
@@ -279,34 +293,90 @@ read_getcmd(EditLine *el, el_action_t *cmdnum, char *ch)
el->el_map.current = el->el_map.key;
} while (cmd == ED_SEQUENCE_LEAD_IN);
*cmdnum = cmd;
- return (OKCMD);
+ return OKCMD;
}
+#ifdef WIDECHAR
+/* utf8_islead():
+ * Test whether a byte is a leading byte of a UTF-8 sequence.
+ */
+private int
+utf8_islead(int c)
+{
+ return c < 0x80 || /* single byte char */
+ (c >= 0xc2 && c <= 0xf4); /* start of multibyte sequence */
+}
+#endif
/* read_char():
* Read a character from the tty.
*/
private int
-read_char(EditLine *el, char *cp)
+read_char(EditLine *el, Char *cp)
{
ssize_t num_read;
int tried = 0;
+ char cbuf[MB_LEN_MAX];
+ size_t cbp = 0;
+ int bytes = 0;
again:
el->el_signal->sig_no = 0;
- while ((num_read = read(el->el_infd, cp, 1)) == -1) {
- if (el->el_signal->sig_no == SIGCONT) {
+ while ((num_read = read(el->el_infd, cbuf + cbp, (size_t)1)) == -1) {
+ int e = errno;
+ switch (el->el_signal->sig_no) {
+ case SIGCONT:
+ FUN(el,set)(el, EL_REFRESH);
+ /*FALLTHROUGH*/
+ case SIGWINCH:
sig_set(el);
- el_set(el, EL_REFRESH);
goto again;
+ default:
+ break;
}
- if (!tried && read__fixio(el->el_infd, errno) == 0)
+ if (!tried && read__fixio(el->el_infd, e) == 0)
tried = 1;
else {
+ errno = e;
*cp = '\0';
- return (-1);
+ return -1;
}
}
+
+ /* Test for EOF */
+ if (num_read == 0) {
+ errno = 0;
+ *cp = '\0';
+ return 0;
+ }
+
+#ifdef WIDECHAR
+ if (el->el_flags & CHARSET_IS_UTF8) {
+ if (!utf8_islead((unsigned char)cbuf[0]))
+ goto again; /* discard the byte we read and try again */
+ ++cbp;
+ if ((bytes = ct_mbtowc(cp, cbuf, cbp)) == -1) {
+ ct_mbtowc_reset;
+ if (cbp >= MB_LEN_MAX) { /* "shouldn't happen" */
+ errno = EILSEQ;
+ *cp = '\0';
+ return -1;
+ }
+ goto again;
+ }
+ } else if (isascii((unsigned char)cbuf[0]) ||
+ /* we don't support other multibyte charsets */
+ ++cbp != 1 ||
+ /* Try non-ASCII characters in a 8-bit character set */
+ (bytes = ct_mbtowc(cp, cbuf, cbp)) != 1)
+#endif
+ *cp = (unsigned char)cbuf[0];
+
+ if ((el->el_flags & IGNORE_EXTCHARS) && bytes > 1) {
+ cbp = 0; /* skip this character */
+ goto again;
+ }
+
return (int)num_read;
}
@@ -329,12 +399,12 @@ read_pop(c_macro_t *ma)
* Read a character
*/
public int
-el_getc(EditLine *el, char *cp)
+FUN(el,getc)(EditLine *el, Char *cp)
{
int num_read;
c_macro_t *ma = &el->el_chared.c_macro;
- term__flush(el);
+ terminal__flush(el);
for (;;) {
if (ma->level < 0) {
if (!read_preread(el))
@@ -349,30 +419,36 @@ el_getc(EditLine *el, char *cp)
continue;
}
- *cp = ma->macro[0][ma->offset++] & 0377;
+ *cp = ma->macro[0][ma->offset++];
if (ma->macro[0][ma->offset] == '\0') {
/* Needed for QuoteMode On */
read_pop(ma);
}
- return (1);
+ return 1;
}
#ifdef DEBUG_READ
(void) fprintf(el->el_errfile, "Turning raw mode on\n");
#endif /* DEBUG_READ */
if (tty_rawmode(el) < 0)/* make sure the tty is set up correctly */
- return (0);
+ return 0;
#ifdef DEBUG_READ
(void) fprintf(el->el_errfile, "Reading a character\n");
#endif /* DEBUG_READ */
num_read = (*el->el_read.read_char)(el, cp);
+ if (num_read < 0)
+ el->el_errno = errno;
+#ifdef WIDECHAR
+ if (el->el_flags & NARROW_READ)
+ *cp = *(char *)(void *)cp;
+#endif
#ifdef DEBUG_READ
(void) fprintf(el->el_errfile, "Got it %c\n", *cp);
#endif /* DEBUG_READ */
- return (num_read);
+ return num_read;
}
protected void
@@ -393,7 +469,7 @@ read_prepare(EditLine *el)
re_refresh(el); /* print the prompt */
if (el->el_flags & UNBUFFERED)
- term__flush(el);
+ terminal__flush(el);
}
protected void
@@ -405,13 +481,13 @@ read_finish(EditLine *el)
sig_clr(el);
}
-public const char *
-el_gets(EditLine *el, int *nread)
+public const Char *
+FUN(el,gets)(EditLine *el, int *nread)
{
int retval;
el_action_t cmdnum = 0;
int num; /* how many chars we have read at NL */
- char ch;
+ Char ch, *cp;
int crlf = 0;
int nrb;
#ifdef FIONREAD
@@ -423,14 +499,14 @@ el_gets(EditLine *el, int *nread)
*nread = 0;
if (el->el_flags & NO_TTY) {
- char *cp = el->el_line.buffer;
size_t idx;
+ cp = el->el_line.buffer;
while ((num = (*el->el_read.read_char)(el, cp)) == 1) {
/* make sure there is space for next character */
if (cp + 1 >= el->el_line.limit) {
- idx = (cp - el->el_line.buffer);
- if (!ch_enlargebufs(el, 2))
+ idx = (size_t)(cp - el->el_line.buffer);
+ if (!ch_enlargebufs(el, (size_t)2))
break;
cp = &el->el_line.buffer[idx];
}
@@ -440,13 +516,13 @@ el_gets(EditLine *el, int *nread)
if (cp[-1] == '\r' || cp[-1] == '\n')
break;
}
- if (num == -1)
+ if (num == -1) {
+ if (errno == EINTR)
+ cp = el->el_line.buffer;
el->el_errno = errno;
+ }
- el->el_line.cursor = el->el_line.lastchar = cp;
- *cp = '\0';
- *nread = (int)(el->el_line.cursor - el->el_line.buffer);
- goto done;
+ goto noedit;
}
@@ -454,12 +530,12 @@ el_gets(EditLine *el, int *nread)
if (el->el_tty.t_mode == EX_IO && ma->level < 0) {
long chrs = 0;
- (void) ioctl(el->el_infd, FIONREAD, (ioctl_t) & chrs);
+ (void) ioctl(el->el_infd, FIONREAD, &chrs);
if (chrs == 0) {
if (tty_rawmode(el) < 0) {
errno = 0;
*nread = 0;
- return (NULL);
+ return NULL;
}
}
}
@@ -469,7 +545,6 @@ el_gets(EditLine *el, int *nread)
read_prepare(el);
if (el->el_flags & EDIT_DISABLED) {
- char *cp;
size_t idx;
if ((el->el_flags & UNBUFFERED) == 0)
@@ -477,13 +552,13 @@ el_gets(EditLine *el, int *nread)
else
cp = el->el_line.lastchar;
- term__flush(el);
+ terminal__flush(el);
while ((num = (*el->el_read.read_char)(el, cp)) == 1) {
/* make sure there is space next character */
if (cp + 1 >= el->el_line.limit) {
- idx = (cp - el->el_line.buffer);
- if (!ch_enlargebufs(el, 2))
+ idx = (size_t)(cp - el->el_line.buffer);
+ if (!ch_enlargebufs(el, (size_t)2))
break;
cp = &el->el_line.buffer[idx];
}
@@ -496,12 +571,12 @@ el_gets(EditLine *el, int *nread)
}
if (num == -1) {
+ if (errno == EINTR)
+ cp = el->el_line.buffer;
el->el_errno = errno;
}
- el->el_line.cursor = el->el_line.lastchar = cp;
- *cp = '\0';
- goto done;
+ goto noedit;
}
for (num = OKCMD; num == OKCMD;) { /* while still editing this
@@ -511,13 +586,20 @@ el_gets(EditLine *el, int *nread)
#endif /* DEBUG_EDIT */
/* if EOF or error */
if ((num = read_getcmd(el, &cmdnum, &ch)) != OKCMD) {
+ num = -1;
#ifdef DEBUG_READ
(void) fprintf(el->el_errfile,
"Returning from el_gets %d\n", num);
#endif /* DEBUG_READ */
break;
}
- if ((unsigned int)cmdnum >= (unsigned int)el->el_map.nfunc) { /* BUG CHECK command */
+ if (el->el_errno == EINTR) {
+ el->el_line.buffer[0] = '\0';
+ el->el_line.lastchar =
+ el->el_line.cursor = el->el_line.buffer;
+ break;
+ }
+ if ((size_t)cmdnum >= 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);
@@ -547,7 +629,7 @@ el_gets(EditLine *el, int *nread)
el->el_chared.c_redo.pos < el->el_chared.c_redo.lim) {
if (cmdnum == VI_DELETE_PREV_CHAR &&
el->el_chared.c_redo.pos != el->el_chared.c_redo.buf
- && isprint((unsigned char)el->el_chared.c_redo.pos[-1]))
+ && Isprint(el->el_chared.c_redo.pos[-1]))
el->el_chared.c_redo.pos--;
else
*el->el_chared.c_redo.pos++ = ch;
@@ -578,7 +660,7 @@ el_gets(EditLine *el, int *nread)
case CC_REFRESH_BEEP:
re_refresh(el);
- term_beep(el);
+ terminal_beep(el);
break;
case CC_NORM: /* normal char */
@@ -610,7 +692,7 @@ el_gets(EditLine *el, int *nread)
/* put (real) cursor in a known place */
re_clear_display(el); /* reset the display stuff */
ch_reset(el, 1); /* reset the input pointers */
- re_refresh(el); /* print the prompt again */
+ re_refresh(el); /* print the prompt again */
break;
case CC_ERROR:
@@ -619,8 +701,8 @@ el_gets(EditLine *el, int *nread)
(void) fprintf(el->el_errfile,
"*** editor ERROR ***\r\n\n");
#endif /* DEBUG_READ */
- term_beep(el);
- term__flush(el);
+ terminal_beep(el);
+ terminal__flush(el);
break;
}
el->el_state.argument = 1;
@@ -630,7 +712,7 @@ el_gets(EditLine *el, int *nread)
break;
}
- term__flush(el); /* flush any buffered output */
+ terminal__flush(el); /* flush any buffered output */
/* make sure the tty is set up correctly */
if ((el->el_flags & UNBUFFERED) == 0) {
read_finish(el);
@@ -638,6 +720,11 @@ el_gets(EditLine *el, int *nread)
} else {
*nread = (int)(el->el_line.lastchar - el->el_line.buffer);
}
+ goto done;
+noedit:
+ el->el_line.cursor = el->el_line.lastchar = cp;
+ *cp = '\0';
+ *nread = (int)(el->el_line.cursor - el->el_line.buffer);
done:
if (*nread == 0) {
if (num == -1) {
diff --git a/lib/libedit/read.h b/lib/libedit/read.h
index 6018934..fa2a611 100644
--- a/lib/libedit/read.h
+++ b/lib/libedit/read.h
@@ -1,3 +1,5 @@
+/* $NetBSD: read.h,v 1.7 2009/12/30 22:37:40 christos Exp $ */
+
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
* All rights reserved.
@@ -26,7 +28,6 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
- * $NetBSD: read.h,v 1.6 2008/04/29 06:53:01 martin Exp $
* $FreeBSD$
*/
@@ -36,7 +37,7 @@
#ifndef _h_el_read
#define _h_el_read
-typedef int (*el_rfunc_t)(EditLine *, char *);
+typedef int (*el_rfunc_t)(EditLine *, Char *);
typedef struct el_read_t {
el_rfunc_t read_char; /* Function to read a character */
diff --git a/lib/libedit/readline.c b/lib/libedit/readline.c
index 20a0f056..2dd7f4f 100644
--- a/lib/libedit/readline.c
+++ b/lib/libedit/readline.c
@@ -1,4 +1,4 @@
-/* $NetBSD: readline.c,v 1.90 2010/08/04 20:29:18 christos Exp $ */
+/* $NetBSD: readline.c,v 1.115 2015/04/01 15:23:15 christos Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -29,8 +29,11 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
+#include "config.h"
+#if !defined(lint) && !defined(SCCSID)
+__RCSID("$NetBSD: readline.c,v 1.115 2015/04/01 15:23:15 christos Exp $");
+#endif /* not lint && not SCCSID */
#include <sys/cdefs.h>
-__RCSID("$NetBSD: readline.c,v 1.90 2010/08/04 20:29:18 christos Exp $");
__FBSDID("$FreeBSD$");
#include <sys/types.h>
@@ -47,9 +50,8 @@ __FBSDID("$FreeBSD$");
#include <fcntl.h>
#include <setjmp.h>
#include <vis.h>
-#include "sys.h"
+
#include "readline/readline.h"
-#include "chartype.h"
#include "el.h"
#include "fcns.h" /* for EL_NUM_FCNS */
#include "histedit.h"
@@ -84,6 +86,14 @@ VFunction *rl_event_hook = NULL;
KEYMAP_ENTRY_ARRAY emacs_standard_keymap,
emacs_meta_keymap,
emacs_ctlx_keymap;
+/*
+ * The following is not implemented; we always catch signals in the
+ * libedit fashion: set handlers on entry to el_gets() and clear them
+ * on the way out. This simplistic approach works for most cases; if
+ * it does not work for your application, please let us know.
+ */
+int rl_catch_signals = 1;
+int rl_catch_sigwinch = 1;
int history_base = 1; /* probably never subject to change */
int history_length = 0;
@@ -100,6 +110,7 @@ char *rl_basic_word_break_characters = break_chars;
char *rl_completer_word_break_characters = NULL;
char *rl_completer_quote_characters = NULL;
Function *rl_completion_entry_function = NULL;
+char *(*rl_completion_word_break_hook)(void) = NULL;
CPPFunction *rl_attempted_completion_function = NULL;
Function *rl_pre_input_hook = NULL;
Function *rl_startup1_hook = NULL;
@@ -108,7 +119,6 @@ char *rl_terminal_name = NULL;
int rl_already_prompted = 0;
int rl_filename_completion_desired = 0;
int rl_ignore_completion_duplicates = 0;
-int rl_catch_signals = 1;
int readline_echoing_p = 1;
int _rl_print_completions_horizontally = 0;
VFunction *rl_redisplay_function = NULL;
@@ -118,10 +128,6 @@ VFunction *rl_prep_term_function = (VFunction *)rl_prep_terminal;
VFunction *rl_deprep_term_function = (VFunction *)rl_deprep_terminal;
KEYMAP_ENTRY_ARRAY emacs_meta_keymap;
-#ifdef WIDECHAR
-static ct_buffer_t conv;
-#endif
-
/*
* The current prompt string.
*/
@@ -154,7 +160,7 @@ int rl_completion_append_character = ' ';
/* stuff below is used internally by libedit for readline emulation */
-static TYPE(History) *h = NULL;
+static History *h = NULL;
static EditLine *e = NULL;
static Function *map[256];
static jmp_buf topbuf;
@@ -178,7 +184,7 @@ static char *
_get_prompt(EditLine *el __attribute__((__unused__)))
{
rl_already_prompted = 1;
- return (rl_prompt);
+ return rl_prompt;
}
@@ -188,16 +194,16 @@ _get_prompt(EditLine *el __attribute__((__unused__)))
static HIST_ENTRY *
_move_history(int op)
{
- TYPE(HistEvent) ev;
+ HistEvent ev;
static HIST_ENTRY rl_he;
- if (FUNW(history)(h, &ev, op) != 0)
- return (HIST_ENTRY *) NULL;
+ if (history(h, &ev, op) != 0)
+ return NULL;
- rl_he.line = ct_encode_string(ev.str, &conv);
+ rl_he.line = ev.str;
rl_he.data = NULL;
- return (&rl_he);
+ return &rl_he;
}
@@ -206,31 +212,46 @@ _move_history(int op)
*/
static int
/*ARGSUSED*/
-_getc_function(EditLine *el, char *c)
+_getc_function(EditLine *el __attribute__((__unused__)), char *c)
{
int i;
i = (*rl_getc_function)(NULL);
if (i == -1)
return 0;
- *c = i;
+ *c = (char)i;
return 1;
}
-static const char _dothistory[] = "/.history";
+static void
+_resize_fun(EditLine *el, void *a)
+{
+ const LineInfo *li;
+ char **ap = a;
+
+ li = el_line(el);
+ /* a cheesy way to get rid of const cast. */
+ *ap = memchr(li->buffer, *li->buffer, (size_t)1);
+}
static const char *
_default_history_file(void)
{
struct passwd *p;
- static char path[PATH_MAX];
+ static char *path;
+ size_t len;
- if (*path)
+ if (path)
return path;
+
if ((p = getpwuid(getuid())) == NULL)
return NULL;
- strlcpy(path, p->pw_dir, PATH_MAX);
- strlcat(path, _dothistory, PATH_MAX);
+
+ len = strlen(p->pw_dir) + sizeof("/.history");
+ if ((path = malloc(len)) == NULL)
+ return NULL;
+
+ (void)snprintf(path, len, "%s/.history", p->pw_dir);
return path;
}
@@ -251,7 +272,7 @@ rl_set_prompt(const char *prompt)
if (rl_prompt != NULL && strcmp(rl_prompt, prompt) == 0)
return 0;
if (rl_prompt)
- free(rl_prompt);
+ el_free(rl_prompt);
rl_prompt = strdup(prompt);
if (rl_prompt == NULL)
return -1;
@@ -268,15 +289,14 @@ rl_set_prompt(const char *prompt)
int
rl_initialize(void)
{
- TYPE(HistEvent) ev;
- const LineInfo *li;
+ HistEvent ev;
int editmode = 1;
struct termios t;
if (e != NULL)
el_end(e);
if (h != NULL)
- FUN(history,end)(h);
+ history_end(h);
if (!rl_instream)
rl_instream = stdin;
@@ -292,24 +312,27 @@ rl_initialize(void)
e = el_init(rl_readline_name, rl_instream, rl_outstream, stderr);
if (!editmode)
- FUN(el,set)(e, EL_EDITMODE, 0);
+ el_set(e, EL_EDITMODE, 0);
- h = FUN(history,init)();
+ h = history_init();
if (!e || !h)
- return (-1);
+ return -1;
- FUNW(history)(h, &ev, H_SETSIZE, INT_MAX); /* unlimited */
+ history(h, &ev, H_SETSIZE, INT_MAX); /* unlimited */
history_length = 0;
max_input_history = INT_MAX;
el_set(e, EL_HIST, history, h);
+ /* Setup resize function */
+ el_set(e, EL_RESIZE, _resize_fun, &rl_line_buffer);
+
/* setup getc function if valid */
if (rl_getc_function)
el_set(e, EL_GETCFN, _getc_function);
/* for proper prompt printing in readline() */
if (rl_set_prompt("") == -1) {
- FUN(history,end)(h);
+ history_end(h);
el_end(e);
return -1;
}
@@ -317,7 +340,7 @@ rl_initialize(void)
el_set(e, EL_SIGNAL, rl_catch_signals);
/* set default mode to "emacs"-style and read setting afterwards */
- /* so this can be overriden */
+ /* so this can be overridden */
el_set(e, EL_EDITOR, "emacs");
if (rl_terminal_name != NULL)
el_set(e, EL_TERMINAL, rl_terminal_name);
@@ -341,6 +364,37 @@ rl_initialize(void)
_el_rl_tstp);
el_set(e, EL_BIND, "^Z", "rl_tstp", NULL);
+ /*
+ * Set some readline compatible key-bindings.
+ */
+ el_set(e, EL_BIND, "^R", "em-inc-search-prev", NULL);
+
+ /*
+ * Allow the use of Home/End keys.
+ */
+ el_set(e, EL_BIND, "\\e[1~", "ed-move-to-beg", NULL);
+ el_set(e, EL_BIND, "\\e[4~", "ed-move-to-end", NULL);
+ el_set(e, EL_BIND, "\\e[7~", "ed-move-to-beg", NULL);
+ el_set(e, EL_BIND, "\\e[8~", "ed-move-to-end", NULL);
+ el_set(e, EL_BIND, "\\e[H", "ed-move-to-beg", NULL);
+ el_set(e, EL_BIND, "\\e[F", "ed-move-to-end", NULL);
+
+ /*
+ * Allow the use of the Delete/Insert keys.
+ */
+ el_set(e, EL_BIND, "\\e[3~", "ed-delete-next-char", NULL);
+ el_set(e, EL_BIND, "\\e[2~", "ed-quoted-insert", NULL);
+
+ /*
+ * Ctrl-left-arrow and Ctrl-right-arrow for word moving.
+ */
+ el_set(e, EL_BIND, "\\e[1;5C", "em-next-word", NULL);
+ el_set(e, EL_BIND, "\\e[1;5D", "ed-prev-word", NULL);
+ el_set(e, EL_BIND, "\\e[5C", "em-next-word", NULL);
+ el_set(e, EL_BIND, "\\e[5D", "ed-prev-word", NULL);
+ el_set(e, EL_BIND, "\\e\\e[C", "em-next-word", NULL);
+ el_set(e, EL_BIND, "\\e\\e[D", "ed-prev-word", NULL);
+
/* read settings from configuration file */
el_source(e, NULL);
@@ -348,15 +402,13 @@ rl_initialize(void)
* Unfortunately, some applications really do use rl_point
* and rl_line_buffer directly.
*/
- li = el_line(e);
- /* a cheesy way to get rid of const cast. */
- rl_line_buffer = memchr(li->buffer, *li->buffer, 1);
+ _resize_fun(e, &rl_line_buffer);
_rl_update_pos();
if (rl_startup_hook)
(*rl_startup_hook)(NULL, 0);
- return (0);
+ return 0;
}
@@ -367,7 +419,7 @@ rl_initialize(void)
char *
readline(const char *p)
{
- TYPE(HistEvent) ev;
+ HistEvent ev;
const char * volatile prompt = p;
int count;
const char *ret;
@@ -415,7 +467,7 @@ readline(const char *p)
} else
buf = NULL;
- FUNW(history)(h, &ev, H_GETSIZE);
+ history(h, &ev, H_GETSIZE);
history_length = ev.num;
return buf;
@@ -465,7 +517,7 @@ _rl_compat_sub(const char *str, const char *what, const char *with,
} else
s++;
}
- r = result = malloc(len + 1);
+ r = result = el_malloc((len + 1) * sizeof(*r));
if (result == NULL)
return NULL;
s = str;
@@ -476,13 +528,13 @@ _rl_compat_sub(const char *str, const char *what, const char *with,
s += what_len;
if (!globally) {
(void)strcpy(r, s);
- return(result);
+ return result;
}
} else
*r++ = *s++;
}
*r = '\0';
- return(result);
+ return result;
}
static char *last_search_pat; /* last !?pat[?] search pattern */
@@ -495,18 +547,18 @@ get_history_event(const char *cmd, int *cindex, int qchar)
size_t len;
char *pat;
const char *rptr;
- TYPE(HistEvent) ev;
+ HistEvent ev;
idx = *cindex;
if (cmd[idx++] != history_expansion_char)
- return(NULL);
+ return NULL;
/* find out which event to take */
if (cmd[idx] == history_expansion_char || cmd[idx] == '\0') {
- if (FUNW(history)(h, &ev, H_FIRST) != 0)
- return(NULL);
+ if (history(h, &ev, H_FIRST) != 0)
+ return NULL;
*cindex = cmd[idx]? (idx + 1):idx;
- return ct_encode_string(ev.str, &conv);
+ return ev.str;
}
sign = 0;
if (cmd[idx] == '-') {
@@ -526,10 +578,10 @@ get_history_event(const char *cmd, int *cindex, int qchar)
num = history_length - num + 1;
if (!(rl_he = history_get(num)))
- return(NULL);
+ return NULL;
*cindex = idx;
- return(rl_he->line);
+ return rl_he->line;
}
sub = 0;
if (cmd[idx] == '?') {
@@ -547,31 +599,31 @@ get_history_event(const char *cmd, int *cindex, int qchar)
break;
idx++;
}
- len = idx - begin;
+ len = (size_t)idx - (size_t)begin;
if (sub && cmd[idx] == '?')
idx++;
if (sub && len == 0 && last_search_pat && *last_search_pat)
pat = last_search_pat;
else if (len == 0)
- return(NULL);
+ return NULL;
else {
- if ((pat = malloc(len + 1)) == NULL)
+ if ((pat = el_malloc((len + 1) * sizeof(*pat))) == NULL)
return NULL;
(void)strncpy(pat, cmd + begin, len);
pat[len] = '\0';
}
- if (FUNW(history)(h, &ev, H_CURR) != 0) {
+ if (history(h, &ev, H_CURR) != 0) {
if (pat != last_search_pat)
- free(pat);
- return (NULL);
+ el_free(pat);
+ return NULL;
}
num = ev.num;
if (sub) {
if (pat != last_search_pat) {
if (last_search_pat)
- free(last_search_pat);
+ el_free(last_search_pat);
last_search_pat = pat;
}
ret = history_search(pat, -1);
@@ -580,29 +632,29 @@ get_history_event(const char *cmd, int *cindex, int qchar)
if (ret == -1) {
/* restore to end of list on failed search */
- FUNW(history)(h, &ev, H_FIRST);
+ history(h, &ev, H_FIRST);
(void)fprintf(rl_outstream, "%s: Event not found\n", pat);
if (pat != last_search_pat)
- free(pat);
- return(NULL);
+ el_free(pat);
+ return NULL;
}
if (sub && len) {
if (last_search_match && last_search_match != pat)
- free(last_search_match);
+ el_free(last_search_match);
last_search_match = pat;
}
if (pat != last_search_pat)
- free(pat);
+ el_free(pat);
- if (FUNW(history)(h, &ev, H_CURR) != 0)
- return(NULL);
+ if (history(h, &ev, H_CURR) != 0)
+ return NULL;
*cindex = idx;
- rptr = ct_encode_string(ev.str, &conv);
+ rptr = ev.str;
/* roll back to original position */
- (void)FUNW(history)(h, &ev, H_SET, num);
+ (void)history(h, &ev, H_SET, num);
return rptr;
}
@@ -615,7 +667,7 @@ get_history_event(const char *cmd, int *cindex, int qchar)
* returns 0 if data was not modified, 1 if it was and 2 if the string
* should be only printed and not executed; in case of error,
* returns -1 and *result points to NULL
- * it's callers responsibility to free() string returned in *result
+ * it's the caller's responsibility to free() the string returned in *result
*/
static int
_history_expand_command(const char *command, size_t offs, size_t cmdlen,
@@ -649,7 +701,8 @@ _history_expand_command(const char *command, size_t offs, size_t cmdlen,
} else {
if (command[offs + 1] == '#') {
/* use command so far */
- if ((aptr = malloc(offs + 1)) == NULL)
+ if ((aptr = el_malloc((offs + 1) * sizeof(*aptr)))
+ == NULL)
return -1;
(void)strncpy(aptr, command, offs);
aptr[offs] = '\0';
@@ -660,19 +713,19 @@ _history_expand_command(const char *command, size_t offs, size_t cmdlen,
qchar = (offs > 0 && command[offs - 1] == '"')? '"':0;
ptr = get_history_event(command + offs, &idx, qchar);
}
- has_mods = command[offs + idx] == ':';
+ has_mods = command[offs + (size_t)idx] == ':';
}
if (ptr == NULL && aptr == NULL)
- return(-1);
+ return -1;
if (!has_mods) {
*result = strdup(aptr ? aptr : ptr);
if (aptr)
- free(aptr);
+ el_free(aptr);
if (*result == NULL)
return -1;
- return(1);
+ return 1;
}
cmd = command + offs + idx + 1;
@@ -717,18 +770,18 @@ _history_expand_command(const char *command, size_t offs, size_t cmdlen,
(void)fprintf(rl_outstream, "%s: Bad word specifier",
command + offs + idx);
if (aptr)
- free(aptr);
- return(-1);
+ el_free(aptr);
+ return -1;
}
} else
tmp = strdup(aptr? aptr:ptr);
if (aptr)
- free(aptr);
+ el_free(aptr);
if (*cmd == '\0' || ((size_t)(cmd - (command + offs)) >= cmdlen)) {
*result = tmp;
- return(1);
+ return 1;
}
for (; *cmd; cmd++) {
@@ -740,7 +793,7 @@ _history_expand_command(const char *command, size_t offs, size_t cmdlen,
} else if (*cmd == 't') { /* remove leading path */
if ((aptr = strrchr(tmp, '/')) != NULL) {
aptr = strdup(aptr + 1);
- free(tmp);
+ el_free(tmp);
tmp = aptr;
}
} else if (*cmd == 'r') { /* remove trailing suffix */
@@ -749,7 +802,7 @@ _history_expand_command(const char *command, size_t offs, size_t cmdlen,
} else if (*cmd == 'e') { /* remove all but suffix */
if ((aptr = strrchr(tmp, '.')) != NULL) {
aptr = strdup(aptr);
- free(tmp);
+ el_free(tmp);
tmp = aptr;
}
} else if (*cmd == 'p') /* print only */
@@ -766,10 +819,10 @@ _history_expand_command(const char *command, size_t offs, size_t cmdlen,
else if (*cmd == 's') {
delim = *(++cmd), cmd++;
size = 16;
- what = realloc(from, size);
+ what = el_realloc(from, size * sizeof(*what));
if (what == NULL) {
- free(from);
- free(tmp);
+ el_free(from);
+ el_free(tmp);
return 0;
}
len = 0;
@@ -778,11 +831,12 @@ _history_expand_command(const char *command, size_t offs, size_t cmdlen,
cmd++;
if (len >= size) {
char *nwhat;
- nwhat = realloc(what,
- (size <<= 1));
+ nwhat = el_realloc(what,
+ (size <<= 1) *
+ sizeof(*nwhat));
if (nwhat == NULL) {
- free(what);
- free(tmp);
+ el_free(what);
+ el_free(tmp);
return 0;
}
what = nwhat;
@@ -792,17 +846,17 @@ _history_expand_command(const char *command, size_t offs, size_t cmdlen,
what[len] = '\0';
from = what;
if (*what == '\0') {
- free(what);
+ el_free(what);
if (search) {
from = strdup(search);
if (from == NULL) {
- free(tmp);
+ el_free(tmp);
return 0;
}
} else {
from = NULL;
- free(tmp);
- return (-1);
+ el_free(tmp);
+ return -1;
}
}
cmd++; /* shift after delim */
@@ -810,10 +864,10 @@ _history_expand_command(const char *command, size_t offs, size_t cmdlen,
continue;
size = 16;
- with = realloc(to, size);
+ with = el_realloc(to, size * sizeof(*with));
if (with == NULL) {
- free(to);
- free(tmp);
+ el_free(to);
+ el_free(tmp);
return -1;
}
len = 0;
@@ -822,10 +876,11 @@ _history_expand_command(const char *command, size_t offs, size_t cmdlen,
if (len + from_len + 1 >= size) {
char *nwith;
size += from_len + 1;
- nwith = realloc(with, size);
+ nwith = el_realloc(with,
+ size * sizeof(*nwith));
if (nwith == NULL) {
- free(with);
- free(tmp);
+ el_free(with);
+ el_free(tmp);
return -1;
}
with = nwith;
@@ -848,14 +903,14 @@ _history_expand_command(const char *command, size_t offs, size_t cmdlen,
aptr = _rl_compat_sub(tmp, from, to, g_on);
if (aptr) {
- free(tmp);
+ el_free(tmp);
tmp = aptr;
}
g_on = 0;
}
}
*result = tmp;
- return (p_on? 2:1);
+ return p_on? 2:1;
}
@@ -874,13 +929,13 @@ history_expand(char *str, char **output)
if (history_expansion_char == 0) {
*output = strdup(str);
- return(0);
+ return 0;
}
*output = NULL;
if (str[0] == history_subst_char) {
/* ^foo^foo2^ is equivalent to !!:s^foo^foo2^ */
- *output = malloc(strlen(str) + 4 + 1);
+ *output = el_malloc((strlen(str) + 4 + 1) * sizeof(**output));
if (*output == NULL)
return 0;
(*output)[0] = (*output)[1] = history_expansion_char;
@@ -897,11 +952,12 @@ history_expand(char *str, char **output)
#define ADD_STRING(what, len, fr) \
{ \
if (idx + len + 1 > size) { \
- char *nresult = realloc(result, (size += len + 1));\
+ char *nresult = el_realloc(result, \
+ (size += len + 1) * sizeof(*nresult)); \
if (nresult == NULL) { \
- free(*output); \
+ el_free(*output); \
if (/*CONSTCOND*/fr) \
- free(tmp); \
+ el_free(tmp); \
return 0; \
} \
result = nresult; \
@@ -925,7 +981,8 @@ loop:
for (; str[j]; j++) {
if (str[j] == '\\' &&
str[j + 1] == history_expansion_char) {
- (void)strcpy(&str[j], &str[j + 1]);
+ len = strlen(&str[j + 1]) + 1;
+ memmove(&str[j], &str[j + 1], len);
continue;
}
if (!loop_again) {
@@ -968,7 +1025,7 @@ loop:
ADD_STRING(tmp, len, 1);
}
if (tmp) {
- free(tmp);
+ el_free(tmp);
tmp = NULL;
}
i = j;
@@ -985,10 +1042,10 @@ loop:
ret = -1;
#endif
}
- free(*output);
+ el_free(*output);
*output = result;
- return (ret);
+ return ret;
}
/*
@@ -1023,14 +1080,14 @@ history_arg_extract(int start, int end, const char *str)
(size_t)end > max || start > end)
goto out;
- for (i = start, len = 0; i <= (size_t)end; i++)
+ for (i = (size_t)start, len = 0; i <= (size_t)end; i++)
len += strlen(arr[i]) + 1;
len++;
- result = malloc(len);
+ result = el_malloc(len * sizeof(*result));
if (result == NULL)
goto out;
- for (i = start, len = 0; i <= (size_t)end; i++) {
+ for (i = (size_t)start, len = 0; i <= (size_t)end; i++) {
(void)strcpy(result + len, arr[i]);
len += strlen(arr[i]);
if (i < (size_t)end)
@@ -1040,8 +1097,8 @@ history_arg_extract(int start, int end, const char *str)
out:
for (i = 0; arr[i]; i++)
- free(arr[i]);
- free(arr);
+ el_free(arr[i]);
+ el_free(arr);
return result;
}
@@ -1080,19 +1137,19 @@ history_tokenize(const char *str)
if (idx + 2 >= size) {
char **nresult;
size <<= 1;
- nresult = realloc(result, size * sizeof(char *));
+ nresult = el_realloc(result, (size_t)size * sizeof(*nresult));
if (nresult == NULL) {
- free(result);
+ el_free(result);
return NULL;
}
result = nresult;
}
- len = i - start;
- temp = malloc(len + 1);
+ len = (size_t)i - (size_t)start;
+ temp = el_malloc((size_t)(len + 1) * sizeof(*temp));
if (temp == NULL) {
for (i = 0; i < idx; i++)
- free(result[i]);
- free(result);
+ el_free(result[i]);
+ el_free(result);
return NULL;
}
(void)strncpy(temp, &str[start], len);
@@ -1102,7 +1159,7 @@ history_tokenize(const char *str)
if (str[i])
i++;
}
- return (result);
+ return result;
}
@@ -1112,12 +1169,12 @@ history_tokenize(const char *str)
void
stifle_history(int max)
{
- TYPE(HistEvent) ev;
+ HistEvent ev;
if (h == NULL || e == NULL)
rl_initialize();
- if (FUNW(history)(h, &ev, H_SETSIZE, max) == 0)
+ if (history(h, &ev, H_SETSIZE, max) == 0)
max_input_history = max;
}
@@ -1128,13 +1185,13 @@ stifle_history(int max)
int
unstifle_history(void)
{
- TYPE(HistEvent) ev;
+ HistEvent ev;
int omax;
- FUNW(history)(h, &ev, H_SETSIZE, INT_MAX);
+ history(h, &ev, H_SETSIZE, INT_MAX);
omax = max_input_history;
max_input_history = INT_MAX;
- return (omax); /* some value _must_ be returned */
+ return omax; /* some value _must_ be returned */
}
@@ -1143,7 +1200,7 @@ history_is_stifled(void)
{
/* cannot return true answer */
- return (max_input_history != INT_MAX);
+ return max_input_history != INT_MAX;
}
static const char _history_tmp_template[] = "/tmp/.historyXXXXXX";
@@ -1178,7 +1235,7 @@ history_truncate_file (const char *filename, int nlines)
}
for(;;) {
- if (fread(buf, sizeof(buf), 1, fp) != 1) {
+ if (fread(buf, sizeof(buf), (size_t)1, fp) != 1) {
if (ferror(fp)) {
ret = errno;
break;
@@ -1188,7 +1245,7 @@ history_truncate_file (const char *filename, int nlines)
ret = errno;
break;
}
- left = fread(buf, 1, sizeof(buf), fp);
+ left = (ssize_t)fread(buf, (size_t)1, sizeof(buf), fp);
if (ferror(fp)) {
ret = errno;
break;
@@ -1196,14 +1253,15 @@ history_truncate_file (const char *filename, int nlines)
if (left == 0) {
count--;
left = sizeof(buf);
- } else if (fwrite(buf, (size_t)left, 1, tp) != 1) {
+ } else if (fwrite(buf, (size_t)left, (size_t)1, tp)
+ != 1) {
ret = errno;
break;
}
fflush(tp);
break;
}
- if (fwrite(buf, sizeof(buf), 1, tp) != 1) {
+ if (fwrite(buf, sizeof(buf), (size_t)1, tp) != 1) {
ret = errno;
break;
}
@@ -1233,7 +1291,7 @@ history_truncate_file (const char *filename, int nlines)
ret = errno;
break;
}
- if (fread(buf, sizeof(buf), 1, tp) != 1) {
+ if (fread(buf, sizeof(buf), (size_t)1, tp) != 1) {
if (ferror(tp)) {
ret = errno;
break;
@@ -1247,7 +1305,7 @@ history_truncate_file (const char *filename, int nlines)
if (ret || nlines > 0)
goto out3;
- if (fseeko(fp, 0, SEEK_SET) == (off_t)-1) {
+ if (fseeko(fp, (off_t)0, SEEK_SET) == (off_t)-1) {
ret = errno;
goto out3;
}
@@ -1259,12 +1317,12 @@ history_truncate_file (const char *filename, int nlines)
}
for(;;) {
- if ((left = fread(buf, 1, sizeof(buf), tp)) == 0) {
+ if ((left = (ssize_t)fread(buf, (size_t)1, sizeof(buf), tp)) == 0) {
if (ferror(fp))
ret = errno;
break;
}
- if (fwrite(buf, (size_t)left, 1, fp) != 1) {
+ if (fwrite(buf, (size_t)left, (size_t)1, fp) != 1) {
ret = errno;
break;
}
@@ -1289,14 +1347,14 @@ out1:
int
read_history(const char *filename)
{
- TYPE(HistEvent) ev;
+ HistEvent ev;
if (h == NULL || e == NULL)
rl_initialize();
if (filename == NULL && (filename = _default_history_file()) == NULL)
return errno;
- return (FUNW(history)(h, &ev, H_LOAD, filename) == -1 ?
- (errno ? errno : EINVAL) : 0);
+ return history(h, &ev, H_LOAD, filename) == -1 ?
+ (errno ? errno : EINVAL) : 0;
}
@@ -1306,14 +1364,14 @@ read_history(const char *filename)
int
write_history(const char *filename)
{
- TYPE(HistEvent) ev;
+ HistEvent ev;
if (h == NULL || e == NULL)
rl_initialize();
if (filename == NULL && (filename = _default_history_file()) == NULL)
return errno;
- return (FUNW(history)(h, &ev, H_SAVE, filename) == -1 ?
- (errno ? errno : EINVAL) : 0);
+ return history(h, &ev, H_SAVE, filename) == -1 ?
+ (errno ? errno : EINVAL) : 0;
}
@@ -1326,31 +1384,31 @@ HIST_ENTRY *
history_get(int num)
{
static HIST_ENTRY she;
- TYPE(HistEvent) ev;
+ HistEvent ev;
int curr_num;
if (h == NULL || e == NULL)
rl_initialize();
/* save current position */
- if (FUNW(history)(h, &ev, H_CURR) != 0)
- return (NULL);
+ if (history(h, &ev, H_CURR) != 0)
+ return NULL;
curr_num = ev.num;
/* start from the oldest */
- if (FUNW(history)(h, &ev, H_LAST) != 0)
- return (NULL); /* error */
+ if (history(h, &ev, H_LAST) != 0)
+ return NULL; /* error */
/* look forwards for event matching specified offset */
- if (FUNW(history)(h, &ev, H_NEXT_EVDATA, num, &she.data))
- return (NULL);
+ if (history(h, &ev, H_NEXT_EVDATA, num, &she.data))
+ return NULL;
- she.line = ct_encode_string(ev.str, &conv);
+ she.line = ev.str;
/* restore pointer to where it was */
- (void)FUNW(history)(h, &ev, H_SET, curr_num);
+ (void)history(h, &ev, H_SET, curr_num);
- return (&she);
+ return &she;
}
@@ -1360,8 +1418,7 @@ history_get(int num)
int
add_history(const char *line)
{
- TYPE(HistEvent) ev;
- const Char *wline;
+ HistEvent ev;
if (line == NULL)
return 0;
@@ -1369,13 +1426,11 @@ add_history(const char *line)
if (h == NULL || e == NULL)
rl_initialize();
- wline = ct_decode_string(line, &conv);
-
- (void)FUNW(history)(h, &ev, H_ENTER, wline);
- if (FUNW(history)(h, &ev, H_GETSIZE) == 0)
+ (void)history(h, &ev, H_ENTER, line);
+ if (history(h, &ev, H_GETSIZE) == 0)
history_length = ev.num;
- return (!(history_length > 0)); /* return 0 if all is okay */
+ return !(history_length > 0); /* return 0 if all is okay */
}
@@ -1386,21 +1441,21 @@ HIST_ENTRY *
remove_history(int num)
{
HIST_ENTRY *he;
- TYPE(HistEvent) ev;
+ HistEvent ev;
if (h == NULL || e == NULL)
rl_initialize();
- if ((he = malloc(sizeof(*he))) == NULL)
+ if ((he = el_malloc(sizeof(*he))) == NULL)
return NULL;
- if (FUNW(history)(h, &ev, H_DELDATA, num, &he->data) != 0) {
- free(he);
+ if (history(h, &ev, H_DELDATA, num, &he->data) != 0) {
+ el_free(he);
return NULL;
}
- he->line = ct_encode_string(ev.str, &conv);
- if (FUNW(history)(h, &ev, H_GETSIZE) == 0)
+ he->line = ev.str;
+ if (history(h, &ev, H_GETSIZE) == 0)
history_length = ev.num;
return he;
@@ -1414,42 +1469,42 @@ HIST_ENTRY *
replace_history_entry(int num, const char *line, histdata_t data)
{
HIST_ENTRY *he;
- TYPE(HistEvent) ev;
+ HistEvent ev;
int curr_num;
if (h == NULL || e == NULL)
rl_initialize();
/* save current position */
- if (FUNW(history)(h, &ev, H_CURR) != 0)
+ if (history(h, &ev, H_CURR) != 0)
return NULL;
curr_num = ev.num;
/* start from the oldest */
- if (FUNW(history)(h, &ev, H_LAST) != 0)
+ if (history(h, &ev, H_LAST) != 0)
return NULL; /* error */
- if ((he = malloc(sizeof(*he))) == NULL)
+ if ((he = el_malloc(sizeof(*he))) == NULL)
return NULL;
/* look forwards for event matching specified offset */
- if (FUNW(history)(h, &ev, H_NEXT_EVDATA, num, &he->data))
+ if (history(h, &ev, H_NEXT_EVDATA, num, &he->data))
goto out;
- he->line = strdup(ct_encode_string(ev.str, &e->el_scratch));
+ he->line = strdup(ev.str);
if (he->line == NULL)
goto out;
- if (FUNW(history)(h, &ev, H_REPLACE, line, data))
+ if (history(h, &ev, H_REPLACE, line, data))
goto out;
/* restore pointer to where it was */
- if (FUNW(history)(h, &ev, H_SET, curr_num))
+ if (history(h, &ev, H_SET, curr_num))
goto out;
return he;
out:
- free(he);
+ el_free(he);
return NULL;
}
@@ -1459,9 +1514,12 @@ out:
void
clear_history(void)
{
- TYPE(HistEvent) ev;
+ HistEvent ev;
- (void)FUNW(history)(h, &ev, H_CLEAR);
+ if (h == NULL || e == NULL)
+ rl_initialize();
+
+ (void)history(h, &ev, H_CLEAR);
history_length = 0;
}
@@ -1472,19 +1530,19 @@ clear_history(void)
int
where_history(void)
{
- TYPE(HistEvent) ev;
+ HistEvent ev;
int curr_num, off;
- if (FUNW(history)(h, &ev, H_CURR) != 0)
- return (0);
+ if (history(h, &ev, H_CURR) != 0)
+ return 0;
curr_num = ev.num;
- (void)FUNW(history)(h, &ev, H_FIRST);
+ (void)history(h, &ev, H_FIRST);
off = 1;
- while (ev.num != curr_num && FUNW(history)(h, &ev, H_NEXT) == 0)
+ while (ev.num != curr_num && history(h, &ev, H_NEXT) == 0)
off++;
- return (off);
+ return off;
}
@@ -1495,7 +1553,7 @@ HIST_ENTRY *
current_history(void)
{
- return (_move_history(H_CURR));
+ return _move_history(H_CURR);
}
@@ -1505,24 +1563,24 @@ current_history(void)
int
history_total_bytes(void)
{
- TYPE(HistEvent) ev;
+ HistEvent ev;
int curr_num;
size_t size;
- if (FUNW(history)(h, &ev, H_CURR) != 0)
- return (-1);
+ if (history(h, &ev, H_CURR) != 0)
+ return -1;
curr_num = ev.num;
- (void)FUNW(history)(h, &ev, H_FIRST);
+ (void)history(h, &ev, H_FIRST);
size = 0;
do
- size += Strlen(ev.str) * sizeof(*ev.str);
- while (FUNW(history)(h, &ev, H_NEXT) == 0);
+ size += strlen(ev.str) * sizeof(*ev.str);
+ while (history(h, &ev, H_NEXT) == 0);
/* get to the same position as before */
- FUNW(history)(h, &ev, H_PREV_EVENT, curr_num);
+ history(h, &ev, H_PREV_EVENT, curr_num);
- return (int)(size);
+ return (int)size;
}
@@ -1532,24 +1590,24 @@ history_total_bytes(void)
int
history_set_pos(int pos)
{
- TYPE(HistEvent) ev;
+ HistEvent ev;
int curr_num;
if (pos >= history_length || pos < 0)
- return (-1);
+ return -1;
- (void)FUNW(history)(h, &ev, H_CURR);
+ (void)history(h, &ev, H_CURR);
curr_num = ev.num;
/*
* use H_DELDATA to set to nth history (without delete) by passing
* (void **)-1
*/
- if (FUNW(history)(h, &ev, H_DELDATA, pos, (void **)-1)) {
- (void)FUNW(history)(h, &ev, H_SET, curr_num);
- return(-1);
+ if (history(h, &ev, H_DELDATA, pos, (void **)-1)) {
+ (void)history(h, &ev, H_SET, curr_num);
+ return -1;
}
- return (0);
+ return 0;
}
@@ -1560,7 +1618,7 @@ HIST_ENTRY *
previous_history(void)
{
- return (_move_history(H_PREV));
+ return _move_history(H_PREV);
}
@@ -1571,7 +1629,7 @@ HIST_ENTRY *
next_history(void)
{
- return (_move_history(H_NEXT));
+ return _move_history(H_NEXT);
}
@@ -1581,24 +1639,22 @@ next_history(void)
int
history_search(const char *str, int direction)
{
- TYPE(HistEvent) ev;
- const Char *strp;
- const Char *wstr;
+ HistEvent ev;
+ const char *strp;
int curr_num;
- if (FUNW(history)(h, &ev, H_CURR) != 0)
- return (-1);
+ if (history(h, &ev, H_CURR) != 0)
+ return -1;
curr_num = ev.num;
- wstr = ct_decode_string(str, &conv);
for (;;) {
- if ((strp = Strstr(ev.str, wstr)) != NULL)
- return (int) (strp - ev.str);
- if (FUNW(history)(h, &ev, direction < 0 ? H_NEXT:H_PREV) != 0)
+ if ((strp = strstr(ev.str, str)) != NULL)
+ return (int)(strp - ev.str);
+ if (history(h, &ev, direction < 0 ? H_NEXT:H_PREV) != 0)
break;
}
- (void)FUNW(history)(h, &ev, H_SET, curr_num);
- return (-1);
+ (void)history(h, &ev, H_SET, curr_num);
+ return -1;
}
@@ -1608,9 +1664,9 @@ history_search(const char *str, int direction)
int
history_search_prefix(const char *str, int direction)
{
- TYPE(HistEvent) ev;
+ HistEvent ev;
- return (FUNW(history)(h, &ev, direction < 0 ?
+ return (history(h, &ev, direction < 0 ?
H_PREV_STR : H_NEXT_STR, str));
}
@@ -1624,33 +1680,31 @@ int
history_search_pos(const char *str,
int direction __attribute__((__unused__)), int pos)
{
- TYPE(HistEvent) ev;
+ HistEvent ev;
int curr_num, off;
- const Char *wstr;
off = (pos > 0) ? pos : -pos;
pos = (pos > 0) ? 1 : -1;
- if (FUNW(history)(h, &ev, H_CURR) != 0)
- return (-1);
+ if (history(h, &ev, H_CURR) != 0)
+ return -1;
curr_num = ev.num;
- if (history_set_pos(off) != 0 || FUNW(history)(h, &ev, H_CURR) != 0)
- return (-1);
+ if (history_set_pos(off) != 0 || history(h, &ev, H_CURR) != 0)
+ return -1;
- wstr = ct_decode_string(str, &conv);
for (;;) {
- if (Strstr(ev.str, wstr))
- return (off);
- if (FUNW(history)(h, &ev, (pos < 0) ? H_PREV : H_NEXT) != 0)
+ if (strstr(ev.str, str))
+ return off;
+ if (history(h, &ev, (pos < 0) ? H_PREV : H_NEXT) != 0)
break;
}
/* set "current" pointer back to previous state */
- (void)FUNW(history)(h, &ev,
+ (void)history(h, &ev,
pos < 0 ? H_NEXT_EVENT : H_PREV_EVENT, curr_num);
- return (-1);
+ return -1;
}
@@ -1673,17 +1727,20 @@ filename_completion_function(const char *name, int state)
* a completion generator for usernames; returns _first_ username
* which starts with supplied text
* text contains a partial username preceded by random character
- * (usually '~'); state is ignored
- * it's callers responsibility to free returned value
+ * (usually '~'); state resets search from start (??? should we do that anyway)
+ * it's the caller's responsibility to free the returned value
*/
char *
username_completion_function(const char *text, int state)
{
- struct passwd *pwd, pwres;
+#if defined(HAVE_GETPW_R_POSIX) || defined(HAVE_GETPW_R_DRAFT)
+ struct passwd pwres;
char pwbuf[1024];
+#endif
+ struct passwd *pass = NULL;
if (text[0] == '\0')
- return (NULL);
+ return NULL;
if (*text == '~')
text++;
@@ -1691,15 +1748,21 @@ username_completion_function(const char *text, int state)
if (state == 0)
setpwent();
- while (getpwent_r(&pwres, pwbuf, sizeof(pwbuf), &pwd) == 0
- && pwd != NULL && text[0] == pwd->pw_name[0]
- && strcmp(text, pwd->pw_name) == 0);
+ while (
+#if defined(HAVE_GETPW_R_POSIX) || defined(HAVE_GETPW_R_DRAFT)
+ getpwent_r(&pwres, pwbuf, sizeof(pwbuf), &pass) == 0 && pass != NULL
+#else
+ (pass = getpwent()) != NULL
+#endif
+ && text[0] == pass->pw_name[0]
+ && strcmp(text, pass->pw_name) == 0)
+ continue;
- if (pwd == NULL) {
+ if (pass == NULL) {
endpwent();
return NULL;
}
- return strdup(pwd->pw_name);
+ return strdup(pass->pw_name);
}
@@ -1732,7 +1795,7 @@ _rl_completion_append_character_function(const char *dummy
__attribute__((__unused__)))
{
static char buf[2];
- buf[0] = rl_completion_append_character;
+ buf[0] = (char)rl_completion_append_character;
buf[1] = '\0';
return buf;
}
@@ -1748,6 +1811,7 @@ rl_complete(int ignore __attribute__((__unused__)), int invoking_key)
#ifdef WIDECHAR
static ct_buffer_t wbreak_conv, sprefix_conv;
#endif
+ char *breakchars;
if (h == NULL || e == NULL)
rl_initialize();
@@ -1757,19 +1821,26 @@ rl_complete(int ignore __attribute__((__unused__)), int invoking_key)
arr[0] = (char)invoking_key;
arr[1] = '\0';
el_insertstr(e, arr);
- return (CC_REFRESH);
+ return CC_REFRESH;
}
+ if (rl_completion_word_break_hook != NULL)
+ breakchars = (*rl_completion_word_break_hook)();
+ else
+ breakchars = rl_basic_word_break_characters;
+
/* Just look at how many global variables modify this operation! */
return fn_complete(e,
(CPFunction *)rl_completion_entry_function,
rl_attempted_completion_function,
ct_decode_string(rl_basic_word_break_characters, &wbreak_conv),
- ct_decode_string(rl_special_prefixes, &sprefix_conv),
+ ct_decode_string(breakchars, &sprefix_conv),
_rl_completion_append_character_function,
(size_t)rl_completion_query_items,
&rl_completion_type, &rl_attempted_completion_over,
&rl_point, &rl_end, NULL, NULL, NULL);
+
+
}
@@ -1800,7 +1871,7 @@ rl_bind_key(int c, rl_command_func_t *func)
e->el_map.key[c] = ED_INSERT;
retval = 0;
}
- return (retval);
+ return retval;
}
@@ -1816,7 +1887,7 @@ rl_read_key(void)
if (e == NULL || h == NULL)
rl_initialize();
- return (el_getc(e, fooarr));
+ return el_getc(e, fooarr);
}
@@ -1846,32 +1917,33 @@ rl_insert(int count, int c)
rl_initialize();
/* XXX - int -> char conversion can lose on multichars */
- arr[0] = c;
+ arr[0] = (char)c;
arr[1] = '\0';
for (; count > 0; count--)
el_push(e, arr);
- return (0);
+ return 0;
}
int
rl_insert_text(const char *text)
{
if (!text || *text == 0)
- return (0);
+ return 0;
if (h == NULL || e == NULL)
rl_initialize();
if (el_insertstr(e, text) < 0)
- return (0);
+ return 0;
return (int)strlen(text);
}
/*ARGSUSED*/
int
-rl_newline(int count, int c)
+rl_newline(int count __attribute__((__unused__)),
+ int c __attribute__((__unused__)))
{
/*
* Readline-4.0 appears to ignore the args.
@@ -1881,7 +1953,7 @@ rl_newline(int count, int c)
/*ARGSUSED*/
static unsigned char
-rl_bind_wrapper(EditLine *el, unsigned char c)
+rl_bind_wrapper(EditLine *el __attribute__((__unused__)), unsigned char c)
{
if (map[c] == NULL)
return CC_ERROR;
@@ -1906,12 +1978,12 @@ rl_add_defun(const char *name, Function *fun, int c)
map[(unsigned char)c] = fun;
el_set(e, EL_ADDFN, name, name, rl_bind_wrapper);
vis(dest, c, VIS_WHITE|VIS_NOSLASH, 0);
- el_set(e, EL_BIND, dest, name);
+ el_set(e, EL_BIND, dest, name, NULL);
return 0;
}
void
-rl_callback_read_char()
+rl_callback_read_char(void)
{
int count = 0, done = 0;
const char *buf = el_gets(e, &count);
@@ -1932,7 +2004,7 @@ rl_callback_read_char()
} else
wbuf = NULL;
(*(void (*)(const char *))rl_linefunc)(wbuf);
- //el_set(e, EL_UNBUFFERED, 1);
+ el_set(e, EL_UNBUFFERED, 1);
}
}
@@ -1958,7 +2030,7 @@ void
rl_redisplay(void)
{
char a[2];
- a[0] = e->el_tty.t_c[TS_IO][C_REPRINT];
+ a[0] = (char)e->el_tty.t_c[TS_IO][C_REPRINT];
a[1] = '\0';
el_push(e, a);
}
@@ -1967,7 +2039,7 @@ int
rl_get_previous_history(int count, int key)
{
char a[2];
- a[0] = key;
+ a[0] = (char)key;
a[1] = '\0';
while (count--)
el_push(e, a);
@@ -1976,7 +2048,7 @@ rl_get_previous_history(int count, int key)
void
/*ARGSUSED*/
-rl_prep_terminal(int meta_flag)
+rl_prep_terminal(int meta_flag __attribute__((__unused__)))
{
el_set(e, EL_PREP_TERM, 1);
}
@@ -1990,7 +2062,7 @@ rl_deprep_terminal(void)
int
rl_read_init_file(const char *s)
{
- return(el_source(e, s));
+ return el_source(e, s);
}
int
@@ -2004,7 +2076,7 @@ rl_parse_and_bind(const char *line)
tok_str(tok, line, &argc, &argv);
argc = el_parse(e, argc, argv);
tok_end(tok);
- return (argc ? 1 : 0);
+ return argc ? 1 : 0;
}
int
@@ -2014,7 +2086,7 @@ rl_variable_bind(const char *var, const char *value)
* The proper return value is undocument, but this is what the
* readline source seems to do.
*/
- return ((el_set(e, EL_BIND, "", var, value) == -1) ? 1 : 0);
+ return el_set(e, EL_BIND, "", var, value, NULL) == -1 ? 1 : 0;
}
void
@@ -2022,7 +2094,7 @@ rl_stuff_char(int c)
{
char buf[2];
- buf[0] = c;
+ buf[0] = (char)c;
buf[1] = '\0';
el_insertstr(e, buf);
}
@@ -2040,23 +2112,23 @@ _rl_event_read_char(EditLine *el, char *cp)
#if defined(FIONREAD)
if (ioctl(el->el_infd, FIONREAD, &n) < 0)
- return(-1);
+ return -1;
if (n)
- num_read = read(el->el_infd, cp, 1);
+ num_read = read(el->el_infd, cp, (size_t)1);
else
num_read = 0;
#elif defined(F_SETFL) && defined(O_NDELAY)
if ((n = fcntl(el->el_infd, F_GETFL, 0)) < 0)
- return(-1);
+ return -1;
if (fcntl(el->el_infd, F_SETFL, n|O_NDELAY) < 0)
- return(-1);
+ return -1;
num_read = read(el->el_infd, cp, 1);
if (fcntl(el->el_infd, F_SETFL, n))
- return(-1);
+ return -1;
#else
/* not non-blocking, but what you gonna do? */
num_read = read(el->el_infd, cp, 1);
- return(-1);
+ return -1;
#endif
if (num_read < 0 && errno == EAGAIN)
@@ -2083,9 +2155,9 @@ void
rl_get_screen_size(int *rows, int *cols)
{
if (rows)
- el_get(e, EL_GETTC, "li", rows);
+ el_get(e, EL_GETTC, "li", rows, (void *)0);
if (cols)
- el_get(e, EL_GETTC, "co", cols);
+ el_get(e, EL_GETTC, "co", cols, (void *)0);
}
void
@@ -2093,9 +2165,9 @@ rl_set_screen_size(int rows, int cols)
{
char buf[64];
(void)snprintf(buf, sizeof(buf), "%d", rows);
- el_set(e, EL_SETTC, "li", buf);
+ el_set(e, EL_SETTC, "li", buf, NULL);
(void)snprintf(buf, sizeof(buf), "%d", cols);
- el_set(e, EL_SETTC, "co", buf);
+ el_set(e, EL_SETTC, "co", buf, NULL);
}
char **
@@ -2106,7 +2178,7 @@ rl_completion_matches(const char *str, rl_compentry_func_t *fun)
len = 1;
max = 10;
- if ((list = malloc(max * sizeof(*list))) == NULL)
+ if ((list = el_malloc(max * sizeof(*list))) == NULL)
return NULL;
while ((match = (*fun)(str, (int)(len - 1))) != NULL) {
@@ -2114,7 +2186,7 @@ rl_completion_matches(const char *str, rl_compentry_func_t *fun)
if (len == max) {
char **nl;
max += 10;
- if ((nl = realloc(list, max * sizeof(*nl))) == NULL)
+ if ((nl = el_realloc(list, max * sizeof(*nl))) == NULL)
goto out;
list = nl;
}
@@ -2141,7 +2213,7 @@ rl_completion_matches(const char *str, rl_compentry_func_t *fun)
if ((list[0] = strdup(str)) == NULL)
goto out;
} else {
- if ((list[0] = malloc(min + 1)) == NULL)
+ if ((list[0] = el_malloc((min + 1) * sizeof(*list[0]))) == NULL)
goto out;
(void)memcpy(list[0], list[1], min);
list[0][min] = '\0';
@@ -2149,7 +2221,7 @@ rl_completion_matches(const char *str, rl_compentry_func_t *fun)
return list;
out:
- free(list);
+ el_free(list);
return NULL;
}
@@ -2184,15 +2256,16 @@ history_get_history_state(void)
{
HISTORY_STATE *hs;
- if ((hs = malloc(sizeof(HISTORY_STATE))) == NULL)
- return (NULL);
+ if ((hs = el_malloc(sizeof(*hs))) == NULL)
+ return NULL;
hs->length = history_length;
- return (hs);
+ return hs;
}
int
/*ARGSUSED*/
-rl_kill_text(int from, int to)
+rl_kill_text(int from __attribute__((__unused__)),
+ int to __attribute__((__unused__)))
{
return 0;
}
@@ -2211,20 +2284,25 @@ rl_get_keymap(void)
void
/*ARGSUSED*/
-rl_set_keymap(Keymap k)
+rl_set_keymap(Keymap k __attribute__((__unused__)))
{
}
int
/*ARGSUSED*/
-rl_generic_bind(int type, const char * keyseq, const char * data, Keymap k)
+rl_generic_bind(int type __attribute__((__unused__)),
+ const char * keyseq __attribute__((__unused__)),
+ const char * data __attribute__((__unused__)),
+ Keymap k __attribute__((__unused__)))
{
return 0;
}
int
/*ARGSUSED*/
-rl_bind_key_in_map(int key, rl_command_func_t *fun, Keymap k)
+rl_bind_key_in_map(int key __attribute__((__unused__)),
+ rl_command_func_t *fun __attribute__((__unused__)),
+ Keymap k __attribute__((__unused__)))
{
return 0;
}
@@ -2240,3 +2318,8 @@ rl_on_new_line(void)
{
return 0;
}
+
+void
+rl_free_line_state(void)
+{
+}
diff --git a/lib/libedit/refresh.c b/lib/libedit/refresh.c
index 8fe8229..c85e845 100644
--- a/lib/libedit/refresh.c
+++ b/lib/libedit/refresh.c
@@ -1,3 +1,5 @@
+/* $NetBSD: refresh.c,v 1.37 2011/07/29 23:44:45 christos Exp $ */
+
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -28,12 +30,15 @@
* 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.
- *
- * $NetBSD: refresh.c,v 1.34 2009/12/28 22:15:36 christos Exp $
*/
+#include "config.h"
#if !defined(lint) && !defined(SCCSID)
+#if 0
static char sccsid[] = "@(#)refresh.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: refresh.c,v 1.37 2011/07/29 23:44:45 christos Exp $");
+#endif
#endif /* not lint && not SCCSID */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
@@ -41,7 +46,6 @@ __FBSDID("$FreeBSD$");
/*
* refresh.c: Lower level screen refreshing functions
*/
-#include "sys.h"
#include <stdio.h>
#include <ctype.h>
#include <unistd.h>
@@ -50,14 +54,14 @@ __FBSDID("$FreeBSD$");
#include "el.h"
private void re_nextline(EditLine *);
-private void re_addc(EditLine *, int);
-private void re_update_line(EditLine *, char *, char *, int);
-private void re_insert (EditLine *, char *, int, int, char *, int);
-private void re_delete(EditLine *, char *, int, int, int);
-private void re_fastputc(EditLine *, int);
+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);
+private void re_delete(EditLine *, Char *, int, int, int);
+private void re_fastputc(EditLine *, Int);
private void re_clear_eol(EditLine *, int, int, int);
-private void re__strncopy(char *, char *, size_t);
-private void re__copy_and_pad(char *, const char *, size_t);
+private void re__strncopy(Char *, Char *, size_t);
+private void re__copy_and_pad(Char *, const Char *, size_t);
#ifdef DEBUG_REFRESH
private void re_printstr(EditLine *, const char *, char *, char *);
@@ -101,9 +105,9 @@ re_nextline(EditLine *el)
* 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];
+ if (el->el_refresh.r_cursor.v + 1 >= el->el_terminal.t_size.v) {
+ int i, lins = el->el_terminal.t_size.v;
+ Char *firstline = el->el_vdisplay[0];
for(i = 1; i < lins; i++)
el->el_vdisplay[i - 1] = el->el_vdisplay[i];
@@ -113,9 +117,9 @@ re_nextline(EditLine *el)
} else
el->el_refresh.r_cursor.v++;
- ELRE_ASSERT(el->el_refresh.r_cursor.v >= el->el_term.t_size.v,
+ ELRE_ASSERT(el->el_refresh.r_cursor.v >= el->el_terminal.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),
+ el->el_refresh.r_cursor.v, el->el_terminal.t_size.v),
abort());
}
@@ -123,38 +127,34 @@ re_nextline(EditLine *el)
* Draw c, expanding tabs, control chars etc.
*/
private void
-re_addc(EditLine *el, int c)
+re_addc(EditLine *el, Int c)
{
-
- if (isprint(c)) {
- re_putc(el, c, 1);
- return;
- }
- 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 */
- re_nextline(el);
- return;
- }
- if (c == '\t') { /* expand the tab */
+ switch (ct_chr_class((Char)c)) {
+ case CHTYPE_TAB: /* expand the tab */
for (;;) {
re_putc(el, ' ', 1);
if ((el->el_refresh.r_cursor.h & 07) == 0)
break; /* go until tab stop */
}
- } else if (iscntrl(c)) {
- re_putc(el, '^', 1);
- if (c == 0177)
- re_putc(el, '?', 1);
- else
- /* uncontrolify it; works only for iso8859-1 like sets */
- re_putc(el, (toascii(c) | 0100), 1);
- } else {
- re_putc(el, '\\', 1);
- re_putc(el, (int) ((((unsigned int) c >> 6) & 07) + '0'), 1);
- re_putc(el, (int) ((((unsigned int) c >> 3) & 07) + '0'), 1);
- re_putc(el, (c & 07) + '0', 1);
+ break;
+ case CHTYPE_NL: {
+ 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 */
+ re_nextline(el);
+ break;
+ }
+ case CHTYPE_PRINT:
+ re_putc(el, c, 1);
+ break;
+ default: {
+ Char visbuf[VISUAL_WIDTH_MAX];
+ ssize_t i, n =
+ ct_visual_char(visbuf, VISUAL_WIDTH_MAX, (Char)c);
+ for (i = 0; n-- > 0; ++i)
+ re_putc(el, visbuf[i], 1);
+ break;
+ }
}
}
@@ -163,23 +163,32 @@ re_addc(EditLine *el, int c)
* Draw the character given
*/
protected void
-re_putc(EditLine *el, int c, int shift)
+re_putc(EditLine *el, Int c, int shift)
{
+ int i, w = Width(c);
+ ELRE_DEBUG(1, (__F, "printing %5x '%c'\r\n", c, c));
- ELRE_DEBUG(1, (__F, "printing %3.3o '%c'\r\n", c, c));
+ while (shift && (el->el_refresh.r_cursor.h + w > el->el_terminal.t_size.h))
+ re_putc(el, ' ', 1);
+
+ el->el_vdisplay[el->el_refresh.r_cursor.v]
+ [el->el_refresh.r_cursor.h] = c;
+ /* assumes !shift is only used for single-column chars */
+ i = w;
+ while (--i > 0)
+ el->el_vdisplay[el->el_refresh.r_cursor.v]
+ [el->el_refresh.r_cursor.h + i] = MB_FILL_CHAR;
- el->el_vdisplay[el->el_refresh.r_cursor.v][el->el_refresh.r_cursor.h] = c;
if (!shift)
return;
- 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_refresh.r_cursor.h += w; /* advance to next place */
+ if (el->el_refresh.r_cursor.h >= el->el_terminal.t_size.h) {
/* assure end of line */
- el->el_vdisplay[el->el_refresh.r_cursor.v][el->el_term.t_size.h]
+ el->el_vdisplay[el->el_refresh.r_cursor.v][el->el_terminal.t_size.h]
= '\0';
re_nextline(el);
}
-
}
@@ -193,7 +202,7 @@ protected void
re_refresh(EditLine *el)
{
int i, rhdiff;
- char *cp, *st;
+ Char *cp, *st;
coord_t cur;
#ifdef notyet
size_t termsz;
@@ -228,7 +237,7 @@ re_refresh(EditLine *el)
/* draw the current input buffer */
#if notyet
- termsz = el->el_term.t_size.h * el->el_term.t_size.v;
+ termsz = el->el_terminal.t_size.h * el->el_terminal.t_size.v;
if (el->el_line.lastchar - el->el_line.buffer > termsz) {
/*
* If line is longer than terminal, process only part
@@ -237,26 +246,33 @@ re_refresh(EditLine *el)
size_t rem = (el->el_line.lastchar-el->el_line.buffer)%termsz;
st = el->el_line.lastchar - rem
- - (termsz - (((rem / el->el_term.t_size.v) - 1)
- * el->el_term.t_size.v));
+ - (termsz - (((rem / el->el_terminal.t_size.v) - 1)
+ * el->el_terminal.t_size.v));
} else
#endif
st = el->el_line.buffer;
for (cp = st; cp < el->el_line.lastchar; cp++) {
if (cp == el->el_line.cursor) {
+ int w = Width(*cp);
/* save for later */
cur.h = el->el_refresh.r_cursor.h;
cur.v = el->el_refresh.r_cursor.v;
+ /* handle being at a linebroken doublewidth char */
+ if (w > 1 && el->el_refresh.r_cursor.h + w >
+ el->el_terminal.t_size.h) {
+ cur.h = 0;
+ cur.v++;
+ }
}
- re_addc(el, (unsigned char) *cp);
+ re_addc(el, *cp);
}
if (cur.h == -1) { /* if I haven't been set yet, I'm at the end */
cur.h = el->el_refresh.r_cursor.h;
cur.v = el->el_refresh.r_cursor.v;
}
- rhdiff = el->el_term.t_size.h - el->el_refresh.r_cursor.h -
+ rhdiff = el->el_terminal.t_size.h - el->el_refresh.r_cursor.h -
el->el_rprompt.p_pos.h;
if (el->el_rprompt.p_pos.h && !el->el_rprompt.p_pos.v &&
!el->el_refresh.r_cursor.v && rhdiff > 1) {
@@ -279,8 +295,8 @@ re_refresh(EditLine *el)
ELRE_DEBUG(1, (__F,
"term.h=%d vcur.h=%d vcur.v=%d vdisplay[0]=\r\n:%80.80s:\r\n",
- el->el_term.t_size.h, el->el_refresh.r_cursor.h,
- el->el_refresh.r_cursor.v, el->el_vdisplay[0]));
+ el->el_terminal.t_size.h, el->el_refresh.r_cursor.h,
+ el->el_refresh.r_cursor.v, ct_encode_string(el->el_vdisplay[0])));
ELRE_DEBUG(1, (__F, "updating %d lines.\r\n", el->el_refresh.r_newcv));
for (i = 0; i <= el->el_refresh.r_newcv; i++) {
@@ -295,7 +311,7 @@ re_refresh(EditLine *el)
* leftover stuff.
*/
re__copy_and_pad(el->el_display[i], el->el_vdisplay[i],
- (size_t) el->el_term.t_size.h);
+ (size_t) el->el_terminal.t_size.h);
}
ELRE_DEBUG(1, (__F,
"\r\nel->el_refresh.r_cursor.v=%d,el->el_refresh.r_oldcv=%d i=%d\r\n",
@@ -303,11 +319,12 @@ re_refresh(EditLine *el)
if (el->el_refresh.r_oldcv > el->el_refresh.r_newcv)
for (; i <= el->el_refresh.r_oldcv; i++) {
- term_move_to_line(el, i);
- term_move_to_char(el, 0);
- term_clear_EOL(el, (int) strlen(el->el_display[i]));
+ terminal_move_to_line(el, i);
+ terminal_move_to_char(el, 0);
+ /* This Strlen should be safe even with MB_FILL_CHARs */
+ terminal_clear_EOL(el, (int) Strlen(el->el_display[i]));
#ifdef DEBUG_REFRESH
- term_overwrite(el, "C\b", (size_t)2);
+ terminal_overwrite(el, "C\b", (size_t)2);
#endif /* DEBUG_REFRESH */
el->el_display[i][0] = '\0';
}
@@ -317,8 +334,8 @@ re_refresh(EditLine *el)
"\r\ncursor.h = %d, cursor.v = %d, cur.h = %d, cur.v = %d\r\n",
el->el_refresh.r_cursor.h, el->el_refresh.r_cursor.v,
cur.h, cur.v));
- term_move_to_line(el, cur.v); /* go to where the cursor is */
- term_move_to_char(el, cur.h);
+ terminal_move_to_line(el, cur.v); /* go to where the cursor is */
+ terminal_move_to_char(el, cur.h);
}
@@ -329,10 +346,10 @@ protected void
re_goto_bottom(EditLine *el)
{
- term_move_to_line(el, el->el_refresh.r_oldcv);
- term__putc(el, '\n');
+ terminal_move_to_line(el, el->el_refresh.r_oldcv);
+ terminal__putc(el, '\n');
re_clear_display(el);
- term__flush(el);
+ terminal__flush(el);
}
@@ -342,10 +359,10 @@ re_goto_bottom(EditLine *el)
*/
private void
/*ARGSUSED*/
-re_insert(EditLine *el __unused,
- char *d, int dat, int dlen, char *s, int num)
+re_insert(EditLine *el __attribute__((__unused__)),
+ Char *d, int dat, int dlen, Char *s, int num)
{
- char *a, *b;
+ Char *a, *b;
if (num <= 0)
return;
@@ -354,8 +371,8 @@ re_insert(EditLine *el __unused,
ELRE_DEBUG(1,
(__F, "re_insert() starting: %d at %d max %d, d == \"%s\"\n",
- num, dat, dlen, d));
- ELRE_DEBUG(1, (__F, "s == \"%s\"\n", s));
+ num, dat, dlen, ct_encode_string(d)));
+ ELRE_DEBUG(1, (__F, "s == \"%s\"\n", ct_encode_string(s)));
/* open up the space for num chars */
if (num > 0) {
@@ -365,19 +382,24 @@ re_insert(EditLine *el __unused,
*b-- = *a--;
d[dlen] = '\0'; /* just in case */
}
+
ELRE_DEBUG(1, (__F,
"re_insert() after insert: %d at %d max %d, d == \"%s\"\n",
- num, dat, dlen, d));
- ELRE_DEBUG(1, (__F, "s == \"%s\"\n", s));
+ num, dat, dlen, ct_encode_string(d)));
+ ELRE_DEBUG(1, (__F, "s == \"%s\"\n", ct_encode_string(s)));
/* copy the characters */
for (a = d + dat; (a < d + dlen) && (num > 0); num--)
*a++ = *s++;
+#ifdef notyet
+ /* ct_encode_string() uses a static buffer, so we can't conveniently
+ * encode both d & s here */
ELRE_DEBUG(1,
(__F, "re_insert() after copy: %d at %d max %d, %s == \"%s\"\n",
num, dat, dlen, d, s));
ELRE_DEBUG(1, (__F, "s == \"%s\"\n", s));
+#endif
}
@@ -386,10 +408,10 @@ re_insert(EditLine *el __unused,
*/
private void
/*ARGSUSED*/
-re_delete(EditLine *el __unused,
- char *d, int dat, int dlen, int num)
+re_delete(EditLine *el __attribute__((__unused__)),
+ Char *d, int dat, int dlen, int num)
{
- char *a, *b;
+ Char *a, *b;
if (num <= 0)
return;
@@ -399,7 +421,7 @@ re_delete(EditLine *el __unused,
}
ELRE_DEBUG(1,
(__F, "re_delete() starting: %d at %d max %d, d == \"%s\"\n",
- num, dat, dlen, d));
+ num, dat, dlen, ct_encode_string(d)));
/* open up the space for num chars */
if (num > 0) {
@@ -411,7 +433,7 @@ re_delete(EditLine *el __unused,
}
ELRE_DEBUG(1,
(__F, "re_delete() after delete: %d at %d max %d, d == \"%s\"\n",
- num, dat, dlen, d));
+ num, dat, dlen, ct_encode_string(d)));
}
@@ -419,7 +441,7 @@ re_delete(EditLine *el __unused,
* Like strncpy without padding.
*/
private void
-re__strncopy(char *a, char *b, size_t n)
+re__strncopy(Char *a, Char *b, size_t n)
{
while (n-- && *b)
@@ -430,7 +452,7 @@ re__strncopy(char *a, char *b, size_t n)
* Find the number of characters we need to clear till the end of line
* in order to make sure that we have cleared the previous contents of
* the line. fx and sx is the number of characters inserted or deleted
- * int the first or second diff, diff is the difference between the
+ * in the first or second diff, diff is the difference between the
* number of characters between the new and old line.
*/
private void
@@ -450,7 +472,7 @@ re_clear_eol(EditLine *el, int fx, int sx, int diff)
diff = sx;
ELRE_DEBUG(1, (__F, "re_clear_eol %d\n", diff));
- term_clear_EOL(el, diff);
+ terminal_clear_EOL(el, diff);
}
/*****************************************************************
@@ -478,11 +500,11 @@ new: eddie> Oh, my little buggy says to me, as lurgid as
#define MIN_END_KEEP 4
private void
-re_update_line(EditLine *el, char *old, char *new, int i)
+re_update_line(EditLine *el, Char *old, Char *new, int i)
{
- char *o, *n, *p, c;
- char *ofd, *ols, *oe, *nfd, *nls, *ne;
- char *osb, *ose, *nsb, *nse;
+ Char *o, *n, *p, c;
+ Char *ofd, *ols, *oe, *nfd, *nls, *ne;
+ Char *osb, *ose, *nsb, *nse;
int fx, sx;
size_t len;
@@ -697,7 +719,7 @@ re_update_line(EditLine *el, char *old, char *new, int i)
* don't have to change the line, we don't move to it. el_cursor.h to
* first diff char
*/
- term_move_to_line(el, i);
+ terminal_move_to_line(el, i);
/*
* at this point we have something like this:
@@ -721,7 +743,7 @@ re_update_line(EditLine *el, char *old, char *new, int i)
* if we have a net insert on the first difference, AND inserting the
* net amount ((nsb-nfd) - (osb-ofd)) won't push the last useful
* character (which is ne if nls != ne, otherwise is nse) off the edge
- * of the screen (el->el_term.t_size.h) else we do the deletes first
+ * of the screen (el->el_terminal.t_size.h) else we do the deletes first
* so that we keep everything we need to.
*/
@@ -743,13 +765,13 @@ re_update_line(EditLine *el, char *old, char *new, int i)
* No insert or delete
*/
if ((nsb != nfd) && fx > 0 &&
- ((p - old) + fx <= el->el_term.t_size.h)) {
+ ((p - old) + fx <= el->el_terminal.t_size.h)) {
ELRE_DEBUG(1,
(__F, "first diff insert at %d...\r\n", nfd - new));
/*
* Move to the first char to insert, where the first diff is.
*/
- term_move_to_char(el, (int)(nfd - new));
+ terminal_move_to_char(el, (int)(nfd - new));
/*
* Check if we have stuff to keep at end
*/
@@ -761,21 +783,21 @@ re_update_line(EditLine *el, char *old, char *new, int i)
if (fx > 0) {
ELRE_DEBUG(!EL_CAN_INSERT, (__F,
"ERROR: cannot insert in early first diff\n"));
- term_insertwrite(el, nfd, fx);
+ terminal_insertwrite(el, nfd, fx);
re_insert(el, old, (int)(ofd - old),
- el->el_term.t_size.h, nfd, fx);
+ el->el_terminal.t_size.h, nfd, fx);
}
/*
* write (nsb-nfd) - fx chars of new starting at
* (nfd + fx)
*/
len = (size_t) ((nsb - nfd) - fx);
- term_overwrite(el, (nfd + fx), len);
+ terminal_overwrite(el, (nfd + fx), len);
re__strncopy(ofd + fx, nfd + fx, len);
} else {
ELRE_DEBUG(1, (__F, "without anything to save\r\n"));
len = (size_t)(nsb - nfd);
- term_overwrite(el, nfd, len);
+ terminal_overwrite(el, nfd, len);
re__strncopy(ofd, nfd, len);
/*
* Done
@@ -788,7 +810,7 @@ re_update_line(EditLine *el, char *old, char *new, int i)
/*
* move to the first char to delete where the first diff is
*/
- term_move_to_char(el, (int)(ofd - old));
+ terminal_move_to_char(el, (int)(ofd - old));
/*
* Check if we have stuff to save
*/
@@ -801,15 +823,15 @@ re_update_line(EditLine *el, char *old, char *new, int i)
if (fx < 0) {
ELRE_DEBUG(!EL_CAN_DELETE, (__F,
"ERROR: cannot delete in first diff\n"));
- term_deletechars(el, -fx);
+ terminal_deletechars(el, -fx);
re_delete(el, old, (int)(ofd - old),
- el->el_term.t_size.h, -fx);
+ el->el_terminal.t_size.h, -fx);
}
/*
* write (nsb-nfd) chars of new starting at nfd
*/
len = (size_t) (nsb - nfd);
- term_overwrite(el, nfd, len);
+ terminal_overwrite(el, nfd, len);
re__strncopy(ofd, nfd, len);
} else {
@@ -818,7 +840,7 @@ re_update_line(EditLine *el, char *old, char *new, int i)
/*
* write (nsb-nfd) chars of new starting at nfd
*/
- term_overwrite(el, nfd, (size_t)(nsb - nfd));
+ terminal_overwrite(el, nfd, (size_t)(nsb - nfd));
re_clear_eol(el, fx, sx,
(int)((oe - old) - (ne - new)));
/*
@@ -829,7 +851,7 @@ re_update_line(EditLine *el, char *old, char *new, int i)
} else
fx = 0;
- if (sx < 0 && (ose - old) + fx < el->el_term.t_size.h) {
+ if (sx < 0 && (ose - old) + fx < el->el_terminal.t_size.h) {
ELRE_DEBUG(1, (__F,
"second diff delete at %d...\r\n", (ose - old) + fx));
/*
@@ -839,7 +861,7 @@ re_update_line(EditLine *el, char *old, char *new, int i)
* fx is the number of characters inserted (+) or deleted (-)
*/
- term_move_to_char(el, (int)((ose - old) + fx));
+ terminal_move_to_char(el, (int)((ose - old) + fx));
/*
* Check if we have stuff to save
*/
@@ -851,16 +873,16 @@ re_update_line(EditLine *el, char *old, char *new, int i)
if (sx < 0) {
ELRE_DEBUG(!EL_CAN_DELETE, (__F,
"ERROR: cannot delete in second diff\n"));
- term_deletechars(el, -sx);
+ terminal_deletechars(el, -sx);
}
/*
* write (nls-nse) chars of new starting at nse
*/
- term_overwrite(el, nse, (size_t)(nls - nse));
+ terminal_overwrite(el, nse, (size_t)(nls - nse));
} else {
ELRE_DEBUG(1, (__F,
"but with nothing left to save\r\n"));
- term_overwrite(el, nse, (size_t)(nls - nse));
+ terminal_overwrite(el, nse, (size_t)(nls - nse));
re_clear_eol(el, fx, sx,
(int)((oe - old) - (ne - new)));
}
@@ -872,7 +894,7 @@ re_update_line(EditLine *el, char *old, char *new, int i)
ELRE_DEBUG(1, (__F, "late first diff insert at %d...\r\n",
nfd - new));
- term_move_to_char(el, (int)(nfd - new));
+ terminal_move_to_char(el, (int)(nfd - new));
/*
* Check if we have stuff to keep at the end
*/
@@ -890,21 +912,21 @@ re_update_line(EditLine *el, char *old, char *new, int i)
*/
ELRE_DEBUG(!EL_CAN_INSERT, (__F,
"ERROR: cannot insert in late first diff\n"));
- term_insertwrite(el, nfd, fx);
+ terminal_insertwrite(el, nfd, fx);
re_insert(el, old, (int)(ofd - old),
- el->el_term.t_size.h, nfd, fx);
+ el->el_terminal.t_size.h, nfd, fx);
}
/*
* write (nsb-nfd) - fx chars of new starting at
* (nfd + fx)
*/
len = (size_t) ((nsb - nfd) - fx);
- term_overwrite(el, (nfd + fx), len);
+ terminal_overwrite(el, (nfd + fx), len);
re__strncopy(ofd + fx, nfd + fx, len);
} else {
ELRE_DEBUG(1, (__F, "without anything to save\r\n"));
len = (size_t) (nsb - nfd);
- term_overwrite(el, nfd, len);
+ terminal_overwrite(el, nfd, len);
re__strncopy(ofd, nfd, len);
}
}
@@ -914,24 +936,24 @@ re_update_line(EditLine *el, char *old, char *new, int i)
if (sx >= 0) {
ELRE_DEBUG(1, (__F,
"second diff insert at %d...\r\n", (int)(nse - new)));
- term_move_to_char(el, (int)(nse - new));
+ terminal_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) {
/* insert sx chars of new starting at nse */
ELRE_DEBUG(!EL_CAN_INSERT, (__F,
"ERROR: cannot insert in second diff\n"));
- term_insertwrite(el, nse, sx);
+ terminal_insertwrite(el, nse, sx);
}
/*
* write (nls-nse) - sx chars of new starting at
* (nse + sx)
*/
- term_overwrite(el, (nse + sx),
+ terminal_overwrite(el, (nse + sx),
(size_t)((nls - nse) - sx));
} else {
ELRE_DEBUG(1, (__F, "without anything to save\r\n"));
- term_overwrite(el, nse, (size_t)(nls - nse));
+ terminal_overwrite(el, nse, (size_t)(nls - nse));
/*
* No need to do a clear-to-end here because we were
@@ -948,7 +970,7 @@ re_update_line(EditLine *el, char *old, char *new, int i)
* Copy string and pad with spaces
*/
private void
-re__copy_and_pad(char *dst, const char *src, size_t width)
+re__copy_and_pad(Char *dst, const Char *src, size_t width)
{
size_t i;
@@ -971,8 +993,8 @@ re__copy_and_pad(char *dst, const char *src, size_t width)
protected void
re_refresh_cursor(EditLine *el)
{
- char *cp, c;
- int h, v, th;
+ Char *cp;
+ int h, v, th, w;
if (el->el_line.cursor >= el->el_line.lastchar) {
if (el->el_map.current == el->el_map.alt
@@ -985,41 +1007,46 @@ re_refresh_cursor(EditLine *el)
/* first we must find where the cursor is... */
h = el->el_prompt.p_pos.h;
v = el->el_prompt.p_pos.v;
- th = el->el_term.t_size.h; /* optimize for speed */
+ th = el->el_terminal.t_size.h; /* optimize for speed */
/* do input buffer to el->el_line.cursor */
for (cp = el->el_line.buffer; cp < el->el_line.cursor; cp++) {
- c = *cp;
-
- switch (c) {
- case '\n': /* handle newline in data part too */
+ switch (ct_chr_class(*cp)) {
+ case CHTYPE_NL: /* handle newline in data part too */
h = 0;
v++;
break;
- case '\t': /* if a tab, to next tab stop */
+ case CHTYPE_TAB: /* 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++;
+ w = Width(*cp);
+ if (w > 1 && h + w > th) { /* won't fit on line */
+ h = 0;
+ v++;
+ }
+ h += ct_visual_width(*cp);
break;
- }
+ }
if (h >= th) { /* check, extra long tabs picked up here also */
h -= th;
v++;
}
}
+ /* if we have a next character, and it's a doublewidth one, we need to
+ * check whether we need to linebreak for it to fit */
+ if (cp < el->el_line.lastchar && (w = Width(*cp)) > 1)
+ if (h + w > th) {
+ h = 0;
+ v++;
+ }
/* now go there */
- term_move_to_line(el, v);
- term_move_to_char(el, h);
- term__flush(el);
+ terminal_move_to_line(el, v);
+ terminal_move_to_char(el, h);
+ terminal__flush(el);
}
@@ -1027,12 +1054,19 @@ re_refresh_cursor(EditLine *el)
* Add a character fast.
*/
private void
-re_fastputc(EditLine *el, int c)
+re_fastputc(EditLine *el, Int c)
{
+ int w = Width((Char)c);
+ while (w > 1 && el->el_cursor.h + w > el->el_terminal.t_size.h)
+ re_fastputc(el, ' ');
- term__putc(el, c);
+ terminal__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) {
+ while (--w > 0)
+ el->el_display[el->el_cursor.v][el->el_cursor.h++]
+ = MB_FILL_CHAR;
+
+ if (el->el_cursor.h >= el->el_terminal.t_size.h) {
/* if we must overflow */
el->el_cursor.h = 0;
@@ -1042,14 +1076,14 @@ re_fastputc(EditLine *el, int c)
* We do this via pointer shuffling - it's safe in this case
* and we avoid memcpy().
*/
- if (el->el_cursor.v + 1 >= el->el_term.t_size.v) {
- int i, lins = el->el_term.t_size.v;
- char *firstline = el->el_display[0];
+ if (el->el_cursor.v + 1 >= el->el_terminal.t_size.v) {
+ int i, lins = el->el_terminal.t_size.v;
+ Char *firstline = el->el_display[0];
for(i = 1; i < lins; i++)
el->el_display[i - 1] = el->el_display[i];
- re__copy_and_pad(firstline, "", 0);
+ re__copy_and_pad(firstline, STR(""), (size_t)0);
el->el_display[i - 1] = firstline;
} else {
el->el_cursor.v++;
@@ -1057,12 +1091,12 @@ re_fastputc(EditLine *el, int c)
}
if (EL_HAS_AUTO_MARGINS) {
if (EL_HAS_MAGIC_MARGINS) {
- term__putc(el, ' ');
- term__putc(el, '\b');
+ terminal__putc(el, ' ');
+ terminal__putc(el, '\b');
}
} else {
- term__putc(el, '\r');
- term__putc(el, '\n');
+ terminal__putc(el, '\r');
+ terminal__putc(el, '\n');
}
}
}
@@ -1075,34 +1109,39 @@ re_fastputc(EditLine *el, int c)
protected void
re_fastaddc(EditLine *el)
{
- char c;
+ Char c;
int rhdiff;
- c = (unsigned char)el->el_line.cursor[-1];
+ c = el->el_line.cursor[-1];
if (c == '\t' || el->el_line.cursor != el->el_line.lastchar) {
re_refresh(el); /* too hard to handle */
return;
}
- rhdiff = el->el_term.t_size.h - el->el_cursor.h -
+ rhdiff = el->el_terminal.t_size.h - el->el_cursor.h -
el->el_rprompt.p_pos.h;
if (el->el_rprompt.p_pos.h && rhdiff < 3) {
re_refresh(el); /* clear out rprompt if less than 1 char gap */
return;
} /* else (only do at end of line, no TAB) */
- if (iscntrl((unsigned char) c)) { /* if control char, do caret */
- char mc = (c == 0177) ? '?' : (toascii(c) | 0100);
- re_fastputc(el, '^');
- re_fastputc(el, mc);
- } else if (isprint((unsigned char) c)) { /* normal char */
+ switch (ct_chr_class(c)) {
+ case CHTYPE_TAB: /* already handled, should never happen here */
+ break;
+ case CHTYPE_NL:
+ case CHTYPE_PRINT:
re_fastputc(el, c);
- } else {
- re_fastputc(el, '\\');
- re_fastputc(el, (int)(((((unsigned int)c) >> 6) & 3) + '0'));
- re_fastputc(el, (int)(((((unsigned int)c) >> 3) & 7) + '0'));
- re_fastputc(el, (c & 7) + '0');
+ break;
+ case CHTYPE_ASCIICTL:
+ case CHTYPE_NONPRINT: {
+ Char visbuf[VISUAL_WIDTH_MAX];
+ ssize_t i, n =
+ ct_visual_char(visbuf, VISUAL_WIDTH_MAX, (Char)c);
+ for (i = 0; n-- > 0; ++i)
+ re_fastputc(el, visbuf[i]);
+ break;
+ }
}
- term__flush(el);
+ terminal__flush(el);
}
@@ -1116,7 +1155,7 @@ re_clear_display(EditLine *el)
el->el_cursor.v = 0;
el->el_cursor.h = 0;
- for (i = 0; i < el->el_term.t_size.v; i++)
+ for (i = 0; i < el->el_terminal.t_size.v; i++)
el->el_display[i][0] = '\0';
el->el_refresh.r_oldcv = 0;
}
@@ -1133,14 +1172,14 @@ re_clear_lines(EditLine *el)
int 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);
+ terminal_move_to_line(el, i);
+ terminal_move_to_char(el, 0);
+ terminal_clear_EOL(el, el->el_terminal.t_size.h);
}
} else {
- term_move_to_line(el, el->el_refresh.r_oldcv);
+ terminal_move_to_line(el, el->el_refresh.r_oldcv);
/* go to last line */
- term__putc(el, '\r'); /* go to BOL */
- term__putc(el, '\n'); /* go to new line */
+ terminal__putc(el, '\r'); /* go to BOL */
+ terminal__putc(el, '\n'); /* go to new line */
}
}
diff --git a/lib/libedit/refresh.h b/lib/libedit/refresh.h
index e44ef9c..71a1587 100644
--- a/lib/libedit/refresh.h
+++ b/lib/libedit/refresh.h
@@ -1,3 +1,5 @@
+/* $NetBSD: refresh.h,v 1.6 2009/12/30 22:37:40 christos Exp $ */
+
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -30,7 +32,6 @@
* SUCH DAMAGE.
*
* @(#)refresh.h 8.1 (Berkeley) 6/4/93
- * $NetBSD: refresh.h,v 1.5 2003/08/07 16:44:33 agc Exp $
* $FreeBSD$
*/
@@ -48,7 +49,7 @@ typedef struct {
int r_newcv;
} el_refresh_t;
-protected void re_putc(EditLine *, int, int);
+protected void re_putc(EditLine *, Int, int);
protected void re_clear_lines(EditLine *);
protected void re_clear_display(EditLine *);
protected void re_refresh(EditLine *);
diff --git a/lib/libedit/search.c b/lib/libedit/search.c
index af3da8c..3cd205a 100644
--- a/lib/libedit/search.c
+++ b/lib/libedit/search.c
@@ -1,3 +1,5 @@
+/* $NetBSD: search.c,v 1.30 2011/10/04 15:27:04 christos Exp $ */
+
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -28,12 +30,15 @@
* 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.
- *
- * $NetBSD: search.c,v 1.21 2009/02/15 21:55:23 christos Exp $
*/
+#include "config.h"
#if !defined(lint) && !defined(SCCSID)
+#if 0
static char sccsid[] = "@(#)search.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: search.c,v 1.30 2011/10/04 15:27:04 christos Exp $");
+#endif
#endif /* not lint && not SCCSID */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
@@ -41,7 +46,6 @@ __FBSDID("$FreeBSD$");
/*
* search.c: History and character search functions
*/
-#include "sys.h"
#include <stdlib.h>
#if defined(REGEX)
#include <regex.h>
@@ -64,15 +68,16 @@ protected int
search_init(EditLine *el)
{
- el->el_search.patbuf = (char *) el_malloc(EL_BUFSIZ);
+ el->el_search.patbuf = el_malloc(EL_BUFSIZ *
+ sizeof(*el->el_search.patbuf));
if (el->el_search.patbuf == NULL)
- return (-1);
+ return -1;
el->el_search.patlen = 0;
el->el_search.patdir = -1;
el->el_search.chacha = '\0';
el->el_search.chadir = CHAR_FWD;
el->el_search.chatflg = 0;
- return (0);
+ return 0;
}
@@ -83,7 +88,7 @@ protected void
search_end(EditLine *el)
{
- el_free((ptr_t) el->el_search.patbuf);
+ el_free(el->el_search.patbuf);
el->el_search.patbuf = NULL;
}
@@ -104,8 +109,11 @@ regerror(const char *msg)
* Return if string matches pattern
*/
protected int
-el_match(const char *str, const char *pat)
+el_match(const Char *str, const Char *pat)
{
+#ifdef WIDECHAR
+ static ct_buffer_t conv;
+#endif
#if defined (REGEX)
regex_t re;
int rv;
@@ -117,30 +125,31 @@ el_match(const char *str, const char *pat)
extern int re_exec(const char *);
#endif
- if (strstr(str, pat) != NULL)
- return (1);
+ if (Strstr(str, pat) != 0)
+ return 1;
#if defined(REGEX)
- if (regcomp(&re, pat, 0) == 0) {
- rv = regexec(&re, str, 0, NULL, 0) == 0;
+ if (regcomp(&re, ct_encode_string(pat, &conv), 0) == 0) {
+ rv = regexec(&re, ct_encode_string(str, &conv), (size_t)0, NULL,
+ 0) == 0;
regfree(&re);
} else {
rv = 0;
}
- return (rv);
+ return rv;
#elif defined(REGEXP)
- if ((re = regcomp(pat)) != NULL) {
- rv = regexec(re, str);
- free((ptr_t) re);
+ if ((re = regcomp(ct_encode_string(pat, &conv))) != NULL) {
+ rv = regexec(re, ct_encode_string(str, &conv));
+ el_free(re);
} else {
rv = 0;
}
- return (rv);
+ return rv;
#else
- if (re_comp(pat) != NULL)
- return (0);
+ if (re_comp(ct_encode_string(pat, &conv)) != NULL)
+ return 0;
else
- return (re_exec(str) == 1);
+ return re_exec(ct_encode_string(str, &conv) == 1);
#endif
}
@@ -149,14 +158,14 @@ el_match(const char *str, const char *pat)
* return True if the pattern matches the prefix
*/
protected int
-c_hmatch(EditLine *el, const char *str)
+c_hmatch(EditLine *el, const Char *str)
{
#ifdef SDEBUG
(void) fprintf(el->el_errfile, "match `%s' with `%s'\n",
el->el_search.patbuf, str);
#endif /* SDEBUG */
- return (el_match(str, el->el_search.patbuf));
+ return el_match(str, el->el_search.patbuf);
}
@@ -168,15 +177,16 @@ c_setpat(EditLine *el)
{
if (el->el_state.lastcmd != ED_SEARCH_PREV_HISTORY &&
el->el_state.lastcmd != ED_SEARCH_NEXT_HISTORY) {
- el->el_search.patlen = EL_CURSOR(el) - el->el_line.buffer;
+ el->el_search.patlen =
+ (size_t)(EL_CURSOR(el) - el->el_line.buffer);
if (el->el_search.patlen >= EL_BUFSIZ)
el->el_search.patlen = EL_BUFSIZ - 1;
if (el->el_search.patlen != 0) {
- (void) strncpy(el->el_search.patbuf, el->el_line.buffer,
+ (void) Strncpy(el->el_search.patbuf, el->el_line.buffer,
el->el_search.patlen);
el->el_search.patbuf[el->el_search.patlen] = '\0';
} else
- el->el_search.patlen = strlen(el->el_search.patbuf);
+ el->el_search.patlen = Strlen(el->el_search.patbuf);
}
#ifdef SDEBUG
(void) fprintf(el->el_errfile, "\neventno = %d\n",
@@ -197,12 +207,12 @@ c_setpat(EditLine *el)
protected el_action_t
ce_inc_search(EditLine *el, int dir)
{
- static const char STRfwd[] = {'f', 'w', 'd', '\0'},
+ static const Char STRfwd[] = {'f', 'w', 'd', '\0'},
STRbck[] = {'b', 'c', 'k', '\0'};
- static char pchar = ':';/* ':' = normal, '?' = failed */
- static char endcmd[2] = {'\0', '\0'};
- char ch, *ocursor = el->el_line.cursor, oldpchar = pchar;
- const char *cp;
+ static Char pchar = ':';/* ':' = normal, '?' = failed */
+ static Char endcmd[2] = {'\0', '\0'};
+ Char ch, *ocursor = el->el_line.cursor, oldpchar = pchar;
+ const Char *cp;
el_action_t ret = CC_NORM;
@@ -211,9 +221,10 @@ ce_inc_search(EditLine *el, int dir)
int newdir = dir;
int done, redo;
- if (el->el_line.lastchar + sizeof(STRfwd) / sizeof(char) + 2 +
+ if (el->el_line.lastchar + sizeof(STRfwd) /
+ sizeof(*el->el_line.lastchar) + 2 +
el->el_search.patlen >= el->el_line.limit)
- return (CC_ERROR);
+ return CC_ERROR;
for (;;) {
@@ -240,14 +251,14 @@ ce_inc_search(EditLine *el, int dir)
*el->el_line.lastchar = '\0';
re_refresh(el);
- if (el_getc(el, &ch) != 1)
- return (ed_end_of_file(el, 0));
+ if (FUN(el,getc)(el, &ch) != 1)
+ return ed_end_of_file(el, 0);
switch (el->el_map.current[(unsigned char) ch]) {
case ED_INSERT:
case ED_DIGIT:
if (el->el_search.patlen >= EL_BUFSIZ - LEN)
- term_beep(el);
+ terminal_beep(el);
else {
el->el_search.patbuf[el->el_search.patlen++] =
ch;
@@ -272,7 +283,7 @@ ce_inc_search(EditLine *el, int dir)
if (el->el_search.patlen > LEN)
done++;
else
- term_beep(el);
+ terminal_beep(el);
break;
default:
@@ -296,7 +307,7 @@ ce_inc_search(EditLine *el, int dir)
*el->el_line.cursor != '\n') {
if (el->el_search.patlen >=
EL_BUFSIZ - LEN) {
- term_beep(el);
+ terminal_beep(el);
break;
}
el->el_search.patbuf[el->el_search.patlen++] =
@@ -309,14 +320,14 @@ ce_inc_search(EditLine *el, int dir)
re_refresh(el);
break;
} else if (isglob(*cp)) {
- term_beep(el);
+ terminal_beep(el);
break;
}
break;
default: /* Terminate and execute cmd */
endcmd[0] = ch;
- el_push(el, endcmd);
+ FUN(el,push)(el, endcmd);
/* FALLTHROUGH */
case 0033: /* ESC: Terminate */
@@ -378,9 +389,10 @@ ce_inc_search(EditLine *el, int dir)
/* avoid c_setpat */
el->el_state.lastcmd =
(el_action_t) newdir;
- ret = newdir == ED_SEARCH_PREV_HISTORY ?
+ ret = (el_action_t)
+ (newdir == ED_SEARCH_PREV_HISTORY ?
ed_search_prev_history(el, 0) :
- ed_search_next_history(el, 0);
+ ed_search_next_history(el, 0));
if (ret != CC_ERROR) {
el->el_line.cursor = newdir ==
ED_SEARCH_PREV_HISTORY ?
@@ -394,13 +406,13 @@ ce_inc_search(EditLine *el, int dir)
el->el_search.patbuf[el->el_search.patlen] =
'\0';
if (ret == CC_ERROR) {
- term_beep(el);
+ terminal_beep(el);
if (el->el_history.eventno !=
ohisteventno) {
el->el_history.eventno =
ohisteventno;
if (hist_get(el) == CC_ERROR)
- return (CC_ERROR);
+ return CC_ERROR;
}
el->el_line.cursor = ocursor;
pchar = '?';
@@ -425,14 +437,14 @@ ce_inc_search(EditLine *el, int dir)
if (el->el_history.eventno != ohisteventno) {
el->el_history.eventno = ohisteventno;
if (hist_get(el) == CC_ERROR)
- return (CC_ERROR);
+ return CC_ERROR;
}
el->el_line.cursor = ocursor;
if (ret == CC_ERROR)
re_refresh(el);
}
if (done || ret != CC_NORM)
- return (ret);
+ return ret;
}
}
@@ -443,9 +455,9 @@ ce_inc_search(EditLine *el, int dir)
protected el_action_t
cv_search(EditLine *el, int dir)
{
- char ch;
- char tmpbuf[EL_BUFSIZ];
- int tmplen;
+ Char ch;
+ Char tmpbuf[EL_BUFSIZ];
+ ssize_t tmplen;
#ifdef ANCHOR
tmpbuf[0] = '.';
@@ -456,7 +468,7 @@ cv_search(EditLine *el, int dir)
el->el_search.patdir = dir;
tmplen = c_gets(el, &tmpbuf[LEN],
- dir == ED_SEARCH_PREV_HISTORY ? "\n/" : "\n?" );
+ dir == ED_SEARCH_PREV_HISTORY ? STR("\n/") : STR("\n?") );
if (tmplen == -1)
return CC_REFRESH;
@@ -470,16 +482,16 @@ cv_search(EditLine *el, int dir)
*/
if (el->el_search.patlen == 0) {
re_refresh(el);
- return (CC_ERROR);
+ return CC_ERROR;
}
#ifdef ANCHOR
if (el->el_search.patbuf[0] != '.' &&
el->el_search.patbuf[0] != '*') {
- (void) strncpy(tmpbuf, el->el_search.patbuf,
- sizeof(tmpbuf) - 1);
+ (void) Strncpy(tmpbuf, el->el_search.patbuf,
+ sizeof(tmpbuf) / sizeof(*tmpbuf) - 1);
el->el_search.patbuf[0] = '.';
el->el_search.patbuf[1] = '*';
- (void) strncpy(&el->el_search.patbuf[2], tmpbuf,
+ (void) Strncpy(&el->el_search.patbuf[2], tmpbuf,
EL_BUFSIZ - 3);
el->el_search.patlen++;
el->el_search.patbuf[el->el_search.patlen++] = '.';
@@ -493,21 +505,21 @@ cv_search(EditLine *el, int dir)
tmpbuf[tmplen++] = '*';
#endif
tmpbuf[tmplen] = '\0';
- (void) strncpy(el->el_search.patbuf, tmpbuf, EL_BUFSIZ - 1);
- el->el_search.patlen = tmplen;
+ (void) Strncpy(el->el_search.patbuf, tmpbuf, EL_BUFSIZ - 1);
+ el->el_search.patlen = (size_t)tmplen;
}
el->el_state.lastcmd = (el_action_t) dir; /* avoid c_setpat */
el->el_line.cursor = el->el_line.lastchar = el->el_line.buffer;
if ((dir == ED_SEARCH_PREV_HISTORY ? ed_search_prev_history(el, 0) :
ed_search_next_history(el, 0)) == CC_ERROR) {
re_refresh(el);
- return (CC_ERROR);
+ return CC_ERROR;
}
if (ch == 0033) {
re_refresh(el);
return ed_newline(el, 0);
}
- return (CC_REFRESH);
+ return CC_REFRESH;
}
@@ -517,9 +529,9 @@ cv_search(EditLine *el, int dir)
protected el_action_t
ce_search_line(EditLine *el, int dir)
{
- char *cp = el->el_line.cursor;
- char *pattern = el->el_search.patbuf;
- char oc, *ocp;
+ Char *cp = el->el_line.cursor;
+ Char *pattern = el->el_search.patbuf;
+ Char oc, *ocp;
#ifdef ANCHOR
ocp = &pattern[1];
oc = *ocp;
@@ -534,21 +546,21 @@ ce_search_line(EditLine *el, int dir)
if (el_match(cp, ocp)) {
*ocp = oc;
el->el_line.cursor = cp;
- return (CC_NORM);
+ return CC_NORM;
}
}
*ocp = oc;
- return (CC_ERROR);
+ return CC_ERROR;
} else {
for (; *cp != '\0' && cp < el->el_line.limit; cp++) {
if (el_match(cp, ocp)) {
*ocp = oc;
el->el_line.cursor = cp;
- return (CC_NORM);
+ return CC_NORM;
}
}
*ocp = oc;
- return (CC_ERROR);
+ return CC_ERROR;
}
}
@@ -557,12 +569,12 @@ ce_search_line(EditLine *el, int dir)
* Vi repeat search
*/
protected el_action_t
-cv_repeat_srch(EditLine *el, int c)
+cv_repeat_srch(EditLine *el, Int c)
{
#ifdef SDEBUG
(void) fprintf(el->el_errfile, "dir %d patlen %d patbuf %s\n",
- c, el->el_search.patlen, el->el_search.patbuf);
+ c, el->el_search.patlen, ct_encode_string(el->el_search.patbuf));
#endif
el->el_state.lastcmd = (el_action_t) c; /* Hack to stop c_setpat */
@@ -570,11 +582,11 @@ cv_repeat_srch(EditLine *el, int c)
switch (c) {
case ED_SEARCH_NEXT_HISTORY:
- return (ed_search_next_history(el, 0));
+ return ed_search_next_history(el, 0);
case ED_SEARCH_PREV_HISTORY:
- return (ed_search_prev_history(el, 0));
+ return ed_search_prev_history(el, 0);
default:
- return (CC_ERROR);
+ return CC_ERROR;
}
}
@@ -583,16 +595,16 @@ cv_repeat_srch(EditLine *el, int c)
* Vi character search
*/
protected el_action_t
-cv_csearch(EditLine *el, int direction, int ch, int count, int tflag)
+cv_csearch(EditLine *el, int direction, Int ch, int count, int tflag)
{
- char *cp;
+ Char *cp;
if (ch == 0)
return CC_ERROR;
- if (ch == -1) {
- char c;
- if (el_getc(el, &c) != 1)
+ if (ch == (Int)-1) {
+ Char c;
+ if (FUN(el,getc)(el, &c) != 1)
return ed_end_of_file(el, 0);
ch = c;
}
@@ -600,18 +612,18 @@ cv_csearch(EditLine *el, int direction, int ch, int count, int tflag)
/* Save for ';' and ',' commands */
el->el_search.chacha = ch;
el->el_search.chadir = direction;
- el->el_search.chatflg = tflag;
+ el->el_search.chatflg = (char)tflag;
cp = el->el_line.cursor;
while (count--) {
- if (*cp == ch)
+ if ((Int)*cp == ch)
cp += direction;
for (;;cp += direction) {
if (cp >= el->el_line.lastchar)
return CC_ERROR;
if (cp < el->el_line.buffer)
return CC_ERROR;
- if (*cp == ch)
+ if ((Int)*cp == ch)
break;
}
}
diff --git a/lib/libedit/search.h b/lib/libedit/search.h
index 725af7c..02c8f5d 100644
--- a/lib/libedit/search.h
+++ b/lib/libedit/search.h
@@ -1,3 +1,5 @@
+/* $NetBSD: search.h,v 1.9 2009/12/30 22:37:40 christos Exp $ */
+
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -30,7 +32,6 @@
* SUCH DAMAGE.
*
* @(#)search.h 8.1 (Berkeley) 6/4/93
- * $NetBSD: search.h,v 1.8 2003/10/18 23:27:36 christos Exp $
* $FreeBSD$
*/
@@ -43,24 +44,24 @@
#include "histedit.h"
typedef struct el_search_t {
- char *patbuf; /* The pattern buffer */
+ Char *patbuf; /* The pattern buffer */
size_t patlen; /* Length of the pattern buffer */
int patdir; /* Direction of the last search */
int chadir; /* Character search direction */
- char chacha; /* Character we are looking for */
+ Char chacha; /* Character we are looking for */
char chatflg; /* 0 if f, 1 if t */
} el_search_t;
-protected int el_match(const char *, const char *);
+protected int el_match(const Char *, const Char *);
protected int search_init(EditLine *);
protected void search_end(EditLine *);
-protected int c_hmatch(EditLine *, const char *);
+protected int c_hmatch(EditLine *, const Char *);
protected void c_setpat(EditLine *);
protected el_action_t ce_inc_search(EditLine *, int);
protected el_action_t cv_search(EditLine *, int);
protected el_action_t ce_search_line(EditLine *, int);
-protected el_action_t cv_repeat_srch(EditLine *, int);
-protected el_action_t cv_csearch(EditLine *, int, int, int, int);
+protected el_action_t cv_repeat_srch(EditLine *, Int);
+protected el_action_t cv_csearch(EditLine *, int, Int, int, int);
#endif /* _h_el_search */
diff --git a/lib/libedit/sig.c b/lib/libedit/sig.c
index e48dbef..babec69 100644
--- a/lib/libedit/sig.c
+++ b/lib/libedit/sig.c
@@ -1,3 +1,5 @@
+/* $NetBSD: sig.c,v 1.17 2011/07/28 20:50:55 christos Exp $ */
+
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -28,12 +30,15 @@
* 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.
- *
- * $NetBSD: sig.c,v 1.15 2009/02/19 15:20:22 christos Exp $
*/
+#include "config.h"
#if !defined(lint) && !defined(SCCSID)
+#if 0
static char sccsid[] = "@(#)sig.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: sig.c,v 1.17 2011/07/28 20:50:55 christos Exp $");
+#endif
#endif /* not lint && not SCCSID */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
@@ -43,7 +48,6 @@ __FBSDID("$FreeBSD$");
* our policy is to trap all signals, set a good state
* and pass the ball to our caller.
*/
-#include "sys.h"
#include "el.h"
#include <stdlib.h>
@@ -80,7 +84,7 @@ sig_handler(int signo)
tty_rawmode(sel);
if (ed_redisplay(sel, 0) == CC_REFRESH)
re_refresh(sel);
- term__flush(sel);
+ terminal__flush(sel);
break;
case SIGWINCH:
@@ -144,7 +148,7 @@ protected void
sig_end(EditLine *el)
{
- el_free((ptr_t) el->el_signal);
+ el_free(el->el_signal);
el->el_signal = NULL;
}
diff --git a/lib/libedit/sig.h b/lib/libedit/sig.h
index 7e38100..a096681 100644
--- a/lib/libedit/sig.h
+++ b/lib/libedit/sig.h
@@ -1,3 +1,5 @@
+/* $NetBSD: sig.h,v 1.8 2009/02/19 15:20:22 christos Exp $ */
+
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -30,7 +32,6 @@
* SUCH DAMAGE.
*
* @(#)sig.h 8.1 (Berkeley) 6/4/93
- * $NetBSD: sig.h,v 1.8 2009/02/19 15:20:22 christos Exp $
* $FreeBSD$
*/
diff --git a/lib/libedit/sys.h b/lib/libedit/sys.h
index 5c017d3..d005ffd 100644
--- a/lib/libedit/sys.h
+++ b/lib/libedit/sys.h
@@ -1,3 +1,5 @@
+/* $NetBSD: sys.h,v 1.17 2011/09/28 14:08:04 christos Exp $ */
+
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -30,7 +32,6 @@
* SUCH DAMAGE.
*
* @(#)sys.h 8.1 (Berkeley) 6/4/93
- * $NetBSD: sys.h,v 1.12 2009/08/31 00:05:43 christos Exp $
* $FreeBSD$
*/
@@ -40,8 +41,24 @@
#ifndef _h_sys
#define _h_sys
+#ifdef HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>
+#endif
+
+#if !defined(__attribute__) && (defined(__cplusplus) || !defined(__GNUC__) || __GNUC__ == 2 && __GNUC_MINOR__ < 8)
+# define __attribute__(A)
+#endif
+#ifndef __BEGIN_DECLS
+# ifdef __cplusplus
+# define __BEGIN_DECLS extern "C" {
+# define __END_DECLS }
+# else
+# define __BEGIN_DECLS
+# define __END_DECLS
+# endif
+#endif
+
#ifndef public
# define public /* Externally visible functions/variables */
#endif
@@ -55,17 +72,47 @@
/* When we want to hide everything */
#endif
-#ifndef _PTR_T
-# define _PTR_T
-typedef void *ptr_t;
+#ifndef __arraycount
+# define __arraycount(a) (sizeof(a) / sizeof(*(a)))
+#endif
+
+#include <stdio.h>
+
+#ifndef HAVE_STRLCAT
+#define strlcat libedit_strlcat
+size_t strlcat(char *dst, const char *src, size_t size);
#endif
-#ifndef _IOCTL_T
-# define _IOCTL_T
-typedef void *ioctl_t;
+#ifndef HAVE_STRLCPY
+#define strlcpy libedit_strlcpy
+size_t strlcpy(char *dst, const char *src, size_t size);
#endif
-#include <stdio.h>
+#ifndef HAVE_FGETLN
+#define fgetln libedit_fgetln
+char *fgetln(FILE *fp, size_t *len);
+#endif
+
+#ifndef HAVE_WCSDUP
+#include <wchar.h>
+wchar_t *wcsdup(const wchar_t *);
+#endif
+
+#ifndef _DIAGASSERT
+#define _DIAGASSERT(x)
+#endif
+
+#ifndef __RCSID
+#define __RCSID(x)
+#endif
+
+#ifndef HAVE_U_INT32_T
+typedef unsigned int u_int32_t;
+#endif
+
+#ifndef SIZE_T_MAX
+#define SIZE_T_MAX ((size_t)-1)
+#endif
#define REGEX /* Use POSIX.2 regular expression functions */
#undef REGEXP /* Use UNIX V8 regular expression functions */
@@ -79,40 +126,4 @@ extern char* tgoto(const char*, int, int);
extern char* tgetstr(char*, char**);
#endif
-#ifdef notdef
-# undef REGEX
-# undef REGEXP
-# include <malloc.h>
-# ifdef __GNUC__
-/*
- * Broken hdrs.
- */
-extern int tgetent(const char *bp, char *name);
-extern int tgetflag(const char *id);
-extern int tgetnum(const char *id);
-extern char *tgetstr(const char *id, char **area);
-extern char *tgoto(const char *cap, int col, int row);
-extern int tputs(const char *str, int affcnt, int (*putc)(int));
-extern char *getenv(const char *);
-extern int fprintf(FILE *, const char *, ...);
-extern int sigsetmask(int);
-extern int sigblock(int);
-extern int fputc(int, FILE *);
-extern int fgetc(FILE *);
-extern int fflush(FILE *);
-extern int tolower(int);
-extern int toupper(int);
-extern int errno, sys_nerr;
-extern char *sys_errlist[];
-extern void perror(const char *);
-# include <string.h>
-# define strerror(e) sys_errlist[e]
-# endif
-# ifdef SABER
-extern ptr_t memcpy(ptr_t, const ptr_t, size_t);
-extern ptr_t memset(ptr_t, int, size_t);
-# endif
-extern char *fgetline(FILE *, int *);
-#endif
-
#endif /* _h_sys */
diff --git a/lib/libedit/term.c b/lib/libedit/terminal.c
index e526484..0709d53 100644
--- a/lib/libedit/term.c
+++ b/lib/libedit/terminal.c
@@ -1,3 +1,5 @@
+/* $NetBSD: terminal.c,v 1.14 2012/05/30 18:21:14 christos Exp $ */
+
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -28,120 +30,66 @@
* 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.
- *
- * $NetBSD: term.c,v 1.56 2009/12/28 21:54:21 christos Exp $
*/
+#include "config.h"
#if !defined(lint) && !defined(SCCSID)
+#if 0
static char sccsid[] = "@(#)term.c 8.2 (Berkeley) 4/30/95";
+#else
+__RCSID("$NetBSD: terminal.c,v 1.14 2012/05/30 18:21:14 christos Exp $");
+#endif
#endif /* not lint && not SCCSID */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
/*
- * term.c: Editor/termcap-curses interface
- * We have to declare a static variable here, since the
- * termcap putchar routine does not take an argument!
+ * terminal.c: Editor/termcap-curses interface
+ * We have to declare a static variable here, since the
+ * termcap putchar routine does not take an argument!
*/
#include <stdio.h>
#include <signal.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
+#include <limits.h>
+#ifdef HAVE_TERMCAP_H
#include <termcap.h>
+#endif
+#ifdef HAVE_CURSES_H
#include <curses.h>
+#elif HAVE_NCURSES_H
#include <ncurses.h>
+#endif
+
+/* Solaris's term.h does horrid things. */
+#if defined(HAVE_TERM_H) && !defined(__sun) && !defined(HAVE_TERMCAP_H)
#include <term.h>
+#endif
+
#include <sys/types.h>
#include <sys/ioctl.h>
+#ifdef _REENTRANT
+#include <pthread.h>
+#endif
+
#include "el.h"
/*
* IMPORTANT NOTE: these routines are allowed to look at the current screen
- * and the current possition assuming that it is correct. If this is not
+ * and the current position assuming that it is correct. If this is not
* true, then the update will be WRONG! This is (should be) a valid
* assumption...
*/
-#define TC_BUFSIZE 2048
+#define TC_BUFSIZE ((size_t)2048)
-#define GoodStr(a) (el->el_term.t_str[a] != NULL && \
- el->el_term.t_str[a][0] != '\0')
-#define Str(a) el->el_term.t_str[a]
-#define Val(a) el->el_term.t_val[a]
-
-#ifdef notdef
-private const struct {
- const char *b_name;
- int b_rate;
-} baud_rate[] = {
-#ifdef B0
- { "0", B0 },
-#endif
-#ifdef B50
- { "50", B50 },
-#endif
-#ifdef B75
- { "75", B75 },
-#endif
-#ifdef B110
- { "110", B110 },
-#endif
-#ifdef B134
- { "134", B134 },
-#endif
-#ifdef B150
- { "150", B150 },
-#endif
-#ifdef B200
- { "200", B200 },
-#endif
-#ifdef B300
- { "300", B300 },
-#endif
-#ifdef B600
- { "600", B600 },
-#endif
-#ifdef B900
- { "900", B900 },
-#endif
-#ifdef B1200
- { "1200", B1200 },
-#endif
-#ifdef B1800
- { "1800", B1800 },
-#endif
-#ifdef B2400
- { "2400", B2400 },
-#endif
-#ifdef B3600
- { "3600", B3600 },
-#endif
-#ifdef B4800
- { "4800", B4800 },
-#endif
-#ifdef B7200
- { "7200", B7200 },
-#endif
-#ifdef B9600
- { "9600", B9600 },
-#endif
-#ifdef EXTA
- { "19200", EXTA },
-#endif
-#ifdef B19200
- { "19200", B19200 },
-#endif
-#ifdef EXTB
- { "38400", EXTB },
-#endif
-#ifdef B38400
- { "38400", B38400 },
-#endif
- { NULL, 0 }
-};
-#endif
+#define GoodStr(a) (el->el_terminal.t_str[a] != NULL && \
+ el->el_terminal.t_str[a][0] != '\0')
+#define Str(a) el->el_terminal.t_str[a]
+#define Val(a) el->el_terminal.t_val[a]
private const struct termcapstr {
const char *name;
@@ -254,27 +202,28 @@ private const struct termcapval {
};
/* do two or more of the attributes use me */
-private void term_setflags(EditLine *);
-private int term_rebuffer_display(EditLine *);
-private void term_free_display(EditLine *);
-private int term_alloc_display(EditLine *);
-private void term_alloc(EditLine *, const struct termcapstr *, const char *);
-private void term_init_arrow(EditLine *);
-private void term_reset_arrow(EditLine *);
-private int term_putc(int);
-private void term_tputs(EditLine *, const char *, int);
+private void terminal_setflags(EditLine *);
+private int terminal_rebuffer_display(EditLine *);
+private void terminal_free_display(EditLine *);
+private int terminal_alloc_display(EditLine *);
+private void terminal_alloc(EditLine *, const struct termcapstr *,
+ const char *);
+private void terminal_init_arrow(EditLine *);
+private void terminal_reset_arrow(EditLine *);
+private int terminal_putc(int);
+private void terminal_tputs(EditLine *, const char *, int);
#ifdef _REENTRANT
-private pthread_mutex_t term_mutex = PTHREAD_MUTEX_INITIALIZER;
+private pthread_mutex_t terminal_mutex = PTHREAD_MUTEX_INITIALIZER;
#endif
-private FILE *term_outfile = NULL;
+private FILE *terminal_outfile = NULL;
-/* term_setflags():
+/* terminal_setflags():
* Set the terminal capability flags
*/
private void
-term_setflags(EditLine *el)
+terminal_setflags(EditLine *el)
{
EL_FLAGS = 0;
if (el->el_tty.t_tabs)
@@ -315,69 +264,77 @@ term_setflags(EditLine *el)
#endif /* DEBUG_SCREEN */
}
-/* term_init():
+/* terminal_init():
* Initialize the terminal stuff
*/
protected int
-term_init(EditLine *el)
+terminal_init(EditLine *el)
{
- el->el_term.t_buf = (char *) el_malloc(TC_BUFSIZE);
- if (el->el_term.t_buf == NULL)
- return (-1);
- el->el_term.t_cap = (char *) el_malloc(TC_BUFSIZE);
- if (el->el_term.t_cap == NULL)
- return (-1);
- el->el_term.t_fkey = (fkey_t *) el_malloc(A_K_NKEYS * sizeof(fkey_t));
- if (el->el_term.t_fkey == NULL)
- return (-1);
- el->el_term.t_loc = 0;
- el->el_term.t_str = (char **) el_malloc(T_str * sizeof(char *));
- if (el->el_term.t_str == NULL)
- return (-1);
- (void) memset(el->el_term.t_str, 0, T_str * sizeof(char *));
- el->el_term.t_val = (int *) el_malloc(T_val * sizeof(int));
- if (el->el_term.t_val == NULL)
- return (-1);
- (void) memset(el->el_term.t_val, 0, T_val * sizeof(int));
- (void) term_set(el, NULL);
- term_init_arrow(el);
- return (0);
+ el->el_terminal.t_buf = el_malloc(TC_BUFSIZE *
+ sizeof(*el->el_terminal.t_buf));
+ if (el->el_terminal.t_buf == NULL)
+ return -1;
+ el->el_terminal.t_cap = el_malloc(TC_BUFSIZE *
+ sizeof(*el->el_terminal.t_cap));
+ if (el->el_terminal.t_cap == NULL)
+ return -1;
+ el->el_terminal.t_fkey = el_malloc(A_K_NKEYS *
+ sizeof(*el->el_terminal.t_fkey));
+ if (el->el_terminal.t_fkey == NULL)
+ return -1;
+ el->el_terminal.t_loc = 0;
+ el->el_terminal.t_str = el_malloc(T_str *
+ sizeof(*el->el_terminal.t_str));
+ if (el->el_terminal.t_str == NULL)
+ return -1;
+ (void) memset(el->el_terminal.t_str, 0, T_str *
+ sizeof(*el->el_terminal.t_str));
+ el->el_terminal.t_val = el_malloc(T_val *
+ sizeof(*el->el_terminal.t_val));
+ if (el->el_terminal.t_val == NULL)
+ return -1;
+ (void) memset(el->el_terminal.t_val, 0, T_val *
+ sizeof(*el->el_terminal.t_val));
+ (void) terminal_set(el, NULL);
+ terminal_init_arrow(el);
+ return 0;
}
-/* term_end():
+/* terminal_end():
* Clean up the terminal stuff
*/
protected void
-term_end(EditLine *el)
+terminal_end(EditLine *el)
{
- el_free((ptr_t) el->el_term.t_buf);
- el->el_term.t_buf = NULL;
- el_free((ptr_t) el->el_term.t_cap);
- el->el_term.t_cap = NULL;
- el->el_term.t_loc = 0;
- el_free((ptr_t) el->el_term.t_str);
- el->el_term.t_str = NULL;
- el_free((ptr_t) el->el_term.t_val);
- el->el_term.t_val = NULL;
- el_free((ptr_t) el->el_term.t_fkey);
- el->el_term.t_fkey = NULL;
- term_free_display(el);
+ el_free(el->el_terminal.t_buf);
+ el->el_terminal.t_buf = NULL;
+ el_free(el->el_terminal.t_cap);
+ el->el_terminal.t_cap = NULL;
+ el->el_terminal.t_loc = 0;
+ el_free(el->el_terminal.t_str);
+ el->el_terminal.t_str = NULL;
+ el_free(el->el_terminal.t_val);
+ el->el_terminal.t_val = NULL;
+ el_free(el->el_terminal.t_fkey);
+ el->el_terminal.t_fkey = NULL;
+ terminal_free_display(el);
}
-/* term_alloc():
+/* terminal_alloc():
* Maintain a string pool for termcap strings
*/
private void
-term_alloc(EditLine *el, const struct termcapstr *t, const char *cap)
+terminal_alloc(EditLine *el, const struct termcapstr *t, const char *cap)
{
char termbuf[TC_BUFSIZE];
size_t tlen, clen;
- char **tlist = el->el_term.t_str;
+ char **tlist = el->el_terminal.t_str;
char **tmp, **str = &tlist[t - tstr];
+ (void) memset(termbuf, 0, sizeof(termbuf));
if (cap == NULL || *cap == '\0') {
*str = NULL;
return;
@@ -397,11 +354,11 @@ term_alloc(EditLine *el, const struct termcapstr *t, const char *cap)
/*
* New string is longer; see if we have enough space to append
*/
- if (el->el_term.t_loc + 3 < TC_BUFSIZE) {
+ if (el->el_terminal.t_loc + 3 < TC_BUFSIZE) {
/* XXX strcpy is safe */
- (void) strcpy(*str = &el->el_term.t_buf[el->el_term.t_loc],
- cap);
- el->el_term.t_loc += (int)clen + 1; /* one for \0 */
+ (void) strcpy(*str = &el->el_terminal.t_buf[
+ el->el_terminal.t_loc], cap);
+ el->el_terminal.t_loc += clen + 1; /* one for \0 */
return;
}
/*
@@ -417,124 +374,126 @@ term_alloc(EditLine *el, const struct termcapstr *t, const char *cap)
continue;
termbuf[tlen++] = '\0';
}
- memcpy(el->el_term.t_buf, termbuf, TC_BUFSIZE);
- el->el_term.t_loc = (int)tlen;
- if (el->el_term.t_loc + 3 >= TC_BUFSIZE) {
+ memcpy(el->el_terminal.t_buf, termbuf, TC_BUFSIZE);
+ el->el_terminal.t_loc = tlen;
+ if (el->el_terminal.t_loc + 3 >= TC_BUFSIZE) {
(void) fprintf(el->el_errfile,
"Out of termcap string space.\n");
return;
}
/* XXX strcpy is safe */
- (void) strcpy(*str = &el->el_term.t_buf[el->el_term.t_loc], cap);
- el->el_term.t_loc += (int)clen + 1; /* one for \0 */
+ (void) strcpy(*str = &el->el_terminal.t_buf[el->el_terminal.t_loc],
+ cap);
+ el->el_terminal.t_loc += (size_t)clen + 1; /* one for \0 */
return;
}
-/* term_rebuffer_display():
+/* terminal_rebuffer_display():
* Rebuffer the display after the screen changed size
*/
private int
-term_rebuffer_display(EditLine *el)
+terminal_rebuffer_display(EditLine *el)
{
- coord_t *c = &el->el_term.t_size;
+ coord_t *c = &el->el_terminal.t_size;
- term_free_display(el);
+ terminal_free_display(el);
c->h = Val(T_co);
c->v = Val(T_li);
- if (term_alloc_display(el) == -1)
- return (-1);
- return (0);
+ if (terminal_alloc_display(el) == -1)
+ return -1;
+ return 0;
}
-/* term_alloc_display():
+/* terminal_alloc_display():
* Allocate a new display.
*/
private int
-term_alloc_display(EditLine *el)
+terminal_alloc_display(EditLine *el)
{
int i;
- char **b;
- coord_t *c = &el->el_term.t_size;
+ Char **b;
+ coord_t *c = &el->el_terminal.t_size;
- b = (char **) el_malloc((size_t) (sizeof(char *) * (c->v + 1)));
+ b = el_malloc(sizeof(*b) * (size_t)(c->v + 1));
if (b == NULL)
- return (-1);
+ return -1;
for (i = 0; i < c->v; i++) {
- b[i] = (char *) el_malloc((size_t) (sizeof(char) * (c->h + 1)));
+ b[i] = el_malloc(sizeof(**b) * (size_t)(c->h + 1));
if (b[i] == NULL) {
while (--i >= 0)
- el_free((ptr_t) b[i]);
- el_free((ptr_t) b);
- return (-1);
+ el_free(b[i]);
+ el_free(b);
+ return -1;
}
}
b[c->v] = NULL;
el->el_display = b;
- b = (char **) el_malloc((size_t) (sizeof(char *) * (c->v + 1)));
+ b = el_malloc(sizeof(*b) * (size_t)(c->v + 1));
if (b == NULL)
- return (-1);
+ return -1;
for (i = 0; i < c->v; i++) {
- b[i] = (char *) el_malloc((size_t) (sizeof(char) * (c->h + 1)));
+ b[i] = el_malloc(sizeof(**b) * (size_t)(c->h + 1));
if (b[i] == NULL) {
while (--i >= 0)
- el_free((ptr_t) b[i]);
- el_free((ptr_t) b);
- return (-1);
+ el_free(b[i]);
+ el_free(b);
+ return -1;
}
}
b[c->v] = NULL;
el->el_vdisplay = b;
- return (0);
+ return 0;
}
-/* term_free_display():
+/* terminal_free_display():
* Free the display buffers
*/
private void
-term_free_display(EditLine *el)
+terminal_free_display(EditLine *el)
{
- char **b;
- char **bufp;
+ Char **b;
+ Char **bufp;
b = el->el_display;
el->el_display = NULL;
if (b != NULL) {
for (bufp = b; *bufp != NULL; bufp++)
- el_free((ptr_t) * bufp);
- el_free((ptr_t) b);
+ el_free(*bufp);
+ el_free(b);
}
b = el->el_vdisplay;
el->el_vdisplay = NULL;
if (b != NULL) {
for (bufp = b; *bufp != NULL; bufp++)
- el_free((ptr_t) * bufp);
- el_free((ptr_t) b);
+ el_free(*bufp);
+ el_free(b);
}
}
-/* term_move_to_line():
+/* terminal_move_to_line():
* move to line <where> (first line == 0)
* as efficiently as possible
*/
protected void
-term_move_to_line(EditLine *el, int where)
+terminal_move_to_line(EditLine *el, int where)
{
int del;
if (where == el->el_cursor.v)
return;
- if (where > el->el_term.t_size.v) {
+ if (where > el->el_terminal.t_size.v) {
#ifdef DEBUG_SCREEN
(void) fprintf(el->el_errfile,
- "term_move_to_line: where is ridiculous: %d\r\n", where);
+ "terminal_move_to_line: where is ridiculous: %d\r\n",
+ where);
#endif /* DEBUG_SCREEN */
return;
}
@@ -542,22 +501,31 @@ term_move_to_line(EditLine *el, int where)
while (del > 0) {
if (EL_HAS_AUTO_MARGINS &&
el->el_display[el->el_cursor.v][0] != '\0') {
+ size_t h = (size_t)
+ (el->el_terminal.t_size.h - 1);
+#ifdef WIDECHAR
+ for (; h > 0 &&
+ el->el_display[el->el_cursor.v][h] ==
+ MB_FILL_CHAR;
+ h--)
+ continue;
+#endif
/* move without newline */
- term_move_to_char(el, el->el_term.t_size.h - 1);
- term_overwrite(el, &el->el_display
+ terminal_move_to_char(el, (int)h);
+ terminal_overwrite(el, &el->el_display
[el->el_cursor.v][el->el_cursor.h],
- (size_t)(el->el_term.t_size.h -
+ (size_t)(el->el_terminal.t_size.h -
el->el_cursor.h));
/* updates Cursor */
del--;
} else {
if ((del > 1) && GoodStr(T_DO)) {
- term_tputs(el, tgoto(Str(T_DO), del,
+ terminal_tputs(el, tgoto(Str(T_DO), del,
del), del);
del = 0;
} else {
for (; del > 0; del--)
- term__putc(el, '\n');
+ terminal__putc(el, '\n');
/* because the \n will become \r\n */
el->el_cursor.h = 0;
}
@@ -565,22 +533,22 @@ term_move_to_line(EditLine *el, int where)
}
} else { /* del < 0 */
if (GoodStr(T_UP) && (-del > 1 || !GoodStr(T_up)))
- term_tputs(el, tgoto(Str(T_UP), -del, -del), -del);
+ terminal_tputs(el, tgoto(Str(T_UP), -del, -del), -del);
else {
if (GoodStr(T_up))
for (; del < 0; del++)
- term_tputs(el, Str(T_up), 1);
+ terminal_tputs(el, Str(T_up), 1);
}
}
el->el_cursor.v = where;/* now where is here */
}
-/* term_move_to_char():
+/* terminal_move_to_char():
* Move to the character position specified
*/
protected void
-term_move_to_char(EditLine *el, int where)
+terminal_move_to_char(EditLine *el, int where)
{
int del, i;
@@ -588,15 +556,16 @@ mc_again:
if (where == el->el_cursor.h)
return;
- if (where > el->el_term.t_size.h) {
+ if (where > el->el_terminal.t_size.h) {
#ifdef DEBUG_SCREEN
(void) fprintf(el->el_errfile,
- "term_move_to_char: where is riduculous: %d\r\n", where);
+ "terminal_move_to_char: where is riduculous: %d\r\n",
+ where);
#endif /* DEBUG_SCREEN */
return;
}
if (!where) { /* if where is first column */
- term__putc(el, '\r'); /* do a CR */
+ terminal__putc(el, '\r'); /* do a CR */
el->el_cursor.h = 0;
return;
}
@@ -604,22 +573,30 @@ mc_again:
if ((del < -4 || del > 4) && GoodStr(T_ch))
/* go there directly */
- term_tputs(el, tgoto(Str(T_ch), where, where), where);
+ terminal_tputs(el, tgoto(Str(T_ch), where, where), where);
else {
if (del > 0) { /* moving forward */
if ((del > 4) && GoodStr(T_RI))
- term_tputs(el, tgoto(Str(T_RI), del, del), del);
+ terminal_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 & ~0x7)) {
+ (where & ~0x7)
+#ifdef WIDECHAR
+ && (el->el_display[
+ el->el_cursor.v][where & 0370] !=
+ MB_FILL_CHAR)
+#endif
+ ) {
/* if not within tab stop */
for (i =
(el->el_cursor.h & 0370);
i < (where & ~0x7);
i += 8)
- term__putc(el, '\t');
+ terminal__putc(el,
+ '\t');
/* then tab over */
el->el_cursor.h = where & ~0x7;
}
@@ -629,17 +606,17 @@ mc_again:
* chars, so we do.
*/
/*
- * NOTE THAT term_overwrite() WILL CHANGE
+ * NOTE THAT terminal_overwrite() WILL CHANGE
* el->el_cursor.h!!!
*/
- term_overwrite(el, &el->el_display[
+ terminal_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))
- term_tputs(el, tgoto(Str(T_LE), -del, -del),
+ terminal_tputs(el, tgoto(Str(T_LE), -del, -del),
-del);
else { /* can't go directly there */
/*
@@ -651,12 +628,12 @@ mc_again:
(((unsigned int) where >> 3) +
(where & 07)))
: (-del > where)) {
- term__putc(el, '\r'); /* do a CR */
+ terminal__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(el, '\b');
+ terminal__putc(el, '\b');
}
}
}
@@ -664,55 +641,62 @@ mc_again:
}
-/* term_overwrite():
+/* terminal_overwrite():
* Overstrike num characters
+ * Assumes MB_FILL_CHARs are present to keep the column count correct
*/
protected void
-term_overwrite(EditLine *el, const char *cp, size_t n)
+terminal_overwrite(EditLine *el, const Char *cp, size_t n)
{
if (n == 0)
return;
- if (n > (size_t)el->el_term.t_size.h) {
+ if (n > (size_t)el->el_terminal.t_size.h) {
#ifdef DEBUG_SCREEN
(void) fprintf(el->el_errfile,
- "term_overwrite: n is riduculous: %d\r\n", n);
+ "terminal_overwrite: n is riduculous: %d\r\n", n);
#endif /* DEBUG_SCREEN */
return;
}
- do {
- term__putc(el, *cp++);
- el->el_cursor.h++;
- } while (--n);
+ do {
+ /* terminal__putc() ignores any MB_FILL_CHARs */
+ terminal__putc(el, *cp++);
+ el->el_cursor.h++;
+ } while (--n);
- if (el->el_cursor.h >= el->el_term.t_size.h) { /* wrap? */
+ if (el->el_cursor.h >= el->el_terminal.t_size.h) { /* wrap? */
if (EL_HAS_AUTO_MARGINS) { /* yes */
el->el_cursor.h = 0;
el->el_cursor.v++;
if (EL_HAS_MAGIC_MARGINS) {
/* force the wrap to avoid the "magic"
* situation */
- char c;
- if ((c = el->el_display[el->el_cursor.v][el->el_cursor.h])
- != '\0')
- term_overwrite(el, &c, 1);
- else {
- term__putc(el, ' ');
+ Char c;
+ if ((c = el->el_display[el->el_cursor.v]
+ [el->el_cursor.h]) != '\0') {
+ terminal_overwrite(el, &c, (size_t)1);
+#ifdef WIDECHAR
+ while (el->el_display[el->el_cursor.v]
+ [el->el_cursor.h] == MB_FILL_CHAR)
+ el->el_cursor.h++;
+#endif
+ } else {
+ terminal__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 - 1;
+ el->el_cursor.h = el->el_terminal.t_size.h - 1;
}
}
-/* term_deletechars():
+/* terminal_deletechars():
* Delete num characters
*/
protected void
-term_deletechars(EditLine *el, int num)
+terminal_deletechars(EditLine *el, int num)
{
if (num <= 0)
return;
@@ -723,37 +707,38 @@ term_deletechars(EditLine *el, int num)
#endif /* DEBUG_EDIT */
return;
}
- if (num > el->el_term.t_size.h) {
+ if (num > el->el_terminal.t_size.h) {
#ifdef DEBUG_SCREEN
(void) fprintf(el->el_errfile,
- "term_deletechars: num is riduculous: %d\r\n", num);
+ "terminal_deletechars: num is riduculous: %d\r\n", num);
#endif /* DEBUG_SCREEN */
return;
}
if (GoodStr(T_DC)) /* if I have multiple delete */
if ((num > 1) || !GoodStr(T_dc)) { /* if dc would be more
* expen. */
- term_tputs(el, tgoto(Str(T_DC), num, num), num);
+ terminal_tputs(el, tgoto(Str(T_DC), num, num), num);
return;
}
if (GoodStr(T_dm)) /* if I have delete mode */
- term_tputs(el, Str(T_dm), 1);
+ terminal_tputs(el, Str(T_dm), 1);
if (GoodStr(T_dc)) /* else do one at a time */
while (num--)
- term_tputs(el, Str(T_dc), 1);
+ terminal_tputs(el, Str(T_dc), 1);
if (GoodStr(T_ed)) /* if I have delete mode */
- term_tputs(el, Str(T_ed), 1);
+ terminal_tputs(el, Str(T_ed), 1);
}
-/* term_insertwrite():
+/* terminal_insertwrite():
* Puts terminal in insert character mode or inserts num
* characters in the line
+ * Assumes MB_FILL_CHARs are present to keep column count correct
*/
protected void
-term_insertwrite(EditLine *el, char *cp, int num)
+terminal_insertwrite(EditLine *el, Char *cp, int num)
{
if (num <= 0)
return;
@@ -763,7 +748,7 @@ term_insertwrite(EditLine *el, char *cp, int num)
#endif /* DEBUG_EDIT */
return;
}
- if (num > el->el_term.t_size.h) {
+ if (num > el->el_terminal.t_size.h) {
#ifdef DEBUG_SCREEN
(void) fprintf(el->el_errfile,
"StartInsert: num is riduculous: %d\r\n", num);
@@ -773,120 +758,106 @@ term_insertwrite(EditLine *el, char *cp, int num)
if (GoodStr(T_IC)) /* if I have multiple insert */
if ((num > 1) || !GoodStr(T_ic)) {
/* if ic would be more expensive */
- term_tputs(el, tgoto(Str(T_IC), num, num), num);
- term_overwrite(el, cp, (size_t)num);
+ terminal_tputs(el, tgoto(Str(T_IC), num, num), num);
+ terminal_overwrite(el, cp, (size_t)num);
/* this updates el_cursor.h */
return;
}
if (GoodStr(T_im) && GoodStr(T_ei)) { /* if I have insert mode */
- term_tputs(el, Str(T_im), 1);
+ terminal_tputs(el, Str(T_im), 1);
el->el_cursor.h += num;
do
- term__putc(el, *cp++);
+ terminal__putc(el, *cp++);
while (--num);
if (GoodStr(T_ip)) /* have to make num chars insert */
- term_tputs(el, Str(T_ip), 1);
+ terminal_tputs(el, Str(T_ip), 1);
- term_tputs(el, Str(T_ei), 1);
+ terminal_tputs(el, Str(T_ei), 1);
return;
}
do {
if (GoodStr(T_ic)) /* have to make num chars insert */
- term_tputs(el, Str(T_ic), 1);
+ terminal_tputs(el, Str(T_ic), 1);
- term__putc(el, *cp++);
+ terminal__putc(el, *cp++);
el->el_cursor.h++;
if (GoodStr(T_ip)) /* have to make num chars insert */
- term_tputs(el, Str(T_ip), 1);
+ terminal_tputs(el, Str(T_ip), 1);
/* pad the inserted char */
} while (--num);
}
-/* term_clear_EOL():
+/* terminal_clear_EOL():
* clear to end of line. There are num characters to clear
*/
protected void
-term_clear_EOL(EditLine *el, int num)
+terminal_clear_EOL(EditLine *el, int num)
{
int i;
if (EL_CAN_CEOL && GoodStr(T_ce))
- term_tputs(el, Str(T_ce), 1);
+ terminal_tputs(el, Str(T_ce), 1);
else {
for (i = 0; i < num; i++)
- term__putc(el, ' ');
+ terminal__putc(el, ' ');
el->el_cursor.h += num; /* have written num spaces */
}
}
-/* term_clear_screen():
+/* terminal_clear_screen():
* Clear the screen
*/
protected void
-term_clear_screen(EditLine *el)
+terminal_clear_screen(EditLine *el)
{ /* clear the whole screen and home */
if (GoodStr(T_cl))
/* send the clear screen code */
- term_tputs(el, Str(T_cl), Val(T_li));
+ terminal_tputs(el, Str(T_cl), Val(T_li));
else if (GoodStr(T_ho) && GoodStr(T_cd)) {
- term_tputs(el, Str(T_ho), Val(T_li)); /* home */
+ terminal_tputs(el, Str(T_ho), Val(T_li)); /* home */
/* clear to bottom of screen */
- term_tputs(el, Str(T_cd), Val(T_li));
+ terminal_tputs(el, Str(T_cd), Val(T_li));
} else {
- term__putc(el, '\r');
- term__putc(el, '\n');
+ terminal__putc(el, '\r');
+ terminal__putc(el, '\n');
}
}
-/* term_beep():
+/* terminal_beep():
* Beep the way the terminal wants us
*/
protected void
-term_beep(EditLine *el)
+terminal_beep(EditLine *el)
{
if (GoodStr(T_bl))
/* what termcap says we should use */
- term_tputs(el, Str(T_bl), 1);
+ terminal_tputs(el, Str(T_bl), 1);
else
- term__putc(el, '\007'); /* an ASCII bell; ^G */
+ terminal__putc(el, '\007'); /* an ASCII bell; ^G */
}
-#ifdef notdef
-/* term_clear_to_bottom():
- * Clear to the bottom of the screen
- */
-protected void
-term_clear_to_bottom(EditLine *el)
-{
- if (GoodStr(T_cd))
- term_tputs(el, Str(T_cd), Val(T_li));
- else if (GoodStr(T_ce))
- term_tputs(el, Str(T_ce), Val(T_li));
-}
-#endif
-
protected void
-term_get(EditLine *el, const char **term)
+terminal_get(EditLine *el, const char **term)
{
- *term = el->el_term.t_name;
+ *term = el->el_terminal.t_name;
}
-/* term_set():
+/* terminal_set():
* Read in the terminal capabilities from the requested terminal
*/
protected int
-term_set(EditLine *el, const char *term)
+terminal_set(EditLine *el, const char *term)
{
int i;
char buf[TC_BUFSIZE];
@@ -911,9 +882,9 @@ term_set(EditLine *el, const char *term)
if (strcmp(term, "emacs") == 0)
el->el_flags |= EDIT_DISABLED;
- memset(el->el_term.t_cap, 0, TC_BUFSIZE);
+ (void) memset(el->el_terminal.t_cap, 0, TC_BUFSIZE);
- i = tgetent(el->el_term.t_cap, term);
+ i = tgetent(el->el_terminal.t_cap, term);
if (i <= 0) {
if (i == -1)
@@ -928,7 +899,7 @@ term_set(EditLine *el, const char *term)
Val(T_pt) = Val(T_km) = Val(T_li) = 0;
Val(T_xt) = Val(T_MT);
for (t = tstr; t->name != NULL; t++)
- term_alloc(el, t, NULL);
+ terminal_alloc(el, t, NULL);
} else {
/* auto/magic margins */
Val(T_am) = tgetflag("am");
@@ -944,7 +915,7 @@ term_set(EditLine *el, const char *term)
Val(T_li) = tgetnum("li");
for (t = tstr; t->name != NULL; t++) {
/* XXX: some systems' tgetstr needs non const */
- term_alloc(el, t, tgetstr(strchr(t->name, *t->name),
+ terminal_alloc(el, t, tgetstr(strchr(t->name, *t->name),
&area));
}
}
@@ -954,28 +925,28 @@ term_set(EditLine *el, const char *term)
if (Val(T_li) < 1)
Val(T_li) = 24;
- el->el_term.t_size.v = Val(T_co);
- el->el_term.t_size.h = Val(T_li);
+ el->el_terminal.t_size.v = Val(T_co);
+ el->el_terminal.t_size.h = Val(T_li);
- term_setflags(el);
+ terminal_setflags(el);
/* get the correct window size */
- (void) term_get_size(el, &lins, &cols);
- if (term_change_size(el, lins, cols) == -1)
- return (-1);
+ (void) terminal_get_size(el, &lins, &cols);
+ if (terminal_change_size(el, lins, cols) == -1)
+ return -1;
(void) sigprocmask(SIG_SETMASK, &oset, NULL);
- term_bind_arrow(el);
- el->el_term.t_name = term;
- return (i <= 0 ? -1 : 0);
+ terminal_bind_arrow(el);
+ el->el_terminal.t_name = term;
+ return i <= 0 ? -1 : 0;
}
-/* term_get_size():
+/* terminal_get_size():
* Return the new window size in lines and cols, and
* true if the size was changed.
*/
protected int
-term_get_size(EditLine *el, int *lins, int *cols)
+terminal_get_size(EditLine *el, int *lins, int *cols)
{
*cols = Val(T_co);
@@ -984,7 +955,7 @@ term_get_size(EditLine *el, int *lins, int *cols)
#ifdef TIOCGWINSZ
{
struct winsize ws;
- if (ioctl(el->el_infd, TIOCGWINSZ, (ioctl_t) & ws) != -1) {
+ if (ioctl(el->el_infd, TIOCGWINSZ, &ws) != -1) {
if (ws.ws_col)
*cols = ws.ws_col;
if (ws.ws_row)
@@ -995,7 +966,7 @@ term_get_size(EditLine *el, int *lins, int *cols)
#ifdef TIOCGSIZE
{
struct ttysize ts;
- if (ioctl(el->el_infd, TIOCGSIZE, (ioctl_t) & ts) != -1) {
+ if (ioctl(el->el_infd, TIOCGSIZE, &ts) != -1) {
if (ts.ts_cols)
*cols = ts.ts_cols;
if (ts.ts_lines)
@@ -1003,15 +974,15 @@ term_get_size(EditLine *el, int *lins, int *cols)
}
}
#endif
- return (Val(T_co) != *cols || Val(T_li) != *lins);
+ return Val(T_co) != *cols || Val(T_li) != *lins;
}
-/* term_change_size():
+/* terminal_change_size():
* Change the size of the terminal
*/
protected int
-term_change_size(EditLine *el, int lins, int cols)
+terminal_change_size(EditLine *el, int lins, int cols)
{
/*
* Just in case
@@ -1020,294 +991,305 @@ term_change_size(EditLine *el, int lins, int cols)
Val(T_li) = (lins < 1) ? 24 : lins;
/* re-make display buffers */
- if (term_rebuffer_display(el) == -1)
- return (-1);
+ if (terminal_rebuffer_display(el) == -1)
+ return -1;
re_clear_display(el);
- return (0);
+ return 0;
}
-/* term_init_arrow():
+/* terminal_init_arrow():
* Initialize the arrow key bindings from termcap
*/
private void
-term_init_arrow(EditLine *el)
+terminal_init_arrow(EditLine *el)
{
- fkey_t *arrow = el->el_term.t_fkey;
+ funckey_t *arrow = el->el_terminal.t_fkey;
- arrow[A_K_DN].name = "down";
+ arrow[A_K_DN].name = STR("down");
arrow[A_K_DN].key = T_kd;
arrow[A_K_DN].fun.cmd = ED_NEXT_HISTORY;
arrow[A_K_DN].type = XK_CMD;
- arrow[A_K_UP].name = "up";
+ arrow[A_K_UP].name = STR("up");
arrow[A_K_UP].key = T_ku;
arrow[A_K_UP].fun.cmd = ED_PREV_HISTORY;
arrow[A_K_UP].type = XK_CMD;
- arrow[A_K_LT].name = "left";
+ arrow[A_K_LT].name = STR("left");
arrow[A_K_LT].key = T_kl;
arrow[A_K_LT].fun.cmd = ED_PREV_CHAR;
arrow[A_K_LT].type = XK_CMD;
- arrow[A_K_RT].name = "right";
+ arrow[A_K_RT].name = STR("right");
arrow[A_K_RT].key = T_kr;
arrow[A_K_RT].fun.cmd = ED_NEXT_CHAR;
arrow[A_K_RT].type = XK_CMD;
- arrow[A_K_HO].name = "home";
+ arrow[A_K_HO].name = STR("home");
arrow[A_K_HO].key = T_kh;
arrow[A_K_HO].fun.cmd = ED_MOVE_TO_BEG;
arrow[A_K_HO].type = XK_CMD;
- arrow[A_K_EN].name = "end";
+ arrow[A_K_EN].name = STR("end");
arrow[A_K_EN].key = T_at7;
arrow[A_K_EN].fun.cmd = ED_MOVE_TO_END;
arrow[A_K_EN].type = XK_CMD;
- arrow[A_K_DE].name = "delete";
+ arrow[A_K_DE].name = STR("delete");
arrow[A_K_DE].key = T_kD;
arrow[A_K_DE].fun.cmd = ED_DELETE_NEXT_CHAR;
arrow[A_K_DE].type = XK_CMD;
}
-/* term_reset_arrow():
+/* terminal_reset_arrow():
* Reset arrow key bindings
*/
private void
-term_reset_arrow(EditLine *el)
+terminal_reset_arrow(EditLine *el)
{
- fkey_t *arrow = el->el_term.t_fkey;
- static const char strA[] = {033, '[', 'A', '\0'};
- static const char strB[] = {033, '[', 'B', '\0'};
- static const char strC[] = {033, '[', 'C', '\0'};
- static const char strD[] = {033, '[', 'D', '\0'};
- static const char strH[] = {033, '[', 'H', '\0'};
- static const char strF[] = {033, '[', 'F', '\0'};
- static const char str1[] = {033, '[', '1', '~', '\0'};
- static const char str4[] = {033, '[', '4', '~', '\0'};
- static const char stOA[] = {033, 'O', 'A', '\0'};
- static const char stOB[] = {033, 'O', 'B', '\0'};
- static const char stOC[] = {033, 'O', 'C', '\0'};
- static const char stOD[] = {033, 'O', 'D', '\0'};
- static const char stOH[] = {033, 'O', 'H', '\0'};
- static const char stOF[] = {033, 'O', 'F', '\0'};
-
- key_add(el, strA, &arrow[A_K_UP].fun, arrow[A_K_UP].type);
- key_add(el, strB, &arrow[A_K_DN].fun, arrow[A_K_DN].type);
- key_add(el, strC, &arrow[A_K_RT].fun, arrow[A_K_RT].type);
- key_add(el, strD, &arrow[A_K_LT].fun, arrow[A_K_LT].type);
- key_add(el, strH, &arrow[A_K_HO].fun, arrow[A_K_HO].type);
- key_add(el, strF, &arrow[A_K_EN].fun, arrow[A_K_EN].type);
- key_add(el, str1, &arrow[A_K_HO].fun, arrow[A_K_HO].type);
- key_add(el, str4, &arrow[A_K_EN].fun, arrow[A_K_EN].type);
- key_add(el, stOA, &arrow[A_K_UP].fun, arrow[A_K_UP].type);
- key_add(el, stOB, &arrow[A_K_DN].fun, arrow[A_K_DN].type);
- key_add(el, stOC, &arrow[A_K_RT].fun, arrow[A_K_RT].type);
- key_add(el, stOD, &arrow[A_K_LT].fun, arrow[A_K_LT].type);
- key_add(el, stOH, &arrow[A_K_HO].fun, arrow[A_K_HO].type);
- key_add(el, stOF, &arrow[A_K_EN].fun, arrow[A_K_EN].type);
-
- if (el->el_map.type == MAP_VI) {
- key_add(el, &strA[1], &arrow[A_K_UP].fun, arrow[A_K_UP].type);
- key_add(el, &strB[1], &arrow[A_K_DN].fun, arrow[A_K_DN].type);
- key_add(el, &strC[1], &arrow[A_K_RT].fun, arrow[A_K_RT].type);
- key_add(el, &strD[1], &arrow[A_K_LT].fun, arrow[A_K_LT].type);
- key_add(el, &strH[1], &arrow[A_K_HO].fun, arrow[A_K_HO].type);
- key_add(el, &strF[1], &arrow[A_K_EN].fun, arrow[A_K_EN].type);
- key_add(el, &str1[1], &arrow[A_K_HO].fun, arrow[A_K_HO].type);
- key_add(el, &str4[1], &arrow[A_K_EN].fun, arrow[A_K_EN].type);
- key_add(el, &stOA[1], &arrow[A_K_UP].fun, arrow[A_K_UP].type);
- key_add(el, &stOB[1], &arrow[A_K_DN].fun, arrow[A_K_DN].type);
- key_add(el, &stOC[1], &arrow[A_K_RT].fun, arrow[A_K_RT].type);
- key_add(el, &stOD[1], &arrow[A_K_LT].fun, arrow[A_K_LT].type);
- key_add(el, &stOH[1], &arrow[A_K_HO].fun, arrow[A_K_HO].type);
- key_add(el, &stOF[1], &arrow[A_K_EN].fun, arrow[A_K_EN].type);
- }
+ funckey_t *arrow = el->el_terminal.t_fkey;
+ static const Char strA[] = {033, '[', 'A', '\0'};
+ static const Char strB[] = {033, '[', 'B', '\0'};
+ static const Char strC[] = {033, '[', 'C', '\0'};
+ static const Char strD[] = {033, '[', 'D', '\0'};
+ static const Char strH[] = {033, '[', 'H', '\0'};
+ static const Char strF[] = {033, '[', 'F', '\0'};
+ static const Char stOA[] = {033, 'O', 'A', '\0'};
+ static const Char stOB[] = {033, 'O', 'B', '\0'};
+ static const Char stOC[] = {033, 'O', 'C', '\0'};
+ static const Char stOD[] = {033, 'O', 'D', '\0'};
+ static const Char stOH[] = {033, 'O', 'H', '\0'};
+ static const Char stOF[] = {033, 'O', 'F', '\0'};
+
+ keymacro_add(el, strA, &arrow[A_K_UP].fun, arrow[A_K_UP].type);
+ keymacro_add(el, strB, &arrow[A_K_DN].fun, arrow[A_K_DN].type);
+ keymacro_add(el, strC, &arrow[A_K_RT].fun, arrow[A_K_RT].type);
+ keymacro_add(el, strD, &arrow[A_K_LT].fun, arrow[A_K_LT].type);
+ keymacro_add(el, strH, &arrow[A_K_HO].fun, arrow[A_K_HO].type);
+ keymacro_add(el, strF, &arrow[A_K_EN].fun, arrow[A_K_EN].type);
+ keymacro_add(el, stOA, &arrow[A_K_UP].fun, arrow[A_K_UP].type);
+ keymacro_add(el, stOB, &arrow[A_K_DN].fun, arrow[A_K_DN].type);
+ keymacro_add(el, stOC, &arrow[A_K_RT].fun, arrow[A_K_RT].type);
+ keymacro_add(el, stOD, &arrow[A_K_LT].fun, arrow[A_K_LT].type);
+ keymacro_add(el, stOH, &arrow[A_K_HO].fun, arrow[A_K_HO].type);
+ keymacro_add(el, stOF, &arrow[A_K_EN].fun, arrow[A_K_EN].type);
+
+ if (el->el_map.type != MAP_VI)
+ return;
+ keymacro_add(el, &strA[1], &arrow[A_K_UP].fun, arrow[A_K_UP].type);
+ keymacro_add(el, &strB[1], &arrow[A_K_DN].fun, arrow[A_K_DN].type);
+ keymacro_add(el, &strC[1], &arrow[A_K_RT].fun, arrow[A_K_RT].type);
+ keymacro_add(el, &strD[1], &arrow[A_K_LT].fun, arrow[A_K_LT].type);
+ keymacro_add(el, &strH[1], &arrow[A_K_HO].fun, arrow[A_K_HO].type);
+ keymacro_add(el, &strF[1], &arrow[A_K_EN].fun, arrow[A_K_EN].type);
+ keymacro_add(el, &stOA[1], &arrow[A_K_UP].fun, arrow[A_K_UP].type);
+ keymacro_add(el, &stOB[1], &arrow[A_K_DN].fun, arrow[A_K_DN].type);
+ keymacro_add(el, &stOC[1], &arrow[A_K_RT].fun, arrow[A_K_RT].type);
+ keymacro_add(el, &stOD[1], &arrow[A_K_LT].fun, arrow[A_K_LT].type);
+ keymacro_add(el, &stOH[1], &arrow[A_K_HO].fun, arrow[A_K_HO].type);
+ keymacro_add(el, &stOF[1], &arrow[A_K_EN].fun, arrow[A_K_EN].type);
}
-/* term_set_arrow():
+/* terminal_set_arrow():
* Set an arrow key binding
*/
protected int
-term_set_arrow(EditLine *el, const char *name, key_value_t *fun, int type)
+terminal_set_arrow(EditLine *el, const Char *name, keymacro_value_t *fun,
+ int type)
{
- fkey_t *arrow = el->el_term.t_fkey;
+ funckey_t *arrow = el->el_terminal.t_fkey;
int i;
for (i = 0; i < A_K_NKEYS; i++)
- if (strcmp(name, arrow[i].name) == 0) {
+ if (Strcmp(name, arrow[i].name) == 0) {
arrow[i].fun = *fun;
arrow[i].type = type;
- return (0);
+ return 0;
}
- return (-1);
+ return -1;
}
-/* term_clear_arrow():
+/* terminal_clear_arrow():
* Clear an arrow key binding
*/
protected int
-term_clear_arrow(EditLine *el, const char *name)
+terminal_clear_arrow(EditLine *el, const Char *name)
{
- fkey_t *arrow = el->el_term.t_fkey;
+ funckey_t *arrow = el->el_terminal.t_fkey;
int i;
for (i = 0; i < A_K_NKEYS; i++)
- if (strcmp(name, arrow[i].name) == 0) {
+ if (Strcmp(name, arrow[i].name) == 0) {
arrow[i].type = XK_NOD;
- return (0);
+ return 0;
}
- return (-1);
+ return -1;
}
-/* term_print_arrow():
+/* terminal_print_arrow():
* Print the arrow key bindings
*/
protected void
-term_print_arrow(EditLine *el, const char *name)
+terminal_print_arrow(EditLine *el, const Char *name)
{
int i;
- fkey_t *arrow = el->el_term.t_fkey;
+ funckey_t *arrow = el->el_terminal.t_fkey;
for (i = 0; i < A_K_NKEYS; i++)
- if (*name == '\0' || strcmp(name, arrow[i].name) == 0)
+ if (*name == '\0' || Strcmp(name, arrow[i].name) == 0)
if (arrow[i].type != XK_NOD)
- key_kprint(el, arrow[i].name, &arrow[i].fun,
- arrow[i].type);
+ keymacro_kprint(el, arrow[i].name,
+ &arrow[i].fun, arrow[i].type);
}
-/* term_bind_arrow():
+/* terminal_bind_arrow():
* Bind the arrow keys
*/
protected void
-term_bind_arrow(EditLine *el)
+terminal_bind_arrow(EditLine *el)
{
el_action_t *map;
const el_action_t *dmap;
int i, j;
char *p;
- fkey_t *arrow = el->el_term.t_fkey;
+ funckey_t *arrow = el->el_terminal.t_fkey;
/* Check if the components needed are initialized */
- if (el->el_term.t_buf == NULL || el->el_map.key == NULL)
+ if (el->el_terminal.t_buf == NULL || el->el_map.key == NULL)
return;
map = el->el_map.type == MAP_VI ? el->el_map.alt : el->el_map.key;
dmap = el->el_map.type == MAP_VI ? el->el_map.vic : el->el_map.emacs;
- term_reset_arrow(el);
+ terminal_reset_arrow(el);
for (i = 0; i < A_K_NKEYS; i++) {
- p = el->el_term.t_str[arrow[i].key];
- if (p && *p) {
- j = (unsigned char) *p;
- /*
- * Assign the arrow keys only if:
- *
- * 1. They are multi-character arrow keys and the user
- * has not re-assigned the leading character, or
- * has re-assigned the leading character to be
- * ED_SEQUENCE_LEAD_IN
- * 2. They are single arrow keys pointing to an
- * unassigned key.
- */
- if (arrow[i].type == XK_NOD)
- key_clear(el, map, p);
- else {
- if (p[1] && (dmap[j] == map[j] ||
- map[j] == ED_SEQUENCE_LEAD_IN)) {
- key_add(el, p, &arrow[i].fun,
+ Char wt_str[VISUAL_WIDTH_MAX];
+ Char *px;
+ size_t n;
+
+ p = el->el_terminal.t_str[arrow[i].key];
+ if (!p || !*p)
+ continue;
+ for (n = 0; n < VISUAL_WIDTH_MAX && p[n]; ++n)
+ wt_str[n] = p[n];
+ while (n < VISUAL_WIDTH_MAX)
+ wt_str[n++] = '\0';
+ px = wt_str;
+ j = (unsigned char) *p;
+ /*
+ * Assign the arrow keys only if:
+ *
+ * 1. They are multi-character arrow keys and the user
+ * has not re-assigned the leading character, or
+ * has re-assigned the leading character to be
+ * ED_SEQUENCE_LEAD_IN
+ * 2. They are single arrow keys pointing to an
+ * unassigned key.
+ */
+ if (arrow[i].type == XK_NOD)
+ keymacro_clear(el, map, px);
+ else {
+ if (p[1] && (dmap[j] == map[j] ||
+ map[j] == ED_SEQUENCE_LEAD_IN)) {
+ keymacro_add(el, px, &arrow[i].fun,
+ arrow[i].type);
+ map[j] = ED_SEQUENCE_LEAD_IN;
+ } else if (map[j] == ED_UNASSIGNED) {
+ keymacro_clear(el, map, px);
+ if (arrow[i].type == XK_CMD)
+ map[j] = arrow[i].fun.cmd;
+ else
+ keymacro_add(el, px, &arrow[i].fun,
arrow[i].type);
- map[j] = ED_SEQUENCE_LEAD_IN;
- } else if (map[j] == ED_UNASSIGNED) {
- key_clear(el, map, p);
- if (arrow[i].type == XK_CMD)
- map[j] = arrow[i].fun.cmd;
- else
- key_add(el, p, &arrow[i].fun,
- arrow[i].type);
- }
}
}
}
}
-/* term_putc():
+/* terminal_putc():
* Add a character
*/
private int
-term_putc(int c)
+terminal_putc(int c)
{
-
- if (term_outfile == NULL)
+ if (terminal_outfile == NULL)
return -1;
- return fputc(c, term_outfile);
+ return fputc(c, terminal_outfile);
}
private void
-term_tputs(EditLine *el, const char *cap, int affcnt)
+terminal_tputs(EditLine *el, const char *cap, int affcnt)
{
#ifdef _REENTRANT
- pthread_mutex_lock(&term_mutex);
+ pthread_mutex_lock(&terminal_mutex);
#endif
- term_outfile = el->el_outfile;
- (void)tputs(cap, affcnt, term_putc);
+ terminal_outfile = el->el_outfile;
+ (void)tputs(cap, affcnt, terminal_putc);
#ifdef _REENTRANT
- pthread_mutex_unlock(&term_mutex);
+ pthread_mutex_unlock(&terminal_mutex);
#endif
}
-/* term__putc():
+/* terminal__putc():
* Add a character
*/
protected int
-term__putc(EditLine *el, int c)
+terminal__putc(EditLine *el, Int c)
{
-
- return fputc(c, el->el_outfile);
+ char buf[MB_LEN_MAX +1];
+ ssize_t i;
+ if (c == (Int)MB_FILL_CHAR)
+ return 0;
+ i = ct_encode_char(buf, (size_t)MB_LEN_MAX, c);
+ if (i <= 0)
+ return (int)i;
+ buf[i] = '\0';
+ return fputs(buf, el->el_outfile);
}
-/* term__flush():
+/* terminal__flush():
* Flush output
*/
protected void
-term__flush(EditLine *el)
+terminal__flush(EditLine *el)
{
(void) fflush(el->el_outfile);
}
-/* term_writec():
+/* terminal_writec():
* Write the given character out, in a human readable form
*/
protected void
-term_writec(EditLine *el, int c)
+terminal_writec(EditLine *el, Int c)
{
- char buf[8];
- size_t cnt = key__decode_char(buf, sizeof(buf), 0, c);
- buf[cnt] = '\0';
- term_overwrite(el, buf, (size_t)cnt);
- term__flush(el);
+ Char visbuf[VISUAL_WIDTH_MAX +1];
+ ssize_t vcnt = ct_visual_char(visbuf, VISUAL_WIDTH_MAX, c);
+ if (vcnt < 0)
+ vcnt = 0;
+ visbuf[vcnt] = '\0';
+ terminal_overwrite(el, visbuf, (size_t)vcnt);
+ terminal__flush(el);
}
-/* term_telltc():
+/* terminal_telltc():
* Print the current termcap characteristics
*/
protected int
/*ARGSUSED*/
-term_telltc(EditLine *el, int argc __unused,
- const char **argv __unused)
+terminal_telltc(EditLine *el, int argc __attribute__((__unused__)),
+ const Char **argv __attribute__((__unused__)))
{
const struct termcapstr *t;
char **ts;
- char upbuf[EL_BUFSIZ];
(void) fprintf(el->el_outfile, "\n\tYour terminal has the\n");
(void) fprintf(el->el_outfile, "\tfollowing characteristics:\n\n");
@@ -1323,39 +1305,42 @@ term_telltc(EditLine *el, int argc __unused,
(void) fprintf(el->el_outfile, "\tIt %s magic margins\n",
EL_HAS_MAGIC_MARGINS ? "has" : "does not have");
- for (t = tstr, ts = el->el_term.t_str; t->name != NULL; t++, ts++) {
+ for (t = tstr, ts = el->el_terminal.t_str; t->name != NULL; t++, ts++) {
const char *ub;
if (*ts && **ts) {
- (void) key__decode_str(*ts, upbuf, sizeof(upbuf), "");
- ub = upbuf;
+ ub = ct_encode_string(ct_visual_string(
+ ct_decode_string(*ts, &el->el_scratch)),
+ &el->el_scratch);
} else {
- ub = "(empty)";
+ ub = "(empty)";
}
(void) fprintf(el->el_outfile, "\t%25s (%s) == %s\n",
t->long_name, t->name, ub);
}
(void) fputc('\n', el->el_outfile);
- return (0);
+ return 0;
}
-/* term_settc():
+/* terminal_settc():
* Change the current terminal characteristics
*/
protected int
/*ARGSUSED*/
-term_settc(EditLine *el, int argc __unused,
- const char **argv)
+terminal_settc(EditLine *el, int argc __attribute__((__unused__)),
+ const Char **argv)
{
const struct termcapstr *ts;
const struct termcapval *tv;
- const char *what, *how;
+ char what[8], how[8];
if (argv == NULL || argv[1] == NULL || argv[2] == NULL)
return -1;
- what = argv[1];
- how = argv[2];
+ strncpy(what, ct_encode_string(argv[1], &el->el_scratch), sizeof(what));
+ what[sizeof(what) - 1] = '\0';
+ strncpy(how, ct_encode_string(argv[2], &el->el_scratch), sizeof(how));
+ how[sizeof(how) - 1] = '\0';
/*
* Do the strings first
@@ -1365,8 +1350,8 @@ term_settc(EditLine *el, int argc __unused,
break;
if (ts->name != NULL) {
- term_alloc(el, ts, how);
- term_setflags(el);
+ terminal_alloc(el, ts, how);
+ terminal_setflags(el);
return 0;
}
/*
@@ -1382,16 +1367,16 @@ term_settc(EditLine *el, int argc __unused,
if (tv == &tval[T_pt] || tv == &tval[T_km] ||
tv == &tval[T_am] || tv == &tval[T_xn]) {
if (strcmp(how, "yes") == 0)
- el->el_term.t_val[tv - tval] = 1;
+ el->el_terminal.t_val[tv - tval] = 1;
else if (strcmp(how, "no") == 0)
- el->el_term.t_val[tv - tval] = 0;
+ el->el_terminal.t_val[tv - tval] = 0;
else {
(void) fprintf(el->el_errfile,
- "%s: Bad value `%s'.\n", argv[0], how);
+ "" FSTR ": Bad value `%s'.\n", argv[0], how);
return -1;
}
- term_setflags(el);
- if (term_change_size(el, Val(T_li), Val(T_co)) == -1)
+ terminal_setflags(el);
+ if (terminal_change_size(el, Val(T_li), Val(T_co)) == -1)
return -1;
return 0;
} else {
@@ -1401,14 +1386,14 @@ term_settc(EditLine *el, int argc __unused,
i = strtol(how, &ep, 10);
if (*ep != '\0') {
(void) fprintf(el->el_errfile,
- "%s: Bad value `%s'.\n", argv[0], how);
+ "" FSTR ": Bad value `%s'.\n", argv[0], how);
return -1;
}
- el->el_term.t_val[tv - tval] = (int) i;
- el->el_term.t_size.v = Val(T_co);
- el->el_term.t_size.h = Val(T_li);
+ el->el_terminal.t_val[tv - tval] = (int) i;
+ el->el_terminal.t_size.v = Val(T_co);
+ el->el_terminal.t_size.h = Val(T_li);
if (tv == &tval[T_co] || tv == &tval[T_li])
- if (term_change_size(el, Val(T_li), Val(T_co))
+ if (terminal_change_size(el, Val(T_li), Val(T_co))
== -1)
return -1;
return 0;
@@ -1416,12 +1401,12 @@ term_settc(EditLine *el, int argc __unused,
}
-/* term_gettc():
+/* terminal_gettc():
* Get the current terminal characteristics
*/
protected int
/*ARGSUSED*/
-term_gettc(EditLine *el, int argc __unused, char **argv)
+terminal_gettc(EditLine *el, int argc __attribute__((__unused__)), char **argv)
{
const struct termcapstr *ts;
const struct termcapval *tv;
@@ -1429,7 +1414,7 @@ term_gettc(EditLine *el, int argc __unused, char **argv)
void *how;
if (argv == NULL || argv[1] == NULL || argv[2] == NULL)
- return (-1);
+ return -1;
what = argv[1];
how = argv[2];
@@ -1442,7 +1427,7 @@ term_gettc(EditLine *el, int argc __unused, char **argv)
break;
if (ts->name != NULL) {
- *(char **)how = el->el_term.t_str[ts - tstr];
+ *(char **)how = el->el_terminal.t_str[ts - tstr];
return 0;
}
/*
@@ -1459,26 +1444,27 @@ term_gettc(EditLine *el, int argc __unused, char **argv)
tv == &tval[T_am] || tv == &tval[T_xn]) {
static char yes[] = "yes";
static char no[] = "no";
- if (el->el_term.t_val[tv - tval])
+ if (el->el_terminal.t_val[tv - tval])
*(char **)how = yes;
else
*(char **)how = no;
return 0;
} else {
- *(int *)how = el->el_term.t_val[tv - tval];
+ *(int *)how = el->el_terminal.t_val[tv - tval];
return 0;
}
}
-/* term_echotc():
+/* terminal_echotc():
* Print the termcap string out with variable substitution
*/
protected int
/*ARGSUSED*/
-term_echotc(EditLine *el, int argc __unused,
- const char **argv)
+terminal_echotc(EditLine *el, int argc __attribute__((__unused__)),
+ const Char **argv)
{
- char *cap, *scap, *ep;
+ char *cap, *scap;
+ Char *ep;
int arg_need, arg_cols, arg_rows;
int verbose = 0, silent = 0;
char *area;
@@ -1490,7 +1476,7 @@ term_echotc(EditLine *el, int argc __unused,
area = buf;
if (argv == NULL || argv[1] == NULL)
- return (-1);
+ return -1;
argv++;
if (argv[0][0] == '-') {
@@ -1508,62 +1494,52 @@ term_echotc(EditLine *el, int argc __unused,
argv++;
}
if (!*argv || *argv[0] == '\0')
- return (0);
- if (strcmp(*argv, "tabs") == 0) {
+ return 0;
+ if (Strcmp(*argv, STR("tabs")) == 0) {
(void) fprintf(el->el_outfile, fmts, EL_CAN_TAB ? "yes" : "no");
- return (0);
- } else if (strcmp(*argv, "meta") == 0) {
+ return 0;
+ } else if (Strcmp(*argv, STR("meta")) == 0) {
(void) fprintf(el->el_outfile, fmts, Val(T_km) ? "yes" : "no");
- return (0);
- } else if (strcmp(*argv, "xn") == 0) {
+ return 0;
+ } else if (Strcmp(*argv, STR("xn")) == 0) {
(void) fprintf(el->el_outfile, fmts, EL_HAS_MAGIC_MARGINS ?
"yes" : "no");
- return (0);
- } else if (strcmp(*argv, "am") == 0) {
+ return 0;
+ } else if (Strcmp(*argv, STR("am")) == 0) {
(void) fprintf(el->el_outfile, fmts, EL_HAS_AUTO_MARGINS ?
"yes" : "no");
- return (0);
- } else if (strcmp(*argv, "baud") == 0) {
-#ifdef notdef
- int i;
-
- for (i = 0; baud_rate[i].b_name != NULL; i++)
- if (el->el_tty.t_speed == baud_rate[i].b_rate) {
- (void) fprintf(el->el_outfile, fmts,
- baud_rate[i].b_name);
- return (0);
- }
- (void) fprintf(el->el_outfile, fmtd, 0);
-#else
+ return 0;
+ } else if (Strcmp(*argv, STR("baud")) == 0) {
(void) fprintf(el->el_outfile, fmtd, (int)el->el_tty.t_speed);
-#endif
- return (0);
- } else if (strcmp(*argv, "rows") == 0 || strcmp(*argv, "lines") == 0) {
+ return 0;
+ } else if (Strcmp(*argv, STR("rows")) == 0 ||
+ Strcmp(*argv, STR("lines")) == 0) {
(void) fprintf(el->el_outfile, fmtd, Val(T_li));
- return (0);
- } else if (strcmp(*argv, "cols") == 0) {
+ return 0;
+ } else if (Strcmp(*argv, STR("cols")) == 0) {
(void) fprintf(el->el_outfile, fmtd, Val(T_co));
- return (0);
+ return 0;
}
/*
* Try to use our local definition first
*/
scap = NULL;
for (t = tstr; t->name != NULL; t++)
- if (strcmp(t->name, *argv) == 0) {
- scap = el->el_term.t_str[t - tstr];
+ if (strcmp(t->name,
+ ct_encode_string(*argv, &el->el_scratch)) == 0) {
+ scap = el->el_terminal.t_str[t - tstr];
break;
}
if (t->name == NULL) {
/* XXX: some systems' tgetstr needs non const */
- scap = tgetstr(strchr(*argv, **argv), &area);
+ scap = tgetstr(ct_encode_string(*argv, &el->el_scratch), &area);
}
if (!scap || scap[0] == '\0') {
if (!silent)
(void) fprintf(el->el_errfile,
- "echotc: Termcap parameter `%s' not found.\n",
+ "echotc: Termcap parameter `" FSTR "' not found.\n",
*argv);
- return (-1);
+ return -1;
}
/*
* Count home many values we need for this capability.
@@ -1604,11 +1580,11 @@ term_echotc(EditLine *el, int argc __unused,
if (*argv && *argv[0]) {
if (!silent)
(void) fprintf(el->el_errfile,
- "echotc: Warning: Extra argument `%s'.\n",
+ "echotc: Warning: Extra argument `" FSTR "'.\n",
*argv);
- return (-1);
+ return -1;
}
- term_tputs(el, scap, 1);
+ terminal_tputs(el, scap, 1);
break;
case 1:
argv++;
@@ -1616,27 +1592,27 @@ term_echotc(EditLine *el, int argc __unused,
if (!silent)
(void) fprintf(el->el_errfile,
"echotc: Warning: Missing argument.\n");
- return (-1);
+ return -1;
}
arg_cols = 0;
- i = strtol(*argv, &ep, 10);
+ i = Strtol(*argv, &ep, 10);
if (*ep != '\0' || i < 0) {
if (!silent)
(void) fprintf(el->el_errfile,
- "echotc: Bad value `%s' for rows.\n",
+ "echotc: Bad value `" FSTR "' for rows.\n",
*argv);
- return (-1);
+ return -1;
}
arg_rows = (int) i;
argv++;
if (*argv && *argv[0]) {
if (!silent)
(void) fprintf(el->el_errfile,
- "echotc: Warning: Extra argument `%s'.\n",
- *argv);
- return (-1);
+ "echotc: Warning: Extra argument `" FSTR
+ "'.\n", *argv);
+ return -1;
}
- term_tputs(el, tgoto(scap, arg_cols, arg_rows), 1);
+ terminal_tputs(el, tgoto(scap, arg_cols, arg_rows), 1);
break;
default:
/* This is wrong, but I will ignore it... */
@@ -1651,15 +1627,15 @@ term_echotc(EditLine *el, int argc __unused,
if (!silent)
(void) fprintf(el->el_errfile,
"echotc: Warning: Missing argument.\n");
- return (-1);
+ return -1;
}
- i = strtol(*argv, &ep, 10);
+ i = Strtol(*argv, &ep, 10);
if (*ep != '\0' || i < 0) {
if (!silent)
(void) fprintf(el->el_errfile,
- "echotc: Bad value `%s' for cols.\n",
+ "echotc: Bad value `" FSTR "' for cols.\n",
*argv);
- return (-1);
+ return -1;
}
arg_cols = (int) i;
argv++;
@@ -1667,33 +1643,33 @@ term_echotc(EditLine *el, int argc __unused,
if (!silent)
(void) fprintf(el->el_errfile,
"echotc: Warning: Missing argument.\n");
- return (-1);
+ return -1;
}
- i = strtol(*argv, &ep, 10);
+ i = Strtol(*argv, &ep, 10);
if (*ep != '\0' || i < 0) {
if (!silent)
(void) fprintf(el->el_errfile,
- "echotc: Bad value `%s' for rows.\n",
+ "echotc: Bad value `" FSTR "' for rows.\n",
*argv);
- return (-1);
+ return -1;
}
arg_rows = (int) i;
if (*ep != '\0') {
if (!silent)
(void) fprintf(el->el_errfile,
- "echotc: Bad value `%s'.\n", *argv);
- return (-1);
+ "echotc: Bad value `" FSTR "'.\n", *argv);
+ return -1;
}
argv++;
if (*argv && *argv[0]) {
if (!silent)
(void) fprintf(el->el_errfile,
- "echotc: Warning: Extra argument `%s'.\n",
- *argv);
- return (-1);
+ "echotc: Warning: Extra argument `" FSTR
+ "'.\n", *argv);
+ return -1;
}
- term_tputs(el, tgoto(scap, arg_cols, arg_rows), arg_rows);
+ terminal_tputs(el, tgoto(scap, arg_cols, arg_rows), arg_rows);
break;
}
- return (0);
+ return 0;
}
diff --git a/lib/libedit/term.h b/lib/libedit/terminal.h
index cf7a909..f26f5e1 100644
--- a/lib/libedit/term.h
+++ b/lib/libedit/terminal.h
@@ -1,3 +1,5 @@
+/* $NetBSD: terminal.h,v 1.4 2012/03/24 20:09:30 christos Exp $ */
+
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -30,24 +32,23 @@
* SUCH DAMAGE.
*
* @(#)term.h 8.1 (Berkeley) 6/4/93
- * $NetBSD: term.h,v 1.20 2009/03/31 17:38:27 christos Exp $
* $FreeBSD$
*/
/*
* el.term.h: Termcap header
*/
-#ifndef _h_el_term
-#define _h_el_term
+#ifndef _h_el_terminal
+#define _h_el_terminal
#include "histedit.h"
typedef struct { /* Symbolic function key bindings */
- const char *name; /* name of the key */
+ const Char *name; /* name of the key */
int key; /* Index in termcap table */
- key_value_t fun; /* Function bound to it */
+ keymacro_value_t fun; /* Function bound to it */
int type; /* Type of function */
-} fkey_t;
+} funckey_t;
typedef struct {
const char *t_name; /* the terminal name */
@@ -63,12 +64,12 @@ typedef struct {
#define TERM_HAS_AUTO_MARGINS 0x080 /* Has auto margins */
#define TERM_HAS_MAGIC_MARGINS 0x100 /* Has magic margins */
char *t_buf; /* Termcap buffer */
- int t_loc; /* location used */
+ size_t t_loc; /* location used */
char **t_str; /* termcap strings */
int *t_val; /* termcap values */
char *t_cap; /* Termcap buffer */
- fkey_t *t_fkey; /* Array of keys */
-} el_term_t;
+ funckey_t *t_fkey; /* Array of keys */
+} el_terminal_t;
/*
* fKey indexes
@@ -82,36 +83,36 @@ typedef struct {
#define A_K_DE 6
#define A_K_NKEYS 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 *, size_t);
-protected void term_insertwrite(EditLine *, char *, int);
-protected void term_deletechars(EditLine *, int);
-protected void term_clear_screen(EditLine *);
-protected void term_beep(EditLine *);
-protected int term_change_size(EditLine *, int, int);
-protected int term_get_size(EditLine *, int *, int *);
-protected int term_init(EditLine *);
-protected void term_bind_arrow(EditLine *);
-protected void term_print_arrow(EditLine *, const char *);
-protected int term_clear_arrow(EditLine *, const char *);
-protected int term_set_arrow(EditLine *, const char *, key_value_t *, int);
-protected void term_end(EditLine *);
-protected void term_get(EditLine *, const char **);
-protected int term_set(EditLine *, const char *);
-protected int term_settc(EditLine *, int, const char **);
-protected int term_gettc(EditLine *, int, char **);
-protected int term_telltc(EditLine *, int, const char **);
-protected int term_echotc(EditLine *, int, const char **);
-protected void term_writec(EditLine *, int);
-protected int term__putc(EditLine *, int);
-protected void term__flush(EditLine *);
+protected void terminal_move_to_line(EditLine *, int);
+protected void terminal_move_to_char(EditLine *, int);
+protected void terminal_clear_EOL(EditLine *, int);
+protected void terminal_overwrite(EditLine *, const Char *, size_t);
+protected void terminal_insertwrite(EditLine *, Char *, int);
+protected void terminal_deletechars(EditLine *, int);
+protected void terminal_clear_screen(EditLine *);
+protected void terminal_beep(EditLine *);
+protected int terminal_change_size(EditLine *, int, int);
+protected int terminal_get_size(EditLine *, int *, int *);
+protected int terminal_init(EditLine *);
+protected void terminal_bind_arrow(EditLine *);
+protected void terminal_print_arrow(EditLine *, const Char *);
+protected int terminal_clear_arrow(EditLine *, const Char *);
+protected int terminal_set_arrow(EditLine *, const Char *, keymacro_value_t *, int);
+protected void terminal_end(EditLine *);
+protected void terminal_get(EditLine *, const char **);
+protected int terminal_set(EditLine *, const char *);
+protected int terminal_settc(EditLine *, int, const Char **);
+protected int terminal_gettc(EditLine *, int, char **);
+protected int terminal_telltc(EditLine *, int, const Char **);
+protected int terminal_echotc(EditLine *, int, const Char **);
+protected void terminal_writec(EditLine *, Int);
+protected int terminal__putc(EditLine *, Int);
+protected void terminal__flush(EditLine *);
/*
* Easy access macros
*/
-#define EL_FLAGS (el)->el_term.t_flags
+#define EL_FLAGS (el)->el_terminal.t_flags
#define EL_CAN_INSERT (EL_FLAGS & TERM_CAN_INSERT)
#define EL_CAN_DELETE (EL_FLAGS & TERM_CAN_DELETE)
@@ -123,4 +124,4 @@ protected void term__flush(EditLine *);
#define EL_HAS_AUTO_MARGINS (EL_FLAGS & TERM_HAS_AUTO_MARGINS)
#define EL_HAS_MAGIC_MARGINS (EL_FLAGS & TERM_HAS_MAGIC_MARGINS)
-#endif /* _h_el_term */
+#endif /* _h_el_terminal */
diff --git a/lib/libedit/tokenizer.c b/lib/libedit/tokenizer.c
index 41284e8..e61ecaf 100644
--- a/lib/libedit/tokenizer.c
+++ b/lib/libedit/tokenizer.c
@@ -1,3 +1,5 @@
+/* $NetBSD: tokenizer.c,v 1.21 2011/08/16 16:25:15 christos Exp $ */
+
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -28,62 +30,66 @@
* 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.
- *
- * $NetBSD: tokenizer.c,v 1.15 2009/02/15 21:55:23 christos Exp $
*/
+#include "config.h"
#if !defined(lint) && !defined(SCCSID)
+#if 0
static char sccsid[] = "@(#)tokenizer.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: tokenizer.c,v 1.21 2011/08/16 16:25:15 christos Exp $");
+#endif
#endif /* not lint && not SCCSID */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
+/* We build this file twice, once as NARROW, once as WIDE. */
/*
* tokenize.c: Bourne shell like tokenizer
*/
-#include "sys.h"
#include <string.h>
#include <stdlib.h>
#include "histedit.h"
+#include "chartype.h"
typedef enum {
Q_none, Q_single, Q_double, Q_one, Q_doubleone
} quote_t;
-#define IFS "\t \n"
-
#define TOK_KEEP 1
#define TOK_EAT 2
#define WINCR 20
#define AINCR 10
-#define tok_strdup(a) strdup(a)
+#define IFS STR("\t \n")
+
#define tok_malloc(a) malloc(a)
#define tok_free(a) free(a)
#define tok_realloc(a, b) realloc(a, b)
+#define tok_strdup(a) Strdup(a)
-struct tokenizer {
- char *ifs; /* In field separator */
- int argc, amax; /* Current and maximum number of args */
- char **argv; /* Argument list */
- char *wptr, *wmax; /* Space and limit on the word buffer */
- char *wstart; /* Beginning of next word */
- char *wspace; /* Space of word buffer */
+struct TYPE(tokenizer) {
+ Char *ifs; /* In field separator */
+ size_t argc, amax; /* Current and maximum number of args */
+ Char **argv; /* Argument list */
+ Char *wptr, *wmax; /* Space and limit on the word buffer */
+ Char *wstart; /* Beginning of next word */
+ Char *wspace; /* Space of word buffer */
quote_t quote; /* Quoting state */
int flags; /* flags; */
};
-private void tok_finish(Tokenizer *);
+private void FUN(tok,finish)(TYPE(Tokenizer) *);
-/* tok_finish():
+/* FUN(tok,finish)():
* Finish a word in the tokenizer.
*/
private void
-tok_finish(Tokenizer *tok)
+FUN(tok,finish)(TYPE(Tokenizer) *tok)
{
*tok->wptr = '\0';
@@ -96,35 +102,35 @@ tok_finish(Tokenizer *tok)
}
-/* tok_init():
+/* FUN(tok,init)():
* Initialize the tokenizer
*/
-public Tokenizer *
-tok_init(const char *ifs)
+public TYPE(Tokenizer) *
+FUN(tok,init)(const Char *ifs)
{
- Tokenizer *tok = (Tokenizer *) tok_malloc(sizeof(Tokenizer));
+ TYPE(Tokenizer) *tok = tok_malloc(sizeof(*tok));
if (tok == NULL)
return NULL;
tok->ifs = tok_strdup(ifs ? ifs : IFS);
if (tok->ifs == NULL) {
- tok_free((ptr_t)tok);
+ tok_free(tok);
return NULL;
}
tok->argc = 0;
tok->amax = AINCR;
- tok->argv = (char **) tok_malloc(sizeof(char *) * tok->amax);
+ tok->argv = tok_malloc(sizeof(*tok->argv) * tok->amax);
if (tok->argv == NULL) {
- tok_free((ptr_t)tok->ifs);
- tok_free((ptr_t)tok);
+ tok_free(tok->ifs);
+ tok_free(tok);
return NULL;
}
tok->argv[0] = NULL;
- tok->wspace = (char *) tok_malloc(WINCR);
+ tok->wspace = tok_malloc(WINCR * sizeof(*tok->wspace));
if (tok->wspace == NULL) {
- tok_free((ptr_t)tok->argv);
- tok_free((ptr_t)tok->ifs);
- tok_free((ptr_t)tok);
+ tok_free(tok->argv);
+ tok_free(tok->ifs);
+ tok_free(tok);
return NULL;
}
tok->wmax = tok->wspace + WINCR;
@@ -133,15 +139,15 @@ tok_init(const char *ifs)
tok->flags = 0;
tok->quote = Q_none;
- return (tok);
+ return tok;
}
-/* tok_reset():
+/* FUN(tok,reset)():
* Reset the tokenizer
*/
public void
-tok_reset(Tokenizer *tok)
+FUN(tok,reset)(TYPE(Tokenizer) *tok)
{
tok->argc = 0;
@@ -152,25 +158,25 @@ tok_reset(Tokenizer *tok)
}
-/* tok_end():
+/* FUN(tok,end)():
* Clean up
*/
public void
-tok_end(Tokenizer *tok)
+FUN(tok,end)(TYPE(Tokenizer) *tok)
{
- tok_free((ptr_t) tok->ifs);
- tok_free((ptr_t) tok->wspace);
- tok_free((ptr_t) tok->argv);
- tok_free((ptr_t) tok);
+ tok_free(tok->ifs);
+ tok_free(tok->wspace);
+ tok_free(tok->argv);
+ tok_free(tok);
}
-/* tok_line():
+/* FUN(tok,line)():
* Bourne shell (sh(1)) like tokenizing
* Arguments:
- * tok current tokenizer state (setup with tok_init())
+ * tok current tokenizer state (setup with FUN(tok,init)())
* line line to parse
* Returns:
* -1 Internal error
@@ -185,19 +191,19 @@ tok_end(Tokenizer *tok)
* cursorv if !NULL, offset in argv[cursorc] of cursor
*/
public int
-tok_line(Tokenizer *tok, const LineInfo *line,
- int *argc, const char ***argv, int *cursorc, int *cursoro)
+FUN(tok,line)(TYPE(Tokenizer) *tok, const TYPE(LineInfo) *line,
+ int *argc, const Char ***argv, int *cursorc, int *cursoro)
{
- const char *ptr;
+ const Char *ptr;
int cc, co;
cc = co = -1;
ptr = line->buffer;
for (ptr = line->buffer; ;ptr++) {
if (ptr >= line->lastchar)
- ptr = "";
+ ptr = STR("");
if (ptr == line->cursor) {
- cc = tok->argc;
+ cc = (int)tok->argc;
co = (int)(tok->wptr - tok->wstart);
}
switch (*ptr) {
@@ -229,7 +235,7 @@ tok_line(Tokenizer *tok, const LineInfo *line,
break;
default:
- return (-1);
+ return -1;
}
break;
@@ -260,7 +266,7 @@ tok_line(Tokenizer *tok, const LineInfo *line,
break;
default:
- return (-1);
+ return -1;
}
break;
@@ -291,7 +297,7 @@ tok_line(Tokenizer *tok, const LineInfo *line,
break;
default:
- return (-1);
+ return -1;
}
break;
@@ -317,7 +323,7 @@ tok_line(Tokenizer *tok, const LineInfo *line,
break;
default:
- return (0);
+ return 0;
}
break;
@@ -327,15 +333,15 @@ tok_line(Tokenizer *tok, const LineInfo *line,
/* Finish word and return */
if (tok->flags & TOK_EAT) {
tok->flags &= ~TOK_EAT;
- return (3);
+ return 3;
}
goto tok_line_outok;
case Q_single:
- return (1);
+ return 1;
case Q_double:
- return (2);
+ return 2;
case Q_doubleone:
tok->quote = Q_double;
@@ -348,7 +354,7 @@ tok_line(Tokenizer *tok, const LineInfo *line,
break;
default:
- return (-1);
+ return -1;
}
break;
@@ -356,8 +362,8 @@ tok_line(Tokenizer *tok, const LineInfo *line,
tok->flags &= ~TOK_EAT;
switch (tok->quote) {
case Q_none:
- if (strchr(tok->ifs, *ptr) != NULL)
- tok_finish(tok);
+ if (Strchr(tok->ifs, *ptr) != NULL)
+ FUN(tok,finish)(tok);
else
*tok->wptr++ = *ptr;
break;
@@ -380,20 +386,21 @@ tok_line(Tokenizer *tok, const LineInfo *line,
break;
default:
- return (-1);
+ return -1;
}
break;
}
if (tok->wptr >= tok->wmax - 4) {
- size_t size = tok->wmax - tok->wspace + WINCR;
- char *s = (char *) tok_realloc(tok->wspace, size);
+ size_t size = (size_t)(tok->wmax - tok->wspace + WINCR);
+ Char *s = tok_realloc(tok->wspace,
+ size * sizeof(*s));
if (s == NULL)
- return (-1);
+ return -1;
if (s != tok->wspace) {
- int i;
+ size_t i;
for (i = 0; i < tok->argc; i++) {
tok->argv[i] =
(tok->argv[i] - tok->wspace) + s;
@@ -405,41 +412,41 @@ tok_line(Tokenizer *tok, const LineInfo *line,
tok->wmax = s + size;
}
if (tok->argc >= tok->amax - 4) {
- char **p;
+ Char **p;
tok->amax += AINCR;
- p = (char **) tok_realloc(tok->argv,
- tok->amax * sizeof(char *));
+ p = tok_realloc(tok->argv, tok->amax * sizeof(*p));
if (p == NULL)
- return (-1);
+ return -1;
tok->argv = p;
}
}
tok_line_outok:
if (cc == -1 && co == -1) {
- cc = tok->argc;
+ cc = (int)tok->argc;
co = (int)(tok->wptr - tok->wstart);
}
if (cursorc != NULL)
*cursorc = cc;
if (cursoro != NULL)
*cursoro = co;
- tok_finish(tok);
- *argv = (const char **)tok->argv;
- *argc = tok->argc;
- return (0);
+ FUN(tok,finish)(tok);
+ *argv = (const Char **)tok->argv;
+ *argc = (int)tok->argc;
+ return 0;
}
-/* tok_str():
+/* FUN(tok,str)():
* Simpler version of tok_line, taking a NUL terminated line
* and splitting into words, ignoring cursor state.
*/
public int
-tok_str(Tokenizer *tok, const char *line, int *argc, const char ***argv)
+FUN(tok,str)(TYPE(Tokenizer) *tok, const Char *line, int *argc,
+ const Char ***argv)
{
- LineInfo li;
+ TYPE(LineInfo) li;
memset(&li, 0, sizeof(li));
li.buffer = line;
- li.cursor = li.lastchar = strchr(line, '\0');
- return (tok_line(tok, &li, argc, argv, NULL, NULL));
+ li.cursor = li.lastchar = Strchr(line, '\0');
+ return FUN(tok,line(tok, &li, argc, argv, NULL, NULL));
}
diff --git a/lib/libedit/tty.c b/lib/libedit/tty.c
index f8bae94..ecf2e2a 100644
--- a/lib/libedit/tty.c
+++ b/lib/libedit/tty.c
@@ -1,3 +1,5 @@
+/* $NetBSD: tty.c,v 1.47 2015/05/14 10:44:15 christos Exp $ */
+
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -28,12 +30,15 @@
* 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.
- *
- * $NetBSD: tty.c,v 1.31 2009/07/22 15:58:09 christos Exp $
*/
+#include "config.h"
#if !defined(lint) && !defined(SCCSID)
+#if 0
static char sccsid[] = "@(#)tty.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: tty.c,v 1.47 2015/05/14 10:44:15 christos Exp $");
+#endif
#endif /* not lint && not SCCSID */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
@@ -42,9 +47,12 @@ __FBSDID("$FreeBSD$");
* tty.c: tty interface stuff
*/
#include <assert.h>
-#include "sys.h"
-#include "tty.h"
+#include <errno.h>
+#include <unistd.h> /* for isatty */
+#include <strings.h> /* for ffs */
+#include <stdlib.h> /* for abort */
#include "el.h"
+#include "tty.h"
typedef struct ttymodes_t {
const char *m_name;
@@ -53,7 +61,7 @@ typedef struct ttymodes_t {
} ttymodes_t;
typedef struct ttymap_t {
- int nch, och; /* Internal and termio rep of chars */
+ Int nch, och; /* Internal and termio rep of chars */
el_action_t bind[3]; /* emacs, vi, and vi-cmd */
} ttymap_t;
@@ -149,7 +157,7 @@ private const ttymap_t tty_map[] = {
{C_LNEXT, VLNEXT,
{ED_QUOTED_INSERT, ED_QUOTED_INSERT, ED_UNASSIGNED}},
#endif /* VLNEXT */
- {-1, -1,
+ {(Int)-1, (Int)-1,
{ED_UNASSIGNED, ED_UNASSIGNED, ED_UNASSIGNED}}
};
@@ -454,6 +462,7 @@ private void tty__getchar(struct termios *, unsigned char *);
private void tty__setchar(struct termios *, unsigned char *);
private speed_t tty__getspeed(struct termios *);
private int tty_setup(EditLine *);
+private void tty_setup_flags(EditLine *, struct termios *, int);
#define t_qu t_ts
@@ -490,21 +499,30 @@ tty_setup(EditLine *el)
int rst = 1;
if (el->el_flags & EDIT_DISABLED)
- return (0);
+ return 0;
- if (tty_getty(el, &el->el_tty.t_ed) == -1) {
+ if (!isatty(el->el_outfd)) {
#ifdef DEBUG_TTY
- (void) fprintf(el->el_errfile,
- "tty_setup: tty_getty: %s\n", strerror(errno));
+ (void) fprintf(el->el_errfile, "%s: isatty: %s\n", __func__,
+ strerror(errno));
+#endif /* DEBUG_TTY */
+ return -1;
+ }
+ if (tty_getty(el, &el->el_tty.t_or) == -1) {
+#ifdef DEBUG_TTY
+ (void) fprintf(el->el_errfile, "%s: tty_getty: %s\n", __func__,
+ strerror(errno));
#endif /* DEBUG_TTY */
- return (-1);
+ return -1;
}
- el->el_tty.t_ts = el->el_tty.t_ex = el->el_tty.t_ed;
+ el->el_tty.t_ts = el->el_tty.t_ex = el->el_tty.t_ed = el->el_tty.t_or;
el->el_tty.t_speed = tty__getspeed(&el->el_tty.t_ex);
el->el_tty.t_tabs = tty__gettabs(&el->el_tty.t_ex);
el->el_tty.t_eight = tty__geteightbit(&el->el_tty.t_ex);
+ tty_setup_flags(el, &el->el_tty.t_ex, EX_IO);
+
/*
* Reset the tty chars to reasonable defaults
* If they are disabled, then enable them.
@@ -528,23 +546,21 @@ tty_setup(EditLine *el)
el->el_tty.t_c[EX_IO][rst] =
el->el_tty.t_c[TS_IO][rst];
}
+ tty__setchar(&el->el_tty.t_ex, el->el_tty.t_c[EX_IO]);
+ if (tty_setty(el, TCSADRAIN, &el->el_tty.t_ex) == -1) {
+#ifdef DEBUG_TTY
+ (void) fprintf(el->el_errfile, "%s: tty_setty: %s\n",
+ __func__, strerror(errno));
+#endif /* DEBUG_TTY */
+ return -1;
+ }
}
- el->el_tty.t_ed.c_iflag &= ~el->el_tty.t_t[ED_IO][MD_INP].t_clrmask;
- el->el_tty.t_ed.c_iflag |= el->el_tty.t_t[ED_IO][MD_INP].t_setmask;
-
- el->el_tty.t_ed.c_oflag &= ~el->el_tty.t_t[ED_IO][MD_OUT].t_clrmask;
- el->el_tty.t_ed.c_oflag |= el->el_tty.t_t[ED_IO][MD_OUT].t_setmask;
-
- el->el_tty.t_ed.c_cflag &= ~el->el_tty.t_t[ED_IO][MD_CTL].t_clrmask;
- el->el_tty.t_ed.c_cflag |= el->el_tty.t_t[ED_IO][MD_CTL].t_setmask;
-
- el->el_tty.t_ed.c_lflag &= ~el->el_tty.t_t[ED_IO][MD_LIN].t_clrmask;
- el->el_tty.t_ed.c_lflag |= el->el_tty.t_t[ED_IO][MD_LIN].t_setmask;
+ tty_setup_flags(el, &el->el_tty.t_ed, ED_IO);
tty__setchar(&el->el_tty.t_ed, el->el_tty.t_c[ED_IO]);
tty_bind_char(el, 1);
- return (0);
+ return 0;
}
protected int
@@ -555,7 +571,7 @@ tty_init(EditLine *el)
el->el_tty.t_vdisable = _POSIX_VDISABLE;
(void) memcpy(el->el_tty.t_t, ttyperm, sizeof(ttyperm_t));
(void) memcpy(el->el_tty.t_c, ttychar, sizeof(ttychar_t));
- return (tty_setup(el));
+ return tty_setup(el);
}
@@ -564,10 +580,14 @@ tty_init(EditLine *el)
*/
protected void
/*ARGSUSED*/
-tty_end(EditLine *el __unused)
+tty_end(EditLine *el)
{
-
- /* XXX: Maybe reset to an initial state? */
+ if (tty_setty(el, TCSAFLUSH, &el->el_tty.t_or) == -1) {
+#ifdef DEBUG_TTY
+ (void) fprintf(el->el_errfile,
+ "%s: tty_setty: %s\n", __func__, strerror(errno));
+#endif /* DEBUG_TTY */
+ }
}
@@ -581,7 +601,7 @@ tty__getspeed(struct termios *td)
if ((spd = cfgetispeed(td)) == 0)
spd = cfgetospeed(td);
- return (spd);
+ return spd;
}
/* tty__getspeed():
@@ -865,7 +885,7 @@ tty_bind_char(EditLine *el, int force)
unsigned char *t_n = el->el_tty.t_c[ED_IO];
unsigned char *t_o = el->el_tty.t_ed.c_cc;
- unsigned char new[2], old[2];
+ Char new[2], old[2];
const ttymap_t *tp;
el_action_t *map, *alt;
const el_action_t *dmap, *dalt;
@@ -881,27 +901,79 @@ tty_bind_char(EditLine *el, int force)
dalt = NULL;
}
- for (tp = tty_map; tp->nch != -1; tp++) {
+ for (tp = tty_map; tp->nch != (Int)-1; tp++) {
new[0] = t_n[tp->nch];
old[0] = t_o[tp->och];
if (new[0] == old[0] && !force)
continue;
/* Put the old default binding back, and set the new binding */
- key_clear(el, map, (char *)old);
- map[old[0]] = dmap[old[0]];
- key_clear(el, map, (char *)new);
+ keymacro_clear(el, map, old);
+ map[UC(old[0])] = dmap[UC(old[0])];
+ keymacro_clear(el, map, new);
/* MAP_VI == 1, MAP_EMACS == 0... */
- map[new[0]] = tp->bind[el->el_map.type];
+ map[UC(new[0])] = tp->bind[el->el_map.type];
if (dalt) {
- key_clear(el, alt, (char *)old);
- alt[old[0]] = dalt[old[0]];
- key_clear(el, alt, (char *)new);
- alt[new[0]] = tp->bind[el->el_map.type + 1];
+ keymacro_clear(el, alt, old);
+ alt[UC(old[0])] = dalt[UC(old[0])];
+ keymacro_clear(el, alt, new);
+ alt[UC(new[0])] = tp->bind[el->el_map.type + 1];
}
}
}
+private tcflag_t *
+tty__get_flag(struct termios *t, int kind) {
+ switch (kind) {
+ case MD_INP:
+ return &t->c_iflag;
+ case MD_OUT:
+ return &t->c_oflag;
+ case MD_CTL:
+ return &t->c_cflag;
+ case MD_LIN:
+ return &t->c_lflag;
+ default:
+ abort();
+ /*NOTREACHED*/
+ }
+}
+
+
+private tcflag_t
+tty_update_flag(EditLine *el, tcflag_t f, int mode, int kind)
+{
+ f &= ~el->el_tty.t_t[mode][kind].t_clrmask;
+ f |= el->el_tty.t_t[mode][kind].t_setmask;
+ return f;
+}
+
+
+private void
+tty_update_flags(EditLine *el, int kind)
+{
+ tcflag_t *tt, *ed, *ex;
+ tt = tty__get_flag(&el->el_tty.t_ts, kind);
+ ed = tty__get_flag(&el->el_tty.t_ed, kind);
+ ex = tty__get_flag(&el->el_tty.t_ex, kind);
+
+ if (*tt != *ex && (kind != MD_CTL || *tt != *ed)) {
+ *ed = tty_update_flag(el, *tt, ED_IO, kind);
+ *ex = tty_update_flag(el, *tt, EX_IO, kind);
+ }
+}
+
+
+private void
+tty_update_char(EditLine *el, int mode, int c) {
+ if (!((el->el_tty.t_t[mode][MD_CHAR].t_setmask & C_SH(c)))
+ && (el->el_tty.t_c[TS_IO][c] != el->el_tty.t_c[EX_IO][c]))
+ el->el_tty.t_c[mode][c] = el->el_tty.t_c[TS_IO][c];
+ if (el->el_tty.t_t[mode][MD_CHAR].t_clrmask & C_SH(c))
+ el->el_tty.t_c[mode][c] = el->el_tty.t_vdisable;
+}
+
+
/* tty_rawmode():
* Set terminal into 1 character at a time mode.
*/
@@ -910,123 +982,80 @@ tty_rawmode(EditLine *el)
{
if (el->el_tty.t_mode == ED_IO || el->el_tty.t_mode == QU_IO)
- return (0);
+ return 0;
if (el->el_flags & EDIT_DISABLED)
- return (0);
+ return 0;
if (tty_getty(el, &el->el_tty.t_ts) == -1) {
#ifdef DEBUG_TTY
- (void) fprintf(el->el_errfile, "tty_rawmode: tty_getty: %s\n",
+ (void) fprintf(el->el_errfile, "%s: tty_getty: %s\n", __func__,
strerror(errno));
#endif /* DEBUG_TTY */
- return (-1);
+ return -1;
}
/*
* We always keep up with the eight bit setting and the speed of the
- * tty. But only we only believe changes that are made to cooked mode!
+ * tty. But we only believe changes that are made to cooked mode!
*/
el->el_tty.t_eight = tty__geteightbit(&el->el_tty.t_ts);
el->el_tty.t_speed = tty__getspeed(&el->el_tty.t_ts);
- if (tty__getspeed(&el->el_tty.t_ed) != el->el_tty.t_speed) {
+ if (tty__getspeed(&el->el_tty.t_ex) != el->el_tty.t_speed ||
+ tty__getspeed(&el->el_tty.t_ed) != el->el_tty.t_speed) {
+ (void) cfsetispeed(&el->el_tty.t_ex, el->el_tty.t_speed);
+ (void) cfsetospeed(&el->el_tty.t_ex, el->el_tty.t_speed);
(void) cfsetispeed(&el->el_tty.t_ed, el->el_tty.t_speed);
(void) cfsetospeed(&el->el_tty.t_ed, el->el_tty.t_speed);
}
if (tty__cooked_mode(&el->el_tty.t_ts)) {
- if ((el->el_tty.t_ts.c_cflag != el->el_tty.t_ex.c_cflag) &&
- (el->el_tty.t_ts.c_cflag != el->el_tty.t_ed.c_cflag)) {
- el->el_tty.t_ed.c_cflag =
- el->el_tty.t_ts.c_cflag;
- el->el_tty.t_ed.c_cflag &=
- ~el->el_tty.t_t[ED_IO][MD_CTL].t_clrmask;
- el->el_tty.t_ed.c_cflag |=
- el->el_tty.t_t[ED_IO][MD_CTL].t_setmask;
- }
- if ((el->el_tty.t_ts.c_lflag != el->el_tty.t_ex.c_lflag) &&
- (el->el_tty.t_ts.c_lflag != el->el_tty.t_ed.c_lflag)) {
- el->el_tty.t_ed.c_lflag =
- el->el_tty.t_ts.c_lflag;
- el->el_tty.t_ed.c_lflag &=
- ~el->el_tty.t_t[ED_IO][MD_LIN].t_clrmask;
- el->el_tty.t_ed.c_lflag |=
- el->el_tty.t_t[ED_IO][MD_LIN].t_setmask;
- }
- if ((el->el_tty.t_ts.c_iflag != el->el_tty.t_ex.c_iflag) &&
- (el->el_tty.t_ts.c_iflag != el->el_tty.t_ed.c_iflag)) {
- el->el_tty.t_ed.c_iflag =
- el->el_tty.t_ts.c_iflag;
- el->el_tty.t_ed.c_iflag &=
- ~el->el_tty.t_t[ED_IO][MD_INP].t_clrmask;
- el->el_tty.t_ed.c_iflag |=
- el->el_tty.t_t[ED_IO][MD_INP].t_setmask;
- }
- if ((el->el_tty.t_ts.c_oflag != el->el_tty.t_ex.c_oflag) &&
- (el->el_tty.t_ts.c_oflag != el->el_tty.t_ed.c_oflag)) {
- el->el_tty.t_ed.c_oflag =
- el->el_tty.t_ts.c_oflag;
- el->el_tty.t_ed.c_oflag &=
- ~el->el_tty.t_t[ED_IO][MD_OUT].t_clrmask;
- el->el_tty.t_ed.c_oflag |=
- el->el_tty.t_t[ED_IO][MD_OUT].t_setmask;
- }
+ int i;
+
+ for (i = MD_INP; i <= MD_LIN; i++)
+ tty_update_flags(el, i);
+
if (tty__gettabs(&el->el_tty.t_ex) == 0)
el->el_tty.t_tabs = 0;
else
el->el_tty.t_tabs = EL_CAN_TAB ? 1 : 0;
- {
- int i;
+ tty__getchar(&el->el_tty.t_ts, el->el_tty.t_c[TS_IO]);
+ /*
+ * Check if the user made any changes.
+ * If he did, then propagate the changes to the
+ * edit and execute data structures.
+ */
+ for (i = 0; i < C_NCC; i++)
+ if (el->el_tty.t_c[TS_IO][i] !=
+ el->el_tty.t_c[EX_IO][i])
+ break;
- tty__getchar(&el->el_tty.t_ts, el->el_tty.t_c[TS_IO]);
+ if (i != C_NCC) {
/*
- * Check if the user made any changes.
- * If he did, then propagate the changes to the
- * edit and execute data structures.
- */
+ * Propagate changes only to the unprotected
+ * chars that have been modified just now.
+ */
for (i = 0; i < C_NCC; i++)
- if (el->el_tty.t_c[TS_IO][i] !=
- el->el_tty.t_c[EX_IO][i])
- break;
-
- if (i != C_NCC) {
- /*
- * Propagate changes only to the unprotected
- * chars that have been modified just now.
- */
- for (i = 0; i < C_NCC; i++) {
- if (!((el->el_tty.t_t[ED_IO][MD_CHAR].t_setmask & C_SH(i)))
- && (el->el_tty.t_c[TS_IO][i] != el->el_tty.t_c[EX_IO][i]))
- el->el_tty.t_c[ED_IO][i] = el->el_tty.t_c[TS_IO][i];
- if (el->el_tty.t_t[ED_IO][MD_CHAR].t_clrmask & C_SH(i))
- el->el_tty.t_c[ED_IO][i] = el->el_tty.t_vdisable;
- }
- tty_bind_char(el, 0);
- tty__setchar(&el->el_tty.t_ed, el->el_tty.t_c[ED_IO]);
-
- for (i = 0; i < C_NCC; i++) {
- if (!((el->el_tty.t_t[EX_IO][MD_CHAR].t_setmask & C_SH(i)))
- && (el->el_tty.t_c[TS_IO][i] != el->el_tty.t_c[EX_IO][i]))
- el->el_tty.t_c[EX_IO][i] = el->el_tty.t_c[TS_IO][i];
- if (el->el_tty.t_t[EX_IO][MD_CHAR].t_clrmask & C_SH(i))
- el->el_tty.t_c[EX_IO][i] = el->el_tty.t_vdisable;
- }
- }
- }
- }
+ tty_update_char(el, ED_IO, i);
- if (el->el_tty.t_mode == EX_IO)
- el->el_tty.t_ex = el->el_tty.t_ts;
+ tty_bind_char(el, 0);
+ tty__setchar(&el->el_tty.t_ed, el->el_tty.t_c[ED_IO]);
+
+ for (i = 0; i < C_NCC; i++)
+ tty_update_char(el, EX_IO, i);
+ tty__setchar(&el->el_tty.t_ex, el->el_tty.t_c[EX_IO]);
+ }
+ }
if (tty_setty(el, TCSADRAIN, &el->el_tty.t_ed) == -1) {
#ifdef DEBUG_TTY
- (void) fprintf(el->el_errfile, "tty_rawmode: tty_setty: %s\n",
+ (void) fprintf(el->el_errfile, "%s: tty_setty: %s\n", __func__,
strerror(errno));
#endif /* DEBUG_TTY */
- return (-1);
+ return -1;
}
el->el_tty.t_mode = ED_IO;
- return (0);
+ return 0;
}
@@ -1038,21 +1067,20 @@ tty_cookedmode(EditLine *el)
{ /* set tty in normal setup */
if (el->el_tty.t_mode == EX_IO)
- return (0);
+ return 0;
if (el->el_flags & EDIT_DISABLED)
- return (0);
+ return 0;
if (tty_setty(el, TCSADRAIN, &el->el_tty.t_ex) == -1) {
#ifdef DEBUG_TTY
- (void) fprintf(el->el_errfile,
- "tty_cookedmode: tty_setty: %s\n",
+ (void) fprintf(el->el_errfile, "%s: tty_setty: %s\n", __func__,
strerror(errno));
#endif /* DEBUG_TTY */
- return (-1);
+ return -1;
}
el->el_tty.t_mode = EX_IO;
- return (0);
+ return 0;
}
@@ -1063,31 +1091,21 @@ protected int
tty_quotemode(EditLine *el)
{
if (el->el_tty.t_mode == QU_IO)
- return (0);
+ return 0;
el->el_tty.t_qu = el->el_tty.t_ed;
- el->el_tty.t_qu.c_iflag &= ~el->el_tty.t_t[QU_IO][MD_INP].t_clrmask;
- el->el_tty.t_qu.c_iflag |= el->el_tty.t_t[QU_IO][MD_INP].t_setmask;
-
- el->el_tty.t_qu.c_oflag &= ~el->el_tty.t_t[QU_IO][MD_OUT].t_clrmask;
- el->el_tty.t_qu.c_oflag |= el->el_tty.t_t[QU_IO][MD_OUT].t_setmask;
-
- el->el_tty.t_qu.c_cflag &= ~el->el_tty.t_t[QU_IO][MD_CTL].t_clrmask;
- el->el_tty.t_qu.c_cflag |= el->el_tty.t_t[QU_IO][MD_CTL].t_setmask;
-
- el->el_tty.t_qu.c_lflag &= ~el->el_tty.t_t[QU_IO][MD_LIN].t_clrmask;
- el->el_tty.t_qu.c_lflag |= el->el_tty.t_t[QU_IO][MD_LIN].t_setmask;
+ tty_setup_flags(el, &el->el_tty.t_qu, QU_IO);
if (tty_setty(el, TCSADRAIN, &el->el_tty.t_qu) == -1) {
#ifdef DEBUG_TTY
- (void) fprintf(el->el_errfile, "QuoteModeOn: tty_setty: %s\n",
+ (void) fprintf(el->el_errfile, "%s: tty_setty: %s\n", __func__,
strerror(errno));
#endif /* DEBUG_TTY */
- return (-1);
+ return -1;
}
el->el_tty.t_mode = QU_IO;
- return (0);
+ return 0;
}
@@ -1099,16 +1117,16 @@ tty_noquotemode(EditLine *el)
{
if (el->el_tty.t_mode != QU_IO)
- return (0);
+ return 0;
if (tty_setty(el, TCSADRAIN, &el->el_tty.t_ed) == -1) {
#ifdef DEBUG_TTY
- (void) fprintf(el->el_errfile, "QuoteModeOff: tty_setty: %s\n",
+ (void) fprintf(el->el_errfile, "%s: tty_setty: %s\n", __func__,
strerror(errno));
#endif /* DEBUG_TTY */
- return (-1);
+ return -1;
}
el->el_tty.t_mode = ED_IO;
- return (0);
+ return 0;
}
@@ -1117,19 +1135,20 @@ tty_noquotemode(EditLine *el)
*/
protected int
/*ARGSUSED*/
-tty_stty(EditLine *el, int argc __unused, const char **argv)
+tty_stty(EditLine *el, int argc __attribute__((__unused__)), const Char **argv)
{
const ttymodes_t *m;
char x;
int aflag = 0;
- const char *s, *d;
- const char *name;
+ const Char *s, *d;
+ char name[EL_BUFSIZ];
struct termios *tios = &el->el_tty.t_ex;
int z = EX_IO;
if (argv == NULL)
- return (-1);
- name = *argv++;
+ return -1;
+ strncpy(name, ct_encode_string(*argv++, &el->el_scratch), sizeof(name));
+ name[sizeof(name) - 1] = '\0';
while (argv && *argv && argv[0][0] == '-' && argv[0][2] == '\0')
switch (argv[0][1]) {
@@ -1154,9 +1173,9 @@ tty_stty(EditLine *el, int argc __unused, const char **argv)
break;
default:
(void) fprintf(el->el_errfile,
- "%s: Unknown switch `%c'.\n",
- name, argv[0][1]);
- return (-1);
+ "%s: Unknown switch `" FCHAR "'.\n",
+ name, (Int)argv[0][1]);
+ return -1;
}
if (!argv || !*argv) {
@@ -1174,8 +1193,9 @@ tty_stty(EditLine *el, int argc __unused, const char **argv)
if (i != -1) {
x = (el->el_tty.t_t[z][i].t_setmask & m->m_value)
? '+' : '\0';
- x = (el->el_tty.t_t[z][i].t_clrmask & m->m_value)
- ? '-' : x;
+
+ if (el->el_tty.t_t[z][i].t_clrmask & m->m_value)
+ x = '-';
} else {
x = '\0';
}
@@ -1184,7 +1204,8 @@ tty_stty(EditLine *el, int argc __unused, const char **argv)
cu = strlen(m->m_name) + (x != '\0') + 1;
- if (len + cu >= (size_t)el->el_term.t_size.h) {
+ if (len + cu >=
+ (size_t)el->el_terminal.t_size.h) {
(void) fprintf(el->el_outfile, "\n%*s",
(int)st, "");
len = st + cu;
@@ -1200,41 +1221,43 @@ tty_stty(EditLine *el, int argc __unused, const char **argv)
}
}
(void) fprintf(el->el_outfile, "\n");
- return (0);
+ return 0;
}
while (argv && (s = *argv++)) {
- const char *p;
+ const Char *p;
switch (*s) {
case '+':
case '-':
- x = *s++;
+ x = (char)*s++;
break;
default:
x = '\0';
break;
}
d = s;
- p = strchr(s, '=');
+ p = Strchr(s, '=');
for (m = ttymodes; m->m_name; m++)
- if ((p ? strncmp(m->m_name, d, (size_t)(p - d)) :
- strcmp(m->m_name, d)) == 0 &&
+ if ((p ? strncmp(m->m_name, ct_encode_string(d,
+ &el->el_scratch), (size_t)(p - d)) :
+ strcmp(m->m_name, ct_encode_string(d,
+ &el->el_scratch))) == 0 &&
(p == NULL || m->m_type == MD_CHAR))
break;
if (!m->m_name) {
(void) fprintf(el->el_errfile,
- "%s: Invalid argument `%s'.\n", name, d);
- return (-1);
+ "%s: Invalid argument `" FSTR "'.\n", name, d);
+ return -1;
}
if (p) {
int c = ffs((int)m->m_value);
- int v = *++p ? parse__escape((const char **) &p) :
+ int v = *++p ? parse__escape(&p) :
el->el_tty.t_vdisable;
assert(c != 0);
c--;
c = tty__getcharindex(c);
assert(c != -1);
- tios->c_cc[c] = v;
+ tios->c_cc[c] = (cc_t)v;
continue;
}
switch (x) {
@@ -1253,17 +1276,18 @@ tty_stty(EditLine *el, int argc __unused, const char **argv)
}
}
+ tty_setup_flags(el, tios, z);
if (el->el_tty.t_mode == z) {
if (tty_setty(el, TCSADRAIN, tios) == -1) {
#ifdef DEBUG_TTY
- (void) fprintf(el->el_errfile,
- "tty_stty: tty_setty: %s\n", strerror(errno));
+ (void) fprintf(el->el_errfile, "%s: tty_setty: %s\n",
+ __func__, strerror(errno));
#endif /* DEBUG_TTY */
- return (-1);
+ return -1;
}
}
- return (0);
+ return 0;
}
@@ -1290,3 +1314,14 @@ tty_printchar(EditLine *el, unsigned char *s)
(void) fprintf(el->el_errfile, "\n");
}
#endif /* notyet */
+
+
+private void
+tty_setup_flags(EditLine *el, struct termios *tios, int mode)
+{
+ int kind;
+ for (kind = MD_INP; kind <= MD_LIN; kind++) {
+ tcflag_t *f = tty__get_flag(tios, kind);
+ *f = tty_update_flag(el, *f, mode, kind);
+ }
+}
diff --git a/lib/libedit/tty.h b/lib/libedit/tty.h
index 3a4e94a..b1fc76e 100644
--- a/lib/libedit/tty.h
+++ b/lib/libedit/tty.h
@@ -1,3 +1,5 @@
+/* $NetBSD: tty.h,v 1.15 2014/05/19 19:54:12 christos Exp $ */
+
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -30,7 +32,6 @@
* SUCH DAMAGE.
*
* @(#)tty.h 8.1 (Berkeley) 6/4/93
- * $NetBSD: tty.h,v 1.11 2005/06/01 11:37:52 lukem Exp $
* $FreeBSD$
*/
@@ -40,6 +41,7 @@
#ifndef _h_el_tty
#define _h_el_tty
+#include "sys.h"
#include "histedit.h"
#include <termios.h>
#include <unistd.h>
@@ -430,7 +432,7 @@
#define C_MIN 23
#define C_TIME 24
#define C_NCC 25
-#define C_SH(A) (1 << (A))
+#define C_SH(A) ((unsigned int)(1 << (A)))
/*
* Terminal dependend data structures
@@ -441,6 +443,7 @@
#define QU_IO 2 /* used only for quoted chars */
#define NN_IO 3 /* The number of entries */
+/* Don't re-order */
#define MD_INP 0
#define MD_OUT 1
#define MD_CTL 2
@@ -458,7 +461,7 @@ typedef unsigned char ttychar_t[NN_IO][C_NCC];
protected int tty_init(EditLine *);
protected void tty_end(EditLine *);
-protected int tty_stty(EditLine *, int, const char **);
+protected int tty_stty(EditLine *, int, const Char **);
protected int tty_rawmode(EditLine *);
protected int tty_cookedmode(EditLine *);
protected int tty_quotemode(EditLine *);
@@ -468,7 +471,7 @@ protected void tty_bind_char(EditLine *, int);
typedef struct {
ttyperm_t t_t;
ttychar_t t_c;
- struct termios t_ex, t_ed, t_ts;
+ struct termios t_or, t_ex, t_ed, t_ts;
int t_tabs;
int t_eight;
speed_t t_speed;
diff --git a/lib/libedit/vi.c b/lib/libedit/vi.c
index 4826901..dfd17e3 100644
--- a/lib/libedit/vi.c
+++ b/lib/libedit/vi.c
@@ -1,3 +1,5 @@
+/* $NetBSD: vi.c,v 1.45 2014/06/18 18:12:28 christos Exp $ */
+
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -28,12 +30,20 @@
* 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.
- *
- * $NetBSD: vi.c,v 1.30 2009/02/21 23:31:56 christos Exp $
*/
+#include "config.h"
+#include <stdlib.h>
+#include <unistd.h>
+#include <limits.h>
+#include <sys/wait.h>
+
#if !defined(lint) && !defined(SCCSID)
+#if 0
static char sccsid[] = "@(#)vi.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: vi.c,v 1.45 2014/06/18 18:12:28 christos Exp $");
+#endif
#endif /* not lint && not SCCSID */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
@@ -41,23 +51,21 @@ __FBSDID("$FreeBSD$");
/*
* vi.c: Vi mode commands.
*/
-#include <sys/wait.h>
-#include "sys.h"
#include "el.h"
-private el_action_t cv_action(EditLine *, int);
-private el_action_t cv_paste(EditLine *, int);
+private el_action_t cv_action(EditLine *, Int);
+private el_action_t cv_paste(EditLine *, Int);
/* cv_action():
* Handle vi actions.
*/
private el_action_t
-cv_action(EditLine *el, int c)
+cv_action(EditLine *el, Int c)
{
if (el->el_chared.c_vcmd.action != NOP) {
/* 'cc', 'dd' and (possibly) friends */
- if (c != el->el_chared.c_vcmd.action)
+ if (c != (Int)el->el_chared.c_vcmd.action)
return CC_ERROR;
if (!(c & YANK))
@@ -73,24 +81,24 @@ cv_action(EditLine *el, int c)
if (c & INSERT)
el->el_map.current = el->el_map.key;
- return (CC_REFRESH);
+ return CC_REFRESH;
}
el->el_chared.c_vcmd.pos = el->el_line.cursor;
el->el_chared.c_vcmd.action = c;
- return (CC_ARGHACK);
+ return CC_ARGHACK;
}
/* cv_paste():
* Paste previous deletion before or after the cursor
*/
private el_action_t
-cv_paste(EditLine *el, int c)
+cv_paste(EditLine *el, Int c)
{
c_kill_t *k = &el->el_chared.c_kill;
size_t len = (size_t)(k->last - k->buf);
if (k->buf == NULL || len == 0)
- return (CC_ERROR);
+ return CC_ERROR;
#ifdef DEBUG_PASTE
(void) fprintf(el->el_errfile, "Paste: \"%.*s\"\n", (int)len, k->buf);
#endif
@@ -102,10 +110,11 @@ cv_paste(EditLine *el, int c)
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);
+ return CC_ERROR;
+ (void) memcpy(el->el_line.cursor, k->buf, len *
+ sizeof(*el->el_line.cursor));
- return (CC_REFRESH);
+ return CC_REFRESH;
}
@@ -115,10 +124,10 @@ cv_paste(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-vi_paste_next(EditLine *el, int c __unused)
+vi_paste_next(EditLine *el, Int c __attribute__((__unused__)))
{
- return (cv_paste(el, 0));
+ return cv_paste(el, 0);
}
@@ -128,10 +137,10 @@ vi_paste_next(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-vi_paste_prev(EditLine *el, int c __unused)
+vi_paste_prev(EditLine *el, Int c __attribute__((__unused__)))
{
- return (cv_paste(el, 1));
+ return cv_paste(el, 1);
}
@@ -141,11 +150,11 @@ vi_paste_prev(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-vi_prev_big_word(EditLine *el, int c)
+vi_prev_big_word(EditLine *el, Int c __attribute__((__unused__)))
{
if (el->el_line.cursor == el->el_line.buffer)
- return (CC_ERROR);
+ return CC_ERROR;
el->el_line.cursor = cv_prev_word(el->el_line.cursor,
el->el_line.buffer,
@@ -154,9 +163,9 @@ vi_prev_big_word(EditLine *el, int c)
if (el->el_chared.c_vcmd.action != NOP) {
cv_delfini(el);
- return (CC_REFRESH);
+ return CC_REFRESH;
}
- return (CC_CURSOR);
+ return CC_CURSOR;
}
@@ -166,11 +175,11 @@ vi_prev_big_word(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-vi_prev_word(EditLine *el, int c __unused)
+vi_prev_word(EditLine *el, Int c __attribute__((__unused__)))
{
if (el->el_line.cursor == el->el_line.buffer)
- return (CC_ERROR);
+ return CC_ERROR;
el->el_line.cursor = cv_prev_word(el->el_line.cursor,
el->el_line.buffer,
@@ -179,9 +188,9 @@ vi_prev_word(EditLine *el, int c __unused)
if (el->el_chared.c_vcmd.action != NOP) {
cv_delfini(el);
- return (CC_REFRESH);
+ return CC_REFRESH;
}
- return (CC_CURSOR);
+ return CC_CURSOR;
}
@@ -191,11 +200,11 @@ vi_prev_word(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-vi_next_big_word(EditLine *el, int c)
+vi_next_big_word(EditLine *el, Int c __attribute__((__unused__)))
{
if (el->el_line.cursor >= el->el_line.lastchar - 1)
- return (CC_ERROR);
+ return CC_ERROR;
el->el_line.cursor = cv_next_word(el, el->el_line.cursor,
el->el_line.lastchar, el->el_state.argument, cv__isWord);
@@ -203,9 +212,9 @@ vi_next_big_word(EditLine *el, int c)
if (el->el_map.type == MAP_VI)
if (el->el_chared.c_vcmd.action != NOP) {
cv_delfini(el);
- return (CC_REFRESH);
+ return CC_REFRESH;
}
- return (CC_CURSOR);
+ return CC_CURSOR;
}
@@ -215,11 +224,11 @@ vi_next_big_word(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-vi_next_word(EditLine *el, int c __unused)
+vi_next_word(EditLine *el, Int c __attribute__((__unused__)))
{
if (el->el_line.cursor >= el->el_line.lastchar - 1)
- return (CC_ERROR);
+ return CC_ERROR;
el->el_line.cursor = cv_next_word(el, el->el_line.cursor,
el->el_line.lastchar, el->el_state.argument, cv__isword);
@@ -227,9 +236,9 @@ vi_next_word(EditLine *el, int c __unused)
if (el->el_map.type == MAP_VI)
if (el->el_chared.c_vcmd.action != NOP) {
cv_delfini(el);
- return (CC_REFRESH);
+ return CC_REFRESH;
}
- return (CC_CURSOR);
+ return CC_CURSOR;
}
@@ -238,20 +247,20 @@ vi_next_word(EditLine *el, int c __unused)
* [~]
*/
protected el_action_t
-vi_change_case(EditLine *el, int c)
+vi_change_case(EditLine *el, Int c)
{
int i;
if (el->el_line.cursor >= el->el_line.lastchar)
- return (CC_ERROR);
+ return CC_ERROR;
cv_undo(el);
for (i = 0; i < el->el_state.argument; i++) {
- c = *(unsigned char *)el->el_line.cursor;
- if (isupper(c))
- *el->el_line.cursor = tolower(c);
- else if (islower(c))
- *el->el_line.cursor = toupper(c);
+ c = *el->el_line.cursor;
+ if (Isupper(c))
+ *el->el_line.cursor = Tolower(c);
+ else if (Islower(c))
+ *el->el_line.cursor = Toupper(c);
if (++el->el_line.cursor >= el->el_line.lastchar) {
el->el_line.cursor--;
@@ -270,14 +279,14 @@ vi_change_case(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-vi_change_meta(EditLine *el, int c __unused)
+vi_change_meta(EditLine *el, Int c __attribute__((__unused__)))
{
/*
* Delete with insert == change: first we delete and then we leave in
* insert mode.
*/
- return (cv_action(el, DELETE | INSERT));
+ return cv_action(el, DELETE | INSERT);
}
@@ -287,13 +296,13 @@ vi_change_meta(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-vi_insert_at_bol(EditLine *el, int c __unused)
+vi_insert_at_bol(EditLine *el, Int c __attribute__((__unused__)))
{
el->el_line.cursor = el->el_line.buffer;
cv_undo(el);
el->el_map.current = el->el_map.key;
- return (CC_CURSOR);
+ return CC_CURSOR;
}
@@ -303,7 +312,7 @@ vi_insert_at_bol(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-vi_replace_char(EditLine *el, int c __unused)
+vi_replace_char(EditLine *el, Int c __attribute__((__unused__)))
{
if (el->el_line.cursor >= el->el_line.lastchar)
@@ -312,7 +321,7 @@ vi_replace_char(EditLine *el, int c __unused)
el->el_map.current = el->el_map.key;
el->el_state.inputmode = MODE_REPLACE_1;
cv_undo(el);
- return (CC_ARGHACK);
+ return CC_ARGHACK;
}
@@ -322,13 +331,13 @@ vi_replace_char(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-vi_replace_mode(EditLine *el, int c __unused)
+vi_replace_mode(EditLine *el, Int c __attribute__((__unused__)))
{
el->el_map.current = el->el_map.key;
el->el_state.inputmode = MODE_REPLACE;
cv_undo(el);
- return (CC_NORM);
+ return CC_NORM;
}
@@ -338,12 +347,12 @@ vi_replace_mode(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-vi_substitute_char(EditLine *el, int c __unused)
+vi_substitute_char(EditLine *el, Int c __attribute__((__unused__)))
{
c_delafter(el, el->el_state.argument);
el->el_map.current = el->el_map.key;
- return (CC_REFRESH);
+ return CC_REFRESH;
}
@@ -353,7 +362,7 @@ vi_substitute_char(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-vi_substitute_line(EditLine *el, int c __unused)
+vi_substitute_line(EditLine *el, Int c __attribute__((__unused__)))
{
cv_undo(el);
@@ -361,7 +370,7 @@ vi_substitute_line(EditLine *el, int c __unused)
(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);
+ return CC_REFRESH;
}
@@ -371,7 +380,7 @@ vi_substitute_line(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-vi_change_to_eol(EditLine *el, int c __unused)
+vi_change_to_eol(EditLine *el, Int c __attribute__((__unused__)))
{
cv_undo(el);
@@ -379,7 +388,7 @@ vi_change_to_eol(EditLine *el, int c __unused)
(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);
+ return CC_REFRESH;
}
@@ -389,12 +398,12 @@ vi_change_to_eol(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-vi_insert(EditLine *el, int c __unused)
+vi_insert(EditLine *el, Int c __attribute__((__unused__)))
{
el->el_map.current = el->el_map.key;
cv_undo(el);
- return (CC_NORM);
+ return CC_NORM;
}
@@ -404,7 +413,7 @@ vi_insert(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-vi_add(EditLine *el, int c __unused)
+vi_add(EditLine *el, Int c __attribute__((__unused__)))
{
int ret;
@@ -419,7 +428,7 @@ vi_add(EditLine *el, int c __unused)
cv_undo(el);
- return (ret);
+ return (el_action_t)ret;
}
@@ -429,13 +438,13 @@ vi_add(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-vi_add_at_eol(EditLine *el, int c __unused)
+vi_add_at_eol(EditLine *el, Int c __attribute__((__unused__)))
{
el->el_map.current = el->el_map.key;
el->el_line.cursor = el->el_line.lastchar;
cv_undo(el);
- return (CC_CURSOR);
+ return CC_CURSOR;
}
@@ -445,10 +454,10 @@ vi_add_at_eol(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-vi_delete_meta(EditLine *el, int c __unused)
+vi_delete_meta(EditLine *el, Int c __attribute__((__unused__)))
{
- return (cv_action(el, DELETE));
+ return cv_action(el, DELETE);
}
@@ -458,11 +467,11 @@ vi_delete_meta(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-vi_end_big_word(EditLine *el, int c)
+vi_end_big_word(EditLine *el, Int c __attribute__((__unused__)))
{
if (el->el_line.cursor == el->el_line.lastchar)
- return (CC_ERROR);
+ return CC_ERROR;
el->el_line.cursor = cv__endword(el->el_line.cursor,
el->el_line.lastchar, el->el_state.argument, cv__isWord);
@@ -470,9 +479,9 @@ vi_end_big_word(EditLine *el, int c)
if (el->el_chared.c_vcmd.action != NOP) {
el->el_line.cursor++;
cv_delfini(el);
- return (CC_REFRESH);
+ return CC_REFRESH;
}
- return (CC_CURSOR);
+ return CC_CURSOR;
}
@@ -482,11 +491,11 @@ vi_end_big_word(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-vi_end_word(EditLine *el, int c __unused)
+vi_end_word(EditLine *el, Int c __attribute__((__unused__)))
{
if (el->el_line.cursor == el->el_line.lastchar)
- return (CC_ERROR);
+ return CC_ERROR;
el->el_line.cursor = cv__endword(el->el_line.cursor,
el->el_line.lastchar, el->el_state.argument, cv__isword);
@@ -494,9 +503,9 @@ vi_end_word(EditLine *el, int c __unused)
if (el->el_chared.c_vcmd.action != NOP) {
el->el_line.cursor++;
cv_delfini(el);
- return (CC_REFRESH);
+ return CC_REFRESH;
}
- return (CC_CURSOR);
+ return CC_CURSOR;
}
@@ -506,7 +515,7 @@ vi_end_word(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-vi_undo(EditLine *el, int c __unused)
+vi_undo(EditLine *el, Int c __attribute__((__unused__)))
{
c_undo_t un = el->el_chared.c_undo;
@@ -523,7 +532,7 @@ vi_undo(EditLine *el, int c __unused)
el->el_line.cursor = un.buf + un.cursor;
el->el_line.lastchar = un.buf + un.len;
- return (CC_REFRESH);
+ return CC_REFRESH;
}
@@ -533,7 +542,7 @@ vi_undo(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-vi_command_mode(EditLine *el, int c __unused)
+vi_command_mode(EditLine *el, Int c __attribute__((__unused__)))
{
/* [Esc] cancels pending action */
@@ -548,7 +557,7 @@ vi_command_mode(EditLine *el, int c __unused)
if (el->el_line.cursor > el->el_line.buffer)
el->el_line.cursor--;
#endif
- return (CC_CURSOR);
+ return CC_CURSOR;
}
@@ -557,7 +566,7 @@ vi_command_mode(EditLine *el, int c __unused)
* [0]
*/
protected el_action_t
-vi_zero(EditLine *el, int c)
+vi_zero(EditLine *el, Int c)
{
if (el->el_state.doingarg)
@@ -566,9 +575,9 @@ vi_zero(EditLine *el, int c)
el->el_line.cursor = el->el_line.buffer;
if (el->el_chared.c_vcmd.action != NOP) {
cv_delfini(el);
- return (CC_REFRESH);
+ return CC_REFRESH;
}
- return (CC_CURSOR);
+ return CC_CURSOR;
}
@@ -578,15 +587,15 @@ vi_zero(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-vi_delete_prev_char(EditLine *el, int c __unused)
+vi_delete_prev_char(EditLine *el, Int c __attribute__((__unused__)))
{
if (el->el_line.cursor <= el->el_line.buffer)
- return (CC_ERROR);
+ return CC_ERROR;
c_delbefore1(el);
el->el_line.cursor--;
- return (CC_REFRESH);
+ return CC_REFRESH;
}
@@ -596,32 +605,32 @@ vi_delete_prev_char(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-vi_list_or_eof(EditLine *el, int c)
+vi_list_or_eof(EditLine *el, Int c)
{
if (el->el_line.cursor == el->el_line.lastchar) {
if (el->el_line.cursor == el->el_line.buffer) {
- term_writec(el, c); /* then do a EOF */
- return (CC_EOF);
+ terminal_writec(el, c); /* then do a EOF */
+ return CC_EOF;
} else {
/*
* Here we could list completions, but it is an
* error right now
*/
- term_beep(el);
- return (CC_ERROR);
+ terminal_beep(el);
+ return CC_ERROR;
}
} else {
#ifdef notyet
re_goto_bottom(el);
*el->el_line.lastchar = '\0'; /* just in case */
- return (CC_LIST_CHOICES);
+ return CC_LIST_CHOICES;
#else
/*
* Just complain for now.
*/
- term_beep(el);
- return (CC_ERROR);
+ terminal_beep(el);
+ return CC_ERROR;
#endif
}
}
@@ -633,9 +642,9 @@ vi_list_or_eof(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-vi_kill_line_prev(EditLine *el, int c __unused)
+vi_kill_line_prev(EditLine *el, Int c __attribute__((__unused__)))
{
- char *kp, *cp;
+ Char *kp, *cp;
cp = el->el_line.buffer;
kp = el->el_chared.c_kill.buf;
@@ -644,7 +653,7 @@ vi_kill_line_prev(EditLine *el, int c __unused)
el->el_chared.c_kill.last = kp;
c_delbefore(el, (int)(el->el_line.cursor - el->el_line.buffer));
el->el_line.cursor = el->el_line.buffer; /* zap! */
- return (CC_REFRESH);
+ return CC_REFRESH;
}
@@ -654,10 +663,10 @@ vi_kill_line_prev(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-vi_search_prev(EditLine *el, int c __unused)
+vi_search_prev(EditLine *el, Int c __attribute__((__unused__)))
{
- return (cv_search(el, ED_SEARCH_PREV_HISTORY));
+ return cv_search(el, ED_SEARCH_PREV_HISTORY);
}
@@ -667,10 +676,10 @@ vi_search_prev(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-vi_search_next(EditLine *el, int c __unused)
+vi_search_next(EditLine *el, Int c __attribute__((__unused__)))
{
- return (cv_search(el, ED_SEARCH_NEXT_HISTORY));
+ return cv_search(el, ED_SEARCH_NEXT_HISTORY);
}
@@ -680,13 +689,13 @@ vi_search_next(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-vi_repeat_search_next(EditLine *el, int c __unused)
+vi_repeat_search_next(EditLine *el, Int c __attribute__((__unused__)))
{
if (el->el_search.patlen == 0)
- return (CC_ERROR);
+ return CC_ERROR;
else
- return (cv_repeat_srch(el, el->el_search.patdir));
+ return cv_repeat_srch(el, el->el_search.patdir);
}
@@ -696,11 +705,11 @@ vi_repeat_search_next(EditLine *el, int c __unused)
*/
/*ARGSUSED*/
protected el_action_t
-vi_repeat_search_prev(EditLine *el, int c __unused)
+vi_repeat_search_prev(EditLine *el, Int c __attribute__((__unused__)))
{
if (el->el_search.patlen == 0)
- return (CC_ERROR);
+ return CC_ERROR;
else
return (cv_repeat_srch(el,
el->el_search.patdir == ED_SEARCH_PREV_HISTORY ?
@@ -714,7 +723,7 @@ vi_repeat_search_prev(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-vi_next_char(EditLine *el, int c __unused)
+vi_next_char(EditLine *el, Int c __attribute__((__unused__)))
{
return cv_csearch(el, CHAR_FWD, -1, el->el_state.argument, 0);
}
@@ -726,7 +735,7 @@ vi_next_char(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-vi_prev_char(EditLine *el, int c __unused)
+vi_prev_char(EditLine *el, Int c __attribute__((__unused__)))
{
return cv_csearch(el, CHAR_BACK, -1, el->el_state.argument, 0);
}
@@ -738,7 +747,7 @@ vi_prev_char(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-vi_to_next_char(EditLine *el, int c __unused)
+vi_to_next_char(EditLine *el, Int c __attribute__((__unused__)))
{
return cv_csearch(el, CHAR_FWD, -1, el->el_state.argument, 1);
}
@@ -750,7 +759,7 @@ vi_to_next_char(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-vi_to_prev_char(EditLine *el, int c __unused)
+vi_to_prev_char(EditLine *el, Int c __attribute__((__unused__)))
{
return cv_csearch(el, CHAR_BACK, -1, el->el_state.argument, 1);
}
@@ -762,7 +771,7 @@ vi_to_prev_char(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-vi_repeat_next_char(EditLine *el, int c __unused)
+vi_repeat_next_char(EditLine *el, Int c __attribute__((__unused__)))
{
return cv_csearch(el, el->el_search.chadir, el->el_search.chacha,
@@ -776,7 +785,7 @@ vi_repeat_next_char(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-vi_repeat_prev_char(EditLine *el, int c __unused)
+vi_repeat_prev_char(EditLine *el, Int c __attribute__((__unused__)))
{
el_action_t r;
int dir = el->el_search.chadir;
@@ -794,20 +803,20 @@ vi_repeat_prev_char(EditLine *el, int c __unused)
*/
protected el_action_t
/*ARGSUSED*/
-vi_match(EditLine *el, int c)
+vi_match(EditLine *el, Int c __attribute__((__unused__)))
{
- const char match_chars[] = "()[]{}";
- char *cp;
+ const Char match_chars[] = STR("()[]{}");
+ Char *cp;
size_t delta, i, count;
- char o_ch, c_ch;
+ Char o_ch, c_ch;
*el->el_line.lastchar = '\0'; /* just in case */
- i = strcspn(el->el_line.cursor, match_chars);
+ i = Strcspn(el->el_line.cursor, match_chars);
o_ch = el->el_line.cursor[i];
if (o_ch == 0)
return CC_ERROR;
- delta = strchr(match_chars, o_ch) - match_chars;
+ delta = (size_t)(Strchr(match_chars, o_ch) - match_chars);
c_ch = match_chars[delta ^ 1];
count = 1;
delta = 1 - (delta & 1) * 2;
@@ -830,9 +839,9 @@ vi_match(EditLine *el, int c)
if (delta > 0)
el->el_line.cursor++;
cv_delfini(el);
- return (CC_REFRESH);
+ return CC_REFRESH;
}
- return (CC_CURSOR);
+ return CC_CURSOR;
}
/* vi_undo_line():
@@ -841,7 +850,7 @@ vi_match(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-vi_undo_line(EditLine *el, int c)
+vi_undo_line(EditLine *el, Int c __attribute__((__unused__)))
{
cv_undo(el);
@@ -855,7 +864,7 @@ vi_undo_line(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-vi_to_column(EditLine *el, int c)
+vi_to_column(EditLine *el, Int c __attribute__((__unused__)))
{
el->el_line.cursor = el->el_line.buffer;
@@ -869,7 +878,7 @@ vi_to_column(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-vi_yank_end(EditLine *el, int c)
+vi_yank_end(EditLine *el, Int c __attribute__((__unused__)))
{
cv_yank(el, el->el_line.cursor,
@@ -883,7 +892,7 @@ vi_yank_end(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-vi_yank(EditLine *el, int c)
+vi_yank(EditLine *el, Int c __attribute__((__unused__)))
{
return cv_action(el, YANK);
@@ -895,7 +904,7 @@ vi_yank(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-vi_comment_out(EditLine *el, int c)
+vi_comment_out(EditLine *el, Int c __attribute__((__unused__)))
{
el->el_line.cursor = el->el_line.buffer;
@@ -913,30 +922,24 @@ vi_comment_out(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-vi_alias(EditLine *el, int c)
+vi_alias(EditLine *el, Int c __attribute__((__unused__)))
{
-#ifdef __weak_extern
char alias_name[3];
- char *alias_text;
- extern char *get_alias_text(const char *);
- __weak_extern(get_alias_text);
+ const char *alias_text;
- if (get_alias_text == 0) {
+ if (el->el_chared.c_aliasfun == NULL)
return CC_ERROR;
- }
alias_name[0] = '_';
alias_name[2] = 0;
if (el_getc(el, &alias_name[1]) != 1)
return CC_ERROR;
- alias_text = get_alias_text(alias_name);
+ alias_text = (*el->el_chared.c_aliasfun)(el->el_chared.c_aliasarg,
+ alias_name);
if (alias_text != NULL)
- el_push(el, alias_text);
+ FUN(el,push)(el, ct_decode_string(alias_text, &el->el_scratch));
return CC_NORM;
-#else
- return CC_ERROR;
-#endif
}
/* vi_to_history_line():
@@ -945,14 +948,14 @@ vi_alias(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-vi_to_history_line(EditLine *el, int c)
+vi_to_history_line(EditLine *el, Int c __attribute__((__unused__)))
{
int sv_event_no = el->el_history.eventno;
el_action_t rval;
if (el->el_history.eventno == 0) {
- (void) strncpy(el->el_history.buf, el->el_line.buffer,
+ (void) Strncpy(el->el_history.buf, el->el_line.buffer,
EL_BUFSIZ);
el->el_history.last = el->el_history.buf +
(el->el_line.lastchar - el->el_line.buffer);
@@ -990,14 +993,16 @@ vi_to_history_line(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-vi_histedit(EditLine *el, int c)
+vi_histedit(EditLine *el, Int c __attribute__((__unused__)))
{
int fd;
pid_t pid;
ssize_t st;
int status;
char tempfile[] = "/tmp/histedit.XXXXXXXXXX";
- char *cp;
+ char *cp = NULL;
+ size_t len;
+ Char *line = NULL;
if (el->el_state.doingarg) {
if (vi_to_history_line(el, 0) == CC_ERROR)
@@ -1007,15 +1012,25 @@ vi_histedit(EditLine *el, int c)
fd = mkstemp(tempfile);
if (fd < 0)
return CC_ERROR;
- cp = el->el_line.buffer;
- write(fd, cp, (size_t)(el->el_line.lastchar - cp));
- write(fd, "\n", 1);
+ len = (size_t)(el->el_line.lastchar - el->el_line.buffer);
+#define TMP_BUFSIZ (EL_BUFSIZ * MB_LEN_MAX)
+ cp = el_malloc(TMP_BUFSIZ * sizeof(*cp));
+ if (cp == NULL)
+ goto error;
+ line = el_malloc(len * sizeof(*line) + 1);
+ if (line == NULL)
+ goto error;
+ Strncpy(line, el->el_line.buffer, len);
+ line[len] = '\0';
+ ct_wcstombs(cp, line, TMP_BUFSIZ - 1);
+ cp[TMP_BUFSIZ - 1] = '\0';
+ len = strlen(cp);
+ write(fd, cp, len);
+ write(fd, "\n", (size_t)1);
pid = fork();
switch (pid) {
case -1:
- close(fd);
- unlink(tempfile);
- return CC_ERROR;
+ goto error;
case 0:
close(fd);
execlp("vi", "vi", tempfile, (char *)NULL);
@@ -1025,11 +1040,20 @@ vi_histedit(EditLine *el, int c)
while (waitpid(pid, &status, 0) != pid)
continue;
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;
- el->el_line.lastchar = cp + st;
+ st = read(fd, cp, TMP_BUFSIZ);
+ if (st > 0) {
+ len = (size_t)(el->el_line.lastchar -
+ el->el_line.buffer);
+ len = ct_mbstowcs(el->el_line.buffer, cp, len);
+ if (len > 0 && el->el_line.buffer[len -1] == '\n')
+ --len;
+ }
+ else
+ len = 0;
+ el->el_line.cursor = el->el_line.buffer;
+ el->el_line.lastchar = el->el_line.buffer + len;
+ el_free(cp);
+ el_free(line);
break;
}
@@ -1037,6 +1061,12 @@ vi_histedit(EditLine *el, int c)
unlink(tempfile);
/* return CC_REFRESH; */
return ed_newline(el, 0);
+error:
+ el_free(line);
+ el_free(cp);
+ close(fd);
+ unlink(tempfile);
+ return CC_ERROR;
}
/* vi_history_word():
@@ -1047,28 +1077,29 @@ vi_histedit(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-vi_history_word(EditLine *el, int c)
+vi_history_word(EditLine *el, Int c __attribute__((__unused__)))
{
- const char *wp = HIST_FIRST(el);
- const char *wep, *wsp;
+ const Char *wp = HIST_FIRST(el);
+ const Char *wep, *wsp;
int len;
- char *cp;
- const char *lim;
+ Char *cp;
+ const Char *lim;
if (wp == NULL)
return CC_ERROR;
wep = wsp = 0;
do {
- while (isspace((unsigned char)*wp))
+ while (Isspace(*wp))
wp++;
if (*wp == 0)
break;
wsp = wp;
- while (*wp && !isspace((unsigned char)*wp))
+ while (*wp && !Isspace(*wp))
wp++;
wep = wp;
- } while ((!el->el_state.doingarg || --el->el_state.argument > 0) && *wp != 0);
+ } while ((!el->el_state.doingarg || --el->el_state.argument > 0)
+ && *wp != 0);
if (wsp == 0 || (el->el_state.doingarg && el->el_state.argument != 0))
return CC_ERROR;
@@ -1096,7 +1127,7 @@ vi_history_word(EditLine *el, int c)
*/
protected el_action_t
/*ARGSUSED*/
-vi_redo(EditLine *el, int c)
+vi_redo(EditLine *el, Int c __attribute__((__unused__)))
{
c_redo_t *r = &el->el_chared.c_redo;
@@ -1112,10 +1143,10 @@ vi_redo(EditLine *el, int c)
/* sanity */
r->pos = r->lim - 1;
r->pos[0] = 0;
- el_push(el, r->buf);
+ FUN(el,push)(el, r->buf);
}
el->el_state.thiscmd = r->cmd;
el->el_state.thisch = r->ch;
- return (*el->el_map.func[r->cmd])(el, r->ch);
+ return (*el->el_map.func[r->cmd])(el, r->ch);
}
diff --git a/lib/libelftc/Makefile b/lib/libelftc/Makefile
new file mode 100644
index 0000000..ccae1a5
--- /dev/null
+++ b/lib/libelftc/Makefile
@@ -0,0 +1,30 @@
+# $FreeBSD$
+.include <bsd.own.mk>
+
+INTERNALLIB=
+
+ELFTCDIR= ${.CURDIR}/../../contrib/elftoolchain
+
+.PATH: ${ELFTCDIR}/libelftc
+
+LIB= elftc
+
+SRCS= elftc_bfdtarget.c \
+ elftc_copyfile.c \
+ elftc_demangle.c \
+ elftc_set_timestamps.c \
+ elftc_string_table.c \
+ elftc_version.c \
+ libelftc_bfdtarget.c \
+ libelftc_dem_arm.c \
+ libelftc_dem_gnu2.c \
+ libelftc_dem_gnu3.c \
+ libelftc_hash.c \
+ libelftc_vstr.c
+
+INCS= libelftc.h
+CFLAGS+=-I${ELFTCDIR}/libelftc -I${ELFTCDIR}/common
+
+NO_MAN= yes
+
+.include <bsd.lib.mk>
diff --git a/lib/libelftc/elftc_version.c b/lib/libelftc/elftc_version.c
new file mode 100644
index 0000000..fb0a731
--- /dev/null
+++ b/lib/libelftc/elftc_version.c
@@ -0,0 +1,10 @@
+/* $FreeBSD$ */
+
+#include <sys/types.h>
+#include <libelftc.h>
+
+const char *
+elftc_version(void)
+{
+ return "elftoolchain r3197M";
+}
diff --git a/lib/libevent/Makefile b/lib/libevent/Makefile
index d8b1e20..1d20bcd 100644
--- a/lib/libevent/Makefile
+++ b/lib/libevent/Makefile
@@ -7,7 +7,6 @@
LIB= event
SHLIB_MAJOR= 1
PRIVATELIB=
-INTERNALLIB=
SRCS= buffer.c evbuffer.c event.c kqueue.c log.c poll.c select.c signal.c
HDRS= event.h
diff --git a/lib/libexecinfo/Makefile b/lib/libexecinfo/Makefile
index 81fa82a..5f9aac5 100644
--- a/lib/libexecinfo/Makefile
+++ b/lib/libexecinfo/Makefile
@@ -10,8 +10,7 @@ SHLIB_MAJOR= 1
INCS= execinfo.h
SRCS= backtrace.c symtab.c unwind.c
-DPADD= ${LIBELF}
-LDADD= -lelf
+LIBADD= elf
MAN= backtrace.3
diff --git a/lib/libexpat/Makefile b/lib/libexpat/Makefile
index 523a74e..0d4bef5 100644
--- a/lib/libexpat/Makefile
+++ b/lib/libexpat/Makefile
@@ -28,6 +28,6 @@ bsdxml.h: expat.h
> ${.TARGET}
bsdxml_external.h: expat_external.h
- cp -f ${.ALLSRC} ${.TARGET}
+ ${CP} ${.ALLSRC} ${.TARGET}
.include <bsd.lib.mk>
diff --git a/lib/libfetch/Makefile b/lib/libfetch/Makefile
index cef5f5a..4f56552 100644
--- a/lib/libfetch/Makefile
+++ b/lib/libfetch/Makefile
@@ -16,11 +16,9 @@ CFLAGS+= -DINET6
.if ${MK_OPENSSL} != "no"
CFLAGS+= -DWITH_SSL
-DPADD= ${LIBSSL} ${LIBCRYPTO}
-LDADD= -lssl -lcrypto
+LIBADD+= ssl crypto
.else
-DPADD= ${LIBMD}
-LDADD= -lmd
+LIBADD+= md
.endif
CFLAGS+= -DFTP_COMBINE_CWDS
diff --git a/lib/libfetch/common.c b/lib/libfetch/common.c
index eabea2b..3095e06 100644
--- a/lib/libfetch/common.c
+++ b/lib/libfetch/common.c
@@ -672,9 +672,7 @@ fetch_ssl_setup_transport_layer(SSL_CTX *ctx, int verbose)
{
long ssl_ctx_options;
- ssl_ctx_options = SSL_OP_ALL | SSL_OP_NO_TICKET;
- if (getenv("SSL_ALLOW_SSL2") == NULL)
- ssl_ctx_options |= SSL_OP_NO_SSLv2;
+ ssl_ctx_options = SSL_OP_ALL | SSL_OP_NO_SSLv2 | SSL_OP_NO_TICKET;
if (getenv("SSL_ALLOW_SSL3") == NULL)
ssl_ctx_options |= SSL_OP_NO_SSLv3;
if (getenv("SSL_NO_TLS1") != NULL)
diff --git a/lib/libfetch/fetch.3 b/lib/libfetch/fetch.3
index 5b9f0db..53a4e42 100644
--- a/lib/libfetch/fetch.3
+++ b/lib/libfetch/fetch.3
@@ -26,7 +26,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd October 15, 2014
+.Dd March 25, 2015
.Dt FETCH 3
.Os
.Sh NAME
@@ -441,10 +441,8 @@ By default
allows TLSv1 and newer when negotiating the connecting with the remote
peer.
You can change this behavior by setting the
-.Ev SSL_ALLOW_SSL2
-and
.Ev SSL_ALLOW_SSL3
-environment variables to allow SSLv2 and SSLv3, respectively, and
+environment variable to allow SSLv3 and
.Ev SSL_NO_TLS1 ,
.Ev SSL_NO_TLS1_1 and
.Ev SSL_NO_TLS1_2
@@ -646,8 +644,6 @@ which proxies should not be used.
Same as
.Ev NO_PROXY ,
for compatibility.
-.It Ev SSL_ALLOW_SSL2
-Allow SSL version 2 when negotiating the connection (not recommended).
.It Ev SSL_ALLOW_SSL3
Allow SSL version 3 when negotiating the connection (not recommended).
.It Ev SSL_CA_CERT_FILE
diff --git a/lib/libfigpar/Makefile.depend b/lib/libfigpar/Makefile.depend
new file mode 100644
index 0000000..467741f
--- /dev/null
+++ b/lib/libfigpar/Makefile.depend
@@ -0,0 +1,20 @@
+# Autogenerated - do NOT edit!
+
+DEP_RELDIR := ${_PARSEDIR:S,${SRCTOP}/,,}
+
+DIRDEPS = \
+ gnu/lib/csu \
+ gnu/lib/libgcc \
+ include \
+ include/xlocale \
+ lib/${CSU_DIR} \
+ lib/libc \
+ lib/libcompiler_rt \
+ usr.bin/xinstall.host \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif
diff --git a/lib/libgeom/Makefile b/lib/libgeom/Makefile
index b19faf6..20b7a4c 100644
--- a/lib/libgeom/Makefile
+++ b/lib/libgeom/Makefile
@@ -13,8 +13,7 @@ CFLAGS += -I${.CURDIR}
WARNS?= 3
-DPADD= ${LIBBSDXML} ${LIBSBUF}
-LDADD= -lbsdxml -lsbuf
+LIBADD+= bsdxml sbuf
MAN= libgeom.3
diff --git a/lib/libgeom/geom_xml2tree.c b/lib/libgeom/geom_xml2tree.c
index 2874cd0..2c23361 100644
--- a/lib/libgeom/geom_xml2tree.c
+++ b/lib/libgeom/geom_xml2tree.c
@@ -186,6 +186,7 @@ static void
EndElement(void *userData, const char *name)
{
struct mystate *mt;
+ struct gconf *c;
struct gconfig *gc;
char *p;
@@ -256,10 +257,18 @@ EndElement(void *userData, const char *name)
if (!strcmp(name, "config")) {
mt->config = NULL;
+ free(p);
return;
}
- if (mt->config != NULL) {
+ if (mt->config != NULL || (!strcmp(name, "wither") &&
+ (mt->provider != NULL || mt->geom != NULL))) {
+ if (mt->config != NULL)
+ c = mt->config;
+ else if (mt->provider != NULL)
+ c = &mt->provider->lg_config;
+ else
+ c = &mt->geom->lg_config;
gc = calloc(1, sizeof *gc);
if (gc == NULL) {
mt->error = errno;
@@ -270,14 +279,15 @@ EndElement(void *userData, const char *name)
}
gc->lg_name = strdup(name);
if (gc->lg_name == NULL) {
+ free(gc);
mt->error = errno;
XML_StopParser(mt->parser, 0);
warn("Cannot allocate memory during processing of '%s' "
"element", name);
return;
}
- gc->lg_val = p;
- LIST_INSERT_HEAD(mt->config, gc, lg_config);
+ gc->lg_val = p ? p : strdup("1");
+ LIST_INSERT_HEAD(c, gc, lg_config);
return;
}
diff --git a/lib/libgpio/Makefile b/lib/libgpio/Makefile
new file mode 100644
index 0000000..4393c79
--- /dev/null
+++ b/lib/libgpio/Makefile
@@ -0,0 +1,36 @@
+# $FreeBSD$
+
+LIB= gpio
+SHLIB_MAJOR= 0
+
+SRCS= gpio.c
+INCS= libgpio.h
+MAN+= gpio.3
+
+CFLAGS+= -I${.CURDIR}
+
+MLINKS= gpio.3 gpio_open.3 \
+ gpio.3 gpio_open_device.3 \
+ gpio.3 gpio_close.3 \
+ gpio.3 gpio_pin_list.3 \
+ gpio.3 gpio_pin_config.3 \
+ gpio.3 gpio_pin_set_flags.3 \
+ gpio.3 gpio_pin_set_name.3 \
+ gpio.3 gpio_pin_get.3 \
+ gpio.3 gpio_pin_set.3 \
+ gpio.3 gpio_pin_low.3 \
+ gpio.3 gpio_pin_high.3 \
+ gpio.3 gpio_pin_input.3 \
+ gpio.3 gpio_pin_output.3 \
+ gpio.3 gpio_pin_opendrain.3 \
+ gpio.3 gpio_pin_pushpull.3 \
+ gpio.3 gpio_pin_tristate.3 \
+ gpio.3 gpio_pin_pullup.3 \
+ gpio.3 gpio_pin_pulldown.3 \
+ gpio.3 gpio_pin_invin.3 \
+ gpio.3 gpio_pin_invout.3 \
+ gpio.3 gpio_pin_pulsate.3
+
+WARNS?= 6
+
+.include <bsd.lib.mk>
diff --git a/lib/libgpio/Makefile.depend b/lib/libgpio/Makefile.depend
new file mode 100644
index 0000000..467741f
--- /dev/null
+++ b/lib/libgpio/Makefile.depend
@@ -0,0 +1,20 @@
+# Autogenerated - do NOT edit!
+
+DEP_RELDIR := ${_PARSEDIR:S,${SRCTOP}/,,}
+
+DIRDEPS = \
+ gnu/lib/csu \
+ gnu/lib/libgcc \
+ include \
+ include/xlocale \
+ lib/${CSU_DIR} \
+ lib/libc \
+ lib/libcompiler_rt \
+ usr.bin/xinstall.host \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif
diff --git a/lib/libgpio/gpio.3 b/lib/libgpio/gpio.3
new file mode 100644
index 0000000..70f6b38
--- /dev/null
+++ b/lib/libgpio/gpio.3
@@ -0,0 +1,198 @@
+.\"
+.\" Copyright (c) 2014 Rui Paulo
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd March 8, 2015
+.Dt GPIO 3
+.Os
+.Sh NAME
+.Nm gpio_open ,
+.Nm gpio_close
+.Nd "library to handle GPIO pins"
+.Sh LIBRARY
+.Lb libgpio
+.Sh SYNOPSIS
+.In libgpio.h
+.Ft "gpio_handle_t"
+.Fn gpio_open "unsigned int unit"
+.Ft "gpio_handle_t"
+.Fn gpio_open_device "const char *device"
+.Ft void
+.Fn gpio_close "gpio_handle_t handle"
+.Ft int
+.Fn gpio_pin_list "gpio_handle_t handle" "gpio_config_t **pcfgs"
+.Ft int
+.Fn gpio_pin_config "gpio_handle_t handle" "gpio_config_t *cfg"
+.Ft int
+.Fn gpio_pin_set_name "gpio_handle_t handle" "gpio_pin_t pin" "char *name"
+.Ft int
+.Fn gpio_pin_set_flags "gpio_handle_t handle" "gpio_config_t *cfg"
+.Ft gpio_value_t
+.Fn gpio_pin_get "gpio_handle_t handle" "gpio_pin_t pin"
+.Ft int
+.Fn gpio_pin_set "gpio_handle_t handle" "gpio_pin_t pin" "gpio_value_t value"
+.Ft int
+.Fn gpio_pin_toggle "gpio_handle_t handle" "gpio_pin_t pin"
+.Ft int
+.Fn gpio_pin_low "gpio_handle_t handle" "gpio_pin_t pin"
+.Ft int
+.Fn gpio_pin_high "gpio_handle_t handle" "gpio_pin_t pin"
+.Ft int
+.Fn gpio_pin_input "gpio_handle_t handle" "gpio_pin_t pin"
+.Ft int
+.Fn gpio_pin_output "gpio_handle_t handle" "gpio_pin_t pin"
+.Ft int
+.Fn gpio_pin_opendrain "gpio_handle_t handle" "gpio_pin_t pin"
+.Ft int
+.Fn gpio_pin_pushpull "gpio_handle_t handle" "gpio_pin_t pin"
+.Ft int
+.Fn gpio_pin_tristate "gpio_handle_t handle" "gpio_pin_t pin"
+.Ft int
+.Fn gpio_pin_pullup "gpio_handle_t handle" "gpio_pin_t pin"
+.Ft int
+.Fn gpio_pin_pulldown "gpio_handle_t handle" "gpio_pin_t pin"
+.Ft int
+.Fn gpio_pin_invin "gpio_handle_t handle" "gpio_pin_t pin"
+.Ft int
+.Fn gpio_pin_invout "gpio_handle_t handle" "gpio_pin_t pin"
+.Ft int
+.Fn gpio_pin_pulsate "gpio_handle_t handle" "gpio_pin_t pin"
+.Sh DESCRIPTION
+The
+.Nm libgpio
+library provides an interface to configure GPIO pins.
+The library operates with a
+.Ft gpio_handle_t
+opaque type which can be created with
+.Fn gpio_open
+or
+.Fn gpio_open_device .
+When no more GPIO operations are needed, this handle can be destroyed
+with
+.Fn gpio_close .
+.Pp
+To get a list of all available pins, one can call
+.Fn gpio_pin_list .
+This function takes a pointer to a
+.Ft gpio_config_t
+which is dynamically allocated.
+This pointer should be freed with
+.Xr free 3
+when it is no longer necessary.
+.Pp
+The function
+.Fn gpio_pin_config
+retrieves the current configuration of a pin.
+The pin number should be passed in via the
+.Ft g_pin
+variable which is part of the
+.Ft gpio_config_t
+structure.
+.Pp
+The function
+.Fn gpio_pin_set_name
+sets the name used to describe a pin.
+.Pp
+The function
+.Fn gpio_pin_set_flags
+configures a pin with the flags passed in by the
+.Ft gpio_config_t
+structure.
+The pin number should also be passed in through the
+.Ft g_pin
+variable.
+All other structure members will be ignored by this function.
+The list of flags can be found in
+.Pa /usr/include/sys/gpio.h .
+.Pp
+The get or set the state of a GPIO pin, the functions
+.Fn gpio_pin_get
+and
+.Fn gpio_pin_set
+are available, respectively.
+To toggle the state, use
+.Fn gpio_pin_toggle .
+.Pp
+The functions
+.Fn gpio_pin_low
+and
+.Fn gpio_pin_high
+are wrappers around
+.Fn gpio_pin_set .
+.Pp
+The functions
+.Fn gpio_pin_input ,
+.Fn gpio_pin_output ,
+.Fn gpio_pin_opendrain ,
+.Fn gpio_pin_pushpull ,
+.Fn gpio_pin_tristate ,
+.Fn gpio_pin_pullup ,
+.Fn gpio_pin_pulldown ,
+.Fn gpio_pin_invin ,
+.Fn gpio_pin_invout
+and
+.Fn gpio_pin_pulsate
+are wrappers around
+.Fn gpio_pin_set_flags .
+.Sh EXAMPLES
+The following example shows how to configure pin 16 as output and then
+drive it high:
+.Bd -literal
+#include <err.h>
+#include <libgpio.h>
+
+gpio_handle_t handle;
+
+handle = gpio_open(0);
+if (handle == GPIO_HANDLE_INVALID)
+ err(1, "gpio_open failed");
+gpio_pin_output(handle, 16);
+gpio_pin_high(handle, 16);
+gpio_close(handle);
+.Ed
+.Pp
+The following example shows how to get a configuration of a pin:
+.Bd -literal
+gpio_config_t cfg;
+
+cfg.g_pin = 32;
+gpio_pin_config(handle, &cfg);
+.Ed
+.Pp
+The structure will contain the name of the pin and its flags.
+.Sh SEE ALSO
+.Xr gpiobus 4 ,
+.Xr gpioctl 8
+.Sh HISTORY
+The
+.Nm libgpio
+library first appeared in
+.Fx 11.0 .
+.Sh AUTHORS
+The
+.Nm libgpio
+library was implemented by
+.An Rui Paulo Aq Mt rpaulo@FreeBSD.org .
diff --git a/lib/libgpio/gpio.c b/lib/libgpio/gpio.c
new file mode 100644
index 0000000..7ec0955
--- /dev/null
+++ b/lib/libgpio/gpio.c
@@ -0,0 +1,278 @@
+/*-
+ * Copyright (c) 2013-2014 Rui Paulo <rpaulo@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 ``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.
+ *
+ * $FreeBSD$
+ */
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include <sys/ioctl.h>
+#include <sys/types.h>
+
+#include <libgpio.h>
+
+gpio_handle_t
+gpio_open(unsigned int unit)
+{
+ char device[16];
+
+ snprintf(device, sizeof(device), "/dev/gpioc%u", unit);
+
+ return (gpio_open_device(device));
+}
+
+gpio_handle_t
+gpio_open_device(const char *device)
+{
+ int fd, maxpins;
+ int serr;
+
+ fd = open(device, O_RDONLY);
+ if (fd < 0)
+ return (GPIO_INVALID_HANDLE);
+ /*
+ * Check whether a simple ioctl works.
+ */
+ if (ioctl(fd, GPIOMAXPIN, &maxpins) < 0) {
+ serr = errno;
+ close(fd);
+ errno = serr;
+ return (GPIO_INVALID_HANDLE);
+ }
+
+ return (fd);
+}
+
+void
+gpio_close(gpio_handle_t handle)
+{
+ close(handle);
+}
+
+int
+gpio_pin_list(gpio_handle_t handle, gpio_config_t **pcfgs)
+{
+ int maxpins, i;
+ gpio_config_t *cfgs;
+
+ *pcfgs = NULL;
+ if (ioctl(handle, GPIOMAXPIN, &maxpins) < 0)
+ return (-1);
+ /* Reasonable values. */
+ if (maxpins < 0 || maxpins > 4096) {
+ errno = EINVAL;
+ return (-1);
+ }
+ cfgs = calloc(maxpins + 1, sizeof(*cfgs));
+ if (cfgs == NULL)
+ return (-1);
+ for (i = 0; i <= maxpins; i++) {
+ cfgs[i].g_pin = i;
+ gpio_pin_config(handle, &cfgs[i]);
+ }
+ *pcfgs = cfgs;
+
+ return (maxpins);
+}
+
+int
+gpio_pin_config(gpio_handle_t handle, gpio_config_t *cfg)
+{
+ struct gpio_pin gppin;
+
+ if (cfg == NULL)
+ return (-1);
+ gppin.gp_pin = cfg->g_pin;
+ if (ioctl(handle, GPIOGETCONFIG, &gppin) < 0)
+ return (-1);
+ strlcpy(cfg->g_name, gppin.gp_name, GPIOMAXNAME);
+ cfg->g_caps = gppin.gp_caps;
+ cfg->g_flags = gppin.gp_flags;
+
+ return (0);
+}
+
+int
+gpio_pin_set_name(gpio_handle_t handle, gpio_pin_t pin, char *name)
+{
+ struct gpio_pin gppin;
+
+ if (name == NULL)
+ return (-1);
+ bzero(&gppin, sizeof(gppin));
+ gppin.gp_pin = pin;
+ strlcpy(gppin.gp_name, name, GPIOMAXNAME);
+ if (ioctl(handle, GPIOSETNAME, &gppin) < 0)
+ return (-1);
+
+ return (0);
+}
+
+int
+gpio_pin_set_flags(gpio_handle_t handle, gpio_config_t *cfg)
+{
+ struct gpio_pin gppin;
+
+ if (cfg == NULL)
+ return (-1);
+ gppin.gp_pin = cfg->g_pin;
+ gppin.gp_flags = cfg->g_flags;
+ if (ioctl(handle, GPIOSETCONFIG, &gppin) < 0)
+ return (-1);
+
+ return (0);
+}
+
+gpio_value_t
+gpio_pin_get(gpio_handle_t handle, gpio_pin_t pin)
+{
+ struct gpio_req gpreq;
+
+ bzero(&gpreq, sizeof(gpreq));
+ gpreq.gp_pin = pin;
+ if (ioctl(handle, GPIOGET, &gpreq) < 0)
+ return (GPIO_VALUE_INVALID);
+
+ return (gpreq.gp_value);
+}
+
+int
+gpio_pin_set(gpio_handle_t handle, gpio_pin_t pin, gpio_value_t value)
+{
+ struct gpio_req gpreq;
+
+ if (value == GPIO_VALUE_INVALID)
+ return (-1);
+ bzero(&gpreq, sizeof(gpreq));
+ gpreq.gp_pin = pin;
+ gpreq.gp_value = value;
+ if (ioctl(handle, GPIOSET, &gpreq) < 0)
+ return (-1);
+
+ return (0);
+}
+
+int
+gpio_pin_toggle(gpio_handle_t handle, gpio_pin_t pin)
+{
+ gpio_value_t value;
+
+ value = gpio_pin_get(handle, pin);
+ if (value == GPIO_VALUE_INVALID)
+ return (-1);
+ value = !value;
+
+ return (gpio_pin_set(handle, pin, value));
+}
+
+int
+gpio_pin_low(gpio_handle_t handle, gpio_pin_t pin)
+{
+ return (gpio_pin_set(handle, pin, GPIO_VALUE_LOW));
+}
+
+int
+gpio_pin_high(gpio_handle_t handle, gpio_pin_t pin)
+{
+ return (gpio_pin_set(handle, pin, GPIO_VALUE_HIGH));
+}
+
+static int
+gpio_pin_set_flag(gpio_handle_t handle, gpio_pin_t pin, uint32_t flag)
+{
+ gpio_config_t cfg;
+
+ bzero(&cfg, sizeof(cfg));
+ cfg.g_pin = pin;
+ if (gpio_pin_config(handle, &cfg) < 0)
+ return (-1);
+ cfg.g_flags = flag;
+
+ return (gpio_pin_set_flags(handle, &cfg));
+}
+
+int
+gpio_pin_input(gpio_handle_t handle, gpio_pin_t pin)
+{
+ return (gpio_pin_set_flag(handle, pin, GPIO_PIN_INPUT));
+}
+
+int
+gpio_pin_output(gpio_handle_t handle, gpio_pin_t pin)
+{
+ return (gpio_pin_set_flag(handle, pin, GPIO_PIN_OUTPUT));
+}
+
+int
+gpio_pin_opendrain(gpio_handle_t handle, gpio_pin_t pin)
+{
+ return (gpio_pin_set_flag(handle, pin, GPIO_PIN_OPENDRAIN));
+}
+
+int
+gpio_pin_pushpull(gpio_handle_t handle, gpio_pin_t pin)
+{
+ return (gpio_pin_set_flag(handle, pin, GPIO_PIN_PUSHPULL));
+}
+
+int
+gpio_pin_tristate(gpio_handle_t handle, gpio_pin_t pin)
+{
+ return (gpio_pin_set_flag(handle, pin, GPIO_PIN_TRISTATE));
+}
+
+int
+gpio_pin_pullup(gpio_handle_t handle, gpio_pin_t pin)
+{
+ return (gpio_pin_set_flag(handle, pin, GPIO_PIN_PULLUP));
+}
+
+int
+gpio_pin_pulldown(gpio_handle_t handle, gpio_pin_t pin)
+{
+ return (gpio_pin_set_flag(handle, pin, GPIO_PIN_PULLDOWN));
+}
+
+int
+gpio_pin_invin(gpio_handle_t handle, gpio_pin_t pin)
+{
+ return (gpio_pin_set_flag(handle, pin, GPIO_PIN_INVIN));
+}
+
+int
+gpio_pin_invout(gpio_handle_t handle, gpio_pin_t pin)
+{
+ return (gpio_pin_set_flag(handle, pin, GPIO_PIN_INVOUT));
+}
+
+int
+gpio_pin_pulsate(gpio_handle_t handle, gpio_pin_t pin)
+{
+ return (gpio_pin_set_flag(handle, pin, GPIO_PIN_PULSATE));
+}
diff --git a/lib/libgpio/libgpio.h b/lib/libgpio/libgpio.h
new file mode 100644
index 0000000..a832234
--- /dev/null
+++ b/lib/libgpio/libgpio.h
@@ -0,0 +1,110 @@
+/*-
+ * Copyright (c) 2013-2014 Rui Paulo <rpaulo@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 ``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.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _LIBGPIO_H_
+#define _LIBGPIO_H_
+
+#include <sys/gpio.h>
+
+__BEGIN_DECLS
+
+#define GPIO_INVALID_HANDLE -1
+typedef int gpio_handle_t;
+typedef uint32_t gpio_pin_t;
+
+/*
+ * Structure describing a GPIO pin configuration.
+ */
+typedef struct {
+ gpio_pin_t g_pin;
+ char g_name[GPIOMAXNAME];
+ uint32_t g_caps;
+ uint32_t g_flags;
+} gpio_config_t;
+
+typedef enum {
+ GPIO_VALUE_INVALID = -1,
+ GPIO_VALUE_LOW = GPIO_PIN_LOW,
+ GPIO_VALUE_HIGH = GPIO_PIN_HIGH
+} gpio_value_t;
+
+/*
+ * Open /dev/gpiocN or a specific device.
+ */
+gpio_handle_t gpio_open(unsigned int);
+gpio_handle_t gpio_open_device(const char *);
+void gpio_close(gpio_handle_t);
+/*
+ * Get a list of all the GPIO pins.
+ */
+int gpio_pin_list(gpio_handle_t, gpio_config_t **);
+/*
+ * GPIO pin configuration.
+ *
+ * Retrieve the configuration of a specific GPIO pin. The pin number is
+ * passed through the gpio_config_t structure.
+ */
+int gpio_pin_config(gpio_handle_t, gpio_config_t *);
+/*
+ * Sets the GPIO pin name. The pin number and pin name to be set are passed
+ * as parameters.
+ */
+int gpio_pin_set_name(gpio_handle_t, gpio_pin_t, char *);
+/*
+ * Sets the GPIO flags on a specific GPIO pin. The pin number and the flags
+ * to be set are passed through the gpio_config_t structure.
+ */
+int gpio_pin_set_flags(gpio_handle_t, gpio_config_t *);
+/*
+ * GPIO pin values.
+ */
+int gpio_pin_get(gpio_handle_t, gpio_pin_t);
+int gpio_pin_set(gpio_handle_t, gpio_pin_t, int);
+int gpio_pin_toggle(gpio_handle_t, gpio_pin_t);
+/*
+ * Helper functions to set pin states.
+ */
+int gpio_pin_low(gpio_handle_t, gpio_pin_t);
+int gpio_pin_high(gpio_handle_t, gpio_pin_t);
+/*
+ * Helper functions to configure pins.
+ */
+int gpio_pin_input(gpio_handle_t, gpio_pin_t);
+int gpio_pin_output(gpio_handle_t, gpio_pin_t);
+int gpio_pin_opendrain(gpio_handle_t, gpio_pin_t);
+int gpio_pin_pushpull(gpio_handle_t, gpio_pin_t);
+int gpio_pin_tristate(gpio_handle_t, gpio_pin_t);
+int gpio_pin_pullup(gpio_handle_t, gpio_pin_t);
+int gpio_pin_pulldown(gpio_handle_t, gpio_pin_t);
+int gpio_pin_invin(gpio_handle_t, gpio_pin_t);
+int gpio_pin_invout(gpio_handle_t, gpio_pin_t);
+int gpio_pin_pulsate(gpio_handle_t, gpio_pin_t);
+
+__END_DECLS
+
+#endif /* _LIBGPIO_H_ */
diff --git a/lib/libgssapi/gss_acquire_cred.3 b/lib/libgssapi/gss_acquire_cred.3
index 0a6caad..29652a3 100644
--- a/lib/libgssapi/gss_acquire_cred.3
+++ b/lib/libgssapi/gss_acquire_cred.3
@@ -189,10 +189,10 @@ The credentials could not be acquired because they have expired.
No credentials were found for the specified name.
.El
.Sh SEE ALSO
-.Xr gss_init_sec_context 3 ,
.Xr gss_accept_sec_context 3 ,
-.Xr gss_inquire_cred 3 ,
+.Xr gss_init_sec_context 3 ,
.Xr gss_inquire_context 3 ,
+.Xr gss_inquire_cred 3 ,
.Xr gss_release_cred 3 ,
.Xr gss_release_oid_set 3
.Sh STANDARDS
diff --git a/lib/libgssapi/gss_add_cred.3 b/lib/libgssapi/gss_add_cred.3
index 32d9885..53648d7 100644
--- a/lib/libgssapi/gss_add_cred.3
+++ b/lib/libgssapi/gss_add_cred.3
@@ -288,11 +288,11 @@ The required credentials could not be added because they have expired.
No credentials were found for the specified name.
.El
.Sh SEE ALSO
-.Xr gss_init_sec_context 3 ,
.Xr gss_accept_sec_context 3 ,
.Xr gss_acquire_cred 3 ,
-.Xr gss_inquire_cred 3 ,
+.Xr gss_init_sec_context 3 ,
.Xr gss_inquire_context 3 ,
+.Xr gss_inquire_cred 3 ,
.Xr gss_release_cred 3 ,
.Xr gss_release_oid_set 3
.Sh STANDARDS
diff --git a/lib/libgssapi/gss_add_oid_set_member.3 b/lib/libgssapi/gss_add_oid_set_member.3
index e812681..2b3bf55 100644
--- a/lib/libgssapi/gss_add_oid_set_member.3
+++ b/lib/libgssapi/gss_add_oid_set_member.3
@@ -85,8 +85,8 @@ The set in which the object identifier should be inserted.
Successful completion
.El
.Sh SEE ALSO
-.Xr gss_create_empty_oid_set 3 ,
-.Xr gss_acquire_cred 3
+.Xr gss_acquire_cred 3 ,
+.Xr gss_create_empty_oid_set 3
.Sh STANDARDS
.Bl -tag -width ".It RFC 2743"
.It RFC 2743
diff --git a/lib/libgssapi/gss_create_empty_oid_set.3 b/lib/libgssapi/gss_create_empty_oid_set.3
index 466ea01..a561be1 100644
--- a/lib/libgssapi/gss_create_empty_oid_set.3
+++ b/lib/libgssapi/gss_create_empty_oid_set.3
@@ -66,8 +66,8 @@ which the application must free after use with a call to
Successful completion
.El
.Sh SEE ALSO
-.Xr gss_add_oid_set_member 3 ,
-.Xr gss_acquire_cred 3
+.Xr gss_acquire_cred 3 ,
+.Xr gss_add_oid_set_member 3
.Sh STANDARDS
.Bl -tag -width ".It RFC 2743"
.It RFC 2743
diff --git a/lib/libgssapi/gss_delete_sec_context.3 b/lib/libgssapi/gss_delete_sec_context.3
index be12165..4bfa984 100644
--- a/lib/libgssapi/gss_delete_sec_context.3
+++ b/lib/libgssapi/gss_delete_sec_context.3
@@ -117,9 +117,9 @@ Successful completion
No valid context was supplied
.El
.Sh SEE ALSO
-.Xr gss_process_context_token 3 ,
+.Xr gss_accept_sec_context 3 ,
.Xr gss_init_sec_context 3 ,
-.Xr gss_accept_sec_context 3
+.Xr gss_process_context_token 3
.Sh STANDARDS
.Bl -tag -width ".It RFC 2743"
.It RFC 2743
diff --git a/lib/libgssapi/gss_get_mic.3 b/lib/libgssapi/gss_get_mic.3
index 431f9e3..cda037a 100644
--- a/lib/libgssapi/gss_get_mic.3
+++ b/lib/libgssapi/gss_get_mic.3
@@ -120,8 +120,8 @@ The context_handle parameter did not identify a valid context
The specified QOP is not supported by the mechanism
.El
.Sh SEE ALSO
-.Xr gss_wrap 3 ,
-.Xr gss_release_buffer 3
+.Xr gss_release_buffer 3 ,
+.Xr gss_wrap 3
.Sh STANDARDS
.Bl -tag -width ".It RFC 2743"
.It RFC 2743
diff --git a/lib/libgssapi/gss_import_sec_context.3 b/lib/libgssapi/gss_import_sec_context.3
index b2e1c78..4d1bc47 100644
--- a/lib/libgssapi/gss_import_sec_context.3
+++ b/lib/libgssapi/gss_import_sec_context.3
@@ -75,8 +75,8 @@ The operation is unavailable
Local policy prevents the import of this context by the current process
.El
.Sh SEE ALSO
-.Xr gss_export_sec_context 3 ,
-.Xr gss_delete_sec_context 3
+.Xr gss_delete_sec_context 3 ,
+.Xr gss_export_sec_context 3
.Sh STANDARDS
.Bl -tag -width ".It RFC 2743"
.It RFC 2743
diff --git a/lib/libgssapi/gss_inquire_context.3 b/lib/libgssapi/gss_inquire_context.3
index d318234..9ab2b64 100644
--- a/lib/libgssapi/gss_inquire_context.3
+++ b/lib/libgssapi/gss_inquire_context.3
@@ -236,11 +236,11 @@ Successful completion
The referenced context could not be accessed
.El
.Sh SEE ALSO
-.Xr gss_release_name 3 ,
-.Xr gss_init_sec_context 3 ,
-.Xr gss_wrap 3 ,
+.Xr gss_export_sec_context 3 ,
.Xr gss_get_mic 3 ,
-.Xr gss_export_sec_context 3
+.Xr gss_init_sec_context 3 ,
+.Xr gss_release_name 3 ,
+.Xr gss_wrap 3
.Sh STANDARDS
.Bl -tag -width ".It RFC 2743"
.It RFC 2743
diff --git a/lib/libgssapi/gss_process_context_token.3 b/lib/libgssapi/gss_process_context_token.3
index a7e0ab4..086dc6c 100644
--- a/lib/libgssapi/gss_process_context_token.3
+++ b/lib/libgssapi/gss_process_context_token.3
@@ -91,8 +91,8 @@ The
did not refer to a valid context
.El
.Sh SEE ALSO
-.Xr gss_init_sec_context 3 ,
-.Xr gss_accept_sec_context 3
+.Xr gss_accept_sec_context 3 ,
+.Xr gss_init_sec_context 3
.Sh STANDARDS
.Bl -tag -width ".It RFC 2743"
.It RFC 2743
diff --git a/lib/libgssapi/gss_test_oid_set_member.3 b/lib/libgssapi/gss_test_oid_set_member.3
index 5588e8a..688bf9e 100644
--- a/lib/libgssapi/gss_test_oid_set_member.3
+++ b/lib/libgssapi/gss_test_oid_set_member.3
@@ -70,8 +70,8 @@ Non-zero if the specified OID is a member of the set, zero if not.
Successful completion
.El
.Sh SEE ALSO
-.Xr gss_indicate_mechs 3 ,
.Xr gss_acquire_cred 3 ,
+.Xr gss_indicate_mechs 3 ,
.Xr gss_inquire_cred 3
.Sh STANDARDS
.Bl -tag -width ".It RFC 2743"
diff --git a/lib/libgssapi/gss_unwrap.3 b/lib/libgssapi/gss_unwrap.3
index 368b361..3f9cc9c 100644
--- a/lib/libgssapi/gss_unwrap.3
+++ b/lib/libgssapi/gss_unwrap.3
@@ -147,8 +147,8 @@ The context has already expired.
The context_handle parameter did not identify a valid context.
.El
.Sh SEE ALSO
-.Xr gss_wrap 3 ,
-.Xr gss_release_buffer 3
+.Xr gss_release_buffer 3 ,
+.Xr gss_wrap 3
.Sh STANDARDS
.Bl -tag -width ".It RFC 2743"
.It RFC 2743
diff --git a/lib/libgssapi/gss_wrap.3 b/lib/libgssapi/gss_wrap.3
index edc1345..fe91853 100644
--- a/lib/libgssapi/gss_wrap.3
+++ b/lib/libgssapi/gss_wrap.3
@@ -134,8 +134,8 @@ The context_handle parameter did not identify a valid context.
The specified QOP is not supported by the mechanism.
.El
.Sh SEE ALSO
-.Xr gss_unwrap 3 ,
-.Xr gss_release_buffer 3
+.Xr gss_release_buffer 3 ,
+.Xr gss_unwrap 3
.Sh STANDARDS
.Bl -tag -width ".It RFC 2743"
.It RFC 2743
diff --git a/lib/libiconv/Makefile b/lib/libiconv/Makefile
deleted file mode 100644
index 1949597..0000000
--- a/lib/libiconv/Makefile
+++ /dev/null
@@ -1,25 +0,0 @@
-# $FreeBSD$
-
-.PATH: ${.CURDIR}/../libc/iconv
-
-LIB= iconv
-SHLIB_MAJOR= 4
-MAN= iconv.3 iconvctl.3 iconv_canonicalize.3 iconvlist.3 \
- __iconv_get_list.3
-MLNKS= iconv.3 iconv_open.3 \
- iconv.3 iconv_open_into.3 \
- iconv.3 iconv_close.3 \
- iconv.3 __iconv.3 \
- __iconv_get_list.3 __iconv_free_list.3
-SRCS= citrus_bcs.c citrus_bcs_strtol.c citrus_bcs_strtoul.c \
- citrus_csmapper.c citrus_db.c citrus_db_factory.c \
- citrus_db_hash.c citrus_esdb.c citrus_hash.c \
- citrus_iconv.c citrus_lookup.c citrus_lookup_factory.c \
- citrus_mapper.c citrus_memstream.c citrus_mmap.c \
- citrus_module.c citrus_none.c citrus_pivot_factory.c \
- citrus_prop.c citrus_stdenc.c iconv.c
-
-CFLAGS.gcc+= --param max-inline-insns-single=128
-CFLAGS+= -I ${.CURDIR}/../../include -I${.CURDIR}/../libc/include
-
-.include <bsd.lib.mk>
diff --git a/lib/libiconv_modules/BIG5/citrus_big5.c b/lib/libiconv_modules/BIG5/citrus_big5.c
index a8376eb..8dffc65 100644
--- a/lib/libiconv_modules/BIG5/citrus_big5.c
+++ b/lib/libiconv_modules/BIG5/citrus_big5.c
@@ -269,12 +269,12 @@ static int
/*ARGSUSED*/
_citrus_BIG5_mbrtowc_priv(_BIG5EncodingInfo * __restrict ei,
wchar_t * __restrict pwc,
- const char ** __restrict s, size_t n,
+ char ** __restrict s, size_t n,
_BIG5State * __restrict psenc,
size_t * __restrict nresult)
{
wchar_t wchar;
- const char *s0;
+ char *s0;
int c, chlenbak;
s0 = *s;
diff --git a/lib/libiconv_modules/DECHanyu/citrus_dechanyu.c b/lib/libiconv_modules/DECHanyu/citrus_dechanyu.c
index fc32018..ec2c597 100644
--- a/lib/libiconv_modules/DECHanyu/citrus_dechanyu.c
+++ b/lib/libiconv_modules/DECHanyu/citrus_dechanyu.c
@@ -165,10 +165,10 @@ is_94charset(int c)
static int
/*ARGSUSED*/
_citrus_DECHanyu_mbrtowc_priv(_DECHanyuEncodingInfo * __restrict ei,
- wchar_t * __restrict pwc, const char ** __restrict s, size_t n,
+ wchar_t * __restrict pwc, char ** __restrict s, size_t n,
_DECHanyuState * __restrict psenc, size_t * __restrict nresult)
{
- const char *s0;
+ char *s0;
wchar_t wc;
int ch;
diff --git a/lib/libiconv_modules/EUC/citrus_euc.c b/lib/libiconv_modules/EUC/citrus_euc.c
index 6483eb5..e0c2d23 100644
--- a/lib/libiconv_modules/EUC/citrus_euc.c
+++ b/lib/libiconv_modules/EUC/citrus_euc.c
@@ -190,12 +190,12 @@ _citrus_EUC_unpack_state(_EUCEncodingInfo *ei __unused, _EUCState *s,
#endif
static int
-_citrus_EUC_mbrtowc_priv(_EUCEncodingInfo *ei, wchar_t *pwc, const char **s,
+_citrus_EUC_mbrtowc_priv(_EUCEncodingInfo *ei, wchar_t *pwc, char **s,
size_t n, _EUCState *psenc, size_t *nresult)
{
wchar_t wchar;
int c, chlenbak, cs, len;
- const char *s0, *s1 = NULL;
+ char *s0, *s1 = NULL;
s0 = *s;
diff --git a/lib/libiconv_modules/EUCTW/citrus_euctw.c b/lib/libiconv_modules/EUCTW/citrus_euctw.c
index c35423e..6c3e9f6 100644
--- a/lib/libiconv_modules/EUCTW/citrus_euctw.c
+++ b/lib/libiconv_modules/EUCTW/citrus_euctw.c
@@ -176,10 +176,10 @@ _citrus_EUCTW_encoding_module_uninit(_EUCTWEncodingInfo *ei __unused)
static int
_citrus_EUCTW_mbrtowc_priv(_EUCTWEncodingInfo * __restrict ei,
- wchar_t * __restrict pwc, const char ** __restrict s,
+ wchar_t * __restrict pwc, char ** __restrict s,
size_t n, _EUCTWState * __restrict psenc, size_t * __restrict nresult)
{
- const char *s0;
+ char *s0;
wchar_t wchar;
int c, chlenbak, cs;
diff --git a/lib/libiconv_modules/GBK2K/citrus_gbk2k.c b/lib/libiconv_modules/GBK2K/citrus_gbk2k.c
index 50ea2da..b64c7e0 100644
--- a/lib/libiconv_modules/GBK2K/citrus_gbk2k.c
+++ b/lib/libiconv_modules/GBK2K/citrus_gbk2k.c
@@ -149,10 +149,10 @@ _mb_count(wchar_t v)
static int
_citrus_GBK2K_mbrtowc_priv(_GBK2KEncodingInfo * __restrict ei,
- wchar_t * __restrict pwc, const char ** __restrict s, size_t n,
+ wchar_t * __restrict pwc, char ** __restrict s, size_t n,
_GBK2KState * __restrict psenc, size_t * __restrict nresult)
{
- const char *s0, *s1;
+ char *s0, *s1;
wchar_t wc;
int chlenbak, len;
diff --git a/lib/libiconv_modules/HZ/citrus_hz.c b/lib/libiconv_modules/HZ/citrus_hz.c
index d772b38..13d2f2c 100644
--- a/lib/libiconv_modules/HZ/citrus_hz.c
+++ b/lib/libiconv_modules/HZ/citrus_hz.c
@@ -175,13 +175,13 @@ _citrus_HZ_unpack_state(_HZEncodingInfo * __restrict ei __unused,
static int
_citrus_HZ_mbrtowc_priv(_HZEncodingInfo * __restrict ei,
- wchar_t * __restrict pwc, const char ** __restrict s, size_t n,
+ wchar_t * __restrict pwc, char ** __restrict s, size_t n,
_HZState * __restrict psenc, size_t * __restrict nresult)
{
escape_t *candidate, *init;
graphic_t *graphic;
const range_t *range;
- const char *s0;
+ char *s0;
wchar_t wc;
int bit, ch, head, len, tail;
diff --git a/lib/libiconv_modules/ISO2022/citrus_iso2022.c b/lib/libiconv_modules/ISO2022/citrus_iso2022.c
index 3402ba8..f3613d6 100644
--- a/lib/libiconv_modules/ISO2022/citrus_iso2022.c
+++ b/lib/libiconv_modules/ISO2022/citrus_iso2022.c
@@ -574,7 +574,7 @@ terminate:
static wchar_t
_ISO2022_sgetwchar(_ISO2022EncodingInfo * __restrict ei __unused,
- const char * __restrict string, size_t n, const char ** __restrict result,
+ char * __restrict string, size_t n, char ** __restrict result,
_ISO2022State * __restrict psenc)
{
const struct seqtable *sp;
@@ -842,10 +842,10 @@ asis:
static int
_citrus_ISO2022_mbrtowc_priv(_ISO2022EncodingInfo * __restrict ei,
- wchar_t * __restrict pwc, const char ** __restrict s,
+ wchar_t * __restrict pwc, char ** __restrict s,
size_t n, _ISO2022State * __restrict psenc, size_t * __restrict nresult)
{
- const char *p, *result, *s0;
+ char *p, *result, *s0;
wchar_t wchar;
int c, chlenbak;
diff --git a/lib/libiconv_modules/JOHAB/citrus_johab.c b/lib/libiconv_modules/JOHAB/citrus_johab.c
index a533a85..459f8c9 100644
--- a/lib/libiconv_modules/JOHAB/citrus_johab.c
+++ b/lib/libiconv_modules/JOHAB/citrus_johab.c
@@ -145,10 +145,10 @@ ishanja(int l, int t)
static int
/*ARGSUSED*/
_citrus_JOHAB_mbrtowc_priv(_JOHABEncodingInfo * __restrict ei,
- wchar_t * __restrict pwc, const char ** __restrict s, size_t n,
+ wchar_t * __restrict pwc, char ** __restrict s, size_t n,
_JOHABState * __restrict psenc, size_t * __restrict nresult)
{
- const char *s0;
+ char *s0;
int l, t;
if (*s == NULL) {
diff --git a/lib/libiconv_modules/MSKanji/citrus_mskanji.c b/lib/libiconv_modules/MSKanji/citrus_mskanji.c
index 8549699..4330cc8 100644
--- a/lib/libiconv_modules/MSKanji/citrus_mskanji.c
+++ b/lib/libiconv_modules/MSKanji/citrus_mskanji.c
@@ -153,10 +153,10 @@ _citrus_MSKanji_unpack_state(_MSKanjiEncodingInfo * __restrict ei __unused,
static int
/*ARGSUSED*/
_citrus_MSKanji_mbrtowc_priv(_MSKanjiEncodingInfo * __restrict ei,
- wchar_t * __restrict pwc, const char ** __restrict s, size_t n,
+ wchar_t * __restrict pwc, char ** __restrict s, size_t n,
_MSKanjiState * __restrict psenc, size_t * __restrict nresult)
{
- const char *s0;
+ char *s0;
wchar_t wchar;
int chlenbak, len;
diff --git a/lib/libiconv_modules/UES/citrus_ues.c b/lib/libiconv_modules/UES/citrus_ues.c
index 45f5416..8516c2a 100644
--- a/lib/libiconv_modules/UES/citrus_ues.c
+++ b/lib/libiconv_modules/UES/citrus_ues.c
@@ -185,10 +185,10 @@ is_basic(wchar_t wc)
static int
_citrus_UES_mbrtowc_priv(_UESEncodingInfo * __restrict ei,
- wchar_t * __restrict pwc, const char ** __restrict s, size_t n,
+ wchar_t * __restrict pwc, char ** __restrict s, size_t n,
_UESState * __restrict psenc, size_t * __restrict nresult)
{
- const char *s0;
+ char *s0;
int ch, head, num, tail;
wchar_t hi, wc;
diff --git a/lib/libiconv_modules/UTF1632/citrus_utf1632.c b/lib/libiconv_modules/UTF1632/citrus_utf1632.c
index 4ef4db1..6682ab2 100644
--- a/lib/libiconv_modules/UTF1632/citrus_utf1632.c
+++ b/lib/libiconv_modules/UTF1632/citrus_utf1632.c
@@ -97,9 +97,9 @@ _citrus_UTF1632_init_state(_UTF1632EncodingInfo *ei __unused,
static int
_citrus_UTF1632_mbrtowc_priv(_UTF1632EncodingInfo *ei, wchar_t *pwc,
- const char **s, size_t n, _UTF1632State *psenc, size_t *nresult)
+ char **s, size_t n, _UTF1632State *psenc, size_t *nresult)
{
- const char *s0;
+ char *s0;
size_t result;
wchar_t wc = L'\0';
int chlenbak, endian, needlen;
diff --git a/lib/libiconv_modules/UTF7/citrus_utf7.c b/lib/libiconv_modules/UTF7/citrus_utf7.c
index 53f4f77..ce74cfe 100644
--- a/lib/libiconv_modules/UTF7/citrus_utf7.c
+++ b/lib/libiconv_modules/UTF7/citrus_utf7.c
@@ -151,11 +151,11 @@ static const char spaces[] = " \t\r\n";
static int
_citrus_UTF7_mbtoutf16(_UTF7EncodingInfo * __restrict ei,
- uint16_t * __restrict u16, const char ** __restrict s, size_t n,
+ uint16_t * __restrict u16, char ** __restrict s, size_t n,
_UTF7State * __restrict psenc, size_t * __restrict nresult)
{
_UTF7State sv;
- const char *s0;
+ char *s0;
int done, i, len;
s0 = *s;
@@ -244,7 +244,7 @@ ilseq:
static int
_citrus_UTF7_mbrtowc_priv(_UTF7EncodingInfo * __restrict ei,
- wchar_t * __restrict pwc, const char ** __restrict s, size_t n,
+ wchar_t * __restrict pwc, char ** __restrict s, size_t n,
_UTF7State * __restrict psenc, size_t * __restrict nresult)
{
uint32_t u32;
diff --git a/lib/libiconv_modules/UTF8/citrus_utf8.c b/lib/libiconv_modules/UTF8/citrus_utf8.c
index d7c78d3..1bf433e 100644
--- a/lib/libiconv_modules/UTF8/citrus_utf8.c
+++ b/lib/libiconv_modules/UTF8/citrus_utf8.c
@@ -177,10 +177,10 @@ _citrus_UTF8_unpack_state(_UTF8EncodingInfo *ei __unused, _UTF8State *s,
#endif
static int
-_citrus_UTF8_mbrtowc_priv(_UTF8EncodingInfo *ei, wchar_t *pwc, const char **s,
+_citrus_UTF8_mbrtowc_priv(_UTF8EncodingInfo *ei, wchar_t *pwc, char **s,
size_t n, _UTF8State *psenc, size_t *nresult)
{
- const char *s0;
+ char *s0;
wchar_t wchar;
int i;
uint8_t c;
diff --git a/lib/libiconv_modules/VIQR/citrus_viqr.c b/lib/libiconv_modules/VIQR/citrus_viqr.c
index dddb0b0..ed91cf6 100644
--- a/lib/libiconv_modules/VIQR/citrus_viqr.c
+++ b/lib/libiconv_modules/VIQR/citrus_viqr.c
@@ -252,11 +252,11 @@ _citrus_VIQR_unpack_state(_VIQREncodingInfo * __restrict ei __unused,
static int
_citrus_VIQR_mbrtowc_priv(_VIQREncodingInfo * __restrict ei,
- wchar_t * __restrict pwc, const char ** __restrict s, size_t n,
+ wchar_t * __restrict pwc, char ** __restrict s, size_t n,
_VIQRState * __restrict psenc, size_t * __restrict nresult)
{
mnemonic_t *m, *m0;
- const char *s0;
+ char *s0;
wchar_t wc;
ssize_t i;
int ch, escape;
diff --git a/lib/libiconv_modules/ZW/citrus_zw.c b/lib/libiconv_modules/ZW/citrus_zw.c
index 097fcfe..1728e3b 100644
--- a/lib/libiconv_modules/ZW/citrus_zw.c
+++ b/lib/libiconv_modules/ZW/citrus_zw.c
@@ -107,10 +107,10 @@ _citrus_ZW_unpack_state(_ZWEncodingInfo * __restrict ei __unused,
static int
_citrus_ZW_mbrtowc_priv(_ZWEncodingInfo * __restrict ei,
- wchar_t * __restrict pwc, const char **__restrict s, size_t n,
+ wchar_t * __restrict pwc, char **__restrict s, size_t n,
_ZWState * __restrict psenc, size_t * __restrict nresult)
{
- const char *s0;
+ char *s0;
wchar_t wc;
int ch, len;
diff --git a/lib/libiconv_modules/iconv_none/citrus_iconv_none.c b/lib/libiconv_modules/iconv_none/citrus_iconv_none.c
index 967ee13..9d6cd31 100644
--- a/lib/libiconv_modules/iconv_none/citrus_iconv_none.c
+++ b/lib/libiconv_modules/iconv_none/citrus_iconv_none.c
@@ -97,7 +97,7 @@ _citrus_iconv_none_iconv_uninit_context(struct _citrus_iconv *cv __unused)
static int
/*ARGSUSED*/
_citrus_iconv_none_iconv_convert(struct _citrus_iconv * __restrict ci __unused,
- const char * __restrict * __restrict in, size_t * __restrict inbytes,
+ char * __restrict * __restrict in, size_t * __restrict inbytes,
char * __restrict * __restrict out, size_t * __restrict outbytes,
uint32_t flags __unused, size_t * __restrict invalids)
{
diff --git a/lib/libiconv_modules/iconv_std/citrus_iconv_std.c b/lib/libiconv_modules/iconv_std/citrus_iconv_std.c
index 7c9b064..fd9a68c 100644
--- a/lib/libiconv_modules/iconv_std/citrus_iconv_std.c
+++ b/lib/libiconv_modules/iconv_std/citrus_iconv_std.c
@@ -104,7 +104,7 @@ init_encoding_state(struct _citrus_iconv_std_encoding *se)
static __inline int
mbtocsx(struct _citrus_iconv_std_encoding *se,
- _csid_t *csid, _index_t *idx, const char **s, size_t n, size_t *nresult,
+ _csid_t *csid, _index_t *idx, char **s, size_t n, size_t *nresult,
struct iconv_hooks *hooks)
{
@@ -461,7 +461,7 @@ _citrus_iconv_std_iconv_uninit_context(struct _citrus_iconv *cv)
static int
_citrus_iconv_std_iconv_convert(struct _citrus_iconv * __restrict cv,
- const char * __restrict * __restrict in, size_t * __restrict inbytes,
+ char * __restrict * __restrict in, size_t * __restrict inbytes,
char * __restrict * __restrict out, size_t * __restrict outbytes,
uint32_t flags, size_t * __restrict invalids)
{
@@ -469,7 +469,7 @@ _citrus_iconv_std_iconv_convert(struct _citrus_iconv * __restrict cv,
struct _citrus_iconv_std_context *sc = cv->cv_closure;
_csid_t csid;
_index_t idx;
- const char *tmpin;
+ char *tmpin;
size_t inval, szrin, szrout;
int ret, state = 0;
diff --git a/lib/libjail/jail.c b/lib/libjail/jail.c
index 207b9f2..0edfb3f 100644
--- a/lib/libjail/jail.c
+++ b/lib/libjail/jail.c
@@ -531,7 +531,7 @@ jailparam_set(struct jailparam *jp, unsigned njp, int flags)
}
i++;
}
- *(const void **)&jiov[i].iov_base = "errmsg";
+ jiov[i].iov_base = __DECONST(char *, "errmsg");
jiov[i].iov_len = sizeof("errmsg");
i++;
jiov[i].iov_base = jail_errmsg;
@@ -601,7 +601,7 @@ jailparam_get(struct jailparam *jp, unsigned njp, int flags)
jiov[ki].iov_len = (jp_key->jp_ctltype & CTLTYPE) == CTLTYPE_STRING
? strlen(jp_key->jp_value) + 1 : jp_key->jp_valuelen;
ki++;
- *(const void **)&jiov[ki].iov_base = "errmsg";
+ jiov[ki].iov_base = __DECONST(char *, "errmsg");
jiov[ki].iov_len = sizeof("errmsg");
ki++;
jiov[ki].iov_base = jail_errmsg;
diff --git a/lib/libjail/jail_getid.c b/lib/libjail/jail_getid.c
index fa10424..dab2dcf 100644
--- a/lib/libjail/jail_getid.c
+++ b/lib/libjail/jail_getid.c
@@ -53,12 +53,12 @@ jail_getid(const char *name)
jid = strtoul(name, &ep, 10);
if (*name && !*ep)
return jid;
- *(const void **)&jiov[0].iov_base = "name";
+ jiov[0].iov_base = __DECONST(char *, "name");
jiov[0].iov_len = sizeof("name");
jiov[1].iov_len = strlen(name) + 1;
jiov[1].iov_base = alloca(jiov[1].iov_len);
strcpy(jiov[1].iov_base, name);
- *(const void **)&jiov[2].iov_base = "errmsg";
+ jiov[2].iov_base = __DECONST(char *, "errmsg");
jiov[2].iov_len = sizeof("errmsg");
jiov[3].iov_base = jail_errmsg;
jiov[3].iov_len = JAIL_ERRMSGLEN;
@@ -80,15 +80,15 @@ jail_getname(int jid)
char *name;
char namebuf[MAXHOSTNAMELEN];
- *(const void **)&jiov[0].iov_base = "jid";
+ jiov[0].iov_base = __DECONST(char *, "jid");
jiov[0].iov_len = sizeof("jid");
jiov[1].iov_base = &jid;
jiov[1].iov_len = sizeof(jid);
- *(const void **)&jiov[2].iov_base = "name";
+ jiov[2].iov_base = __DECONST(char *, "name");
jiov[2].iov_len = sizeof("name");
jiov[3].iov_base = namebuf;
jiov[3].iov_len = sizeof(namebuf);
- *(const void **)&jiov[4].iov_base = "errmsg";
+ jiov[4].iov_base = __DECONST(char *, "errmsg");
jiov[4].iov_len = sizeof("errmsg");
jiov[5].iov_base = jail_errmsg;
jiov[5].iov_len = JAIL_ERRMSGLEN;
diff --git a/lib/libkiconv/xlat16_iconv.c b/lib/libkiconv/xlat16_iconv.c
index fee3c77..3efb779 100644
--- a/lib/libkiconv/xlat16_iconv.c
+++ b/lib/libkiconv/xlat16_iconv.c
@@ -62,7 +62,7 @@ static int chklocale(int, const char *);
typedef void *iconv_t;
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 size_t (*my_iconv)(iconv_t, char **, size_t *, char **, size_t *);
static int (*my_iconv_close)(iconv_t);
#else
#include <iconv.h>
@@ -71,7 +71,7 @@ static int (*my_iconv_close)(iconv_t);
#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 *);
+static size_t my_iconv_char(iconv_t, u_char **, size_t *, u_char **, size_t *);
int
kiconv_add_xlat16_cspair(const char *tocode, const char *fromcode, int flag)
@@ -221,8 +221,8 @@ kiconv_xlat16_open(const char *tocode, const char *fromcode, int lcase)
src[0] = (u_char)(c >> 8);
src[1] = (u_char)c;
- ret = my_iconv_char(cd, (const u_char **)&srcp,
- &inbytesleft, &dstp, &outbytesleft);
+ ret = my_iconv_char(cd, &srcp, &inbytesleft,
+ &dstp, &outbytesleft);
if (ret == -1) {
table[us] = 0;
continue;
@@ -338,11 +338,10 @@ my_iconv_init(void)
#endif
static size_t
-my_iconv_char(iconv_t cd, const u_char **ibuf, size_t * ilen, u_char **obuf,
+my_iconv_char(iconv_t cd, u_char **ibuf, size_t * ilen, u_char **obuf,
size_t * olen)
{
- const u_char *sp;
- u_char *dp, ilocal[3], olocal[3];
+ u_char *sp, *dp, ilocal[3], olocal[3];
u_char c1, c2;
int ret;
size_t ir, or;
@@ -352,7 +351,7 @@ my_iconv_char(iconv_t cd, const u_char **ibuf, size_t * ilen, u_char **obuf,
ir = *ilen;
bzero(*obuf, *olen);
- ret = my_iconv(cd, (const char **)&sp, ilen, (char **)&dp, olen);
+ ret = my_iconv(cd, (char **)&sp, ilen, (char **)&dp, olen);
c1 = (*obuf)[0];
c2 = (*obuf)[1];
@@ -375,7 +374,7 @@ my_iconv_char(iconv_t cd, const u_char **ibuf, size_t * ilen, u_char **obuf,
sp = ilocal;
dp = olocal;
- if ((my_iconv(cd,(const char **)&sp, &ir, (char **)&dp, &or)) != -1) {
+ if ((my_iconv(cd,(char **)&sp, &ir, (char **)&dp, &or)) != -1) {
if (olocal[0] != c1)
return (ret);
@@ -429,7 +428,7 @@ my_iconv_char(iconv_t cd, const u_char **ibuf, size_t * ilen, u_char **obuf,
sp = ilocal + 1;
dp = olocal;
- if ((my_iconv(cd,(const char **)&sp, &ir, (char **)&dp, &or)) != -1) {
+ if ((my_iconv(cd,(char **)&sp, &ir, (char **)&dp, &or)) != -1) {
if (olocal[0] == c2)
/*
* inbuf is a single byte char
diff --git a/lib/libc/powerpc64/sys/__vdso_gettc.c b/lib/libkvm/kvm_aarch64.c
index b99bbc4..f98ef36 100644
--- a/lib/libc/powerpc64/sys/__vdso_gettc.c
+++ b/lib/libkvm/kvm_aarch64.c
@@ -1,5 +1,9 @@
/*-
- * Copyright (c) 2013 Konstantin Belousov <kib@FreeBSD.org>
+ * Copyright (c) 2014 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Andrew Turner under
+ * sponsorship from the FreeBSD Foundation.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -26,23 +30,35 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/vdso.h>
-#include <errno.h>
+#include <sys/param.h>
+
+#include <limits.h>
+#include <kvm.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "kvm_private.h"
+
+void
+_kvm_freevtop(kvm_t *kd)
+{
+
+ printf("_kvm_freevtop\n");
+ abort();
+}
-#pragma weak __vdso_gettc
-u_int
-__vdso_gettc(const struct vdso_timehands *th)
+int
+_kvm_initvtop(kvm_t *kd)
{
- return (0);
+ printf("_kvm_initvtop\n");
+ abort();
}
-#pragma weak __vdso_gettimekeep
int
-__vdso_gettimekeep(struct vdso_timekeep **tk)
+_kvm_kvatop(kvm_t *kd, u_long va, off_t *pa)
{
- return (ENOSYS);
+ printf("_kvm_kvatop\n");
+ abort();
}
diff --git a/lib/libldns/Makefile b/lib/libldns/Makefile
index db4b989..9a436cd 100644
--- a/lib/libldns/Makefile
+++ b/lib/libldns/Makefile
@@ -18,8 +18,7 @@ SRCS= buffer.c dane.c dname.c dnssec.c dnssec_sign.c dnssec_verify.c \
SRCS+= b64_ntop.c b64_pton.c
-DPADD+= ${LIBCRYPTO}
-LDADD+= -lcrypto
+LIBADD= crypto
WARNS ?= 3
diff --git a/lib/liblzma/Makefile b/lib/liblzma/Makefile
index 8d614cf..39b929f 100644
--- a/lib/liblzma/Makefile
+++ b/lib/liblzma/Makefile
@@ -4,7 +4,7 @@ LIB= lzma
LZMADIR= ${.CURDIR}/../../contrib/xz/src/liblzma
.PATH: ${LZMADIR}/../common
-SRCS+= tuklib_physmem.c
+SRCS+= tuklib_physmem.c tuklib_cpucores.c
.PATH: ${LZMADIR}/api/lzma
@@ -21,7 +21,7 @@ LZMAINCS+= base.h \
hardware.h \
index.h \
index_hash.h \
- lzma.h \
+ lzma12.h \
stream_flags.h \
version.h \
vli.h
@@ -36,6 +36,7 @@ SRCS+= common.c \
easy_preset.c \
filter_common.c \
hardware_physmem.c \
+ hardware_cputhreads.c \
index.c \
stream_flags_common.c \
vli_size.c \
@@ -68,7 +69,10 @@ SRCS+= common.c \
stream_buffer_decoder.c \
stream_decoder.c \
stream_flags_decoder.c \
- vli_decoder.c
+ stream_encoder_mt.c \
+ vli_decoder.c \
+ outqueue.c
+
.PATH: ${LZMADIR}/check
SRCS+= check.c \
@@ -117,7 +121,16 @@ SRCS+= simple_coder.c \
arm.c \
armthumb.c \
sparc.c
-
+
+.PATH: ${LZMADIR}
+
+VERSION_MAJOR!= awk '$$1 == "\#define" && $$2 == "LZMA_VERSION_MAJOR" {print $$3 } ' \
+ ${LZMADIR}/api/lzma/version.h
+VERSION_MINOR!= awk '$$1 == "\#define" && $$2 == "LZMA_VERSION_MINOR" {print $$3 } ' \
+ ${LZMADIR}/api/lzma/version.h
+VERSION_PATCH!= awk '$$1 == "\#define" && $$2 == "LZMA_VERSION_PATCH" {print $$3 } ' \
+ ${LZMADIR}/api/lzma/version.h
+
WARNS?= 3
CFLAGS+= -DHAVE_CONFIG_H \
@@ -133,8 +146,29 @@ CFLAGS+= -DHAVE_CONFIG_H \
-I${LZMADIR}/simple \
-I${LZMADIR}/../common
+LIBADD+= pthread
+
VERSION_DEF= ${.CURDIR}/Versions.def
SYMBOL_MAPS= ${.CURDIR}/Symbol.map
CFLAGS+= -DSYMBOL_VERSIONING
+CLEANFILES+= liblzma.pc
+
+.if !defined(LIBRARIES_ONLY)
+all: liblzma.pc
+liblzma.pc: liblzma.pc.in
+ @sed -e 's,@prefix@,/usr,g ; \
+ s,@exec_prefix@,/usr,g ; \
+ s,@libdir@,/usr/lib,g ; \
+ s,@includedir@,/usr/include,g ; \
+ s,@PACKAGE_URL@,http://tukaani.org/xz/,g ; \
+ s,@PACKAGE_VERSION@,${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH},g ; \
+ s,@PTHREAD_CFLAGS@,,g ; \
+ s,@PTHREAD_LIBS@,,g' ${.ALLSRC} > ${.TARGET}
+
+beforeinstall:
+ @${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
+ liblzma.pc ${DESTDIR}${LIBDATADIR}/pkgconfig
+.endif
+
.include <bsd.lib.mk>
diff --git a/lib/liblzma/Makefile.depend b/lib/liblzma/Makefile.depend
index 4acc32f..e855f90 100644
--- a/lib/liblzma/Makefile.depend
+++ b/lib/liblzma/Makefile.depend
@@ -9,8 +9,10 @@ DIRDEPS = \
include \
include/xlocale \
lib/${CSU_DIR} \
+ lib/clang/include.host \
lib/libc \
lib/libcompiler_rt \
+ lib/libthr \
usr.bin/xinstall.host \
diff --git a/lib/liblzma/Symbol.map b/lib/liblzma/Symbol.map
index 3638bde..c297625 100644
--- a/lib/liblzma/Symbol.map
+++ b/lib/liblzma/Symbol.map
@@ -98,9 +98,19 @@ XZ_5.0 {
lzma_vli_size;
};
+XZ_5.2 {
+ lzma_block_uncomp_encode;
+ lzma_cputhreads;
+ lzma_get_progress;
+ lzma_stream_encoder_mt;
+ lzma_stream_encoder_mt_memusage;
+};
+
XZprivate_1.0 {
lzma_alloc;
+ lzma_alloc_zero;
lzma_alone_decoder_init;
+ lzma_block_buffer_bound64;
lzma_block_decoder_init;
lzma_block_encoder_init;
lzma_bufcpy;
@@ -123,6 +133,7 @@ XZprivate_1.0 {
lzma_lz_decoder_uncompressed;
lzma_lz_encoder_init;
lzma_lz_encoder_memusage;
+ lzma_lzma2_block_size;
lzma_lzma2_decoder_init;
lzma_lzma2_decoder_memusage;
lzma_lzma2_encoder_init;
@@ -155,9 +166,16 @@ XZprivate_1.0 {
lzma_mf_hc3_skip;
lzma_mf_hc4_find;
lzma_mf_hc4_skip;
+ lzma_mt_block_size;
lzma_next_end;
lzma_next_filter_init;
lzma_next_filter_update;
+ lzma_outq_end;
+ lzma_outq_get_buf;
+ lzma_outq_init;
+ lzma_outq_is_readable;
+ lzma_outq_memusage;
+ lzma_outq_read;
lzma_raw_coder_init;
lzma_raw_coder_memusage;
lzma_raw_decoder_init;
@@ -182,7 +200,7 @@ XZprivate_1.0 {
lzma_simple_x86_decoder_init;
lzma_simple_x86_encoder_init;
lzma_stream_decoder_init;
- lzma_stream_encoder_init;
lzma_strm_init;
+ lzma_tuklib_cpucores;
lzma_tuklib_physmem;
};
diff --git a/lib/liblzma/Versions.def b/lib/liblzma/Versions.def
index 1f65670..6786240 100644
--- a/lib/liblzma/Versions.def
+++ b/lib/liblzma/Versions.def
@@ -3,7 +3,9 @@
XZ_5.0 {
};
+XZ_5.2 {
+} XZ_5.0;
XZprivate_1.0 {
-} XZ_5.0;
+} XZ_5.2;
diff --git a/lib/liblzma/config.h b/lib/liblzma/config.h
index 9d97247..1d0f0bc 100644
--- a/lib/liblzma/config.h
+++ b/lib/liblzma/config.h
@@ -1,88 +1,427 @@
-// $FreeBSD$
+/* $FreeBSD$ */
+/* config.h. Generated from config.h.in by configure. */
+/* config.h.in. Generated from configure.ac by autoheader. */
+
+/* Define if building universal (internal helper macro) */
+/* #undef AC_APPLE_UNIVERSAL_BUILD */
+
+/* How many MiB of RAM to assume if the real amount cannot be determined. */
#define ASSUME_RAM 128
+
+/* Define to 1 if translation of program messages to the user's native
+ language is requested. */
+/* FreeBSD - disabled intentionally */
+/* #undef ENABLE_NLS */
+
+/* Define to 1 if bswap_16 is available. */
+/* #undef HAVE_BSWAP_16 */
+
+/* Define to 1 if bswap_32 is available. */
+/* #undef HAVE_BSWAP_32 */
+
+/* Define to 1 if bswap_64 is available. */
+/* #undef HAVE_BSWAP_64 */
+
+/* Define to 1 if you have the <byteswap.h> header file. */
+/* #undef HAVE_BYTESWAP_H */
+
+/* Define to 1 if the system has the type `CC_SHA256_CTX'. */
+/* #undef HAVE_CC_SHA256_CTX */
+
+/* Define to 1 if you have the `CC_SHA256_Init' function. */
+/* #undef HAVE_CC_SHA256_INIT */
+
+/* Define to 1 if you have the MacOS X function CFLocaleCopyCurrent in the
+ CoreFoundation framework. */
+/* #undef HAVE_CFLOCALECOPYCURRENT */
+
+/* Define to 1 if you have the MacOS X function CFPreferencesCopyAppValue in
+ the CoreFoundation framework. */
+/* #undef HAVE_CFPREFERENCESCOPYAPPVALUE */
+
+/* Define to 1 if crc32 integrity check is enabled. */
#define HAVE_CHECK_CRC32 1
+
+/* Define to 1 if crc64 integrity check is enabled. */
#define HAVE_CHECK_CRC64 1
+
+/* Define to 1 if sha256 integrity check is enabled. */
#define HAVE_CHECK_SHA256 1
+
+/* Define to 1 if you have the `clock_gettime' function. */
+#define HAVE_CLOCK_GETTIME 1
+
+/* Define to 1 if you have the <CommonCrypto/CommonDigest.h> header file. */
+/* #undef HAVE_COMMONCRYPTO_COMMONDIGEST_H */
+
+/* Define if the GNU dcgettext() function is already present or preinstalled.
+ */
+/* FreeBSD - disabled intentionally */
+/* #undef HAVE_DCGETTEXT */
+
+/* Define to 1 if you have the declaration of `CLOCK_MONOTONIC', and to 0 if
+ you don't. */
+#define HAVE_DECL_CLOCK_MONOTONIC 1
+
+/* Define to 1 if you have the declaration of `program_invocation_name', and
+ to 0 if you don't. */
#define HAVE_DECL_PROGRAM_INVOCATION_NAME 0
+
+/* Define to 1 if arm decoder is enabled. */
#define HAVE_DECODER_ARM 1
+
+/* Define to 1 if armthumb decoder is enabled. */
#define HAVE_DECODER_ARMTHUMB 1
+
+/* Define to 1 if delta decoder is enabled. */
#define HAVE_DECODER_DELTA 1
+
+/* Define to 1 if ia64 decoder is enabled. */
#define HAVE_DECODER_IA64 1
+
+/* Define to 1 if lzma1 decoder is enabled. */
#define HAVE_DECODER_LZMA1 1
+
+/* Define to 1 if lzma2 decoder is enabled. */
#define HAVE_DECODER_LZMA2 1
+
+/* Define to 1 if powerpc decoder is enabled. */
#define HAVE_DECODER_POWERPC 1
+
+/* Define to 1 if sparc decoder is enabled. */
#define HAVE_DECODER_SPARC 1
+
+/* Define to 1 if x86 decoder is enabled. */
#define HAVE_DECODER_X86 1
+
+/* Define to 1 if you have the <dlfcn.h> header file. */
#define HAVE_DLFCN_H 1
+
+/* Define to 1 if arm encoder is enabled. */
#define HAVE_ENCODER_ARM 1
+
+/* Define to 1 if armthumb encoder is enabled. */
#define HAVE_ENCODER_ARMTHUMB 1
+
+/* Define to 1 if delta encoder is enabled. */
#define HAVE_ENCODER_DELTA 1
+
+/* Define to 1 if ia64 encoder is enabled. */
#define HAVE_ENCODER_IA64 1
+
+/* Define to 1 if lzma1 encoder is enabled. */
#define HAVE_ENCODER_LZMA1 1
+
+/* Define to 1 if lzma2 encoder is enabled. */
#define HAVE_ENCODER_LZMA2 1
+
+/* Define to 1 if powerpc encoder is enabled. */
#define HAVE_ENCODER_POWERPC 1
+
+/* Define to 1 if sparc encoder is enabled. */
#define HAVE_ENCODER_SPARC 1
+
+/* Define to 1 if x86 encoder is enabled. */
#define HAVE_ENCODER_X86 1
+
+/* Define to 1 if you have the <fcntl.h> header file. */
#define HAVE_FCNTL_H 1
-#define HAVE_FUTIMES 1
+
+/* Define to 1 if you have the `futimens' function. */
+#define HAVE_FUTIMENS 1
+
+/* Define to 1 if you have the `futimes' function. */
+/* #undef HAVE_FUTIMES */
+
+/* Define to 1 if you have the `futimesat' function. */
+/* #undef HAVE_FUTIMESAT */
+
+/* Define to 1 if you have the <getopt.h> header file. */
#define HAVE_GETOPT_H 1
+
+/* Define to 1 if you have the `getopt_long' function. */
#define HAVE_GETOPT_LONG 1
+
+/* Define if the GNU gettext() function is already present or preinstalled. */
+/* FreeBSD - disabled intentionally */
+/* #undef HAVE_GETTEXT */
+
+/* Define if you have the iconv() function and it works. */
+#define HAVE_ICONV 1
+
+/* Define to 1 if you have the <immintrin.h> header file. */
+#if defined(__FreeBSD__) && defined(__amd64__)
+#define HAVE_IMMINTRIN_H 1
+#endif
+
+/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1
+
+/* Define to 1 if you have the <limits.h> header file. */
#define HAVE_LIMITS_H 1
+
+/* Define to 1 if mbrtowc and mbstate_t are properly declared. */
#define HAVE_MBRTOWC 1
+
+/* Define to 1 if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 1
+
+/* Define to 1 to enable bt2 match finder. */
#define HAVE_MF_BT2 1
+
+/* Define to 1 to enable bt3 match finder. */
#define HAVE_MF_BT3 1
+
+/* Define to 1 to enable bt4 match finder. */
#define HAVE_MF_BT4 1
+
+/* Define to 1 to enable hc3 match finder. */
#define HAVE_MF_HC3 1
+
+/* Define to 1 to enable hc4 match finder. */
#define HAVE_MF_HC4 1
+
+/* Define to 1 if you have the <minix/sha2.h> header file. */
+/* #undef HAVE_MINIX_SHA2_H */
+
+/* Define to 1 if getopt.h declares extern int optreset. */
#define HAVE_OPTRESET 1
-#define HAVE_PTHREAD 1
+
+/* Define to 1 if you have the `pipe2' function. */
+#define HAVE_PIPE2 1
+
+/* Define to 1 if you have the `posix_fadvise' function. */
+#define HAVE_POSIX_FADVISE 1
+
+/* Define to 1 if you have the `pthread_condattr_setclock' function. */
+#define HAVE_PTHREAD_CONDATTR_SETCLOCK 1
+
+/* Have PTHREAD_PRIO_INHERIT. */
+#define HAVE_PTHREAD_PRIO_INHERIT 1
+
+/* Define to 1 if you have the `SHA256Init' function. */
+/* #undef HAVE_SHA256INIT */
+
+/* Define to 1 if the system has the type `SHA256_CTX'. */
+/* FreeBSD - disabled libmd SHA256 for now */
+/* #undef HAVE_SHA256_CTX */
+
+/* Define to 1 if you have the <sha256.h> header file. */
+/* FreeBSD - disabled libmd SHA256 for now */
+/* #undef HAVE_SHA256_H */
+
+/* Define to 1 if you have the `SHA256_Init' function. */
+/* FreeBSD - disabled libmd SHA256 for now */
+/* #undef HAVE_SHA256_INIT */
+
+/* Define to 1 if the system has the type `SHA2_CTX'. */
+/* #undef HAVE_SHA2_CTX */
+
+/* Define to 1 if you have the <sha2.h> header file. */
+/* #undef HAVE_SHA2_H */
+
+/* Define to 1 if optimizing for size. */
+/* #undef HAVE_SMALL */
+
+/* Define to 1 if stdbool.h conforms to C99. */
#define HAVE_STDBOOL_H 1
+
+/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 1
+
+/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1
+
+/* Define to 1 if you have the <strings.h> header file. */
#define HAVE_STRINGS_H 1
+
+/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1
+
+/* Define to 1 if `st_atimensec' is a member of `struct stat'. */
+/* #undef HAVE_STRUCT_STAT_ST_ATIMENSEC */
+
+/* Define to 1 if `st_atimespec.tv_nsec' is a member of `struct stat'. */
#define HAVE_STRUCT_STAT_ST_ATIMESPEC_TV_NSEC 1
+
+/* Define to 1 if `st_atim.st__tim.tv_nsec' is a member of `struct stat'. */
+/* #undef HAVE_STRUCT_STAT_ST_ATIM_ST__TIM_TV_NSEC */
+
+/* Define to 1 if `st_atim.tv_nsec' is a member of `struct stat'. */
+#define HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC 1
+
+/* Define to 1 if `st_uatime' is a member of `struct stat'. */
+/* #undef HAVE_STRUCT_STAT_ST_UATIME */
+
+/* Define to 1 if you have the <sys/byteorder.h> header file. */
+/* #undef HAVE_SYS_BYTEORDER_H */
+
+/* Define to 1 if you have the <sys/endian.h> header file. */
#define HAVE_SYS_ENDIAN_H 1
+
+/* Define to 1 if you have the <sys/param.h> header file. */
#define HAVE_SYS_PARAM_H 1
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the <sys/time.h> header file. */
#define HAVE_SYS_TIME_H 1
+
+/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if the system has the type `uintptr_t'. */
#define HAVE_UINTPTR_T 1
+
+/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1
+
+/* Define to 1 if you have the `utime' function. */
+/* #undef HAVE_UTIME */
+
+/* Define to 1 if you have the `utimes' function. */
+/* #undef HAVE_UTIMES */
+
+/* Define to 1 or 0, depending whether the compiler supports simple visibility
+ declarations. */
#define HAVE_VISIBILITY 1
+
+/* Define to 1 if you have the `wcwidth' function. */
#define HAVE_WCWIDTH 1
+
+/* Define to 1 if the system has the type `_Bool'. */
#define HAVE__BOOL 1
+
+/* Define to 1 if _mm_movemask_epi8 is available. */
+#if defined(__FreeBSD__) && defined(__amd64__)
+#define HAVE__MM_MOVEMASK_EPI8 1
+#endif
+
+/* Define to the sub-directory where libtool stores uninstalled libraries. */
#define LT_OBJDIR ".libs/"
+
+/* Define to 1 when using POSIX threads (pthreads). */
+#define MYTHREAD_POSIX 1
+
+/* Define to 1 when using Windows Vista compatible threads. This uses features
+ that are not available on Windows XP. */
+/* #undef MYTHREAD_VISTA */
+
+/* Define to 1 when using Windows 95 (and thus XP) compatible threads. This
+ avoids use of features that were added in Windows Vista. */
+/* #undef MYTHREAD_WIN95 */
+
+/* Define to 1 to disable debugging code. */
#define NDEBUG 1
+
+/* Name of package */
#define PACKAGE "xz"
+
+/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT "lasse.collin@tukaani.org"
+
+/* Define to the full name of this package. */
#define PACKAGE_NAME "XZ Utils"
-#define PACKAGE_STRING "XZ Utils 5.0.3"
+
+/* Define to the full name and version of this package. */
+#define PACKAGE_STRING "XZ Utils 5.2.1"
+
+/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "xz"
+
+/* Define to the home page for this package. */
#define PACKAGE_URL "http://tukaani.org/xz/"
-#define PACKAGE_VERSION "5.0.3"
+
+/* Define to the version of this package. */
+#define PACKAGE_VERSION "5.2.1"
+
+/* Define to necessary symbol if this constant uses a non-standard name on
+ your system. */
+/* #undef PTHREAD_CREATE_JOINABLE */
+
+/* The size of `size_t', as computed by sizeof. */
#define SIZEOF_SIZE_T 8
+
+/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1
-#define TUKLIB_CPUCORES_SYSCTL 1
+
+/* Define to 1 if the number of available CPU cores can be detected with
+ cpuset(2). */
+#define TUKLIB_CPUCORES_CPUSET 1
+
+/* Define to 1 if the number of available CPU cores can be detected with
+ pstat_getdynamic(). */
+/* #undef TUKLIB_CPUCORES_PSTAT_GETDYNAMIC */
+
+/* Define to 1 if the number of available CPU cores can be detected with
+ sysconf(_SC_NPROCESSORS_ONLN) or sysconf(_SC_NPROC_ONLN). */
+/* #undef TUKLIB_CPUCORES_SYSCONF */
+
+/* Define to 1 if the number of available CPU cores can be detected with
+ sysctl(). */
+/* #undef TUKLIB_CPUCORES_SYSCTL */
+
+/* Define to 1 if the system supports fast unaligned access to 16-bit and
+ 32-bit integers. */
+/* FreeBSD - derive from __NO_STRICT_ALIGNMENT */
+/* #undef TUKLIB_FAST_UNALIGNED_ACCESS */
+
+/* Define to 1 if the amount of physical memory can be detected with
+ _system_configuration.physmem. */
+/* #undef TUKLIB_PHYSMEM_AIX */
+
+/* Define to 1 if the amount of physical memory can be detected with
+ getinvent_r(). */
+/* #undef TUKLIB_PHYSMEM_GETINVENT_R */
+
+/* Define to 1 if the amount of physical memory can be detected with
+ getsysinfo(). */
+/* #undef TUKLIB_PHYSMEM_GETSYSINFO */
+
+/* Define to 1 if the amount of physical memory can be detected with
+ pstat_getstatic(). */
+/* #undef TUKLIB_PHYSMEM_PSTAT_GETSTATIC */
+
+/* Define to 1 if the amount of physical memory can be detected with
+ sysconf(_SC_PAGESIZE) and sysconf(_SC_PHYS_PAGES). */
#define TUKLIB_PHYSMEM_SYSCONF 1
+
+/* Define to 1 if the amount of physical memory can be detected with sysctl().
+ */
+/* #undef TUKLIB_PHYSMEM_SYSCTL */
+
+/* Define to 1 if the amount of physical memory can be detected with Linux
+ sysinfo(). */
+/* #undef TUKLIB_PHYSMEM_SYSINFO */
+
+/* Enable extensions on AIX 3, Interix. */
#ifndef _ALL_SOURCE
# define _ALL_SOURCE 1
#endif
+/* Enable GNU extensions on systems that have them. */
#ifndef _GNU_SOURCE
# define _GNU_SOURCE 1
#endif
+/* Enable threading extensions on Solaris. */
#ifndef _POSIX_PTHREAD_SEMANTICS
# define _POSIX_PTHREAD_SEMANTICS 1
#endif
+/* Enable extensions on HP NonStop. */
#ifndef _TANDEM_SOURCE
# define _TANDEM_SOURCE 1
#endif
+/* Enable general extensions on Solaris. */
#ifndef __EXTENSIONS__
# define __EXTENSIONS__ 1
#endif
-#define VERSION "5.0.3"
+
+
+/* Version number of package */
+#define VERSION "5.2.1"
+
+/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
+ significant byte first (like Motorola and SPARC, unlike Intel). */
#if defined(__FreeBSD__)
#include <sys/_types.h>
#if defined(__NO_STRICT_ALIGNMENT)
@@ -92,14 +431,72 @@
#if _BYTE_ORDER == _BIG_ENDIAN
# define WORDS_BIGENDIAN 1
#endif
-#else
-#if defined AC_APPLE_UNIVERSAL_BUILD
-# if defined __BIG_ENDIAN__
-# define WORDS_BIGENDIAN 1
-# endif
-#else
-# ifndef WORDS_BIGENDIAN
-/* # undef WORDS_BIGENDIAN */
-# endif
#endif
+
+/* Enable large inode numbers on Mac OS X 10.5. */
+#ifndef _DARWIN_USE_64_BIT_INODE
+# define _DARWIN_USE_64_BIT_INODE 1
#endif
+
+/* Number of bits in a file offset, on hosts where this is settable. */
+/* #undef _FILE_OFFSET_BITS */
+
+/* Define for large files, on AIX-style hosts. */
+/* #undef _LARGE_FILES */
+
+/* Define to 1 if on MINIX. */
+/* #undef _MINIX */
+
+/* Define to 2 if the system does not provide POSIX.1 features except with
+ this defined. */
+/* #undef _POSIX_1_SOURCE */
+
+/* Define to 1 if you need to in order for `stat' and other things to work. */
+/* #undef _POSIX_SOURCE */
+
+/* Define for Solaris 2.5.1 so the uint32_t typedef from <sys/synch.h>,
+ <pthread.h>, or <semaphore.h> is not used. If the typedef were allowed, the
+ #define below would cause a syntax error. */
+/* #undef _UINT32_T */
+
+/* Define for Solaris 2.5.1 so the uint64_t typedef from <sys/synch.h>,
+ <pthread.h>, or <semaphore.h> is not used. If the typedef were allowed, the
+ #define below would cause a syntax error. */
+/* #undef _UINT64_T */
+
+/* Define for Solaris 2.5.1 so the uint8_t typedef from <sys/synch.h>,
+ <pthread.h>, or <semaphore.h> is not used. If the typedef were allowed, the
+ #define below would cause a syntax error. */
+/* #undef _UINT8_T */
+
+/* Define to rpl_ if the getopt replacement functions and variables should be
+ used. */
+/* #undef __GETOPT_PREFIX */
+
+/* Define to the type of a signed integer type of width exactly 32 bits if
+ such a type exists and the standard includes do not define it. */
+/* #undef int32_t */
+
+/* Define to the type of a signed integer type of width exactly 64 bits if
+ such a type exists and the standard includes do not define it. */
+/* #undef int64_t */
+
+/* Define to the type of an unsigned integer type of width exactly 16 bits if
+ such a type exists and the standard includes do not define it. */
+/* #undef uint16_t */
+
+/* Define to the type of an unsigned integer type of width exactly 32 bits if
+ such a type exists and the standard includes do not define it. */
+/* #undef uint32_t */
+
+/* Define to the type of an unsigned integer type of width exactly 64 bits if
+ such a type exists and the standard includes do not define it. */
+/* #undef uint64_t */
+
+/* Define to the type of an unsigned integer type of width exactly 8 bits if
+ such a type exists and the standard includes do not define it. */
+/* #undef uint8_t */
+
+/* Define to the type of an unsigned integer type wide enough to hold a
+ pointer, if such a type exists, and if the system does not define it. */
+/* #undef uintptr_t */
diff --git a/lib/libmagic/Makefile b/lib/libmagic/Makefile
index 14f1702..2add1d3 100644
--- a/lib/libmagic/Makefile
+++ b/lib/libmagic/Makefile
@@ -7,8 +7,7 @@ CONTRDIR= ${.CURDIR}/../../contrib/file
LIB= magic
SHLIB_MAJOR= 4
-DPADD= ${LIBZ}
-LDADD= -lz
+LIBADD= z
MAN= libmagic.3 magic.5
SRCS= apprentice.c apptype.c ascmagic.c cdf.c cdf_time.c compress.c \
diff --git a/lib/libmagic/config.h b/lib/libmagic/config.h
index d80926d..47f3347 100644
--- a/lib/libmagic/config.h
+++ b/lib/libmagic/config.h
@@ -1,5 +1,13 @@
/* $FreeBSD$ */
+/* Get __FreeBSD_version. */
+#include <osreldate.h>
+
+/* Only specific versions of FreeBSD support xlocale */
+#if __FreeBSD_version >= 1000002 || (__FreeBSD_version < 1000000 && __FreeBSD_version >= 900506)
+#define FREEBSD_XLOCALE_SUPPORT 1
+#endif
+
/* config.h. Generated from config.h.in by configure. */
/* config.h.in. Generated from configure.ac by autoheader. */
@@ -47,6 +55,11 @@
/* Define to 1 if you have the `fork' function. */
#define HAVE_FORK 1
+/* Define to 1 if you have the `freelocale' function. */
+#ifdef FREEBSD_XLOCALE_SUPPORT
+#define HAVE_FREELOCALE 1
+#endif
+
/* Define to 1 if fseeko (and presumably ftello) exists and is declared. */
#define HAVE_FSEEKO 1
@@ -98,9 +111,17 @@
/* Define to 1 if you have a working `mmap' system call. */
#define HAVE_MMAP 1
+/* Define to 1 if you have the `newlocale' function. */
+#ifdef FREEBSD_XLOCALE_SUPPORT
+#define HAVE_NEWLOCALE 1
+#endif
+
/* Define to 1 if you have the `pread' function. */
#define HAVE_PREAD 1
+/* Define to 1 if you have the `setlocale' function. */
+#define HAVE_SETLOCALE 1
+
/* Define to 1 if you have the <stddef.h> header file. */
#define HAVE_STDDEF_H 1
@@ -185,6 +206,11 @@
/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1
+/* Define to 1 if you have the `uselocale' function. */
+#ifdef FREEBSD_XLOCALE_SUPPORT
+#define HAVE_USELOCALE 1
+#endif
+
/* Define to 1 if you have the `utime' function. */
#define HAVE_UTIME 1
@@ -222,6 +248,11 @@
/* Define to 1 if `vfork' works. */
#define HAVE_WORKING_VFORK 1
+/* Define to 1 if you have the <xlocale.h> header file. */
+#ifdef FREEBSD_XLOCALE_SUPPORT
+#define HAVE_XLOCALE_H 1
+#endif
+
/* Define to 1 if you have the <zlib.h> header file. */
#define HAVE_ZLIB_H 1
@@ -247,7 +278,7 @@
#define PACKAGE_NAME "file"
/* Define to the full name and version of this package. */
-#define PACKAGE_STRING "file 5.19"
+#define PACKAGE_STRING "file 5.22"
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "file"
@@ -256,7 +287,7 @@
#define PACKAGE_URL ""
/* Define to the version of this package. */
-#define PACKAGE_VERSION "5.19"
+#define PACKAGE_VERSION "5.22"
/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1
@@ -287,7 +318,7 @@
/* Version number of package */
-#define VERSION "5.19"
+#define VERSION "5.22"
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
significant byte first (like Motorola and SPARC, unlike Intel). */
diff --git a/lib/libmandoc/Makefile b/lib/libmandoc/Makefile
deleted file mode 100644
index b857b8a..0000000
--- a/lib/libmandoc/Makefile
+++ /dev/null
@@ -1,20 +0,0 @@
-# $FreeBSD$
-
-MDOCMLDIR= ${.CURDIR}/../../contrib/mdocml
-.PATH: ${MDOCMLDIR}
-
-LIB= mandoc
-#NO_PIC=
-INTERNALLIB=
-MAN= mandoc.3
-SRCS= arch.c att.c chars.c \
- compat_fgetln.c compat_getsubopt.c compat_strlcat.c compat_strlcpy.c \
- eqn.c lib.c man.c man_hash.c man_macro.c man_validate.c mandoc.c \
- mdoc.c mdoc_argv.c mdoc_hash.c mdoc_macro.c mdoc_validate.c \
- msec.c read.c roff.c st.c \
- tbl.c tbl_data.c tbl_layout.c tbl_opts.c vol.c
-
-WARNS?= 3
-CFLAGS+= -DHAVE_CONFIG_H
-
-.include <bsd.lib.mk>
diff --git a/lib/libmd/Makefile b/lib/libmd/Makefile
index 727fd86..61bea29 100644
--- a/lib/libmd/Makefile
+++ b/lib/libmd/Makefile
@@ -42,7 +42,13 @@ CLEANFILES+= md[245]hl.c md[245].ref md[245].3 mddriver \
sha0.ref sha0hl.c sha1.ref sha1hl.c shadriver \
sha256.ref sha256hl.c sha512.ref sha512hl.c
-CFLAGS+= -I${.CURDIR}
+# Define WEAK_REFS to provide weak aliases for libmd symbols
+#
+# Note that the same sources are also used internally by libcrypt,
+# in which case:
+# * macros are used to rename symbols to libcrypt internal names
+# * no weak aliases are generated
+CFLAGS+= -I${.CURDIR} -DWEAK_REFS
.PATH: ${.CURDIR}/${MACHINE_ARCH} ${.CURDIR}/../../sys/crypto/sha2
.if exists(${MACHINE_ARCH}/sha.S)
diff --git a/lib/libmd/Makefile.depend.host b/lib/libmd/Makefile.depend.host
new file mode 100644
index 0000000..beeaf30
--- /dev/null
+++ b/lib/libmd/Makefile.depend.host
@@ -0,0 +1,36 @@
+# Autogenerated - do NOT edit!
+
+DEP_RELDIR := ${_PARSEDIR:S,${SRCTOP}/,,}
+
+DIRDEPS = \
+ bin/cat \
+ gnu/usr.bin/binutils/ld \
+ usr.bin/xinstall \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+md4hl.So: md4hl.c
+md4hl.o: md4hl.c
+md4hl.po: md4hl.c
+md5hl.So: md5hl.c
+md5hl.o: md5hl.c
+md5hl.po: md5hl.c
+rmd160hl.So: rmd160hl.c
+rmd160hl.o: rmd160hl.c
+rmd160hl.po: rmd160hl.c
+sha0hl.So: sha0hl.c
+sha0hl.o: sha0hl.c
+sha0hl.po: sha0hl.c
+sha1hl.So: sha1hl.c
+sha1hl.o: sha1hl.c
+sha1hl.po: sha1hl.c
+sha256hl.So: sha256hl.c
+sha256hl.o: sha256hl.c
+sha256hl.po: sha256hl.c
+sha512hl.So: sha512hl.c
+sha512hl.o: sha512hl.c
+sha512hl.po: sha512hl.c
+.endif
diff --git a/lib/libmd/md4.h b/lib/libmd/md4.h
index 4773513..086a27b 100644
--- a/lib/libmd/md4.h
+++ b/lib/libmd/md4.h
@@ -35,6 +35,34 @@ typedef struct MD4Context {
#include <sys/cdefs.h>
__BEGIN_DECLS
+
+/* Ensure libmd symbols do not clash with libcrypto */
+
+#ifndef MD4Init
+#define MD4Init _libmd_MD4Init
+#endif
+#ifndef MD4Update
+#define MD4Update _libmd_MD4Update
+#endif
+#ifndef MD4Pad
+#define MD4Pad _libmd_MD4Pad
+#endif
+#ifndef MD4Final
+#define MD4Final _libmd_MD4Final
+#endif
+#ifndef MD4End
+#define MD4End _libmd_MD4End
+#endif
+#ifndef MD4File
+#define MD4File _libmd_MD4File
+#endif
+#ifndef MD4FileChunk
+#define MD4FileChunk _libmd_MD4FileChunk
+#endif
+#ifndef MD4Data
+#define MD4Data _libmd_MD4Data
+#endif
+
void MD4Init(MD4_CTX *);
void MD4Update(MD4_CTX *, const void *, unsigned int);
void MD4Pad(MD4_CTX *);
diff --git a/lib/libmd/md4c.c b/lib/libmd/md4c.c
index 1211a98..de1a7b4a 100644
--- a/lib/libmd/md4c.c
+++ b/lib/libmd/md4c.c
@@ -290,3 +290,18 @@ unsigned int len;
output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) |
(((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24);
}
+
+#ifdef WEAK_REFS
+/* When building libmd, provide weak references. Note: this is not
+ activated in the context of compiling these sources for internal
+ use in libcrypt.
+ */
+#undef MD4Init
+__weak_reference(_libmd_MD4Init, MD4Init);
+#undef MD4Update
+__weak_reference(_libmd_MD4Update, MD4Update);
+#undef MD4Pad
+__weak_reference(_libmd_MD4Pad, MD4Pad);
+#undef MD4Final
+__weak_reference(_libmd_MD4Final, MD4Final);
+#endif
diff --git a/lib/libmd/md5.h b/lib/libmd/md5.h
index 803a88f..5ab3b14 100644
--- a/lib/libmd/md5.h
+++ b/lib/libmd/md5.h
@@ -1,4 +1,41 @@
+/* $FreeBSD$ */
+
#ifndef _MD5_H_
#define _MD5_H_
+
+#ifndef _KERNEL
+
+/* Ensure libmd symbols do not clash with libcrypto */
+
+#ifndef MD5Init
+#define MD5Init _libmd_MD5Init
+#endif
+#ifndef MD5Update
+#define MD5Update _libmd_MD5Update
+#endif
+#ifndef MD5Pad
+#define MD5Pad _libmd_MD5Pad
+#endif
+#ifndef MD5Final
+#define MD5Final _libmd_MD5Final
+#endif
+#ifndef MD5Transform
+#define MD5Transform _libmd_MD5Transform
+#endif
+#ifndef MD5End
+#define MD5End _libmd_MD5End
+#endif
+#ifndef MD5File
+#define MD5File _libmd_MD5File
+#endif
+#ifndef MD5FileChunk
+#define MD5FileChunk _libmd_MD5FileChunk
+#endif
+#ifndef MD5Data
+#define MD5Data _libmd_MD5Data
+#endif
+
+#endif
+
#include <sys/md5.h>
#endif /* _MD5_H_ */
diff --git a/lib/libmd/md5c.c b/lib/libmd/md5c.c
index d097390..6b50464 100644
--- a/lib/libmd/md5c.c
+++ b/lib/libmd/md5c.c
@@ -39,7 +39,7 @@ __FBSDID("$FreeBSD$");
#include <machine/endian.h>
#include <sys/endian.h>
-#include <sys/md5.h>
+#include "md5.h"
static void MD5Transform(u_int32_t [4], const unsigned char [64]);
@@ -335,3 +335,20 @@ MD5Transform (state, block)
/* Zeroize sensitive information. */
memset ((void *)x, 0, sizeof (x));
}
+
+#ifdef WEAK_REFS
+/* When building libmd, provide weak references. Note: this is not
+ activated in the context of compiling these sources for internal
+ use in libcrypt.
+ */
+#undef MD5Init
+__weak_reference(_libmd_MD5Init, MD5Init);
+#undef MD5Update
+__weak_reference(_libmd_MD5Update, MD5Update);
+#undef MD5Pad
+__weak_reference(_libmd_MD5Pad, MD5Pad);
+#undef MD5Final
+__weak_reference(_libmd_MD5Final, MD5Final);
+#undef MD5Transform
+__weak_reference(_libmd_MD5Transform, MD5Transform);
+#endif
diff --git a/lib/libmd/mdXhl.c b/lib/libmd/mdXhl.c
index e69e5e5..62be235 100644
--- a/lib/libmd/mdXhl.c
+++ b/lib/libmd/mdXhl.c
@@ -74,7 +74,7 @@ MDXFileChunk(const char *filename, char *buf, off_t ofs, off_t len)
i = read(f, buffer, sizeof(buffer));
else
i = read(f, buffer, n);
- if (i < 0)
+ if (i <= 0)
break;
MDXUpdate(&ctx, buffer, i);
n -= i;
@@ -96,3 +96,18 @@ MDXData (const void *data, unsigned int len, char *buf)
MDXUpdate(&ctx,data,len);
return (MDXEnd(&ctx, buf));
}
+
+#ifdef WEAK_REFS
+/* When building libmd, provide weak references. Note: this is not
+ activated in the context of compiling these sources for internal
+ use in libcrypt.
+ */
+#undef MDXEnd
+__weak_reference(_libmd_MDXEnd, MDXEnd);
+#undef MDXFile
+__weak_reference(_libmd_MDXFile, MDXFile);
+#undef MDXFileChunk
+__weak_reference(_libmd_MDXFileChunk, MDXFileChunk);
+#undef MDXData
+__weak_reference(_libmd_MDXData, MDXData);
+#endif
diff --git a/lib/libmd/ripemd.h b/lib/libmd/ripemd.h
index 2ff35cc..778808f 100644
--- a/lib/libmd/ripemd.h
+++ b/lib/libmd/ripemd.h
@@ -81,6 +81,41 @@ typedef struct RIPEMD160state_st {
} RIPEMD160_CTX;
__BEGIN_DECLS
+
+/* Ensure libmd symbols do not clash with libcrypto */
+
+#ifndef RIPEMD160_Init
+#define RIPEMD160_Init _libmd_RIPEMD160_Init
+#endif
+#ifndef RIPEMD160_Update
+#define RIPEMD160_Update _libmd_RIPEMD160_Update
+#endif
+#ifndef RIPEMD160_Final
+#define RIPEMD160_Final _libmd_RIPEMD160_Final
+#endif
+#ifndef RIPEMD160_End
+#define RIPEMD160_End _libmd_RIPEMD160_End
+#endif
+#ifndef RIPEMD160_File
+#define RIPEMD160_File _libmd_RIPEMD160_File
+#endif
+#ifndef RIPEMD160_FileChunk
+#define RIPEMD160_FileChunk _libmd_RIPEMD160_FileChunk
+#endif
+#ifndef RIPEMD160_Data
+#define RIPEMD160_Data _libmd_RIPEMD160_Data
+#endif
+
+#ifndef RIPEMD160_Transform
+#define RIPEMD160_Transform _libmd_RIPEMD160_Transform
+#endif
+#ifndef RMD160_version
+#define RMD160_version _libmd_RMD160_version
+#endif
+#ifndef ripemd160_block
+#define ripemd160_block _libmd_ripemd160_block
+#endif
+
void RIPEMD160_Init(RIPEMD160_CTX *c);
void RIPEMD160_Update(RIPEMD160_CTX *c, const void *data,
size_t len);
diff --git a/lib/libmd/rmd160c.c b/lib/libmd/rmd160c.c
index e01f1e0..5a3b783 100644
--- a/lib/libmd/rmd160c.c
+++ b/lib/libmd/rmd160c.c
@@ -545,3 +545,22 @@ unsigned long *l;
}
}
#endif
+
+#ifdef WEAK_REFS
+/* When building libmd, provide weak references. Note: this is not
+ activated in the context of compiling these sources for internal
+ use in libcrypt.
+ */
+#undef RIPEMD160_Init
+__weak_reference(_libmd_RIPEMD160_Init, RIPEMD160_Init);
+#undef RIPEMD160_Update
+__weak_reference(_libmd_RIPEMD160_Update, RIPEMD160_Update);
+#undef RIPEMD160_Final
+__weak_reference(_libmd_RIPEMD160_Final, RIPEMD160_Final);
+#undef RIPEMD160_Transform
+__weak_reference(_libmd_RIPEMD160_Transform, RIPEMD160_Transform);
+#undef RMD160_version
+__weak_reference(_libmd_RMD160_version, RMD160_version);
+#undef ripemd160_block
+__weak_reference(_libmd_ripemd160_block, ripemd160_block);
+#endif
diff --git a/lib/libmd/sha.h b/lib/libmd/sha.h
index 8a0b7c2..c608c5b 100644
--- a/lib/libmd/sha.h
+++ b/lib/libmd/sha.h
@@ -79,6 +79,73 @@ typedef struct SHAstate_st {
#define SHA1_CTX SHA_CTX
__BEGIN_DECLS
+
+/* Ensure libmd symbols do not clash with libcrypto */
+
+#ifndef SHA_Init
+#define SHA_Init _libmd_SHA_Init
+#endif
+#ifndef SHA_Update
+#define SHA_Update _libmd_SHA_Update
+#endif
+#ifndef SHA_Final
+#define SHA_Final _libmd_SHA_Final
+#endif
+#ifndef SHA_End
+#define SHA_End _libmd_SHA_End
+#endif
+#ifndef SHA_File
+#define SHA_File _libmd_SHA_File
+#endif
+#ifndef SHA_FileChunk
+#define SHA_FileChunk _libmd_SHA_FileChunk
+#endif
+#ifndef SHA_Data
+#define SHA_Data _libmd_SHA_Data
+#endif
+
+#ifndef SHA_Transform
+#define SHA_Transform _libmd_SHA_Transform
+#endif
+#ifndef SHA_version
+#define SHA_version _libmd_SHA_version
+#endif
+#ifndef sha_block
+#define sha_block _libmd_sha_block
+#endif
+
+#ifndef SHA1_Init
+#define SHA1_Init _libmd_SHA1_Init
+#endif
+#ifndef SHA1_Update
+#define SHA1_Update _libmd_SHA1_Update
+#endif
+#ifndef SHA1_Final
+#define SHA1_Final _libmd_SHA1_Final
+#endif
+#ifndef SHA1_End
+#define SHA1_End _libmd_SHA1_End
+#endif
+#ifndef SHA1_File
+#define SHA1_File _libmd_SHA1_File
+#endif
+#ifndef SHA1_FileChunk
+#define SHA1_FileChunk _libmd_SHA1_FileChunk
+#endif
+#ifndef SHA1_Data
+#define SHA1_Data _libmd_SHA1_Data
+#endif
+
+#ifndef SHA1_Transform
+#define SHA1_Transform _libmd_SHA1_Transform
+#endif
+#ifndef SHA1_version
+#define SHA1_version _libmd_SHA1_version
+#endif
+#ifndef sha1_block
+#define sha1_block _libmd_sha1_block
+#endif
+
void SHA_Init(SHA_CTX *c);
void SHA_Update(SHA_CTX *c, const void *data, size_t len);
void SHA_Final(unsigned char *md, SHA_CTX *c);
@@ -86,6 +153,7 @@ char *SHA_End(SHA_CTX *, char *);
char *SHA_File(const char *, char *);
char *SHA_FileChunk(const char *, char *, off_t, off_t);
char *SHA_Data(const void *, unsigned int, char *);
+
void SHA1_Init(SHA_CTX *c);
void SHA1_Update(SHA_CTX *c, const void *data, size_t len);
void SHA1_Final(unsigned char *md, SHA_CTX *c);
diff --git a/lib/libmd/sha1c.c b/lib/libmd/sha1c.c
index ba3278a..93a4ff3 100644
--- a/lib/libmd/sha1c.c
+++ b/lib/libmd/sha1c.c
@@ -488,3 +488,33 @@ SHA_CTX *c;
/* memset((char *)&c,0,sizeof(c));*/
}
+#ifdef WEAK_REFS
+/* When building libmd, provide weak references. Note: this is not
+ activated in the context of compiling these sources for internal
+ use in libcrypt.
+ */
+#undef SHA_Init
+__weak_reference(_libmd_SHA_Init, SHA_Init);
+#undef SHA_Update
+__weak_reference(_libmd_SHA_Update, SHA_Update);
+#undef SHA_Final
+__weak_reference(_libmd_SHA_Final, SHA_Final);
+#undef SHA_Transform
+__weak_reference(_libmd_SHA_Transform, SHA_Transform);
+#undef SHA_version
+__weak_reference(_libmd_SHA_version, SHA_version);
+#undef sha_block
+__weak_reference(_libmd_sha_block, sha_block);
+#undef SHA1_Init
+__weak_reference(_libmd_SHA1_Init, SHA1_Init);
+#undef SHA1_Update
+__weak_reference(_libmd_SHA1_Update, SHA1_Update);
+#undef SHA1_Final
+__weak_reference(_libmd_SHA1_Final, SHA1_Final);
+#undef SHA1_Transform
+__weak_reference(_libmd_SHA1_Transform, SHA1_Transform);
+#undef SHA1_version
+__weak_reference(_libmd_SHA1_version, SHA1_version);
+#undef sha1_block
+__weak_reference(_libmd_sha1_block, sha1_block);
+#endif
diff --git a/lib/libmd/sha256.h b/lib/libmd/sha256.h
index 1b6a4f4..f55d1d3 100644
--- a/lib/libmd/sha256.h
+++ b/lib/libmd/sha256.h
@@ -38,6 +38,38 @@ typedef struct SHA256Context {
} SHA256_CTX;
__BEGIN_DECLS
+
+/* Ensure libmd symbols do not clash with libcrypto */
+
+#ifndef SHA256_Init
+#define SHA256_Init _libmd_SHA256_Init
+#endif
+#ifndef SHA256_Update
+#define SHA256_Update _libmd_SHA256_Update
+#endif
+#ifndef SHA256_Final
+#define SHA256_Final _libmd_SHA256_Final
+#endif
+#ifndef SHA256_End
+#define SHA256_End _libmd_SHA256_End
+#endif
+#ifndef SHA256_File
+#define SHA256_File _libmd_SHA256_File
+#endif
+#ifndef SHA256_FileChunk
+#define SHA256_FileChunk _libmd_SHA256_FileChunk
+#endif
+#ifndef SHA256_Data
+#define SHA256_Data _libmd_SHA256_Data
+#endif
+
+#ifndef SHA256_Transform
+#define SHA256_Transform _libmd_SHA256_Transform
+#endif
+#ifndef SHA256_version
+#define SHA256_version _libmd_SHA256_version
+#endif
+
void SHA256_Init(SHA256_CTX *);
void SHA256_Update(SHA256_CTX *, const void *, size_t);
void SHA256_Final(unsigned char [32], SHA256_CTX *);
diff --git a/lib/libmd/sha256c.c b/lib/libmd/sha256c.c
index 76cec8e..4227b0c 100644
--- a/lib/libmd/sha256c.c
+++ b/lib/libmd/sha256c.c
@@ -295,3 +295,18 @@ SHA256_Final(unsigned char digest[32], SHA256_CTX * ctx)
/* Clear the context state */
memset((void *)ctx, 0, sizeof(*ctx));
}
+
+#ifdef WEAK_REFS
+/* When building libmd, provide weak references. Note: this is not
+ activated in the context of compiling these sources for internal
+ use in libcrypt.
+ */
+#undef SHA256_Init
+__weak_reference(_libmd_SHA256_Init, SHA256_Init);
+#undef SHA256_Update
+__weak_reference(_libmd_SHA256_Update, SHA256_Update);
+#undef SHA256_Final
+__weak_reference(_libmd_SHA256_Final, SHA256_Final);
+#undef SHA256_Transform
+__weak_reference(_libmd_SHA256_Transform, SHA256_Transform);
+#endif
diff --git a/lib/libmd/sha512.h b/lib/libmd/sha512.h
index 8998f4c..b034ca5 100644
--- a/lib/libmd/sha512.h
+++ b/lib/libmd/sha512.h
@@ -38,6 +38,38 @@ typedef struct SHA512Context {
} SHA512_CTX;
__BEGIN_DECLS
+
+/* Ensure libmd symbols do not clash with libcrypto */
+
+#ifndef SHA512_Init
+#define SHA512_Init _libmd_SHA512_Init
+#endif
+#ifndef SHA512_Update
+#define SHA512_Update _libmd_SHA512_Update
+#endif
+#ifndef SHA512_Final
+#define SHA512_Final _libmd_SHA512_Final
+#endif
+#ifndef SHA512_End
+#define SHA512_End _libmd_SHA512_End
+#endif
+#ifndef SHA512_File
+#define SHA512_File _libmd_SHA512_File
+#endif
+#ifndef SHA512_FileChunk
+#define SHA512_FileChunk _libmd_SHA512_FileChunk
+#endif
+#ifndef SHA512_Data
+#define SHA512_Data _libmd_SHA512_Data
+#endif
+
+#ifndef SHA512_Transform
+#define SHA512_Transform _libmd_SHA512_Transform
+#endif
+#ifndef SHA512_version
+#define SHA512_version _libmd_SHA512_version
+#endif
+
void SHA512_Init(SHA512_CTX *);
void SHA512_Update(SHA512_CTX *, const void *, size_t);
void SHA512_Final(unsigned char [64], SHA512_CTX *);
diff --git a/lib/libmd/sha512c.c b/lib/libmd/sha512c.c
index c2a93be..e5e52a8 100644
--- a/lib/libmd/sha512c.c
+++ b/lib/libmd/sha512c.c
@@ -318,3 +318,18 @@ SHA512_Final(unsigned char digest[64], SHA512_CTX * ctx)
/* Clear the context state */
memset((void *)ctx, 0, sizeof(*ctx));
}
+
+#ifdef WEAK_REFS
+/* When building libmd, provide weak references. Note: this is not
+ activated in the context of compiling these sources for internal
+ use in libcrypt.
+ */
+#undef SHA512_Init
+__weak_reference(_libmd_SHA512_Init, SHA512_Init);
+#undef SHA512_Update
+__weak_reference(_libmd_SHA512_Update, SHA512_Update);
+#undef SHA512_Final
+__weak_reference(_libmd_SHA512_Final, SHA512_Final);
+#undef SHA512_Transform
+__weak_reference(_libmd_SHA512_Transform, SHA512_Transform);
+#endif
diff --git a/lib/libmd/shadriver.c b/lib/libmd/shadriver.c
index adaf684..29a3cf0 100644
--- a/lib/libmd/shadriver.c
+++ b/lib/libmd/shadriver.c
@@ -31,10 +31,13 @@ __FBSDID("$FreeBSD$");
#endif
#if SHA == 1
+#undef SHA_Data
#define SHA_Data SHA1_Data
#elif SHA == 256
+#undef SHA_Data
#define SHA_Data SHA256_Data
#elif SHA == 512
+#undef SHA_Data
#define SHA_Data SHA512_Data
#endif
diff --git a/lib/libmemstat/Makefile b/lib/libmemstat/Makefile
index d261085..597dc6d 100644
--- a/lib/libmemstat/Makefile
+++ b/lib/libmemstat/Makefile
@@ -3,8 +3,7 @@
WARNS?= 3
LIB= memstat
SHLIB_MAJOR= 3
-DPADD= ${LIBKVM}
-LDADD= -lkvm
+LIBADD+= kvm
SRCS+= memstat.c
SRCS+= memstat_all.c
SRCS+= memstat_malloc.c
diff --git a/lib/libmp/Makefile b/lib/libmp/Makefile
index 5d0e7a7..6a73658 100644
--- a/lib/libmp/Makefile
+++ b/lib/libmp/Makefile
@@ -4,8 +4,7 @@
LIB= mp
SHLIB_MAJOR= 7
-DPADD= ${LIBCRYPTO}
-LDADD= -lcrypto
+LIBADD= crypto
MAN= libmp.3
INCS= mp.h
SRCS= mpasbn.c
diff --git a/lib/libmp/tests/Makefile b/lib/libmp/tests/Makefile
index 0f591eb..e74e806 100644
--- a/lib/libmp/tests/Makefile
+++ b/lib/libmp/tests/Makefile
@@ -4,7 +4,6 @@ TESTSDIR= ${TESTSBASE}/lib/libmp
TAP_TESTS_C+= legacy_test
-DPADD+= ${LIBCRYPTO} ${LIBMP}
-LDADD+= -lcrypto -lmp
+LIBADD+= mp
.include <bsd.test.mk>
diff --git a/lib/libmt/Makefile b/lib/libmt/Makefile
new file mode 100644
index 0000000..6fe5920
--- /dev/null
+++ b/lib/libmt/Makefile
@@ -0,0 +1,12 @@
+# $FreeBSD$
+
+LIB= mt
+SHLIBDIR?= /lib
+SRCS= mtlib.c
+INCS= mtlib.h
+
+LIBADD= sbuf bsdxml
+
+MAN= mt.3
+
+.include <bsd.lib.mk>
diff --git a/lib/libmt/Makefile.depend b/lib/libmt/Makefile.depend
new file mode 100644
index 0000000..acc7f35
--- /dev/null
+++ b/lib/libmt/Makefile.depend
@@ -0,0 +1,22 @@
+# Autogenerated - do NOT edit!
+
+DEP_RELDIR := ${_PARSEDIR:S,${SRCTOP}/,,}
+
+DIRDEPS = \
+ gnu/lib/csu \
+ gnu/lib/libgcc \
+ include \
+ include/xlocale \
+ lib/${CSU_DIR} \
+ lib/libc \
+ lib/libcompiler_rt \
+ lib/libexpat \
+ lib/libsbuf \
+ usr.bin/xinstall.host \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif
diff --git a/lib/libmt/mt.3 b/lib/libmt/mt.3
new file mode 100644
index 0000000..eaf0194
--- /dev/null
+++ b/lib/libmt/mt.3
@@ -0,0 +1,454 @@
+.\"
+.\" Copyright (c) 2013, 2015 Spectra Logic Corporation
+.\" 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,
+.\" without modification.
+.\" 2. Redistributions in binary form must reproduce at minimum a disclaimer
+.\" substantially similar to the "NO WARRANTY" disclaimer below
+.\" ("Disclaimer") and any redistribution must be conditioned upon
+.\" including a substantially similar Disclaimer requirement for further
+.\" binary redistribution.
+.\"
+.\" NO WARRANTY
+.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+.\" "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
+.\" A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+.\" HOLDERS OR CONTRIBUTORS BE LIABLE FOR 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 DAMAGES.
+.\"
+.\" Authors: Ken Merry (Spectra Logic Corporation)
+.\"
+.\" $FreeBSD$
+.\"
+.Dd February 13, 2015
+.Dt MT 3
+.Os
+.Sh NAME
+.Nm mt_start_element ,
+.Nm mt_end_element ,
+.Nm mt_char_handler ,
+.Nm mt_status_tree_sbuf ,
+.Nm mt_status_tree_print ,
+.Nm mt_status_entry_free ,
+.Nm mt_status_free ,
+.Nm mt_entry_sbuf ,
+.Nm mt_param_parent_print ,
+.Nm mt_param_entry_print ,
+.Nm mt_protect_print ,
+.Nm mt_param_list ,
+.Nm mt_density_name ,
+.Nm mt_density_bp ,
+.Nm mt_density_num ,
+.Nm mt_get_xml_str ,
+.Nm mt_get_status
+.Nd Magnetic Tape library
+.Sh LIBRARY
+.Lb libmt
+.Sh SYNOPSIS
+.In sys/sbuf.h
+.In bsdxml.h
+.In mtlib.h
+.Ft void
+.Fo mt_start_element
+.Fa "void *user_data"
+.Fa "const char *name"
+.Fa "const char **attr"
+.Fc
+.Ft void
+.Fo mt_end_element
+.Fa "void *user_data"
+.Fa "const char *name"
+.Fc
+.Ft void
+.Fo mt_char_handler
+.Fa "void *user_data"
+.Fa "const XML_Char *str"
+.Fa "int len"
+.Fc
+.Ft void
+.Fo mt_status_tree_sbuf
+.Fa "struct sbuf *sb"
+.Fa "struct mt_status_entry *entry"
+.Fa "int indent"
+.Fa "void (*sbuf_func)(struct sbuf *sb, struct mt_status_entry *entry, void *arg)"
+.Fa "void *arg"
+.Fc
+.Ft void
+.Fo mt_status_tree_print
+.Fa "struct mt_status_entry *entry"
+.Fa "int indent"
+.Fa "void (*print_func)(struct mt_status_entry *entry, void *arg)"
+.Fa "void *arg"
+.Fc
+.Ft "struct mt_status_entry *"
+.Fo mt_entry_find
+.Fa "struct mt_status_entry *entry"
+.Fa "char *name"
+.Fc
+.Ft "struct mt_status_entry *"
+.Fo mt_status_entry_find
+.Fa "struct mt_status_data *status_data"
+.Fa "char *name"
+.Fc
+.Ft void
+.Fo mt_status_entry_free
+.Fa "struct mt_status_entry *entry)"
+.Fc
+.Ft void
+.Fo mt_status_free
+.Fa "struct mt_status_data *status_data"
+.Fc
+.Ft void
+.Fo mt_entry_sbuf
+.Fa "struct sbuf *sb"
+.Fa "struct mt_status_entry *entry"
+.Fa "char *fmt"
+.Fc
+.Ft void
+.Fo mt_param_parent_sbuf
+.Fa "struct sbuf *sb"
+.Fa "struct mt_status_entry *entry"
+.Fa "struct mt_print_params *print_params"
+.Fc
+.Ft void
+.Fo mt_param_parent_print
+.Fa "struct mt_status_entry *entry"
+.Fa "struct mt_print_params *print_params"
+.Fc
+.Ft void
+.Fo mt_param_entry_sbuf
+.Fa "struct sbuf *sb"
+.Fa "struct mt_status_entry *entry"
+.Fa "void *arg"
+.Fc
+.Ft void
+.Fo mt_param_entry_print
+.Fa "struct mt_status_entry *entry"
+.Fa "void *arg"
+.Fc
+.Ft int
+.Fo mt_protect_print
+.Fa "struct mt_status_data *status_data"
+.Fa "int verbose"
+.Fc
+.Ft int
+.Fo mt_param_list
+.Fa "struct mt_status_data *status_data"
+.Fa "char *param_name"
+.Fa "int quiet"
+.Fc
+.Ft "const char *"
+.Fo mt_density_name
+.Fa "int density_num"
+.Fc
+.Ft int
+.Fo mt_density_bp
+.Fa "int density_num"
+.Fa "int bpi"
+.Fc
+.Ft int
+.Fo mt_density_num
+.Fa "const char *density_name"
+.Fc
+.Ft int
+.Fo mt_get_status
+.Fa "char *xml_str"
+.Fa "struct mt_status_data *status_data"
+.Fc
+.Sh DESCRIPTION
+The MT library consists of a number of functions designed to aid in
+interacting with the
+.Xr sa 4
+driver.
+The
+.Xr sa 4
+driver returns some status data as XML-formatted strings, and
+the primary purpose of this library is to make it easier for the
+software developer to parse those strings and extract the status values.
+.Pp
+The
+.Fn mt_start_element ,
+.Fn mt_end_element ,
+and
+.Fn mt_char_handler
+functions are designed to work with the
+.Xr libbbsdxml 3
+library, which is an XML parsing library.
+The user data for the XML parser should be set with
+.Fn XML_SetUserData
+to a zeroed struct
+mt_status_data with the entries list initialized.
+The element handlers for the XML parser should be set to
+.Fn mt_start_element
+and
+.Fn mt_end_element
+with
+.Fn XML_SetElementHandler .
+The character data handler should be set to
+.Fn mt_char_handler
+with the
+.Fn XML_SetCharacterDataHandler
+function.
+The error member of the status_data structure will be set to 0 if parsing
+is successful, and non-zero if parsing failed.
+In the event of a failure, the error_str member will contain an error
+message describing the failure.
+These functions will build a tree of tape driver status data that can be
+searched and printed using the other functions in this library.
+.Pp
+.Fn mt_status_tree_sbuf
+takes the root node of a tree of
+.Xr sa 4
+driver status information, and displays it in an
+.Xr sbuf 9 .
+The
+.Ar sb
+argument is the destination sbuf.
+The
+.Ar entry
+argument is the root of the tree.
+The
+.Ar indent
+argument is the number of characters to indent the output.
+Each recursive call to
+.Fn mt_status_tree_sbuf
+will have the indent level incremented by 2.
+The
+.Ar sbuf_func
+argument is for a user-supplied alternate printing function.
+If it is non-NULL, it will be called instead of the default output printing
+code.
+The
+.Ar arg
+argument is an argument for the
+.Ar sbuf_func
+function.
+.Pp
+The
+.Fn mt_status_tree_print
+function is the same as the
+.Fn mt_status_tree_sbuf
+function, except that the tree is printed to standard out instead of to a
+sbuf.
+.Pp
+The
+.Fn mt_entry_find
+function returns the first entry in the tree starting at
+.Ar entry
+that matches
+.Ar name .
+The supplied node name can be a single level name like "foo", or it can
+specify mulitple node names that must be matched, for instance "foo.bar.baz".
+In the case of a single level name, it will match any node beneath
+.Ar entry
+that matches
+.Ar name .
+In the case of a multi-level name like "foo.bar.baz", it will return the
+first entry named "baz" whose immediate parent is "bar" and where the
+parent of "bar" is named "foo".
+.Pp
+The
+.Fn mt_status_entry_find
+is the same as
+.Fn mt_entry_find ,
+except that it operates on the top level mt_status_data and all
+mt_status_entry nodes below it instead of just an mt_status_entry
+structure.
+.Pp
+The
+.Fn mt_status_entry_free
+function frees the tree of status data underneath
+.Ar entry .
+.Pp
+The
+.Fn mt_status_free
+function frees the tree of status data underneath
+.Ar status_data .
+.Pp
+The
+.Fn mt_entry_sbuf
+function prints
+.Ar entry
+to the supplied sbuf
+.Ar sb ,
+optionally using the
+.Xr printf 3
+format
+.Ar fmt .
+If
+.Ar fmt
+is NULL, then
+.Fn mt_entry_sbuf
+will render integer types in base 10 without special formatting and all
+other types as they were rendered in the XML.
+.Pp
+.Fn mt_param_parent_sbuf
+prints the parents of the given
+.Ar entry
+to the supplied sbuf
+.Ar sb
+subject to the print parameters
+.Ar print_params .
+The result will be formatted with a period between each level, like
+"foo.bar.baz".
+.Pp
+.Fn mt_param_parent_print
+is like
+.Fn mt_param_parent_sbuf
+except that it prints the results to standard output instead of an sbuf.
+.Pp
+.Fn mt_param_entry_sbuf
+prints the
+.Ar entry
+to the given sbuf
+.Ar sb .
+The argument
+.Ar arg
+is a pointer to struct mt_print_params, which allows the caller to control
+the printing output.
+This function is intended to be supplied as an argument to
+.Fn mt_status_tree_sbuf .
+.Pp
+.Fn mt_param_entry_print
+is like
+.Fn mt_param_entry_sbuf
+except that it prints to standard output instead of an sbuf.
+It is intended to be used as an argument to
+.Fn mt_status_tree_print .
+.Pp
+.Fn mt_protect_print
+prints tape drive protection information from the supplied
+.Ar status_data
+beginning at the node name defined as the root node for protection data.
+If the
+.Ar verbose
+argument is non-zero, protection entry descriptions will be printed.
+If it is zero, protection entry descriptions will not be printed.
+.Pp
+.Fn mt_param_list
+prints tape driver parameters information from the supplied
+.Ar status_data .
+If the
+.Ar param_name
+is non-NULL, only the named parameter will be printed.
+If
+.Ar quiet
+is non-zero, parameter descriptions will be omitted in the output.
+.Pp
+.Fn mt_density_name
+Returns a text identifier for the supplied numeric
+.Ar density_num .
+The
+.Ar density_num
+should currently be a value between 0 and 255 inclusive, since that is the
+valid range for
+.Tn SCSI
+density code values.
+See below for notes on the return values.
+.Pp
+.Fn mt_density_bp
+Returns the bits per inch or bits per mm values for a given density entry
+specified by the
+.Ar density_num .
+If the
+.Ar bpi
+argument is non-zero, the bits per inch value is returned.
+Otherwise, the bits per mm value is returned.
+.Pp
+.Fn mt_density_num
+returns a numeric value for a text density description.
+It does a case-insensitive comparison of density names in the density table
+to the supplied density name.
+.Pp
+.Fn mt_get_xml_str
+gets the current XML status / parameter string from the sa(4) driver
+instance referenced by the open file descriptor
+.Ar mtfd .
+The
+.Xr mtio 4
+.Xr ioctl 2
+to be used is supplied as the
+.Ar cmd
+argument.
+Currently the
+.Fn mt_get_xml_str
+function will work with the
+.Dv MTIOCEXTGET
+and
+.Dv MTIOCPARAMGET
+ioctls.
+The supplied
+.Ar xml_str
+will be filled in with a pointer to the complete XML status string.
+Multiple calls to the given
+.Xr ioctl 2
+are made and more space is malloced until all of the XML string is fetched.
+The string returned in the
+.Ar xml_str
+argument should be freed when it is no longer in use.
+.Sh RETURN VALUES
+.Fn mt_entry_find
+returns the first matching entry, or NULL if it fails to find a match.
+.Pp
+.Fn mt_status_entry_find
+returns the first matching entry, or NULL if it fails to find a match.
+.Pp
+.Fn mt_protect_print
+Returns 0 for success, and non-zero for failure.
+.Fn mt_protect_print
+can only fail if it cannot find protection information in the supplied
+status data.
+.Pp
+.Fn mt_param_list
+Returns 0 for success and non-zero for failure.
+.Fn mt_param_list
+can only fail if it cannot find parameter information in the supplied
+status data.
+.Pp
+.Fn mt_density_name
+returns a text description of a numeric density.
+The special density value 0 is decoded as "default".
+The special density value 0x7f is decoded as "same".
+If the density is not known,
+.Fn mt_density_name
+will return "UNKNOWN".
+.Pp
+.Fn mt_density_bp
+returns the bits per inch value for the given density (if the
+.Ar bpi
+field is non-zero), the bits per mm value otherwise, or 0 if the supplied
+.Ar density_num
+is not in the density table or the table entry does not include bpi / bpmm
+values.
+.Pp
+.Fn mt_density_num
+returns a numeric density value between 0 and 255 for the supplied density
+name.
+It returns 0 if the density name is not recognized.
+.Pp
+.Fn mt_get_xml_str
+returns 0 for success, and -1 for failure.
+.Sh SEE ALSO
+.Xr mt 1 ,
+.Xr mtio 4 ,
+.Xr sa 4
+.Sh HISTORY
+The MT library first appeared in
+.Fx 10.1 .
+.Sh AUTHORS
+.An Ken Merry Aq ken@FreeBSD.org
+.Sh BUGS
+The library interface is not complete, and may change in the future.
+Application authors should not rely on the library interface to be
+consistent in the immediate future.
diff --git a/lib/libmt/mtlib.c b/lib/libmt/mtlib.c
new file mode 100644
index 0000000..f6acba2
--- /dev/null
+++ b/lib/libmt/mtlib.c
@@ -0,0 +1,773 @@
+/*-
+ * Copyright (c) 2013, 2014, 2015 Spectra Logic Corporation
+ * 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,
+ * without modification.
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
+ * substantially similar to the "NO WARRANTY" disclaimer below
+ * ("Disclaimer") and any redistribution must be conditioned upon
+ * including a substantially similar Disclaimer requirement for further
+ * binary redistribution.
+ *
+ * NO WARRANTY
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR 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 DAMAGES.
+ *
+ * Authors: Ken Merry (Spectra Logic Corporation)
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <sys/mtio.h>
+#include <sys/queue.h>
+#include <sys/sbuf.h>
+
+#include <ctype.h>
+#include <err.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdint.h>
+#include <errno.h>
+#include <bsdxml.h>
+#include <mtlib.h>
+
+/*
+ * Called at the start of each XML element, and includes the list of
+ * attributes for the element.
+ */
+void
+mt_start_element(void *user_data, const char *name, const char **attr)
+{
+ int i;
+ struct mt_status_data *mtinfo;
+ struct mt_status_entry *entry;
+
+ mtinfo = (struct mt_status_data *)user_data;
+
+ if (mtinfo->error != 0)
+ return;
+
+ mtinfo->level++;
+ if ((u_int)mtinfo->level >= (sizeof(mtinfo->cur_sb) /
+ sizeof(mtinfo->cur_sb[0]))) {
+ mtinfo->error = 1;
+ snprintf(mtinfo->error_str, sizeof(mtinfo->error_str),
+ "%s: too many nesting levels, %zd max", __func__,
+ sizeof(mtinfo->cur_sb) / sizeof(mtinfo->cur_sb[0]));
+ return;
+ }
+
+ mtinfo->cur_sb[mtinfo->level] = sbuf_new_auto();
+ if (mtinfo->cur_sb[mtinfo->level] == NULL) {
+ mtinfo->error = 1;
+ snprintf(mtinfo->error_str, sizeof(mtinfo->error_str),
+ "%s: Unable to allocate sbuf", __func__);
+ return;
+ }
+
+ entry = malloc(sizeof(*entry));
+ if (entry == NULL) {
+ mtinfo->error = 1;
+ snprintf(mtinfo->error_str, sizeof(mtinfo->error_str),
+ "%s: unable to allocate %zd bytes", __func__,
+ sizeof(*entry));
+ return;
+ }
+ bzero(entry, sizeof(*entry));
+ STAILQ_INIT(&entry->nv_list);
+ STAILQ_INIT(&entry->child_entries);
+ entry->entry_name = strdup(name);
+ mtinfo->cur_entry[mtinfo->level] = entry;
+ if (mtinfo->cur_entry[mtinfo->level - 1] == NULL) {
+ STAILQ_INSERT_TAIL(&mtinfo->entries, entry, links);
+ } else {
+ STAILQ_INSERT_TAIL(
+ &mtinfo->cur_entry[mtinfo->level - 1]->child_entries,
+ entry, links);
+ entry->parent = mtinfo->cur_entry[mtinfo->level - 1];
+ }
+ for (i = 0; attr[i] != NULL; i+=2) {
+ struct mt_status_nv *nv;
+ int need_nv;
+
+ need_nv = 0;
+
+ if (strcmp(attr[i], "size") == 0) {
+ entry->size = strtoull(attr[i+1], NULL, 0);
+ } else if (strcmp(attr[i], "type") == 0) {
+ if (strcmp(attr[i+1], "int") == 0) {
+ entry->var_type = MT_TYPE_INT;
+ } else if (strcmp(attr[i+1], "uint") == 0) {
+ entry->var_type = MT_TYPE_UINT;
+ } else if (strcmp(attr[i+1], "str") == 0) {
+ entry->var_type = MT_TYPE_STRING;
+ } else if (strcmp(attr[i+1], "node") == 0) {
+ entry->var_type = MT_TYPE_NODE;
+ } else {
+ need_nv = 1;
+ }
+ } else if (strcmp(attr[i], "fmt") == 0) {
+ entry->fmt = strdup(attr[i+1]);
+ } else if (strcmp(attr[i], "desc") == 0) {
+ entry->desc = strdup(attr[i+1]);
+ } else {
+ need_nv = 1;
+ }
+ if (need_nv != 0) {
+ nv = malloc(sizeof(*nv));
+ if (nv == NULL) {
+ mtinfo->error = 1;
+ snprintf(mtinfo->error_str,
+ sizeof(mtinfo->error_str),
+ "%s: error allocating %zd bytes",
+ __func__, sizeof(*nv));
+ }
+ bzero(nv, sizeof(*nv));
+ nv->name = strdup(attr[i]);
+ nv->value = strdup(attr[i+1]);
+ STAILQ_INSERT_TAIL(&entry->nv_list, nv, links);
+ }
+ }
+}
+
+/*
+ * Called on XML element close.
+ */
+void
+mt_end_element(void *user_data, const char *name)
+{
+ struct mt_status_data *mtinfo;
+ char *str;
+
+ mtinfo = (struct mt_status_data *)user_data;
+
+ if (mtinfo->error != 0)
+ return;
+
+ if (mtinfo->cur_sb[mtinfo->level] == NULL) {
+ mtinfo->error = 1;
+ snprintf(mtinfo->error_str, sizeof(mtinfo->error_str),
+ "%s: no valid sbuf at level %d (name %s)", __func__,
+ mtinfo->level, name);
+ return;
+ }
+ sbuf_finish(mtinfo->cur_sb[mtinfo->level]);
+ str = strdup(sbuf_data(mtinfo->cur_sb[mtinfo->level]));
+ if (str == NULL) {
+ mtinfo->error = 1;
+ snprintf(mtinfo->error_str, sizeof(mtinfo->error_str),
+ "%s can't allocate %zd bytes for string", __func__,
+ sbuf_len(mtinfo->cur_sb[mtinfo->level]));
+ return;
+ }
+
+ if (strlen(str) == 0) {
+ free(str);
+ str = NULL;
+ }
+ if (str != NULL) {
+ struct mt_status_entry *entry;
+
+ entry = mtinfo->cur_entry[mtinfo->level];
+ switch(entry->var_type) {
+ case MT_TYPE_INT:
+ entry->value_signed = strtoll(str, NULL, 0);
+ break;
+ case MT_TYPE_UINT:
+ entry->value_unsigned = strtoull(str, NULL, 0);
+ break;
+ default:
+ break;
+ }
+ }
+
+ mtinfo->cur_entry[mtinfo->level]->value = str;
+
+ sbuf_delete(mtinfo->cur_sb[mtinfo->level]);
+ mtinfo->cur_sb[mtinfo->level] = NULL;
+ mtinfo->cur_entry[mtinfo->level] = NULL;
+ mtinfo->level--;
+}
+
+/*
+ * Called to handle character strings in the current element.
+ */
+void
+mt_char_handler(void *user_data, const XML_Char *str, int len)
+{
+ struct mt_status_data *mtinfo;
+
+ mtinfo = (struct mt_status_data *)user_data;
+ if (mtinfo->error != 0)
+ return;
+
+ sbuf_bcat(mtinfo->cur_sb[mtinfo->level], str, len);
+}
+
+void
+mt_status_tree_sbuf(struct sbuf *sb, struct mt_status_entry *entry, int indent,
+ void (*sbuf_func)(struct sbuf *sb, struct mt_status_entry *entry,
+ void *arg), void *arg)
+{
+ struct mt_status_nv *nv;
+ struct mt_status_entry *entry2;
+
+ if (sbuf_func != NULL) {
+ sbuf_func(sb, entry, arg);
+ } else {
+ sbuf_printf(sb, "%*sname: %s, value: %s, fmt: %s, size: %zd, "
+ "type: %d, desc: %s\n", indent, "", entry->entry_name,
+ entry->value, entry->fmt, entry->size, entry->var_type,
+ entry->desc);
+ STAILQ_FOREACH(nv, &entry->nv_list, links) {
+ sbuf_printf(sb, "%*snv: name: %s, value: %s\n",
+ indent + 1, "", nv->name, nv->value);
+ }
+ }
+
+ STAILQ_FOREACH(entry2, &entry->child_entries, links)
+ mt_status_tree_sbuf(sb, entry2, indent + 2, sbuf_func, arg);
+}
+
+void
+mt_status_tree_print(struct mt_status_entry *entry, int indent,
+ void (*print_func)(struct mt_status_entry *entry, void *arg), void *arg)
+{
+
+ if (print_func != NULL) {
+ struct mt_status_entry *entry2;
+
+ print_func(entry, arg);
+ STAILQ_FOREACH(entry2, &entry->child_entries, links)
+ mt_status_tree_print(entry2, indent + 2, print_func,
+ arg);
+ } else {
+ struct sbuf *sb;
+
+ sb = sbuf_new_auto();
+ if (sb == NULL)
+ return;
+ mt_status_tree_sbuf(sb, entry, indent, NULL, NULL);
+ sbuf_finish(sb);
+
+ printf("%s", sbuf_data(sb));
+ sbuf_delete(sb);
+ }
+}
+
+/*
+ * Given a parameter name in the form "foo" or "foo.bar.baz", traverse the
+ * tree looking for the parameter (the first case) or series of parameters
+ * (second case).
+ */
+struct mt_status_entry *
+mt_entry_find(struct mt_status_entry *entry, char *name)
+{
+ struct mt_status_entry *entry2;
+ char *tmpname = NULL, *tmpname2 = NULL, *tmpstr = NULL;
+
+ tmpname = strdup(name);
+ if (tmpname == NULL)
+ goto bailout;
+
+ /* Save a pointer so we can free this later */
+ tmpname2 = tmpname;
+
+ tmpstr = strsep(&tmpname, ".");
+
+ /*
+ * Is this the entry we're looking for? Or do we have further
+ * child entries that we need to grab?
+ */
+ if (strcmp(entry->entry_name, tmpstr) == 0) {
+ if (tmpname == NULL) {
+ /*
+ * There are no further child entries to find. We
+ * have a complete match.
+ */
+ free(tmpname2);
+ return (entry);
+ } else {
+ /*
+ * There are more child entries that we need to find.
+ * Fall through to the recursive search off of this
+ * entry, below. Use tmpname, which will contain
+ * everything after the first period.
+ */
+ name = tmpname;
+ }
+ }
+
+ /*
+ * Recursively look for further entries.
+ */
+ STAILQ_FOREACH(entry2, &entry->child_entries, links) {
+ struct mt_status_entry *entry3;
+
+ entry3 = mt_entry_find(entry2, name);
+ if (entry3 != NULL) {
+ free(tmpname2);
+ return (entry3);
+ }
+ }
+
+bailout:
+ free(tmpname2);
+
+ return (NULL);
+}
+
+struct mt_status_entry *
+mt_status_entry_find(struct mt_status_data *status_data, char *name)
+{
+ struct mt_status_entry *entry, *entry2;
+
+ STAILQ_FOREACH(entry, &status_data->entries, links) {
+ entry2 = mt_entry_find(entry, name);
+ if (entry2 != NULL)
+ return (entry2);
+ }
+
+ return (NULL);
+}
+
+void
+mt_status_entry_free(struct mt_status_entry *entry)
+{
+ struct mt_status_entry *entry2, *entry3;
+ struct mt_status_nv *nv, *nv2;
+
+ STAILQ_FOREACH_SAFE(entry2, &entry->child_entries, links, entry3) {
+ STAILQ_REMOVE(&entry->child_entries, entry2, mt_status_entry,
+ links);
+ mt_status_entry_free(entry2);
+ }
+
+ free(entry->entry_name);
+ free(entry->value);
+ free(entry->fmt);
+ free(entry->desc);
+
+ STAILQ_FOREACH_SAFE(nv, &entry->nv_list, links, nv2) {
+ STAILQ_REMOVE(&entry->nv_list, nv, mt_status_nv, links);
+ free(nv->name);
+ free(nv->value);
+ free(nv);
+ }
+ free(entry);
+}
+
+void
+mt_status_free(struct mt_status_data *status_data)
+{
+ struct mt_status_entry *entry, *entry2;
+
+ STAILQ_FOREACH_SAFE(entry, &status_data->entries, links, entry2) {
+ STAILQ_REMOVE(&status_data->entries, entry, mt_status_entry,
+ links);
+ mt_status_entry_free(entry);
+ }
+}
+
+void
+mt_entry_sbuf(struct sbuf *sb, struct mt_status_entry *entry, char *fmt)
+{
+ switch(entry->var_type) {
+ case MT_TYPE_INT:
+ if (fmt != NULL)
+ sbuf_printf(sb, fmt, (intmax_t)entry->value_signed);
+ else
+ sbuf_printf(sb, "%jd",
+ (intmax_t)entry->value_signed);
+ break;
+ case MT_TYPE_UINT:
+ if (fmt != NULL)
+ sbuf_printf(sb, fmt, (uintmax_t)entry->value_unsigned);
+ else
+ sbuf_printf(sb, "%ju",
+ (uintmax_t)entry->value_unsigned);
+ break;
+ default:
+ if (fmt != NULL)
+ sbuf_printf(sb, fmt, entry->value);
+ else
+ sbuf_printf(sb, "%s", entry->value);
+ break;
+ }
+}
+
+void
+mt_param_parent_print(struct mt_status_entry *entry,
+ struct mt_print_params *print_params)
+{
+ if (entry->parent != NULL)
+ mt_param_parent_print(entry->parent, print_params);
+
+ if (((print_params->flags & MT_PF_INCLUDE_ROOT) == 0)
+ && (strcmp(entry->entry_name, print_params->root_name) == 0))
+ return;
+
+ printf("%s.", entry->entry_name);
+}
+
+void
+mt_param_parent_sbuf(struct sbuf *sb, struct mt_status_entry *entry,
+ struct mt_print_params *print_params)
+{
+ if (entry->parent != NULL)
+ mt_param_parent_sbuf(sb, entry->parent, print_params);
+
+ if (((print_params->flags & MT_PF_INCLUDE_ROOT) == 0)
+ && (strcmp(entry->entry_name, print_params->root_name) == 0))
+ return;
+
+ sbuf_printf(sb, "%s.", entry->entry_name);
+}
+
+void
+mt_param_entry_sbuf(struct sbuf *sb, struct mt_status_entry *entry, void *arg)
+{
+ struct mt_print_params *print_params;
+
+ print_params = (struct mt_print_params *)arg;
+
+ /*
+ * We don't want to print nodes.
+ */
+ if (entry->var_type == MT_TYPE_NODE)
+ return;
+
+ if ((print_params->flags & MT_PF_FULL_PATH)
+ && (entry->parent != NULL))
+ mt_param_parent_sbuf(sb, entry->parent, print_params);
+
+ sbuf_printf(sb, "%s: %s", entry->entry_name, entry->value);
+ if ((print_params->flags & MT_PF_VERBOSE)
+ && (entry->desc != NULL)
+ && (strlen(entry->desc) > 0))
+ sbuf_printf(sb, " (%s)", entry->desc);
+ sbuf_printf(sb, "\n");
+
+}
+
+void
+mt_param_entry_print(struct mt_status_entry *entry, void *arg)
+{
+ struct mt_print_params *print_params;
+
+ print_params = (struct mt_print_params *)arg;
+
+ /*
+ * We don't want to print nodes.
+ */
+ if (entry->var_type == MT_TYPE_NODE)
+ return;
+
+ if ((print_params->flags & MT_PF_FULL_PATH)
+ && (entry->parent != NULL))
+ mt_param_parent_print(entry->parent, print_params);
+
+ printf("%s: %s", entry->entry_name, entry->value);
+ if ((print_params->flags & MT_PF_VERBOSE)
+ && (entry->desc != NULL)
+ && (strlen(entry->desc) > 0))
+ printf(" (%s)", entry->desc);
+ printf("\n");
+}
+
+int
+mt_protect_print(struct mt_status_data *status_data, int verbose)
+{
+ struct mt_status_entry *entry;
+ const char *prot_name = MT_PROTECTION_NAME;
+ struct mt_print_params print_params;
+
+ snprintf(print_params.root_name, sizeof(print_params.root_name),
+ MT_PARAM_ROOT_NAME);
+ print_params.flags = MT_PF_FULL_PATH;
+ if (verbose != 0)
+ print_params.flags |= MT_PF_VERBOSE;
+
+ entry = mt_status_entry_find(status_data, __DECONST(char *,prot_name));
+ if (entry == NULL)
+ return (1);
+ mt_status_tree_print(entry, 0, mt_param_entry_print, &print_params);
+
+ return (0);
+}
+
+int
+mt_param_list(struct mt_status_data *status_data, char *param_name, int quiet)
+{
+ struct mt_status_entry *entry;
+ struct mt_print_params print_params;
+ char root_name[20];
+
+ snprintf(root_name, sizeof(root_name), "mtparamget");
+ strlcpy(print_params.root_name, root_name,
+ sizeof(print_params.root_name));
+
+ print_params.flags = MT_PF_FULL_PATH;
+ if (quiet == 0)
+ print_params.flags |= MT_PF_VERBOSE;
+
+ if (param_name != NULL) {
+ entry = mt_status_entry_find(status_data, param_name);
+ if (entry == NULL)
+ return (1);
+
+ mt_param_entry_print(entry, &print_params);
+
+ return (0);
+ } else {
+ entry = mt_status_entry_find(status_data, root_name);
+
+ STAILQ_FOREACH(entry, &status_data->entries, links)
+ mt_status_tree_print(entry, 0, mt_param_entry_print,
+ &print_params);
+ }
+
+ return (0);
+}
+
+static struct densities {
+ int dens;
+ int bpmm;
+ int bpi;
+ const char *name;
+} dens[] = {
+ /*
+ * Taken from T10 Project 997D
+ * SCSI-3 Stream Device Commands (SSC)
+ * Revision 11, 4-Nov-97
+ *
+ * LTO 1-6 definitions obtained from the eighth edition of the
+ * IBM TotalStorage LTO Ultrium Tape Drive SCSI Reference
+ * (July 2007) and the second edition of the IBM System Storage LTO
+ * Tape Drive SCSI Reference (February 13, 2013).
+ *
+ * IBM 3592 definitions obtained from second edition of the IBM
+ * System Storage Tape Drive 3592 SCSI Reference (May 25, 2012).
+ *
+ * DAT-72 and DAT-160 bpi values taken from "HP StorageWorks DAT160
+ * tape drive white paper", dated June 2007.
+ *
+ * DAT-160 / SDLT220 density code (0x48) conflict information
+ * found here:
+ *
+ * http://h20564.www2.hp.com/hpsc/doc/public/display?docId=emr_na-c01065117&sp4ts.oid=429311
+ * (Document ID c01065117)
+ */
+ /*Num. bpmm bpi Reference */
+ { 0x1, 32, 800, "X3.22-1983" },
+ { 0x2, 63, 1600, "X3.39-1986" },
+ { 0x3, 246, 6250, "X3.54-1986" },
+ { 0x5, 315, 8000, "X3.136-1986" },
+ { 0x6, 126, 3200, "X3.157-1987" },
+ { 0x7, 252, 6400, "X3.116-1986" },
+ { 0x8, 315, 8000, "X3.158-1987" },
+ { 0x9, 491, 37871, "X3.180" },
+ { 0xA, 262, 6667, "X3B5/86-199" },
+ { 0xB, 63, 1600, "X3.56-1986" },
+ { 0xC, 500, 12690, "HI-TC1" },
+ { 0xD, 999, 25380, "HI-TC2" },
+ { 0xF, 394, 10000, "QIC-120" },
+ { 0x10, 394, 10000, "QIC-150" },
+ { 0x11, 630, 16000, "QIC-320" },
+ { 0x12, 2034, 51667, "QIC-1350" },
+ { 0x13, 2400, 61000, "X3B5/88-185A" },
+ { 0x14, 1703, 43245, "X3.202-1991" },
+ { 0x15, 1789, 45434, "ECMA TC17" },
+ { 0x16, 394, 10000, "X3.193-1990" },
+ { 0x17, 1673, 42500, "X3B5/91-174" },
+ { 0x18, 1673, 42500, "X3B5/92-50" },
+ { 0x19, 2460, 62500, "DLTapeIII" },
+ { 0x1A, 3214, 81633, "DLTapeIV(20GB)" },
+ { 0x1B, 3383, 85937, "DLTapeIV(35GB)" },
+ { 0x1C, 1654, 42000, "QIC-385M" },
+ { 0x1D, 1512, 38400, "QIC-410M" },
+ { 0x1E, 1385, 36000, "QIC-1000C" },
+ { 0x1F, 2666, 67733, "QIC-2100C" },
+ { 0x20, 2666, 67733, "QIC-6GB(M)" },
+ { 0x21, 2666, 67733, "QIC-20GB(C)" },
+ { 0x22, 1600, 40640, "QIC-2GB(C)" },
+ { 0x23, 2666, 67733, "QIC-875M" },
+ { 0x24, 2400, 61000, "DDS-2" },
+ { 0x25, 3816, 97000, "DDS-3" },
+ { 0x26, 3816, 97000, "DDS-4" },
+ { 0x27, 3056, 77611, "Mammoth" },
+ { 0x28, 1491, 37871, "X3.224" },
+ { 0x40, 4880, 123952, "LTO-1" },
+ { 0x41, 3868, 98250, "DLTapeIV(40GB)" },
+ { 0x42, 7398, 187909, "LTO-2" },
+ { 0x44, 9638, 244805, "LTO-3" },
+ { 0x46, 12725, 323215, "LTO-4" },
+ { 0x47, 6417, 163000, "DAT-72" },
+ /*
+ * XXX KDM note that 0x48 is also the density code for DAT-160.
+ * For some reason they used overlapping density codes.
+ */
+#if 0
+ { 0x48, 6870, 174500, "DAT-160" },
+#endif
+ { 0x48, 5236, 133000, "SDLTapeI(110)" },
+ { 0x49, 7598, 193000, "SDLTapeI(160)" },
+ { 0x4a, 0, 0, "T10000A" },
+ { 0x4b, 0, 0, "T10000B" },
+ { 0x4c, 0, 0, "T10000C" },
+ { 0x4d, 0, 0, "T10000D" },
+ { 0x51, 11800, 299720, "3592A1 (unencrypted)" },
+ { 0x52, 11800, 299720, "3592A2 (unencrypted)" },
+ { 0x53, 13452, 341681, "3592A3 (unencrypted)" },
+ { 0x54, 19686, 500024, "3592A4 (unencrypted)" },
+ { 0x55, 20670, 525018, "3592A5 (unencrypted)" },
+ { 0x58, 15142, 384607, "LTO-5" },
+ { 0x5A, 15142, 384607, "LTO-6" },
+ { 0x71, 11800, 299720, "3592A1 (encrypted)" },
+ { 0x72, 11800, 299720, "3592A2 (encrypted)" },
+ { 0x73, 13452, 341681, "3592A3 (encrypted)" },
+ { 0x74, 19686, 500024, "3592A4 (encrypted)" },
+ { 0x75, 20670, 525018, "3592A5 (encrypted)" },
+ { 0x8c, 1789, 45434, "EXB-8500c" },
+ { 0x90, 1703, 43245, "EXB-8200c" },
+ { 0, 0, 0, NULL }
+};
+
+const char *
+mt_density_name(int density_num)
+{
+ struct densities *sd;
+
+ /* densities 0 and 0x7f are handled as special cases */
+ if (density_num == 0)
+ return ("default");
+ if (density_num == 0x7f)
+ return ("same");
+
+ for (sd = dens; sd->dens != 0; sd++)
+ if (sd->dens == density_num)
+ break;
+ if (sd->dens == 0)
+ return ("UNKNOWN");
+ return (sd->name);
+}
+
+/*
+ * Given a specific density number, return either the bits per inch or bits
+ * per millimeter for the given density.
+ */
+int
+mt_density_bp(int density_num, int bpi)
+{
+ struct densities *sd;
+
+ for (sd = dens; sd->dens; sd++)
+ if (sd->dens == density_num)
+ break;
+ if (sd->dens == 0)
+ return (0);
+ if (bpi)
+ return (sd->bpi);
+ else
+ return (sd->bpmm);
+}
+
+int
+mt_density_num(const char *density_name)
+{
+ struct densities *sd;
+ size_t l = strlen(density_name);
+
+ for (sd = dens; sd->dens; sd++)
+ if (strncasecmp(sd->name, density_name, l) == 0)
+ break;
+ return (sd->dens);
+}
+
+/*
+ * Get the current status XML string.
+ * Returns 0 on success, -1 on failure (with errno set, and *xml_str == NULL).
+ */
+int
+mt_get_xml_str(int mtfd, unsigned long cmd, char **xml_str)
+{
+ size_t alloc_len = 32768;
+ struct mtextget extget;
+ int error;
+
+ *xml_str = NULL;
+
+ for (;;) {
+ bzero(&extget, sizeof(extget));
+ *xml_str = malloc(alloc_len);
+ if (*xml_str == NULL)
+ return (-1);
+ extget.status_xml = *xml_str;
+ extget.alloc_len = alloc_len;
+
+ error = ioctl(mtfd, cmd, (caddr_t)&extget);
+ if (error == 0 && extget.status == MT_EXT_GET_OK)
+ break;
+
+ free(*xml_str);
+ *xml_str = NULL;
+
+ if (error != 0 || extget.status != MT_EXT_GET_NEED_MORE_SPACE)
+ return (-1);
+
+ /* The driver needs more space, so double and try again. */
+ alloc_len *= 2;
+ }
+ return (0);
+}
+
+/*
+ * Populate a struct mt_status_data from the XML string via mt_get_xml_str().
+ *
+ * Returns XML_STATUS_OK on success.
+ * If XML_STATUS_ERROR is returned, errno may be set to indicate the reason.
+ * The caller must check status_data->error.
+ */
+int
+mt_get_status(char *xml_str, struct mt_status_data *status_data)
+{
+ XML_Parser parser;
+ int retval;
+
+ bzero(status_data, sizeof(*status_data));
+ STAILQ_INIT(&status_data->entries);
+
+ parser = XML_ParserCreate(NULL);
+ if (parser == NULL) {
+ errno = ENOMEM;
+ return (XML_STATUS_ERROR);
+ }
+
+ XML_SetUserData(parser, status_data);
+ XML_SetElementHandler(parser, mt_start_element, mt_end_element);
+ XML_SetCharacterDataHandler(parser, mt_char_handler);
+
+ retval = XML_Parse(parser, xml_str, strlen(xml_str), 1);
+ XML_ParserFree(parser);
+ return (retval);
+}
diff --git a/lib/libmt/mtlib.h b/lib/libmt/mtlib.h
new file mode 100644
index 0000000..a61a15d
--- /dev/null
+++ b/lib/libmt/mtlib.h
@@ -0,0 +1,122 @@
+/*-
+ * Copyright (c) 2013, 2014 Spectra Logic Corporation
+ * 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,
+ * without modification.
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
+ * substantially similar to the "NO WARRANTY" disclaimer below
+ * ("Disclaimer") and any redistribution must be conditioned upon
+ * including a substantially similar Disclaimer requirement for further
+ * binary redistribution.
+ *
+ * NO WARRANTY
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR 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 DAMAGES.
+ *
+ * Authors: Ken Merry (Spectra Logic Corporation)
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _MTLIB_H
+#define _MTLIB_H
+
+typedef enum {
+ MT_TYPE_NONE,
+ MT_TYPE_STRING,
+ MT_TYPE_INT,
+ MT_TYPE_UINT,
+ MT_TYPE_NODE
+} mt_variable_type;
+
+struct mt_status_nv {
+ char *name;
+ char *value;
+ STAILQ_ENTRY(mt_status_nv) links;
+};
+
+struct mt_status_entry {
+ char *entry_name;
+ char *value;
+ uint64_t value_unsigned;
+ int64_t value_signed;
+ char *fmt;
+ char *desc;
+ size_t size;
+ mt_variable_type var_type;
+ struct mt_status_entry *parent;
+ STAILQ_HEAD(, mt_status_nv) nv_list;
+ STAILQ_HEAD(, mt_status_entry) child_entries;
+ STAILQ_ENTRY(mt_status_entry) links;
+};
+
+struct mt_status_data {
+ int level;
+ struct sbuf *cur_sb[32];
+ struct mt_status_entry *cur_entry[32];
+ int error;
+ char error_str[128];
+ STAILQ_HEAD(, mt_status_entry) entries;
+};
+
+typedef enum {
+ MT_PF_NONE = 0x00,
+ MT_PF_VERBOSE = 0x01,
+ MT_PF_FULL_PATH = 0x02,
+ MT_PF_INCLUDE_ROOT = 0x04
+} mt_print_flags;
+
+struct mt_print_params {
+ mt_print_flags flags;
+ char root_name[64];
+};
+
+__BEGIN_DECLS
+void mt_start_element(void *user_data, const char *name, const char **attr);
+void mt_end_element(void *user_data, const char *name);
+void mt_char_handler(void *user_data, const XML_Char *str, int len);
+void mt_status_tree_sbuf(struct sbuf *sb, struct mt_status_entry *entry,
+ int indent, void (*sbuf_func)(struct sbuf *sb,
+ struct mt_status_entry *entry, void *arg), void *arg);
+void mt_status_tree_print(struct mt_status_entry *entry, int indent,
+ void (*print_func)(struct mt_status_entry *entry,
+ void *arg), void *arg);
+struct mt_status_entry *mt_entry_find(struct mt_status_entry *entry,
+ char *name);
+struct mt_status_entry *mt_status_entry_find(struct mt_status_data *status_data,
+ char *name);
+void mt_status_entry_free(struct mt_status_entry *entry);
+void mt_status_free(struct mt_status_data *status_data);
+void mt_entry_sbuf(struct sbuf *sb, struct mt_status_entry *entry, char *fmt);
+void mt_param_parent_print(struct mt_status_entry *entry,
+ struct mt_print_params *print_params);
+void mt_param_parent_sbuf(struct sbuf *sb, struct mt_status_entry *entry,
+ struct mt_print_params *print_params);
+void mt_param_entry_sbuf(struct sbuf *sb, struct mt_status_entry *entry,
+ void *arg);
+void mt_param_entry_print(struct mt_status_entry *entry, void *arg);
+int mt_protect_print(struct mt_status_data *status_data, int verbose);
+int mt_param_list(struct mt_status_data *status_data, char *param_name,
+ int quiet);
+const char *mt_density_name(int density_num);
+int mt_density_bp(int density_num, int bpi);
+int mt_density_num(const char *density_name);
+int mt_get_xml_str(int mtfd, unsigned long cmd, char **xml_str);
+int mt_get_status(char *xml_str, struct mt_status_data *status_data);
+__END_DECLS
+
+#endif /* _MTLIB_H */
diff --git a/lib/libnetgraph/debug.c b/lib/libnetgraph/debug.c
index 6d0579f..f445041 100644
--- a/lib/libnetgraph/debug.c
+++ b/lib/libnetgraph/debug.c
@@ -62,12 +62,15 @@ __FBSDID("$FreeBSD$");
#include <netgraph/ng_atmllc.h>
#include <netgraph/ng_bpf.h>
#include <netgraph/ng_bridge.h>
+#include <netgraph/ng_car.h>
#include <netgraph/ng_cisco.h>
+#include <netgraph/ng_deflate.h>
#include <netgraph/ng_device.h>
#include <netgraph/ng_echo.h>
#include <netgraph/ng_eiface.h>
#include <netgraph/ng_etf.h>
#include <netgraph/ng_ether.h>
+#include <netgraph/ng_ether_echo.h>
#include <netgraph/ng_frame_relay.h>
#include <netgraph/ng_gif.h>
#include <netgraph/ng_gif_demux.h>
@@ -81,15 +84,20 @@ __FBSDID("$FreeBSD$");
#include <netgraph/ng_lmi.h>
#include <netgraph/ng_mppc.h>
#include <netgraph/ng_nat.h>
+#include <netgraph/netflow/ng_netflow.h>
#include <netgraph/ng_one2many.h>
+#include <netgraph/ng_patch.h>
+#include <netgraph/ng_pipe.h>
#include <netgraph/ng_ppp.h>
#include <netgraph/ng_pppoe.h>
#include <netgraph/ng_pptpgre.h>
+#include <netgraph/ng_pred1.h>
#include <netgraph/ng_rfc1490.h>
#include <netgraph/ng_socket.h>
#include <netgraph/ng_source.h>
#include <netgraph/ng_split.h>
#include <netgraph/ng_sppp.h>
+#include <netgraph/ng_tag.h>
#include <netgraph/ng_tcpmss.h>
#include <netgraph/ng_tee.h>
#include <netgraph/ng_tty.h>
@@ -129,12 +137,15 @@ static const struct ng_cookie cookies[] = {
COOKIE(ATMLLC),
COOKIE(BPF),
COOKIE(BRIDGE),
+ COOKIE(CAR),
COOKIE(CISCO),
+ COOKIE(DEFLATE),
COOKIE(DEVICE),
COOKIE(ECHO),
COOKIE(EIFACE),
COOKIE(ETF),
COOKIE(ETHER),
+ COOKIE(ETHER_ECHO),
COOKIE(FRAMERELAY),
COOKIE(GIF),
COOKIE(GIF_DEMUX),
@@ -149,15 +160,20 @@ static const struct ng_cookie cookies[] = {
COOKIE(LMI),
COOKIE(MPPC),
COOKIE(NAT),
+ COOKIE(NETFLOW),
COOKIE(ONE2MANY),
+ COOKIE(PATCH),
+ COOKIE(PIPE),
COOKIE(PPP),
COOKIE(PPPOE),
COOKIE(PPTPGRE),
+ COOKIE(PRED1),
COOKIE(RFC1490),
COOKIE(SOCKET),
COOKIE(SOURCE),
COOKIE(SPLIT),
COOKIE(SPPP),
+ COOKIE(TAG),
COOKIE(TCPMSS),
COOKIE(TEE),
COOKIE(TTY),
@@ -181,9 +197,8 @@ NgSetDebug(int level)
{
int old = _gNgDebugLevel;
- if (level < 0)
- level = old;
- _gNgDebugLevel = level;
+ if (level >= 0)
+ _gNgDebugLevel = level;
return (old);
}
@@ -225,10 +240,10 @@ _NgDebugMsg(const struct ng_mesg *msg, const char *path)
/* Display header stuff */
NGLOGX("NG_MESG :");
NGLOGX(" vers %d", msg->header.version);
- NGLOGX(" arglen %d", msg->header.arglen);
- NGLOGX(" flags %ld", msg->header.flags);
- NGLOGX(" token %lu", (u_long)msg->header.token);
- NGLOGX(" cookie %s (%d)",
+ NGLOGX(" arglen %u", msg->header.arglen);
+ NGLOGX(" flags %x", msg->header.flags);
+ NGLOGX(" token %u", msg->header.token);
+ NGLOGX(" cookie %s (%u)",
NgCookie(msg->header.typecookie), msg->header.typecookie);
/* At lower debugging levels, skip ASCII translation */
diff --git a/lib/libnv/Makefile b/lib/libnv/Makefile
index e9371bc..8b2fc78 100644
--- a/lib/libnv/Makefile
+++ b/lib/libnv/Makefile
@@ -7,10 +7,13 @@ SHLIBDIR?= /lib
LIB= nv
SHLIB_MAJOR= 0
-SRCS= dnvlist.c
+.PATH: ${.CURDIR}/../../sys/kern ${.CURDIR}/../../sys/sys
+CFLAGS+=-I${.CURDIR}/../../sys -I${.CURDIR}
+
+SRCS= subr_dnvlist.c
SRCS+= msgio.c
-SRCS+= nvlist.c
-SRCS+= nvpair.c
+SRCS+= subr_nvlist.c
+SRCS+= subr_nvpair.c
INCS= dnv.h
INCS+= nv.h
@@ -19,145 +22,66 @@ MAN+= nv.3
MLINKS+=nv.3 libnv.3 \
nv.3 nvlist.3
-MLINKS+=nv.3 nvlist_create.3 \
- nv.3 nvlist_destroy.3 \
- nv.3 nvlist_error.3 \
- nv.3 nvlist_empty.3 \
+MLINKS+=nv.3 nvlist_add_binary.3 \
+ nv.3 nvlist_add_bool.3 \
+ nv.3 nvlist_add_descriptor.3 \
+ nv.3 nvlist_add_null.3 \
+ nv.3 nvlist_add_number.3 \
+ nv.3 nvlist_add_nvlist.3 \
+ nv.3 nvlist_add_string.3 \
+ nv.3 nvlist_add_stringf.3 \
+ nv.3 nvlist_add_stringv.3 \
nv.3 nvlist_clone.3 \
+ nv.3 nvlist_create.3 \
+ nv.3 nvlist_destroy.3 \
nv.3 nvlist_dump.3 \
- nv.3 nvlist_fdump.3 \
- nv.3 nvlist_size.3 \
- nv.3 nvlist_pack.3 \
- nv.3 nvlist_unpack.3 \
- nv.3 nvlist_send.3 \
- nv.3 nvlist_recv.3 \
- nv.3 nvlist_xfer.3 \
- nv.3 nvlist_next.3 \
+ nv.3 nvlist_empty.3 \
+ nv.3 nvlist_error.3 \
nv.3 nvlist_exists.3 \
- nv.3 nvlist_exists_type.3 \
- nv.3 nvlist_exists_null.3 \
+ nv.3 nvlist_exists_binary.3 \
nv.3 nvlist_exists_bool.3 \
+ nv.3 nvlist_exists_descriptor.3 \
+ nv.3 nvlist_exists_null.3 \
nv.3 nvlist_exists_number.3 \
- nv.3 nvlist_exists_string.3 \
nv.3 nvlist_exists_nvlist.3 \
- nv.3 nvlist_exists_descriptor.3 \
- nv.3 nvlist_exists_binary.3 \
- nv.3 nvlist_add_null.3 \
- nv.3 nvlist_add_bool.3 \
- nv.3 nvlist_add_number.3 \
- nv.3 nvlist_add_string.3 \
- nv.3 nvlist_add_stringf.3 \
- nv.3 nvlist_add_stringv.3 \
- nv.3 nvlist_add_nvlist.3 \
- nv.3 nvlist_add_descriptor.3 \
- nv.3 nvlist_add_binary.3 \
- nv.3 nvlist_move_string.3 \
- nv.3 nvlist_move_nvlist.3 \
- nv.3 nvlist_move_descriptor.3 \
- nv.3 nvlist_move_binary.3 \
+ nv.3 nvlist_exists_string.3 \
+ nv.3 nvlist_exists_type.3 \
+ nv.3 nvlist_fdump.3 \
+ nv.3 nvlist_flags.3 \
+ nv.3 nvlist_free.3 \
+ nv.3 nvlist_free_binary.3 \
+ nv.3 nvlist_free_bool.3 \
+ nv.3 nvlist_free_descriptor.3 \
+ nv.3 nvlist_free_null.3 \
+ nv.3 nvlist_free_number.3 \
+ nv.3 nvlist_free_nvlist.3 \
+ nv.3 nvlist_free_string.3 \
+ nv.3 nvlist_free_type.3 \
+ nv.3 nvlist_get_binary.3 \
nv.3 nvlist_get_bool.3 \
+ nv.3 nvlist_get_descriptor.3 \
nv.3 nvlist_get_number.3 \
- nv.3 nvlist_get_string.3 \
nv.3 nvlist_get_nvlist.3 \
- nv.3 nvlist_get_descriptor.3 \
- nv.3 nvlist_get_binary.3 \
+ nv.3 nvlist_get_parent.3 \
+ nv.3 nvlist_get_string.3 \
+ nv.3 nvlist_move_binary.3 \
+ nv.3 nvlist_move_descriptor.3 \
+ nv.3 nvlist_move_nvlist.3 \
+ nv.3 nvlist_move_string.3 \
+ nv.3 nvlist_next.3 \
+ nv.3 nvlist_pack.3 \
+ nv.3 nvlist_recv.3 \
+ nv.3 nvlist_send.3 \
+ nv.3 nvlist_set_error.3 \
+ nv.3 nvlist_size.3 \
+ nv.3 nvlist_take_binary.3 \
nv.3 nvlist_take_bool.3 \
+ nv.3 nvlist_take_descriptor.3 \
nv.3 nvlist_take_number.3 \
- nv.3 nvlist_take_string.3 \
nv.3 nvlist_take_nvlist.3 \
- nv.3 nvlist_take_descriptor.3 \
- nv.3 nvlist_take_binary.3 \
- nv.3 nvlist_free.3 \
- nv.3 nvlist_free_type.3 \
- nv.3 nvlist_free_null.3 \
- nv.3 nvlist_free_bool.3 \
- nv.3 nvlist_free_number.3 \
- nv.3 nvlist_free_string.3 \
- nv.3 nvlist_free_nvlist.3 \
- nv.3 nvlist_free_descriptor.3 \
- nv.3 nvlist_free_binary.3
-MLINKS+=nv.3 nvlist_existsf.3 \
- nv.3 nvlist_existsf_type.3 \
- nv.3 nvlist_existsf_null.3 \
- nv.3 nvlist_existsf_bool.3 \
- nv.3 nvlist_existsf_number.3 \
- nv.3 nvlist_existsf_string.3 \
- nv.3 nvlist_existsf_nvlist.3 \
- nv.3 nvlist_existsf_descriptor.3 \
- nv.3 nvlist_existsf_binary.3 \
- nv.3 nvlist_addf_null.3 \
- nv.3 nvlist_addf_bool.3 \
- nv.3 nvlist_addf_number.3 \
- nv.3 nvlist_addf_string.3 \
- nv.3 nvlist_addf_nvlist.3 \
- nv.3 nvlist_addf_descriptor.3 \
- nv.3 nvlist_addf_binary.3 \
- nv.3 nvlist_movef_string.3 \
- nv.3 nvlist_movef_nvlist.3 \
- nv.3 nvlist_movef_descriptor.3 \
- nv.3 nvlist_movef_binary.3 \
- nv.3 nvlist_getf_bool.3 \
- nv.3 nvlist_getf_number.3 \
- nv.3 nvlist_getf_string.3 \
- nv.3 nvlist_getf_nvlist.3 \
- nv.3 nvlist_getf_descriptor.3 \
- nv.3 nvlist_getf_binary.3 \
- nv.3 nvlist_takef_bool.3 \
- nv.3 nvlist_takef_number.3 \
- nv.3 nvlist_takef_string.3 \
- nv.3 nvlist_takef_nvlist.3 \
- nv.3 nvlist_takef_descriptor.3 \
- nv.3 nvlist_takef_binary.3 \
- nv.3 nvlist_freef.3 \
- nv.3 nvlist_freef_type.3 \
- nv.3 nvlist_freef_null.3 \
- nv.3 nvlist_freef_bool.3 \
- nv.3 nvlist_freef_number.3 \
- nv.3 nvlist_freef_string.3 \
- nv.3 nvlist_freef_nvlist.3 \
- nv.3 nvlist_freef_descriptor.3 \
- nv.3 nvlist_freef_binary.3
-MLINKS+=nv.3 nvlist_existsv.3 \
- nv.3 nvlist_existsv_type.3 \
- nv.3 nvlist_existsv_null.3 \
- nv.3 nvlist_existsv_bool.3 \
- nv.3 nvlist_existsv_number.3 \
- nv.3 nvlist_existsv_string.3 \
- nv.3 nvlist_existsv_nvlist.3 \
- nv.3 nvlist_existsv_descriptor.3 \
- nv.3 nvlist_existsv_binary.3 \
- nv.3 nvlist_addv_null.3 \
- nv.3 nvlist_addv_bool.3 \
- nv.3 nvlist_addv_number.3 \
- nv.3 nvlist_addv_string.3 \
- nv.3 nvlist_addv_nvlist.3 \
- nv.3 nvlist_addv_descriptor.3 \
- nv.3 nvlist_addv_binary.3 \
- nv.3 nvlist_movev_string.3 \
- nv.3 nvlist_movev_nvlist.3 \
- nv.3 nvlist_movev_descriptor.3 \
- nv.3 nvlist_movev_binary.3 \
- nv.3 nvlist_getv_bool.3 \
- nv.3 nvlist_getv_number.3 \
- nv.3 nvlist_getv_string.3 \
- nv.3 nvlist_getv_nvlist.3 \
- nv.3 nvlist_getv_descriptor.3 \
- nv.3 nvlist_getv_binary.3 \
- nv.3 nvlist_takev_bool.3 \
- nv.3 nvlist_takev_number.3 \
- nv.3 nvlist_takev_string.3 \
- nv.3 nvlist_takev_nvlist.3 \
- nv.3 nvlist_takev_descriptor.3 \
- nv.3 nvlist_takev_binary.3 \
- nv.3 nvlist_freev.3 \
- nv.3 nvlist_freev_type.3 \
- nv.3 nvlist_freev_null.3 \
- nv.3 nvlist_freev_bool.3 \
- nv.3 nvlist_freev_number.3 \
- nv.3 nvlist_freev_string.3 \
- nv.3 nvlist_freev_nvlist.3 \
- nv.3 nvlist_freev_descriptor.3 \
- nv.3 nvlist_freev_binary.3
+ nv.3 nvlist_take_string.3 \
+ nv.3 nvlist_unpack.3 \
+ nv.3 nvlist_xfer.3
WARNS?= 6
diff --git a/lib/libnv/dnv.h b/lib/libnv/dnv.h
deleted file mode 100644
index ac1e57c..0000000
--- a/lib/libnv/dnv.h
+++ /dev/null
@@ -1,106 +0,0 @@
-/*-
- * Copyright (c) 2013 The FreeBSD Foundation
- * All rights reserved.
- *
- * This software was developed by Pawel Jakub Dawidek under sponsorship from
- * the FreeBSD Foundation.
- *
- * 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 AUTHORS 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 AUTHORS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-#ifndef _DNV_H_
-#define _DNV_H_
-
-#include <sys/cdefs.h>
-
-#include <stdarg.h>
-#include <stdbool.h>
-#include <stdint.h>
-
-#ifndef _NVLIST_T_DECLARED
-#define _NVLIST_T_DECLARED
-struct nvlist;
-
-typedef struct nvlist nvlist_t;
-#endif
-
-/*
- * The dnvlist_get functions returns value associated with the given name.
- * If it returns a pointer, the pointer represents internal buffer and should
- * not be freed by the caller.
- * If no element of the given name and type exists, the function will return
- * provided default value.
- */
-
-bool dnvlist_get_bool(const nvlist_t *nvl, const char *name, bool defval);
-uint64_t dnvlist_get_number(const nvlist_t *nvl, const char *name, uint64_t defval);
-const char *dnvlist_get_string(const nvlist_t *nvl, const char *name, const char *defval);
-const nvlist_t *dnvlist_get_nvlist(const nvlist_t *nvl, const char *name, const nvlist_t *defval);
-int dnvlist_get_descriptor(const nvlist_t *nvl, const char *name, int defval);
-const void *dnvlist_get_binary(const nvlist_t *nvl, const char *name, size_t *sizep, const void *defval, size_t defsize);
-
-bool dnvlist_getf_bool(const nvlist_t *nvl, bool defval, const char *namefmt, ...) __printflike(3, 4);
-uint64_t dnvlist_getf_number(const nvlist_t *nvl, uint64_t defval, const char *namefmt, ...) __printflike(3, 4);
-const char *dnvlist_getf_string(const nvlist_t *nvl, const char *defval, const char *namefmt, ...) __printflike(3, 4);
-const nvlist_t *dnvlist_getf_nvlist(const nvlist_t *nvl, const nvlist_t *defval, const char *namefmt, ...) __printflike(3, 4);
-int dnvlist_getf_descriptor(const nvlist_t *nvl, int defval, const char *namefmt, ...) __printflike(3, 4);
-const void *dnvlist_getf_binary(const nvlist_t *nvl, size_t *sizep, const void *defval, size_t defsize, const char *namefmt, ...) __printflike(5, 6);
-
-bool dnvlist_getv_bool(const nvlist_t *nvl, bool defval, const char *namefmt, va_list nameap) __printflike(3, 0);
-uint64_t dnvlist_getv_number(const nvlist_t *nvl, uint64_t defval, const char *namefmt, va_list nameap) __printflike(3, 0);
-const char *dnvlist_getv_string(const nvlist_t *nvl, const char *defval, const char *namefmt, va_list nameap) __printflike(3, 0);
-const nvlist_t *dnvlist_getv_nvlist(const nvlist_t *nvl, const nvlist_t *defval, const char *namefmt, va_list nameap) __printflike(3, 0);
-int dnvlist_getv_descriptor(const nvlist_t *nvl, int defval, const char *namefmt, va_list nameap) __printflike(3, 0);
-const void *dnvlist_getv_binary(const nvlist_t *nvl, size_t *sizep, const void *defval, size_t defsize, const char *namefmt, va_list nameap) __printflike(5, 0);
-
-/*
- * The dnvlist_take functions returns value associated with the given name and
- * remove corresponding nvpair.
- * If it returns a pointer, the caller has to free it.
- * If no element of the given name and type exists, the function will return
- * provided default value.
- */
-
-bool dnvlist_take_bool(nvlist_t *nvl, const char *name, bool defval);
-uint64_t dnvlist_take_number(nvlist_t *nvl, const char *name, uint64_t defval);
-char *dnvlist_take_string(nvlist_t *nvl, const char *name, char *defval);
-nvlist_t *dnvlist_take_nvlist(nvlist_t *nvl, const char *name, nvlist_t *defval);
-int dnvlist_take_descriptor(nvlist_t *nvl, const char *name, int defval);
-void *dnvlist_take_binary(nvlist_t *nvl, const char *name, size_t *sizep, void *defval, size_t defsize);
-
-bool dnvlist_takef_bool(nvlist_t *nvl, bool defval, const char *namefmt, ...) __printflike(3, 4);
-uint64_t dnvlist_takef_number(nvlist_t *nvl, uint64_t defval, const char *namefmt, ...) __printflike(3, 4);
-char *dnvlist_takef_string(nvlist_t *nvl, char *defval, const char *namefmt, ...) __printflike(3, 4);
-nvlist_t *dnvlist_takef_nvlist(nvlist_t *nvl, nvlist_t *defval, const char *namefmt, ...) __printflike(3, 4);
-int dnvlist_takef_descriptor(nvlist_t *nvl, int defval, const char *namefmt, ...) __printflike(3, 4);
-void *dnvlist_takef_binary(nvlist_t *nvl, size_t *sizep, void *defval, size_t defsize, const char *namefmt, ...) __printflike(5, 6);
-
-bool dnvlist_takev_bool(nvlist_t *nvl, bool defval, const char *namefmt, va_list nameap) __printflike(3, 0);
-uint64_t dnvlist_takev_number(nvlist_t *nvl, uint64_t defval, const char *namefmt, va_list nameap) __printflike(3, 0);
-char *dnvlist_takev_string(nvlist_t *nvl, char *defval, const char *namefmt, va_list nameap) __printflike(3, 0);
-nvlist_t *dnvlist_takev_nvlist(nvlist_t *nvl, nvlist_t *defval, const char *namefmt, va_list nameap) __printflike(3, 0);
-int dnvlist_takev_descriptor(nvlist_t *nvl, int defval, const char *namefmt, va_list nameap) __printflike(3, 0);
-void *dnvlist_takev_binary(nvlist_t *nvl, size_t *sizep, void *defval, size_t defsize, const char *namefmt, va_list nameap) __printflike(5, 0);
-
-#endif /* !_DNV_H_ */
diff --git a/lib/libnv/dnvlist.c b/lib/libnv/dnvlist.c
deleted file mode 100644
index b758bbf..0000000
--- a/lib/libnv/dnvlist.c
+++ /dev/null
@@ -1,252 +0,0 @@
-/*-
- * Copyright (c) 2013 The FreeBSD Foundation
- * All rights reserved.
- *
- * This software was developed by Pawel Jakub Dawidek under sponsorship from
- * the FreeBSD Foundation.
- *
- * 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 AUTHORS 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 AUTHORS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <stdarg.h>
-#include <stdbool.h>
-#include <stdint.h>
-
-#include "nv.h"
-#include "nv_impl.h"
-
-#include "dnv.h"
-
-#define DNVLIST_GET(ftype, type) \
-ftype \
-dnvlist_get_##type(const nvlist_t *nvl, const char *name, ftype defval) \
-{ \
- \
- return (dnvlist_getf_##type(nvl, defval, "%s", name)); \
-}
-
-DNVLIST_GET(bool, bool)
-DNVLIST_GET(uint64_t, number)
-DNVLIST_GET(const char *, string)
-DNVLIST_GET(const nvlist_t *, nvlist)
-DNVLIST_GET(int, descriptor)
-
-#undef DNVLIST_GET
-
-const void *
-dnvlist_get_binary(const nvlist_t *nvl, const char *name, size_t *sizep,
- const void *defval, size_t defsize)
-{
-
- return (dnvlist_getf_binary(nvl, sizep, defval, defsize, "%s", name));
-}
-
-#define DNVLIST_GETF(ftype, type) \
-ftype \
-dnvlist_getf_##type(const nvlist_t *nvl, ftype defval, \
- const char *namefmt, ...) \
-{ \
- va_list nameap; \
- ftype value; \
- \
- va_start(nameap, namefmt); \
- value = dnvlist_getv_##type(nvl, defval, namefmt, nameap); \
- va_end(nameap); \
- \
- return (value); \
-}
-
-DNVLIST_GETF(bool, bool)
-DNVLIST_GETF(uint64_t, number)
-DNVLIST_GETF(const char *, string)
-DNVLIST_GETF(const nvlist_t *, nvlist)
-DNVLIST_GETF(int, descriptor)
-
-#undef DNVLIST_GETF
-
-const void *
-dnvlist_getf_binary(const nvlist_t *nvl, size_t *sizep, const void *defval,
- size_t defsize, const char *namefmt, ...)
-{
- va_list nameap;
- const void *value;
-
- va_start(nameap, namefmt);
- value = dnvlist_getv_binary(nvl, sizep, defval, defsize, namefmt,
- nameap);
- va_end(nameap);
-
- return (value);
-}
-
-#define DNVLIST_GETV(ftype, type) \
-ftype \
-dnvlist_getv_##type(const nvlist_t *nvl, ftype defval, \
- const char *namefmt, va_list nameap) \
-{ \
- va_list cnameap; \
- ftype value; \
- \
- va_copy(cnameap, nameap); \
- if (nvlist_existsv_##type(nvl, namefmt, cnameap)) \
- value = nvlist_getv_##type(nvl, namefmt, nameap); \
- else \
- value = defval; \
- va_end(cnameap); \
- return (value); \
-}
-
-DNVLIST_GETV(bool, bool)
-DNVLIST_GETV(uint64_t, number)
-DNVLIST_GETV(const char *, string)
-DNVLIST_GETV(const nvlist_t *, nvlist)
-DNVLIST_GETV(int, descriptor)
-
-#undef DNVLIST_GETV
-
-const void *
-dnvlist_getv_binary(const nvlist_t *nvl, size_t *sizep, const void *defval,
- size_t defsize, const char *namefmt, va_list nameap)
-{
- va_list cnameap;
- const void *value;
-
- va_copy(cnameap, nameap);
- if (nvlist_existsv_binary(nvl, namefmt, cnameap)) {
- value = nvlist_getv_binary(nvl, sizep, namefmt, nameap);
- } else {
- if (sizep != NULL)
- *sizep = defsize;
- value = defval;
- }
- va_end(cnameap);
- return (value);
-}
-
-#define DNVLIST_TAKE(ftype, type) \
-ftype \
-dnvlist_take_##type(nvlist_t *nvl, const char *name, ftype defval) \
-{ \
- \
- return (dnvlist_takef_##type(nvl, defval, "%s", name)); \
-}
-
-DNVLIST_TAKE(bool, bool)
-DNVLIST_TAKE(uint64_t, number)
-DNVLIST_TAKE(char *, string)
-DNVLIST_TAKE(nvlist_t *, nvlist)
-DNVLIST_TAKE(int, descriptor)
-
-#undef DNVLIST_TAKE
-
-void *
-dnvlist_take_binary(nvlist_t *nvl, const char *name, size_t *sizep,
- void *defval, size_t defsize)
-{
-
- return (dnvlist_takef_binary(nvl, sizep, defval, defsize, "%s", name));
-}
-
-#define DNVLIST_TAKEF(ftype, type) \
-ftype \
-dnvlist_takef_##type(nvlist_t *nvl, ftype defval, \
- const char *namefmt, ...) \
-{ \
- va_list nameap; \
- ftype value; \
- \
- va_start(nameap, namefmt); \
- value = dnvlist_takev_##type(nvl, defval, namefmt, nameap); \
- va_end(nameap); \
- \
- return (value); \
-}
-
-DNVLIST_TAKEF(bool, bool)
-DNVLIST_TAKEF(uint64_t, number)
-DNVLIST_TAKEF(char *, string)
-DNVLIST_TAKEF(nvlist_t *, nvlist)
-DNVLIST_TAKEF(int, descriptor)
-
-#undef DNVLIST_TAKEF
-
-void *
-dnvlist_takef_binary(nvlist_t *nvl, size_t *sizep, void *defval,
- size_t defsize, const char *namefmt, ...)
-{
- va_list nameap;
- void *value;
-
- va_start(nameap, namefmt);
- value = dnvlist_takev_binary(nvl, sizep, defval, defsize, namefmt,
- nameap);
- va_end(nameap);
-
- return (value);
-}
-
-#define DNVLIST_TAKEV(ftype, type) \
-ftype \
-dnvlist_takev_##type(nvlist_t *nvl, ftype defval, const char *namefmt, \
- va_list nameap) \
-{ \
- va_list cnameap; \
- ftype value; \
- \
- va_copy(cnameap, nameap); \
- if (nvlist_existsv_##type(nvl, namefmt, cnameap)) \
- value = nvlist_takev_##type(nvl, namefmt, nameap); \
- else \
- value = defval; \
- va_end(cnameap); \
- return (value); \
-}
-
-DNVLIST_TAKEV(bool, bool)
-DNVLIST_TAKEV(uint64_t, number)
-DNVLIST_TAKEV(char *, string)
-DNVLIST_TAKEV(nvlist_t *, nvlist)
-DNVLIST_TAKEV(int, descriptor)
-
-#undef DNVLIST_TAKEV
-
-void *
-dnvlist_takev_binary(nvlist_t *nvl, size_t *sizep, void *defval,
- size_t defsize, const char *namefmt, va_list nameap)
-{
- va_list cnameap;
- void *value;
-
- va_copy(cnameap, nameap);
- if (nvlist_existsv_binary(nvl, namefmt, cnameap)) {
- value = nvlist_takev_binary(nvl, sizep, namefmt, nameap);
- } else {
- if (sizep != NULL)
- *sizep = defsize;
- value = defval;
- }
- va_end(cnameap);
- return (value);
-}
diff --git a/lib/libnv/nv.3 b/lib/libnv/nv.3
index 29ba744..58033be 100644
--- a/lib/libnv/nv.3
+++ b/lib/libnv/nv.3
@@ -28,14 +28,16 @@
.\"
.\" $FreeBSD$
.\"
-.Dd September 25, 2014
+.Dd May 2, 2015
.Dt NV 3
.Os
.Sh NAME
.Nm nvlist_create ,
.Nm nvlist_destroy ,
.Nm nvlist_error ,
+.Nm nvlist_set_error ,
.Nm nvlist_empty ,
+.Nm nvlist_flags ,
.Nm nvlist_exists ,
.Nm nvlist_free ,
.Nm nvlist_clone ,
@@ -63,8 +65,12 @@
.Fn nvlist_destroy "nvlist_t *nvl"
.Ft int
.Fn nvlist_error "const nvlist_t *nvl"
+.Ft void
+.Fn nvlist_set_error "nvlist_t *nvl, int error"
.Ft bool
.Fn nvlist_empty "const nvlist_t *nvl"
+.Ft int
+.Fn nvlist_flags "const nvlist_t *nvl"
.\"
.Ft "nvlist_t *"
.Fn nvlist_clone "const nvlist_t *nvl"
@@ -79,14 +85,14 @@
.Ft "void *"
.Fn nvlist_pack "const nvlist_t *nvl" "size_t *sizep"
.Ft "nvlist_t *"
-.Fn nvlist_unpack "const void *buf" "size_t size"
+.Fn nvlist_unpack "const void *buf" "size_t size" "int flags"
.\"
.Ft int
.Fn nvlist_send "int sock" "const nvlist_t *nvl"
.Ft "nvlist_t *"
-.Fn nvlist_recv "int sock"
+.Fn nvlist_recv "int sock" "int flags"
.Ft "nvlist_t *"
-.Fn nvlist_xfer "int sock" "nvlist_t *nvl"
+.Fn nvlist_xfer "int sock" "nvlist_t *nvl" "int flags"
.\"
.Ft "const char *"
.Fn nvlist_next "const nvlist_t *nvl" "int *typep" "void **cookiep"
@@ -151,7 +157,7 @@
.Ft "const void *"
.Fn nvlist_get_binary "const nvlist_t *nvl" "const char *name" "size_t *sizep"
.Ft "const nvlist_t *"
-.Fn nvlist_get_parent "const nvlist_t *nvl"
+.Fn nvlist_get_parent "const nvlist_t *nvl" "void **cookiep"
.\"
.Ft bool
.Fn nvlist_take_bool "nvlist_t *nvl" "const char *name"
@@ -226,6 +232,8 @@ The following flag can be provided:
.Bl -tag -width "NV_FLAG_IGNORE_CASE" -compact -offset indent
.It Dv NV_FLAG_IGNORE_CASE
Perform case-insensitive lookups of provided names.
+.It Dv NV_FLAG_NO_UNIQUE
+Names in the nvlist do not have to be unique.
.El
.Pp
The
@@ -248,8 +256,17 @@ the
error will be returned.
.Pp
The
+.Fn nvlist_set_error
+function sets an nvlist to be in the error state.
+Subsequent calls to
+.Fn nvlist_error
+will return the given error value.
+This function cannot be used to clear the error state from an nvlist.
+This function does nothing if the nvlist is already in the error state.
+.Pp
+The
.Fn nvlist_empty
-functions returns
+function returns
.Dv true
if the given nvlist is empty and
.Dv false
@@ -257,6 +274,12 @@ otherwise.
The nvlist must not be in error state.
.Pp
The
+.Fn nvlist_flags
+function returns flags used to create the nvlist with the
+.Fn nvlist_create
+function.
+.Pp
+The
.Fn nvlist_clone
functions clones the given nvlist.
The clone shares no resources with its origin.
@@ -304,6 +327,18 @@ The nvlist must not be in error state.
The
.Fn nvlist_unpack
function converts the given buffer to the nvlist.
+The
+.Fa flags
+argument defines what type of the top level nvlist is expected to be.
+Flags are set up using the
+.Fn nvlist_create
+function.
+If the nvlist flags do not match the flags passed to
+.Fn nvlist_unpack ,
+the nvlist will not be returned.
+Every nested nvlist list should be checked using
+.Fn nvlist_flags
+function.
The function returns
.Dv NULL
in case of an error.
@@ -322,12 +357,36 @@ The
function receives nvlist over the socket given by the
.Fa sock
argument.
+The
+.Fa flags
+argument defines what type of the top level nvlist is expected to be.
+Flags are set up using the
+.Fn nvlist_create
+function.
+If the nvlist flags do not match the flags passed to
+.Fn nvlist_recv ,
+the nvlist will not be returned.
+Every nested nvlist list should be checked using
+.Fn nvlist_flags
+function.
.Pp
The
.Fn nvlist_xfer
function sends the given nvlist over the socket given by the
.Fa sock
argument and receives nvlist over the same socket.
+The
+.Fa flags
+argument defines what type of the top level nvlist is expected to be.
+Flags are set up using the
+.Fn nvlist_create
+function.
+If the nvlist flags do not match the flags passed to
+.Fn nvlist_xfer ,
+the nvlist will not be returned.
+Every nested nvlist list should be checked using
+.Fn nvlist_flags
+function.
The given nvlist is always destroyed.
.Pp
The
@@ -538,7 +597,7 @@ const char *command;
char *filename;
int fd;
-nvl = nvlist_recv(sock);
+nvl = nvlist_recv(sock, 0);
if (nvl == NULL)
err(1, "nvlist_recv() failed");
@@ -567,7 +626,7 @@ const char *name;
void *cookie;
int type;
-nvl = nvlist_recv(sock);
+nvl = nvlist_recv(sock, 0);
if (nvl == NULL)
err(1, "nvlist_recv() failed");
@@ -588,6 +647,28 @@ while ((name = nvlist_next(nvl, &type, &cookie)) != NULL) {
printf("\\n");
}
.Ed
+.Pp
+Iterating over every nested nvlist:
+.Bd -literal
+nvlist_t *nvl;
+const char *name;
+void *cookie;
+int type;
+
+nvl = nvlist_recv(sock, 0);
+if (nvl == NULL)
+ err(1, "nvlist_recv() failed");
+
+cookie = NULL;
+do {
+ while ((name = nvlist_next(nvl, &type, &cookie)) != NULL) {
+ if (type == NV_TYPE_NVLIST) {
+ nvl = nvlist_get_nvlist(nvl, name);
+ cookie = NULL;
+ }
+ }
+} while ((nvl = nvlist_get_parent(nvl, &cookie)) != NULL);
+.Ed
.Sh SEE ALSO
.Xr close 2 ,
.Xr dup 2 ,
diff --git a/lib/libnv/nv.h b/lib/libnv/nv.h
deleted file mode 100644
index 1b55be1..0000000
--- a/lib/libnv/nv.h
+++ /dev/null
@@ -1,275 +0,0 @@
-/*-
- * Copyright (c) 2009-2013 The FreeBSD Foundation
- * All rights reserved.
- *
- * This software was developed by Pawel Jakub Dawidek under sponsorship from
- * the FreeBSD Foundation.
- *
- * 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 AUTHORS 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 AUTHORS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-#ifndef _NV_H_
-#define _NV_H_
-
-#include <sys/cdefs.h>
-
-#include <stdarg.h>
-#include <stdbool.h>
-#include <stdint.h>
-#include <stdio.h>
-
-#ifndef _NVLIST_T_DECLARED
-#define _NVLIST_T_DECLARED
-struct nvlist;
-
-typedef struct nvlist nvlist_t;
-#endif
-
-#define NV_NAME_MAX 2048
-
-#define NV_TYPE_NONE 0
-
-#define NV_TYPE_NULL 1
-#define NV_TYPE_BOOL 2
-#define NV_TYPE_NUMBER 3
-#define NV_TYPE_STRING 4
-#define NV_TYPE_NVLIST 5
-#define NV_TYPE_DESCRIPTOR 6
-#define NV_TYPE_BINARY 7
-
-/*
- * Perform case-insensitive lookups of provided names.
- */
-#define NV_FLAG_IGNORE_CASE 0x01
-
-nvlist_t *nvlist_create(int flags);
-void nvlist_destroy(nvlist_t *nvl);
-int nvlist_error(const nvlist_t *nvl);
-bool nvlist_empty(const nvlist_t *nvl);
-
-nvlist_t *nvlist_clone(const nvlist_t *nvl);
-
-void nvlist_dump(const nvlist_t *nvl, int fd);
-void nvlist_fdump(const nvlist_t *nvl, FILE *fp);
-
-size_t nvlist_size(const nvlist_t *nvl);
-void *nvlist_pack(const nvlist_t *nvl, size_t *sizep);
-nvlist_t *nvlist_unpack(const void *buf, size_t size);
-
-int nvlist_send(int sock, const nvlist_t *nvl);
-nvlist_t *nvlist_recv(int sock);
-nvlist_t *nvlist_xfer(int sock, nvlist_t *nvl);
-
-const char *nvlist_next(const nvlist_t *nvl, int *typep, void **cookiep);
-
-const nvlist_t *nvlist_get_parent(const nvlist_t *nvl);
-
-/*
- * The nvlist_exists functions check if the given name (optionally of the given
- * type) exists on nvlist.
- */
-
-bool nvlist_exists(const nvlist_t *nvl, const char *name);
-bool nvlist_exists_type(const nvlist_t *nvl, const char *name, int type);
-
-bool nvlist_exists_null(const nvlist_t *nvl, const char *name);
-bool nvlist_exists_bool(const nvlist_t *nvl, const char *name);
-bool nvlist_exists_number(const nvlist_t *nvl, const char *name);
-bool nvlist_exists_string(const nvlist_t *nvl, const char *name);
-bool nvlist_exists_nvlist(const nvlist_t *nvl, const char *name);
-bool nvlist_exists_descriptor(const nvlist_t *nvl, const char *name);
-bool nvlist_exists_binary(const nvlist_t *nvl, const char *name);
-
-/*
- * The nvlist_add functions add the given name/value pair.
- * If a pointer is provided, nvlist_add will internally allocate memory for the
- * given data (in other words it won't consume provided buffer).
- */
-
-void nvlist_add_null(nvlist_t *nvl, const char *name);
-void nvlist_add_bool(nvlist_t *nvl, const char *name, bool value);
-void nvlist_add_number(nvlist_t *nvl, const char *name, uint64_t value);
-void nvlist_add_string(nvlist_t *nvl, const char *name, const char *value);
-void nvlist_add_stringf(nvlist_t *nvl, const char *name, const char *valuefmt, ...) __printflike(3, 4);
-void nvlist_add_stringv(nvlist_t *nvl, const char *name, const char *valuefmt, va_list valueap) __printflike(3, 0);
-void nvlist_add_nvlist(nvlist_t *nvl, const char *name, const nvlist_t *value);
-void nvlist_add_descriptor(nvlist_t *nvl, const char *name, int value);
-void nvlist_add_binary(nvlist_t *nvl, const char *name, const void *value, size_t size);
-
-/*
- * The nvlist_move functions add the given name/value pair.
- * The functions consumes provided buffer.
- */
-
-void nvlist_move_string(nvlist_t *nvl, const char *name, char *value);
-void nvlist_move_nvlist(nvlist_t *nvl, const char *name, nvlist_t *value);
-void nvlist_move_descriptor(nvlist_t *nvl, const char *name, int value);
-void nvlist_move_binary(nvlist_t *nvl, const char *name, void *value, size_t size);
-
-/*
- * The nvlist_get functions returns value associated with the given name.
- * If it returns a pointer, the pointer represents internal buffer and should
- * not be freed by the caller.
- */
-
-bool nvlist_get_bool(const nvlist_t *nvl, const char *name);
-uint64_t nvlist_get_number(const nvlist_t *nvl, const char *name);
-const char *nvlist_get_string(const nvlist_t *nvl, const char *name);
-const nvlist_t *nvlist_get_nvlist(const nvlist_t *nvl, const char *name);
-int nvlist_get_descriptor(const nvlist_t *nvl, const char *name);
-const void *nvlist_get_binary(const nvlist_t *nvl, const char *name, size_t *sizep);
-
-/*
- * The nvlist_take functions returns value associated with the given name and
- * remove the given entry from the nvlist.
- * The caller is responsible for freeing received data.
- */
-
-bool nvlist_take_bool(nvlist_t *nvl, const char *name);
-uint64_t nvlist_take_number(nvlist_t *nvl, const char *name);
-char *nvlist_take_string(nvlist_t *nvl, const char *name);
-nvlist_t *nvlist_take_nvlist(nvlist_t *nvl, const char *name);
-int nvlist_take_descriptor(nvlist_t *nvl, const char *name);
-void *nvlist_take_binary(nvlist_t *nvl, const char *name, size_t *sizep);
-
-/*
- * The nvlist_free functions removes the given name/value pair from the nvlist
- * and frees memory associated with it.
- */
-
-void nvlist_free(nvlist_t *nvl, const char *name);
-void nvlist_free_type(nvlist_t *nvl, const char *name, int type);
-
-void nvlist_free_null(nvlist_t *nvl, const char *name);
-void nvlist_free_bool(nvlist_t *nvl, const char *name);
-void nvlist_free_number(nvlist_t *nvl, const char *name);
-void nvlist_free_string(nvlist_t *nvl, const char *name);
-void nvlist_free_nvlist(nvlist_t *nvl, const char *name);
-void nvlist_free_descriptor(nvlist_t *nvl, const char *name);
-void nvlist_free_binary(nvlist_t *nvl, const char *name);
-
-/*
- * Below are the same functions, but which operate on format strings and
- * variable argument lists.
- */
-
-bool nvlist_existsf(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
-bool nvlist_existsf_type(const nvlist_t *nvl, int type, const char *namefmt, ...) __printflike(3, 4);
-
-bool nvlist_existsf_null(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
-bool nvlist_existsf_bool(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
-bool nvlist_existsf_number(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
-bool nvlist_existsf_string(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
-bool nvlist_existsf_nvlist(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
-bool nvlist_existsf_descriptor(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
-bool nvlist_existsf_binary(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
-
-bool nvlist_existsv(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
-bool nvlist_existsv_type(const nvlist_t *nvl, int type, const char *namefmt, va_list nameap) __printflike(3, 0);
-
-bool nvlist_existsv_null(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
-bool nvlist_existsv_bool(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
-bool nvlist_existsv_number(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
-bool nvlist_existsv_string(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
-bool nvlist_existsv_nvlist(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
-bool nvlist_existsv_descriptor(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
-bool nvlist_existsv_binary(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
-
-void nvlist_addf_null(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
-void nvlist_addf_bool(nvlist_t *nvl, bool value, const char *namefmt, ...) __printflike(3, 4);
-void nvlist_addf_number(nvlist_t *nvl, uint64_t value, const char *namefmt, ...) __printflike(3, 4);
-void nvlist_addf_string(nvlist_t *nvl, const char *value, const char *namefmt, ...) __printflike(3, 4);
-void nvlist_addf_nvlist(nvlist_t *nvl, const nvlist_t *value, const char *namefmt, ...) __printflike(3, 4);
-void nvlist_addf_descriptor(nvlist_t *nvl, int value, const char *namefmt, ...) __printflike(3, 4);
-void nvlist_addf_binary(nvlist_t *nvl, const void *value, size_t size, const char *namefmt, ...) __printflike(4, 5);
-
-void nvlist_addv_null(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
-void nvlist_addv_bool(nvlist_t *nvl, bool value, const char *namefmt, va_list nameap) __printflike(3, 0);
-void nvlist_addv_number(nvlist_t *nvl, uint64_t value, const char *namefmt, va_list nameap) __printflike(3, 0);
-void nvlist_addv_string(nvlist_t *nvl, const char *value, const char *namefmt, va_list nameap) __printflike(3, 0);
-void nvlist_addv_nvlist(nvlist_t *nvl, const nvlist_t *value, const char *namefmt, va_list nameap) __printflike(3, 0);
-void nvlist_addv_descriptor(nvlist_t *nvl, int value, const char *namefmt, va_list nameap) __printflike(3, 0);
-void nvlist_addv_binary(nvlist_t *nvl, const void *value, size_t size, const char *namefmt, va_list nameap) __printflike(4, 0);
-
-void nvlist_movef_string(nvlist_t *nvl, char *value, const char *namefmt, ...) __printflike(3, 4);
-void nvlist_movef_nvlist(nvlist_t *nvl, nvlist_t *value, const char *namefmt, ...) __printflike(3, 4);
-void nvlist_movef_descriptor(nvlist_t *nvl, int value, const char *namefmt, ...) __printflike(3, 4);
-void nvlist_movef_binary(nvlist_t *nvl, void *value, size_t size, const char *namefmt, ...) __printflike(4, 5);
-
-void nvlist_movev_string(nvlist_t *nvl, char *value, const char *namefmt, va_list nameap) __printflike(3, 0);
-void nvlist_movev_nvlist(nvlist_t *nvl, nvlist_t *value, const char *namefmt, va_list nameap) __printflike(3, 0);
-void nvlist_movev_descriptor(nvlist_t *nvl, int value, const char *namefmt, va_list nameap) __printflike(3, 0);
-void nvlist_movev_binary(nvlist_t *nvl, void *value, size_t size, const char *namefmt, va_list nameap) __printflike(4, 0);
-
-bool nvlist_getf_bool(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
-uint64_t nvlist_getf_number(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
-const char *nvlist_getf_string(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
-const nvlist_t *nvlist_getf_nvlist(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
-int nvlist_getf_descriptor(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
-const void *nvlist_getf_binary(const nvlist_t *nvl, size_t *sizep, const char *namefmt, ...) __printflike(3, 4);
-
-bool nvlist_getv_bool(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
-uint64_t nvlist_getv_number(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
-const char *nvlist_getv_string(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
-const nvlist_t *nvlist_getv_nvlist(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
-int nvlist_getv_descriptor(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
-const void *nvlist_getv_binary(const nvlist_t *nvl, size_t *sizep, const char *namefmt, va_list nameap) __printflike(3, 0);
-
-bool nvlist_takef_bool(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
-uint64_t nvlist_takef_number(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
-char *nvlist_takef_string(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
-nvlist_t *nvlist_takef_nvlist(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
-int nvlist_takef_descriptor(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
-void *nvlist_takef_binary(nvlist_t *nvl, size_t *sizep, const char *namefmt, ...) __printflike(3, 4);
-
-bool nvlist_takev_bool(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
-uint64_t nvlist_takev_number(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
-char *nvlist_takev_string(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
-nvlist_t *nvlist_takev_nvlist(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
-int nvlist_takev_descriptor(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
-void *nvlist_takev_binary(nvlist_t *nvl, size_t *sizep, const char *namefmt, va_list nameap) __printflike(3, 0);
-
-void nvlist_freef(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
-void nvlist_freef_type(nvlist_t *nvl, int type, const char *namefmt, ...) __printflike(3, 4);
-
-void nvlist_freef_null(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
-void nvlist_freef_bool(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
-void nvlist_freef_number(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
-void nvlist_freef_string(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
-void nvlist_freef_nvlist(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
-void nvlist_freef_descriptor(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
-void nvlist_freef_binary(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
-
-void nvlist_freev(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
-void nvlist_freev_type(nvlist_t *nvl, int type, const char *namefmt, va_list nameap) __printflike(3, 0);
-
-void nvlist_freev_null(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
-void nvlist_freev_bool(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
-void nvlist_freev_number(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
-void nvlist_freev_string(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
-void nvlist_freev_nvlist(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
-void nvlist_freev_descriptor(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
-void nvlist_freev_binary(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
-
-#endif /* !_NV_H_ */
diff --git a/lib/libnv/nv_impl.h b/lib/libnv/nv_impl.h
deleted file mode 100644
index 3ed45b3..0000000
--- a/lib/libnv/nv_impl.h
+++ /dev/null
@@ -1,134 +0,0 @@
-/*-
- * Copyright (c) 2013 The FreeBSD Foundation
- * All rights reserved.
- *
- * This software was developed by Pawel Jakub Dawidek under sponsorship from
- * the FreeBSD Foundation.
- *
- * 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 AUTHORS 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 AUTHORS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-#ifndef _NV_IMPL_H_
-#define _NV_IMPL_H_
-
-#ifndef _NVPAIR_T_DECLARED
-#define _NVPAIR_T_DECLARED
-struct nvpair;
-
-typedef struct nvpair nvpair_t;
-#endif
-
-#define NV_TYPE_NVLIST_UP 255
-
-#define NV_TYPE_FIRST NV_TYPE_NULL
-#define NV_TYPE_LAST NV_TYPE_BINARY
-
-#define NV_FLAG_BIG_ENDIAN 0x80
-
-int *nvlist_descriptors(const nvlist_t *nvl, size_t *nitemsp);
-size_t nvlist_ndescriptors(const nvlist_t *nvl);
-
-nvpair_t *nvlist_first_nvpair(const nvlist_t *nvl);
-nvpair_t *nvlist_next_nvpair(const nvlist_t *nvl, const nvpair_t *nvp);
-nvpair_t *nvlist_prev_nvpair(const nvlist_t *nvl, const nvpair_t *nvp);
-
-void nvlist_add_nvpair(nvlist_t *nvl, const nvpair_t *nvp);
-
-void nvlist_move_nvpair(nvlist_t *nvl, nvpair_t *nvp);
-
-void nvlist_set_parent(nvlist_t *nvl, nvpair_t *parent);
-
-const nvpair_t *nvlist_get_nvpair(const nvlist_t *nvl, const char *name);
-
-nvpair_t *nvlist_take_nvpair(nvlist_t *nvl, const char *name);
-
-/* Function removes the given nvpair from the nvlist. */
-void nvlist_remove_nvpair(nvlist_t *nvl, nvpair_t *nvp);
-
-void nvlist_free_nvpair(nvlist_t *nvl, nvpair_t *nvp);
-
-int nvpair_type(const nvpair_t *nvp);
-const char *nvpair_name(const nvpair_t *nvp);
-
-nvpair_t *nvpair_clone(const nvpair_t *nvp);
-
-nvpair_t *nvpair_create_null(const char *name);
-nvpair_t *nvpair_create_bool(const char *name, bool value);
-nvpair_t *nvpair_create_number(const char *name, uint64_t value);
-nvpair_t *nvpair_create_string(const char *name, const char *value);
-nvpair_t *nvpair_create_stringf(const char *name, const char *valuefmt, ...) __printflike(2, 3);
-nvpair_t *nvpair_create_stringv(const char *name, const char *valuefmt, va_list valueap) __printflike(2, 0);
-nvpair_t *nvpair_create_nvlist(const char *name, const nvlist_t *value);
-nvpair_t *nvpair_create_descriptor(const char *name, int value);
-nvpair_t *nvpair_create_binary(const char *name, const void *value, size_t size);
-
-nvpair_t *nvpair_move_string(const char *name, char *value);
-nvpair_t *nvpair_move_nvlist(const char *name, nvlist_t *value);
-nvpair_t *nvpair_move_descriptor(const char *name, int value);
-nvpair_t *nvpair_move_binary(const char *name, void *value, size_t size);
-
-bool nvpair_get_bool(const nvpair_t *nvp);
-uint64_t nvpair_get_number(const nvpair_t *nvp);
-const char *nvpair_get_string(const nvpair_t *nvp);
-const nvlist_t *nvpair_get_nvlist(const nvpair_t *nvp);
-int nvpair_get_descriptor(const nvpair_t *nvp);
-const void *nvpair_get_binary(const nvpair_t *nvp, size_t *sizep);
-
-void nvpair_free(nvpair_t *nvp);
-
-const nvpair_t *nvlist_getf_nvpair(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
-
-const nvpair_t *nvlist_getv_nvpair(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
-
-nvpair_t *nvlist_takef_nvpair(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
-
-nvpair_t *nvlist_takev_nvpair(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
-
-nvpair_t *nvpair_createf_null(const char *namefmt, ...) __printflike(1, 2);
-nvpair_t *nvpair_createf_bool(bool value, const char *namefmt, ...) __printflike(2, 3);
-nvpair_t *nvpair_createf_number(uint64_t value, const char *namefmt, ...) __printflike(2, 3);
-nvpair_t *nvpair_createf_string(const char *value, const char *namefmt, ...) __printflike(2, 3);
-nvpair_t *nvpair_createf_nvlist(const nvlist_t *value, const char *namefmt, ...) __printflike(2, 3);
-nvpair_t *nvpair_createf_descriptor(int value, const char *namefmt, ...) __printflike(2, 3);
-nvpair_t *nvpair_createf_binary(const void *value, size_t size, const char *namefmt, ...) __printflike(3, 4);
-
-nvpair_t *nvpair_createv_null(const char *namefmt, va_list nameap) __printflike(1, 0);
-nvpair_t *nvpair_createv_bool(bool value, const char *namefmt, va_list nameap) __printflike(2, 0);
-nvpair_t *nvpair_createv_number(uint64_t value, const char *namefmt, va_list nameap) __printflike(2, 0);
-nvpair_t *nvpair_createv_string(const char *value, const char *namefmt, va_list nameap) __printflike(2, 0);
-nvpair_t *nvpair_createv_nvlist(const nvlist_t *value, const char *namefmt, va_list nameap) __printflike(2, 0);
-nvpair_t *nvpair_createv_descriptor(int value, const char *namefmt, va_list nameap) __printflike(2, 0);
-nvpair_t *nvpair_createv_binary(const void *value, size_t size, const char *namefmt, va_list nameap) __printflike(3, 0);
-
-nvpair_t *nvpair_movef_string(char *value, const char *namefmt, ...) __printflike(2, 3);
-nvpair_t *nvpair_movef_nvlist(nvlist_t *value, const char *namefmt, ...) __printflike(2, 3);
-nvpair_t *nvpair_movef_descriptor(int value, const char *namefmt, ...) __printflike(2, 3);
-nvpair_t *nvpair_movef_binary(void *value, size_t size, const char *namefmt, ...) __printflike(3, 4);
-
-nvpair_t *nvpair_movev_string(char *value, const char *namefmt, va_list nameap) __printflike(2, 0);
-nvpair_t *nvpair_movev_nvlist(nvlist_t *value, const char *namefmt, va_list nameap) __printflike(2, 0);
-nvpair_t *nvpair_movev_descriptor(int value, const char *namefmt, va_list nameap) __printflike(2, 0);
-nvpair_t *nvpair_movev_binary(void *value, size_t size, const char *namefmt, va_list nameap) __printflike(3, 0);
-
-#endif /* !_NV_IMPL_H_ */
diff --git a/lib/libnv/nvlist.c b/lib/libnv/nvlist.c
deleted file mode 100644
index b495441..0000000
--- a/lib/libnv/nvlist.c
+++ /dev/null
@@ -1,1848 +0,0 @@
-/*-
- * Copyright (c) 2009-2013 The FreeBSD Foundation
- * All rights reserved.
- *
- * This software was developed by Pawel Jakub Dawidek under sponsorship from
- * the FreeBSD Foundation.
- *
- * 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 AUTHORS 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 AUTHORS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/param.h>
-#include <sys/endian.h>
-#include <sys/queue.h>
-#include <sys/socket.h>
-
-#include <errno.h>
-#include <stdarg.h>
-#include <stdbool.h>
-#include <stdint.h>
-#define _WITH_DPRINTF
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#ifdef HAVE_PJDLOG
-#include <pjdlog.h>
-#endif
-
-#include "msgio.h"
-#include "nv.h"
-#include "nv_impl.h"
-#include "nvlist_impl.h"
-#include "nvpair_impl.h"
-
-#ifndef HAVE_PJDLOG
-#include <assert.h>
-#define PJDLOG_ASSERT(...) assert(__VA_ARGS__)
-#define PJDLOG_RASSERT(expr, ...) assert(expr)
-#define PJDLOG_ABORT(...) do { \
- fprintf(stderr, "%s:%u: ", __FILE__, __LINE__); \
- fprintf(stderr, __VA_ARGS__); \
- fprintf(stderr, "\n"); \
- abort(); \
-} while (0)
-#endif
-
-#define NV_FLAG_PRIVATE_MASK (NV_FLAG_BIG_ENDIAN)
-#define NV_FLAG_PUBLIC_MASK (NV_FLAG_IGNORE_CASE)
-#define NV_FLAG_ALL_MASK (NV_FLAG_PRIVATE_MASK | NV_FLAG_PUBLIC_MASK)
-
-#define NVLIST_MAGIC 0x6e766c /* "nvl" */
-struct nvlist {
- int nvl_magic;
- int nvl_error;
- int nvl_flags;
- nvpair_t *nvl_parent;
- struct nvl_head nvl_head;
-};
-
-#define NVLIST_ASSERT(nvl) do { \
- PJDLOG_ASSERT((nvl) != NULL); \
- PJDLOG_ASSERT((nvl)->nvl_magic == NVLIST_MAGIC); \
-} while (0)
-
-#define NVPAIR_ASSERT(nvp) nvpair_assert(nvp)
-
-#define NVLIST_HEADER_MAGIC 0x6c
-#define NVLIST_HEADER_VERSION 0x00
-struct nvlist_header {
- uint8_t nvlh_magic;
- uint8_t nvlh_version;
- uint8_t nvlh_flags;
- uint64_t nvlh_descriptors;
- uint64_t nvlh_size;
-} __packed;
-
-nvlist_t *
-nvlist_create(int flags)
-{
- nvlist_t *nvl;
-
- PJDLOG_ASSERT((flags & ~(NV_FLAG_PUBLIC_MASK)) == 0);
-
- nvl = malloc(sizeof(*nvl));
- nvl->nvl_error = 0;
- nvl->nvl_flags = flags;
- nvl->nvl_parent = NULL;
- TAILQ_INIT(&nvl->nvl_head);
- nvl->nvl_magic = NVLIST_MAGIC;
-
- return (nvl);
-}
-
-void
-nvlist_destroy(nvlist_t *nvl)
-{
- nvpair_t *nvp;
- int serrno;
-
- if (nvl == NULL)
- return;
-
- serrno = errno;
-
- NVLIST_ASSERT(nvl);
-
- while ((nvp = nvlist_first_nvpair(nvl)) != NULL) {
- nvlist_remove_nvpair(nvl, nvp);
- nvpair_free(nvp);
- }
- nvl->nvl_magic = 0;
- free(nvl);
-
- errno = serrno;
-}
-
-int
-nvlist_error(const nvlist_t *nvl)
-{
-
- if (nvl == NULL)
- return (ENOMEM);
-
- NVLIST_ASSERT(nvl);
-
- return (nvl->nvl_error);
-}
-
-nvpair_t *
-nvlist_get_nvpair_parent(const nvlist_t *nvl)
-{
-
- NVLIST_ASSERT(nvl);
-
- return (nvl->nvl_parent);
-}
-
-const nvlist_t *
-nvlist_get_parent(const nvlist_t *nvl)
-{
-
- NVLIST_ASSERT(nvl);
-
- if (nvl->nvl_parent == NULL)
- return (NULL);
-
- return (nvpair_nvlist(nvl->nvl_parent));
-}
-
-void
-nvlist_set_parent(nvlist_t *nvl, nvpair_t *parent)
-{
-
- NVLIST_ASSERT(nvl);
-
- nvl->nvl_parent = parent;
-}
-
-bool
-nvlist_empty(const nvlist_t *nvl)
-{
-
- NVLIST_ASSERT(nvl);
- PJDLOG_ASSERT(nvl->nvl_error == 0);
-
- return (nvlist_first_nvpair(nvl) == NULL);
-}
-
-static void
-nvlist_report_missing(int type, const char *namefmt, va_list nameap)
-{
- char *name;
-
- vasprintf(&name, namefmt, nameap);
- PJDLOG_ABORT("Element '%s' of type %s doesn't exist.",
- name != NULL ? name : "N/A", nvpair_type_string(type));
-}
-
-static nvpair_t *
-nvlist_findv(const nvlist_t *nvl, int type, const char *namefmt, va_list nameap)
-{
- nvpair_t *nvp;
- char *name;
-
- NVLIST_ASSERT(nvl);
- PJDLOG_ASSERT(nvl->nvl_error == 0);
- PJDLOG_ASSERT(type == NV_TYPE_NONE ||
- (type >= NV_TYPE_FIRST && type <= NV_TYPE_LAST));
-
- if (vasprintf(&name, namefmt, nameap) < 0)
- return (NULL);
-
- for (nvp = nvlist_first_nvpair(nvl); nvp != NULL;
- nvp = nvlist_next_nvpair(nvl, nvp)) {
- if (type != NV_TYPE_NONE && nvpair_type(nvp) != type)
- continue;
- if ((nvl->nvl_flags & NV_FLAG_IGNORE_CASE) != 0) {
- if (strcasecmp(nvpair_name(nvp), name) != 0)
- continue;
- } else {
- if (strcmp(nvpair_name(nvp), name) != 0)
- continue;
- }
- break;
- }
-
- free(name);
-
- if (nvp == NULL)
- errno = ENOENT;
-
- return (nvp);
-}
-
-bool
-nvlist_exists_type(const nvlist_t *nvl, const char *name, int type)
-{
-
- return (nvlist_existsf_type(nvl, type, "%s", name));
-}
-
-bool
-nvlist_existsf_type(const nvlist_t *nvl, int type, const char *namefmt, ...)
-{
- va_list nameap;
- bool ret;
-
- va_start(nameap, namefmt);
- ret = nvlist_existsv_type(nvl, type, namefmt, nameap);
- va_end(nameap);
-
- return (ret);
-}
-
-bool
-nvlist_existsv_type(const nvlist_t *nvl, int type, const char *namefmt,
- va_list nameap)
-{
-
- NVLIST_ASSERT(nvl);
- PJDLOG_ASSERT(nvl->nvl_error == 0);
- PJDLOG_ASSERT(type == NV_TYPE_NONE ||
- (type >= NV_TYPE_FIRST && type <= NV_TYPE_LAST));
-
- return (nvlist_findv(nvl, type, namefmt, nameap) != NULL);
-}
-
-void
-nvlist_free_type(nvlist_t *nvl, const char *name, int type)
-{
-
- nvlist_freef_type(nvl, type, "%s", name);
-}
-
-void
-nvlist_freef_type(nvlist_t *nvl, int type, const char *namefmt, ...)
-{
- va_list nameap;
-
- va_start(nameap, namefmt);
- nvlist_freev_type(nvl, type, namefmt, nameap);
- va_end(nameap);
-}
-
-void
-nvlist_freev_type(nvlist_t *nvl, int type, const char *namefmt, va_list nameap)
-{
- va_list cnameap;
- nvpair_t *nvp;
-
- NVLIST_ASSERT(nvl);
- PJDLOG_ASSERT(nvl->nvl_error == 0);
- PJDLOG_ASSERT(type == NV_TYPE_NONE ||
- (type >= NV_TYPE_FIRST && type <= NV_TYPE_LAST));
-
- va_copy(cnameap, nameap);
- nvp = nvlist_findv(nvl, type, namefmt, cnameap);
- va_end(cnameap);
- if (nvp != NULL)
- nvlist_free_nvpair(nvl, nvp);
- else
- nvlist_report_missing(type, namefmt, nameap);
-}
-
-nvlist_t *
-nvlist_clone(const nvlist_t *nvl)
-{
- nvlist_t *newnvl;
- nvpair_t *nvp, *newnvp;
-
- NVLIST_ASSERT(nvl);
-
- if (nvl->nvl_error != 0) {
- errno = nvl->nvl_error;
- return (NULL);
- }
-
- newnvl = nvlist_create(nvl->nvl_flags & NV_FLAG_PUBLIC_MASK);
- for (nvp = nvlist_first_nvpair(nvl); nvp != NULL;
- nvp = nvlist_next_nvpair(nvl, nvp)) {
- newnvp = nvpair_clone(nvp);
- if (newnvp == NULL)
- break;
- nvlist_move_nvpair(newnvl, newnvp);
- }
- if (nvp != NULL) {
- nvlist_destroy(newnvl);
- return (NULL);
- }
- return (newnvl);
-}
-
-static bool
-nvlist_dump_error_check(const nvlist_t *nvl, int fd, int level)
-{
-
- if (nvlist_error(nvl) != 0) {
- dprintf(fd, "%*serror: %d\n", level * 4, "",
- nvlist_error(nvl));
- return (true);
- }
-
- return (false);
-}
-
-/*
- * Dump content of nvlist.
- */
-void
-nvlist_dump(const nvlist_t *nvl, int fd)
-{
- nvpair_t *nvp;
- int level;
-
- level = 0;
- if (nvlist_dump_error_check(nvl, fd, level))
- return;
-
- nvp = nvlist_first_nvpair(nvl);
- while (nvp != NULL) {
- dprintf(fd, "%*s%s (%s):", level * 4, "", nvpair_name(nvp),
- nvpair_type_string(nvpair_type(nvp)));
- switch (nvpair_type(nvp)) {
- case NV_TYPE_NULL:
- dprintf(fd, " null\n");
- break;
- case NV_TYPE_BOOL:
- dprintf(fd, " %s\n", nvpair_get_bool(nvp) ?
- "TRUE" : "FALSE");
- break;
- case NV_TYPE_NUMBER:
- dprintf(fd, " %ju (%jd) (0x%jx)\n",
- (uintmax_t)nvpair_get_number(nvp),
- (intmax_t)nvpair_get_number(nvp),
- (uintmax_t)nvpair_get_number(nvp));
- break;
- case NV_TYPE_STRING:
- dprintf(fd, " [%s]\n", nvpair_get_string(nvp));
- break;
- case NV_TYPE_NVLIST:
- dprintf(fd, "\n");
- nvl = nvpair_get_nvlist(nvp);
- if (nvlist_dump_error_check(nvl, fd, level + 1)) {
- nvl = nvlist_get_parent(nvl);
- break;
- }
- level += 1;
- nvp = nvlist_first_nvpair(nvl);
- continue;
- case NV_TYPE_DESCRIPTOR:
- dprintf(fd, " %d\n", nvpair_get_descriptor(nvp));
- break;
- case NV_TYPE_BINARY:
- {
- const unsigned char *binary;
- unsigned int ii;
- size_t size;
-
- binary = nvpair_get_binary(nvp, &size);
- dprintf(fd, " %zu ", size);
- for (ii = 0; ii < size; ii++)
- dprintf(fd, "%02hhx", binary[ii]);
- dprintf(fd, "\n");
- break;
- }
- default:
- PJDLOG_ABORT("Unknown type: %d.", nvpair_type(nvp));
- }
-
- while ((nvp = nvlist_next_nvpair(nvl, nvp)) == NULL) {
- nvp = nvlist_get_nvpair_parent(nvl);
- if (nvp == NULL)
- return;
- nvl = nvlist_get_parent(nvl);
- level --;
- }
- }
-}
-
-void
-nvlist_fdump(const nvlist_t *nvl, FILE *fp)
-{
-
- fflush(fp);
- nvlist_dump(nvl, fileno(fp));
-}
-
-/*
- * The function obtains size of the nvlist after nvlist_pack().
- */
-size_t
-nvlist_size(const nvlist_t *nvl)
-{
- const nvpair_t *nvp;
- size_t size;
-
- NVLIST_ASSERT(nvl);
- PJDLOG_ASSERT(nvl->nvl_error == 0);
-
- size = sizeof(struct nvlist_header);
- nvp = nvlist_first_nvpair(nvl);
- while (nvp != NULL) {
- size += nvpair_header_size();
- size += strlen(nvpair_name(nvp)) + 1;
- if (nvpair_type(nvp) == NV_TYPE_NVLIST) {
- size += sizeof(struct nvlist_header);
- size += nvpair_header_size() + 1;
- nvl = nvpair_get_nvlist(nvp);
- PJDLOG_ASSERT(nvl->nvl_error == 0);
- nvp = nvlist_first_nvpair(nvl);
- continue;
- } else {
- size += nvpair_size(nvp);
- }
-
- while ((nvp = nvlist_next_nvpair(nvl, nvp)) == NULL) {
- nvp = nvlist_get_nvpair_parent(nvl);
- if (nvp == NULL)
- goto out;
- nvl = nvlist_get_parent(nvl);
- }
- }
-
-out:
- return (size);
-}
-
-static int *
-nvlist_xdescriptors(const nvlist_t *nvl, int *descs, int level)
-{
- const nvpair_t *nvp;
-
- NVLIST_ASSERT(nvl);
- PJDLOG_ASSERT(nvl->nvl_error == 0);
- PJDLOG_ASSERT(level < 3);
-
- for (nvp = nvlist_first_nvpair(nvl); nvp != NULL;
- nvp = nvlist_next_nvpair(nvl, nvp)) {
- switch (nvpair_type(nvp)) {
- case NV_TYPE_DESCRIPTOR:
- *descs = nvpair_get_descriptor(nvp);
- descs++;
- break;
- case NV_TYPE_NVLIST:
- descs = nvlist_xdescriptors(nvpair_get_nvlist(nvp),
- descs, level + 1);
- break;
- }
- }
-
- return (descs);
-}
-
-int *
-nvlist_descriptors(const nvlist_t *nvl, size_t *nitemsp)
-{
- size_t nitems;
- int *fds;
-
- nitems = nvlist_ndescriptors(nvl);
- fds = malloc(sizeof(fds[0]) * (nitems + 1));
- if (fds == NULL)
- return (NULL);
- if (nitems > 0)
- nvlist_xdescriptors(nvl, fds, 0);
- fds[nitems] = -1;
- if (nitemsp != NULL)
- *nitemsp = nitems;
- return (fds);
-}
-
-static size_t
-nvlist_xndescriptors(const nvlist_t *nvl, int level)
-{
- const nvpair_t *nvp;
- size_t ndescs;
-
- NVLIST_ASSERT(nvl);
- PJDLOG_ASSERT(nvl->nvl_error == 0);
- PJDLOG_ASSERT(level < 3);
-
- ndescs = 0;
- for (nvp = nvlist_first_nvpair(nvl); nvp != NULL;
- nvp = nvlist_next_nvpair(nvl, nvp)) {
- switch (nvpair_type(nvp)) {
- case NV_TYPE_DESCRIPTOR:
- ndescs++;
- break;
- case NV_TYPE_NVLIST:
- ndescs += nvlist_xndescriptors(nvpair_get_nvlist(nvp),
- level + 1);
- break;
- }
- }
-
- return (ndescs);
-}
-
-size_t
-nvlist_ndescriptors(const nvlist_t *nvl)
-{
-
- return (nvlist_xndescriptors(nvl, 0));
-}
-
-static unsigned char *
-nvlist_pack_header(const nvlist_t *nvl, unsigned char *ptr, size_t *leftp)
-{
- struct nvlist_header nvlhdr;
-
- NVLIST_ASSERT(nvl);
-
- nvlhdr.nvlh_magic = NVLIST_HEADER_MAGIC;
- nvlhdr.nvlh_version = NVLIST_HEADER_VERSION;
- nvlhdr.nvlh_flags = nvl->nvl_flags;
-#if BYTE_ORDER == BIG_ENDIAN
- nvlhdr.nvlh_flags |= NV_FLAG_BIG_ENDIAN;
-#endif
- nvlhdr.nvlh_descriptors = nvlist_ndescriptors(nvl);
- nvlhdr.nvlh_size = *leftp - sizeof(nvlhdr);
- PJDLOG_ASSERT(*leftp >= sizeof(nvlhdr));
- memcpy(ptr, &nvlhdr, sizeof(nvlhdr));
- ptr += sizeof(nvlhdr);
- *leftp -= sizeof(nvlhdr);
-
- return (ptr);
-}
-
-void *
-nvlist_xpack(const nvlist_t *nvl, int64_t *fdidxp, size_t *sizep)
-{
- unsigned char *buf, *ptr;
- size_t left, size;
- nvpair_t *nvp;
-
- NVLIST_ASSERT(nvl);
-
- if (nvl->nvl_error != 0) {
- errno = nvl->nvl_error;
- return (NULL);
- }
-
- size = nvlist_size(nvl);
- buf = malloc(size);
- if (buf == NULL)
- return (NULL);
-
- ptr = buf;
- left = size;
-
- ptr = nvlist_pack_header(nvl, ptr, &left);
-
- nvp = nvlist_first_nvpair(nvl);
- while (nvp != NULL) {
- NVPAIR_ASSERT(nvp);
-
- nvpair_init_datasize(nvp);
- ptr = nvpair_pack_header(nvp, ptr, &left);
- if (ptr == NULL) {
- free(buf);
- return (NULL);
- }
- switch (nvpair_type(nvp)) {
- case NV_TYPE_NULL:
- ptr = nvpair_pack_null(nvp, ptr, &left);
- break;
- case NV_TYPE_BOOL:
- ptr = nvpair_pack_bool(nvp, ptr, &left);
- break;
- case NV_TYPE_NUMBER:
- ptr = nvpair_pack_number(nvp, ptr, &left);
- break;
- case NV_TYPE_STRING:
- ptr = nvpair_pack_string(nvp, ptr, &left);
- break;
- case NV_TYPE_NVLIST:
- nvl = nvpair_get_nvlist(nvp);
- nvp = nvlist_first_nvpair(nvl);
- ptr = nvlist_pack_header(nvl, ptr, &left);
- continue;
- case NV_TYPE_DESCRIPTOR:
- ptr = nvpair_pack_descriptor(nvp, ptr, fdidxp, &left);
- break;
- case NV_TYPE_BINARY:
- ptr = nvpair_pack_binary(nvp, ptr, &left);
- break;
- default:
- PJDLOG_ABORT("Invalid type (%d).", nvpair_type(nvp));
- }
- if (ptr == NULL) {
- free(buf);
- return (NULL);
- }
- while ((nvp = nvlist_next_nvpair(nvl, nvp)) == NULL) {
- nvp = nvlist_get_nvpair_parent(nvl);
- if (nvp == NULL)
- goto out;
- ptr = nvpair_pack_nvlist_up(ptr, &left);
- if (ptr == NULL)
- goto out;
- nvl = nvlist_get_parent(nvl);
- }
- }
-
-out:
- if (sizep != NULL)
- *sizep = size;
- return (buf);
-}
-
-void *
-nvlist_pack(const nvlist_t *nvl, size_t *sizep)
-{
-
- NVLIST_ASSERT(nvl);
-
- if (nvl->nvl_error != 0) {
- errno = nvl->nvl_error;
- return (NULL);
- }
-
- if (nvlist_ndescriptors(nvl) > 0) {
- errno = EOPNOTSUPP;
- return (NULL);
- }
-
- return (nvlist_xpack(nvl, NULL, sizep));
-}
-
-static bool
-nvlist_check_header(struct nvlist_header *nvlhdrp)
-{
-
- if (nvlhdrp->nvlh_magic != NVLIST_HEADER_MAGIC) {
- errno = EINVAL;
- return (false);
- }
- if ((nvlhdrp->nvlh_flags & ~NV_FLAG_ALL_MASK) != 0) {
- errno = EINVAL;
- return (false);
- }
-#if BYTE_ORDER == BIG_ENDIAN
- if ((nvlhdrp->nvlh_flags & NV_FLAG_BIG_ENDIAN) == 0) {
- nvlhdrp->nvlh_size = le64toh(nvlhdrp->nvlh_size);
- nvlhdrp->nvlh_descriptors = le64toh(nvlhdrp->nvlh_descriptors);
- }
-#else
- if ((nvlhdrp->nvlh_flags & NV_FLAG_BIG_ENDIAN) != 0) {
- nvlhdrp->nvlh_size = be64toh(nvlhdrp->nvlh_size);
- nvlhdrp->nvlh_descriptors = be64toh(nvlhdrp->nvlh_descriptors);
- }
-#endif
- return (true);
-}
-
-const unsigned char *
-nvlist_unpack_header(nvlist_t *nvl, const unsigned char *ptr, size_t nfds,
- bool *isbep, size_t *leftp)
-{
- struct nvlist_header nvlhdr;
-
- if (*leftp < sizeof(nvlhdr))
- goto failed;
-
- memcpy(&nvlhdr, ptr, sizeof(nvlhdr));
-
- if (!nvlist_check_header(&nvlhdr))
- goto failed;
-
- if (nvlhdr.nvlh_size != *leftp - sizeof(nvlhdr))
- goto failed;
-
- /*
- * nvlh_descriptors might be smaller than nfds in embedded nvlists.
- */
- if (nvlhdr.nvlh_descriptors > nfds)
- goto failed;
-
- if ((nvlhdr.nvlh_flags & ~NV_FLAG_ALL_MASK) != 0)
- goto failed;
-
- nvl->nvl_flags = (nvlhdr.nvlh_flags & NV_FLAG_PUBLIC_MASK);
-
- ptr += sizeof(nvlhdr);
- if (isbep != NULL)
- *isbep = (((int)nvlhdr.nvlh_flags & NV_FLAG_BIG_ENDIAN) != 0);
- *leftp -= sizeof(nvlhdr);
-
- return (ptr);
-failed:
- errno = EINVAL;
- return (NULL);
-}
-
-nvlist_t *
-nvlist_xunpack(const void *buf, size_t size, const int *fds, size_t nfds)
-{
- const unsigned char *ptr;
- nvlist_t *nvl, *retnvl, *tmpnvl;
- nvpair_t *nvp;
- size_t left;
- bool isbe;
-
- left = size;
- ptr = buf;
-
- tmpnvl = NULL;
- nvl = retnvl = nvlist_create(0);
- if (nvl == NULL)
- goto failed;
-
- ptr = nvlist_unpack_header(nvl, ptr, nfds, &isbe, &left);
- if (ptr == NULL)
- goto failed;
-
- while (left > 0) {
- ptr = nvpair_unpack(isbe, ptr, &left, &nvp);
- if (ptr == NULL)
- goto failed;
- switch (nvpair_type(nvp)) {
- case NV_TYPE_NULL:
- ptr = nvpair_unpack_null(isbe, nvp, ptr, &left);
- break;
- case NV_TYPE_BOOL:
- ptr = nvpair_unpack_bool(isbe, nvp, ptr, &left);
- break;
- case NV_TYPE_NUMBER:
- ptr = nvpair_unpack_number(isbe, nvp, ptr, &left);
- break;
- case NV_TYPE_STRING:
- ptr = nvpair_unpack_string(isbe, nvp, ptr, &left);
- break;
- case NV_TYPE_NVLIST:
- ptr = nvpair_unpack_nvlist(isbe, nvp, ptr, &left, nfds,
- &tmpnvl);
- nvlist_set_parent(tmpnvl, nvp);
- break;
- case NV_TYPE_DESCRIPTOR:
- ptr = nvpair_unpack_descriptor(isbe, nvp, ptr, &left,
- fds, nfds);
- break;
- case NV_TYPE_BINARY:
- ptr = nvpair_unpack_binary(isbe, nvp, ptr, &left);
- break;
- case NV_TYPE_NVLIST_UP:
- if (nvl->nvl_parent == NULL)
- goto failed;
- nvl = nvpair_nvlist(nvl->nvl_parent);
- continue;
- default:
- PJDLOG_ABORT("Invalid type (%d).", nvpair_type(nvp));
- }
- if (ptr == NULL)
- goto failed;
- nvlist_move_nvpair(nvl, nvp);
- if (tmpnvl != NULL) {
- nvl = tmpnvl;
- tmpnvl = NULL;
- }
- }
-
- return (retnvl);
-failed:
- nvlist_destroy(retnvl);
- return (NULL);
-}
-
-nvlist_t *
-nvlist_unpack(const void *buf, size_t size)
-{
-
- return (nvlist_xunpack(buf, size, NULL, 0));
-}
-
-int
-nvlist_send(int sock, const nvlist_t *nvl)
-{
- size_t datasize, nfds;
- int *fds;
- void *data;
- int64_t fdidx;
- int serrno, ret;
-
- if (nvlist_error(nvl) != 0) {
- errno = nvlist_error(nvl);
- return (-1);
- }
-
- fds = nvlist_descriptors(nvl, &nfds);
- if (fds == NULL)
- return (-1);
-
- ret = -1;
- data = NULL;
- fdidx = 0;
-
- data = nvlist_xpack(nvl, &fdidx, &datasize);
- if (data == NULL)
- goto out;
-
- if (buf_send(sock, data, datasize) == -1)
- goto out;
-
- if (nfds > 0) {
- if (fd_send(sock, fds, nfds) == -1)
- goto out;
- }
-
- ret = 0;
-out:
- serrno = errno;
- free(fds);
- free(data);
- errno = serrno;
- return (ret);
-}
-
-nvlist_t *
-nvlist_recv(int sock)
-{
- struct nvlist_header nvlhdr;
- nvlist_t *nvl, *ret;
- unsigned char *buf;
- size_t nfds, size, i;
- int serrno, *fds;
-
- if (buf_recv(sock, &nvlhdr, sizeof(nvlhdr)) == -1)
- return (NULL);
-
- if (!nvlist_check_header(&nvlhdr))
- return (NULL);
-
- nfds = (size_t)nvlhdr.nvlh_descriptors;
- size = sizeof(nvlhdr) + (size_t)nvlhdr.nvlh_size;
-
- buf = malloc(size);
- if (buf == NULL)
- return (NULL);
-
- memcpy(buf, &nvlhdr, sizeof(nvlhdr));
-
- ret = NULL;
- fds = NULL;
-
- if (buf_recv(sock, buf + sizeof(nvlhdr), size - sizeof(nvlhdr)) == -1)
- goto out;
-
- if (nfds > 0) {
- fds = malloc(nfds * sizeof(fds[0]));
- if (fds == NULL)
- goto out;
- if (fd_recv(sock, fds, nfds) == -1)
- goto out;
- }
-
- nvl = nvlist_xunpack(buf, size, fds, nfds);
- if (nvl == NULL) {
- for (i = 0; i < nfds; i++)
- close(fds[i]);
- goto out;
- }
-
- ret = nvl;
-out:
- serrno = errno;
- free(buf);
- free(fds);
- errno = serrno;
-
- return (ret);
-}
-
-nvlist_t *
-nvlist_xfer(int sock, nvlist_t *nvl)
-{
-
- if (nvlist_send(sock, nvl) < 0) {
- nvlist_destroy(nvl);
- return (NULL);
- }
- nvlist_destroy(nvl);
- return (nvlist_recv(sock));
-}
-
-nvpair_t *
-nvlist_first_nvpair(const nvlist_t *nvl)
-{
-
- NVLIST_ASSERT(nvl);
-
- return (TAILQ_FIRST(&nvl->nvl_head));
-}
-
-nvpair_t *
-nvlist_next_nvpair(const nvlist_t *nvl, const nvpair_t *nvp)
-{
- nvpair_t *retnvp;
-
- NVLIST_ASSERT(nvl);
- NVPAIR_ASSERT(nvp);
- PJDLOG_ASSERT(nvpair_nvlist(nvp) == nvl);
-
- retnvp = nvpair_next(nvp);
- PJDLOG_ASSERT(retnvp == NULL || nvpair_nvlist(retnvp) == nvl);
-
- return (retnvp);
-
-}
-
-nvpair_t *
-nvlist_prev_nvpair(const nvlist_t *nvl, const nvpair_t *nvp)
-{
- nvpair_t *retnvp;
-
- NVLIST_ASSERT(nvl);
- NVPAIR_ASSERT(nvp);
- PJDLOG_ASSERT(nvpair_nvlist(nvp) == nvl);
-
- retnvp = nvpair_prev(nvp);
- PJDLOG_ASSERT(nvpair_nvlist(retnvp) == nvl);
-
- return (retnvp);
-}
-
-const char *
-nvlist_next(const nvlist_t *nvl, int *typep, void **cookiep)
-{
- nvpair_t *nvp;
-
- NVLIST_ASSERT(nvl);
- PJDLOG_ASSERT(cookiep != NULL);
-
- if (*cookiep == NULL)
- nvp = nvlist_first_nvpair(nvl);
- else
- nvp = nvlist_next_nvpair(nvl, *cookiep);
- if (nvp == NULL)
- return (NULL);
- if (typep != NULL)
- *typep = nvpair_type(nvp);
- *cookiep = nvp;
- return (nvpair_name(nvp));
-}
-
-bool
-nvlist_exists(const nvlist_t *nvl, const char *name)
-{
-
- return (nvlist_existsf(nvl, "%s", name));
-}
-
-#define NVLIST_EXISTS(type) \
-bool \
-nvlist_exists_##type(const nvlist_t *nvl, const char *name) \
-{ \
- \
- return (nvlist_existsf_##type(nvl, "%s", name)); \
-}
-
-NVLIST_EXISTS(null)
-NVLIST_EXISTS(bool)
-NVLIST_EXISTS(number)
-NVLIST_EXISTS(string)
-NVLIST_EXISTS(nvlist)
-NVLIST_EXISTS(descriptor)
-NVLIST_EXISTS(binary)
-
-#undef NVLIST_EXISTS
-
-bool
-nvlist_existsf(const nvlist_t *nvl, const char *namefmt, ...)
-{
- va_list nameap;
- bool ret;
-
- va_start(nameap, namefmt);
- ret = nvlist_existsv(nvl, namefmt, nameap);
- va_end(nameap);
- return (ret);
-}
-
-#define NVLIST_EXISTSF(type) \
-bool \
-nvlist_existsf_##type(const nvlist_t *nvl, const char *namefmt, ...) \
-{ \
- va_list nameap; \
- bool ret; \
- \
- va_start(nameap, namefmt); \
- ret = nvlist_existsv_##type(nvl, namefmt, nameap); \
- va_end(nameap); \
- return (ret); \
-}
-
-NVLIST_EXISTSF(null)
-NVLIST_EXISTSF(bool)
-NVLIST_EXISTSF(number)
-NVLIST_EXISTSF(string)
-NVLIST_EXISTSF(nvlist)
-NVLIST_EXISTSF(descriptor)
-NVLIST_EXISTSF(binary)
-
-#undef NVLIST_EXISTSF
-
-bool
-nvlist_existsv(const nvlist_t *nvl, const char *namefmt, va_list nameap)
-{
-
- return (nvlist_findv(nvl, NV_TYPE_NONE, namefmt, nameap) != NULL);
-}
-
-#define NVLIST_EXISTSV(type, TYPE) \
-bool \
-nvlist_existsv_##type(const nvlist_t *nvl, const char *namefmt, \
- va_list nameap) \
-{ \
- \
- return (nvlist_findv(nvl, NV_TYPE_##TYPE, namefmt, nameap) != \
- NULL); \
-}
-
-NVLIST_EXISTSV(null, NULL)
-NVLIST_EXISTSV(bool, BOOL)
-NVLIST_EXISTSV(number, NUMBER)
-NVLIST_EXISTSV(string, STRING)
-NVLIST_EXISTSV(nvlist, NVLIST)
-NVLIST_EXISTSV(descriptor, DESCRIPTOR)
-NVLIST_EXISTSV(binary, BINARY)
-
-#undef NVLIST_EXISTSV
-
-void
-nvlist_add_nvpair(nvlist_t *nvl, const nvpair_t *nvp)
-{
- nvpair_t *newnvp;
-
- NVPAIR_ASSERT(nvp);
-
- if (nvlist_error(nvl) != 0) {
- errno = nvlist_error(nvl);
- return;
- }
- if (nvlist_exists(nvl, nvpair_name(nvp))) {
- nvl->nvl_error = errno = EEXIST;
- return;
- }
-
- newnvp = nvpair_clone(nvp);
- if (newnvp == NULL) {
- nvl->nvl_error = errno = (errno != 0 ? errno : ENOMEM);
- return;
- }
-
- nvpair_insert(&nvl->nvl_head, newnvp, nvl);
-}
-
-void
-nvlist_add_null(nvlist_t *nvl, const char *name)
-{
-
- nvlist_addf_null(nvl, "%s", name);
-}
-
-void
-nvlist_add_bool(nvlist_t *nvl, const char *name, bool value)
-{
-
- nvlist_addf_bool(nvl, value, "%s", name);
-}
-
-void
-nvlist_add_number(nvlist_t *nvl, const char *name, uint64_t value)
-{
-
- nvlist_addf_number(nvl, value, "%s", name);
-}
-
-void
-nvlist_add_string(nvlist_t *nvl, const char *name, const char *value)
-{
-
- nvlist_addf_string(nvl, value, "%s", name);
-}
-
-void
-nvlist_add_stringf(nvlist_t *nvl, const char *name, const char *valuefmt, ...)
-{
- va_list valueap;
-
- va_start(valueap, valuefmt);
- nvlist_add_stringv(nvl, name, valuefmt, valueap);
- va_end(valueap);
-}
-
-void
-nvlist_add_stringv(nvlist_t *nvl, const char *name, const char *valuefmt,
- va_list valueap)
-{
- nvpair_t *nvp;
-
- if (nvlist_error(nvl) != 0) {
- errno = nvlist_error(nvl);
- return;
- }
-
- nvp = nvpair_create_stringv(name, valuefmt, valueap);
- if (nvp == NULL)
- nvl->nvl_error = errno = (errno != 0 ? errno : ENOMEM);
- else
- nvlist_move_nvpair(nvl, nvp);
-}
-
-void
-nvlist_add_nvlist(nvlist_t *nvl, const char *name, const nvlist_t *value)
-{
-
- nvlist_addf_nvlist(nvl, value, "%s", name);
-}
-
-void
-nvlist_add_descriptor(nvlist_t *nvl, const char *name, int value)
-{
-
- nvlist_addf_descriptor(nvl, value, "%s", name);
-}
-
-void
-nvlist_add_binary(nvlist_t *nvl, const char *name, const void *value,
- size_t size)
-{
-
- nvlist_addf_binary(nvl, value, size, "%s", name);
-}
-
-void
-nvlist_addf_null(nvlist_t *nvl, const char *namefmt, ...)
-{
- va_list nameap;
-
- va_start(nameap, namefmt);
- nvlist_addv_null(nvl, namefmt, nameap);
- va_end(nameap);
-}
-
-void
-nvlist_addf_bool(nvlist_t *nvl, bool value, const char *namefmt, ...)
-{
- va_list nameap;
-
- va_start(nameap, namefmt);
- nvlist_addv_bool(nvl, value, namefmt, nameap);
- va_end(nameap);
-}
-
-void
-nvlist_addf_number(nvlist_t *nvl, uint64_t value, const char *namefmt, ...)
-{
- va_list nameap;
-
- va_start(nameap, namefmt);
- nvlist_addv_number(nvl, value, namefmt, nameap);
- va_end(nameap);
-}
-
-void
-nvlist_addf_string(nvlist_t *nvl, const char *value, const char *namefmt, ...)
-{
- va_list nameap;
-
- va_start(nameap, namefmt);
- nvlist_addv_string(nvl, value, namefmt, nameap);
- va_end(nameap);
-}
-
-void
-nvlist_addf_nvlist(nvlist_t *nvl, const nvlist_t *value, const char *namefmt,
- ...)
-{
- va_list nameap;
-
- va_start(nameap, namefmt);
- nvlist_addv_nvlist(nvl, value, namefmt, nameap);
- va_end(nameap);
-}
-
-void
-nvlist_addf_descriptor(nvlist_t *nvl, int value, const char *namefmt, ...)
-{
- va_list nameap;
-
- va_start(nameap, namefmt);
- nvlist_addv_descriptor(nvl, value, namefmt, nameap);
- va_end(nameap);
-}
-
-void
-nvlist_addf_binary(nvlist_t *nvl, const void *value, size_t size,
- const char *namefmt, ...)
-{
- va_list nameap;
-
- va_start(nameap, namefmt);
- nvlist_addv_binary(nvl, value, size, namefmt, nameap);
- va_end(nameap);
-}
-
-void
-nvlist_addv_null(nvlist_t *nvl, const char *namefmt, va_list nameap)
-{
- nvpair_t *nvp;
-
- if (nvlist_error(nvl) != 0) {
- errno = nvlist_error(nvl);
- return;
- }
-
- nvp = nvpair_createv_null(namefmt, nameap);
- if (nvp == NULL)
- nvl->nvl_error = errno = (errno != 0 ? errno : ENOMEM);
- else
- nvlist_move_nvpair(nvl, nvp);
-}
-
-void
-nvlist_addv_bool(nvlist_t *nvl, bool value, const char *namefmt, va_list nameap)
-{
- nvpair_t *nvp;
-
- if (nvlist_error(nvl) != 0) {
- errno = nvlist_error(nvl);
- return;
- }
-
- nvp = nvpair_createv_bool(value, namefmt, nameap);
- if (nvp == NULL)
- nvl->nvl_error = errno = (errno != 0 ? errno : ENOMEM);
- else
- nvlist_move_nvpair(nvl, nvp);
-}
-
-void
-nvlist_addv_number(nvlist_t *nvl, uint64_t value, const char *namefmt,
- va_list nameap)
-{
- nvpair_t *nvp;
-
- if (nvlist_error(nvl) != 0) {
- errno = nvlist_error(nvl);
- return;
- }
-
- nvp = nvpair_createv_number(value, namefmt, nameap);
- if (nvp == NULL)
- nvl->nvl_error = errno = (errno != 0 ? errno : ENOMEM);
- else
- nvlist_move_nvpair(nvl, nvp);
-}
-
-void
-nvlist_addv_string(nvlist_t *nvl, const char *value, const char *namefmt,
- va_list nameap)
-{
- nvpair_t *nvp;
-
- if (nvlist_error(nvl) != 0) {
- errno = nvlist_error(nvl);
- return;
- }
-
- nvp = nvpair_createv_string(value, namefmt, nameap);
- if (nvp == NULL)
- nvl->nvl_error = errno = (errno != 0 ? errno : ENOMEM);
- else
- nvlist_move_nvpair(nvl, nvp);
-}
-
-void
-nvlist_addv_nvlist(nvlist_t *nvl, const nvlist_t *value, const char *namefmt,
- va_list nameap)
-{
- nvpair_t *nvp;
-
- if (nvlist_error(nvl) != 0) {
- errno = nvlist_error(nvl);
- return;
- }
-
- nvp = nvpair_createv_nvlist(value, namefmt, nameap);
- if (nvp == NULL)
- nvl->nvl_error = errno = (errno != 0 ? errno : ENOMEM);
- else
- nvlist_move_nvpair(nvl, nvp);
-}
-
-void
-nvlist_addv_descriptor(nvlist_t *nvl, int value, const char *namefmt,
- va_list nameap)
-{
- nvpair_t *nvp;
-
- if (nvlist_error(nvl) != 0) {
- errno = nvlist_error(nvl);
- return;
- }
-
- nvp = nvpair_createv_descriptor(value, namefmt, nameap);
- if (nvp == NULL)
- nvl->nvl_error = errno = (errno != 0 ? errno : ENOMEM);
- else
- nvlist_move_nvpair(nvl, nvp);
-}
-
-void
-nvlist_addv_binary(nvlist_t *nvl, const void *value, size_t size,
- const char *namefmt, va_list nameap)
-{
- nvpair_t *nvp;
-
- if (nvlist_error(nvl) != 0) {
- errno = nvlist_error(nvl);
- return;
- }
-
- nvp = nvpair_createv_binary(value, size, namefmt, nameap);
- if (nvp == NULL)
- nvl->nvl_error = errno = (errno != 0 ? errno : ENOMEM);
- else
- nvlist_move_nvpair(nvl, nvp);
-}
-
-void
-nvlist_move_nvpair(nvlist_t *nvl, nvpair_t *nvp)
-{
-
- NVPAIR_ASSERT(nvp);
- PJDLOG_ASSERT(nvpair_nvlist(nvp) == NULL);
-
- if (nvlist_error(nvl) != 0) {
- nvpair_free(nvp);
- errno = nvlist_error(nvl);
- return;
- }
- if (nvlist_exists(nvl, nvpair_name(nvp))) {
- nvpair_free(nvp);
- nvl->nvl_error = errno = EEXIST;
- return;
- }
-
- nvpair_insert(&nvl->nvl_head, nvp, nvl);
-}
-
-#define NVLIST_MOVE(vtype, type) \
-void \
-nvlist_move_##type(nvlist_t *nvl, const char *name, vtype value) \
-{ \
- \
- nvlist_movef_##type(nvl, value, "%s", name); \
-}
-
-NVLIST_MOVE(char *, string)
-NVLIST_MOVE(nvlist_t *, nvlist)
-NVLIST_MOVE(int, descriptor)
-
-#undef NVLIST_MOVE
-
-void
-nvlist_move_binary(nvlist_t *nvl, const char *name, void *value, size_t size)
-{
-
- nvlist_movef_binary(nvl, value, size, "%s", name);
-}
-
-#define NVLIST_MOVEF(vtype, type) \
-void \
-nvlist_movef_##type(nvlist_t *nvl, vtype value, const char *namefmt, \
- ...) \
-{ \
- va_list nameap; \
- \
- va_start(nameap, namefmt); \
- nvlist_movev_##type(nvl, value, namefmt, nameap); \
- va_end(nameap); \
-}
-
-NVLIST_MOVEF(char *, string)
-NVLIST_MOVEF(nvlist_t *, nvlist)
-NVLIST_MOVEF(int, descriptor)
-
-#undef NVLIST_MOVEF
-
-void
-nvlist_movef_binary(nvlist_t *nvl, void *value, size_t size,
- const char *namefmt, ...)
-{
- va_list nameap;
-
- va_start(nameap, namefmt);
- nvlist_movev_binary(nvl, value, size, namefmt, nameap);
- va_end(nameap);
-}
-
-void
-nvlist_movev_string(nvlist_t *nvl, char *value, const char *namefmt,
- va_list nameap)
-{
- nvpair_t *nvp;
-
- if (nvlist_error(nvl) != 0) {
- free(value);
- errno = nvlist_error(nvl);
- return;
- }
-
- nvp = nvpair_movev_string(value, namefmt, nameap);
- if (nvp == NULL)
- nvl->nvl_error = errno = (errno != 0 ? errno : ENOMEM);
- else
- nvlist_move_nvpair(nvl, nvp);
-}
-
-void
-nvlist_movev_nvlist(nvlist_t *nvl, nvlist_t *value, const char *namefmt,
- va_list nameap)
-{
- nvpair_t *nvp;
-
- if (nvlist_error(nvl) != 0) {
- if (value != NULL && nvlist_get_nvpair_parent(value) != NULL)
- nvlist_destroy(value);
- errno = nvlist_error(nvl);
- return;
- }
-
- nvp = nvpair_movev_nvlist(value, namefmt, nameap);
- if (nvp == NULL)
- nvl->nvl_error = errno = (errno != 0 ? errno : ENOMEM);
- else
- nvlist_move_nvpair(nvl, nvp);
-}
-
-void
-nvlist_movev_descriptor(nvlist_t *nvl, int value, const char *namefmt,
- va_list nameap)
-{
- nvpair_t *nvp;
-
- if (nvlist_error(nvl) != 0) {
- close(value);
- errno = nvlist_error(nvl);
- return;
- }
-
- nvp = nvpair_movev_descriptor(value, namefmt, nameap);
- if (nvp == NULL)
- nvl->nvl_error = errno = (errno != 0 ? errno : ENOMEM);
- else
- nvlist_move_nvpair(nvl, nvp);
-}
-
-void
-nvlist_movev_binary(nvlist_t *nvl, void *value, size_t size,
- const char *namefmt, va_list nameap)
-{
- nvpair_t *nvp;
-
- if (nvlist_error(nvl) != 0) {
- free(value);
- errno = nvlist_error(nvl);
- return;
- }
-
- nvp = nvpair_movev_binary(value, size, namefmt, nameap);
- if (nvp == NULL)
- nvl->nvl_error = errno = (errno != 0 ? errno : ENOMEM);
- else
- nvlist_move_nvpair(nvl, nvp);
-}
-
-#define NVLIST_GET(ftype, type) \
-ftype \
-nvlist_get_##type(const nvlist_t *nvl, const char *name) \
-{ \
- \
- return (nvlist_getf_##type(nvl, "%s", name)); \
-}
-
-NVLIST_GET(const nvpair_t *, nvpair)
-NVLIST_GET(bool, bool)
-NVLIST_GET(uint64_t, number)
-NVLIST_GET(const char *, string)
-NVLIST_GET(const nvlist_t *, nvlist)
-NVLIST_GET(int, descriptor)
-
-#undef NVLIST_GET
-
-const void *
-nvlist_get_binary(const nvlist_t *nvl, const char *name, size_t *sizep)
-{
-
- return (nvlist_getf_binary(nvl, sizep, "%s", name));
-}
-
-#define NVLIST_GETF(ftype, type) \
-ftype \
-nvlist_getf_##type(const nvlist_t *nvl, const char *namefmt, ...) \
-{ \
- va_list nameap; \
- ftype value; \
- \
- va_start(nameap, namefmt); \
- value = nvlist_getv_##type(nvl, namefmt, nameap); \
- va_end(nameap); \
- \
- return (value); \
-}
-
-NVLIST_GETF(const nvpair_t *, nvpair)
-NVLIST_GETF(bool, bool)
-NVLIST_GETF(uint64_t, number)
-NVLIST_GETF(const char *, string)
-NVLIST_GETF(const nvlist_t *, nvlist)
-NVLIST_GETF(int, descriptor)
-
-#undef NVLIST_GETF
-
-const void *
-nvlist_getf_binary(const nvlist_t *nvl, size_t *sizep, const char *namefmt, ...)
-{
- va_list nameap;
- const void *value;
-
- va_start(nameap, namefmt);
- value = nvlist_getv_binary(nvl, sizep, namefmt, nameap);
- va_end(nameap);
-
- return (value);
-}
-
-const nvpair_t *
-nvlist_getv_nvpair(const nvlist_t *nvl, const char *namefmt, va_list nameap)
-{
-
- return (nvlist_findv(nvl, NV_TYPE_NONE, namefmt, nameap));
-}
-
-#define NVLIST_GETV(ftype, type, TYPE) \
-ftype \
-nvlist_getv_##type(const nvlist_t *nvl, const char *namefmt, \
- va_list nameap) \
-{ \
- va_list cnameap; \
- const nvpair_t *nvp; \
- \
- va_copy(cnameap, nameap); \
- nvp = nvlist_findv(nvl, NV_TYPE_##TYPE, namefmt, cnameap); \
- va_end(cnameap); \
- if (nvp == NULL) \
- nvlist_report_missing(NV_TYPE_##TYPE, namefmt, nameap); \
- return (nvpair_get_##type(nvp)); \
-}
-
-NVLIST_GETV(bool, bool, BOOL)
-NVLIST_GETV(uint64_t, number, NUMBER)
-NVLIST_GETV(const char *, string, STRING)
-NVLIST_GETV(const nvlist_t *, nvlist, NVLIST)
-NVLIST_GETV(int, descriptor, DESCRIPTOR)
-
-#undef NVLIST_GETV
-
-const void *
-nvlist_getv_binary(const nvlist_t *nvl, size_t *sizep, const char *namefmt,
- va_list nameap)
-{
- va_list cnameap;
- const nvpair_t *nvp;
-
- va_copy(cnameap, nameap);
- nvp = nvlist_findv(nvl, NV_TYPE_BINARY, namefmt, cnameap);
- va_end(cnameap);
- if (nvp == NULL)
- nvlist_report_missing(NV_TYPE_BINARY, namefmt, nameap);
-
- return (nvpair_get_binary(nvp, sizep));
-}
-
-#define NVLIST_TAKE(ftype, type) \
-ftype \
-nvlist_take_##type(nvlist_t *nvl, const char *name) \
-{ \
- \
- return (nvlist_takef_##type(nvl, "%s", name)); \
-}
-
-NVLIST_TAKE(nvpair_t *, nvpair)
-NVLIST_TAKE(bool, bool)
-NVLIST_TAKE(uint64_t, number)
-NVLIST_TAKE(char *, string)
-NVLIST_TAKE(nvlist_t *, nvlist)
-NVLIST_TAKE(int, descriptor)
-
-#undef NVLIST_TAKE
-
-void *
-nvlist_take_binary(nvlist_t *nvl, const char *name, size_t *sizep)
-{
-
- return (nvlist_takef_binary(nvl, sizep, "%s", name));
-}
-
-#define NVLIST_TAKEF(ftype, type) \
-ftype \
-nvlist_takef_##type(nvlist_t *nvl, const char *namefmt, ...) \
-{ \
- va_list nameap; \
- ftype value; \
- \
- va_start(nameap, namefmt); \
- value = nvlist_takev_##type(nvl, namefmt, nameap); \
- va_end(nameap); \
- \
- return (value); \
-}
-
-NVLIST_TAKEF(nvpair_t *, nvpair)
-NVLIST_TAKEF(bool, bool)
-NVLIST_TAKEF(uint64_t, number)
-NVLIST_TAKEF(char *, string)
-NVLIST_TAKEF(nvlist_t *, nvlist)
-NVLIST_TAKEF(int, descriptor)
-
-#undef NVLIST_TAKEF
-
-void *
-nvlist_takef_binary(nvlist_t *nvl, size_t *sizep, const char *namefmt, ...)
-{
- va_list nameap;
- void *value;
-
- va_start(nameap, namefmt);
- value = nvlist_takev_binary(nvl, sizep, namefmt, nameap);
- va_end(nameap);
-
- return (value);
-}
-
-nvpair_t *
-nvlist_takev_nvpair(nvlist_t *nvl, const char *namefmt, va_list nameap)
-{
- nvpair_t *nvp;
-
- nvp = nvlist_findv(nvl, NV_TYPE_NONE, namefmt, nameap);
- if (nvp != NULL)
- nvlist_remove_nvpair(nvl, nvp);
- return (nvp);
-}
-
-#define NVLIST_TAKEV(ftype, type, TYPE) \
-ftype \
-nvlist_takev_##type(nvlist_t *nvl, const char *namefmt, va_list nameap) \
-{ \
- va_list cnameap; \
- nvpair_t *nvp; \
- ftype value; \
- \
- va_copy(cnameap, nameap); \
- nvp = nvlist_findv(nvl, NV_TYPE_##TYPE, namefmt, cnameap); \
- va_end(cnameap); \
- if (nvp == NULL) \
- nvlist_report_missing(NV_TYPE_##TYPE, namefmt, nameap); \
- value = (ftype)(intptr_t)nvpair_get_##type(nvp); \
- nvlist_remove_nvpair(nvl, nvp); \
- nvpair_free_structure(nvp); \
- return (value); \
-}
-
-NVLIST_TAKEV(bool, bool, BOOL)
-NVLIST_TAKEV(uint64_t, number, NUMBER)
-NVLIST_TAKEV(char *, string, STRING)
-NVLIST_TAKEV(nvlist_t *, nvlist, NVLIST)
-NVLIST_TAKEV(int, descriptor, DESCRIPTOR)
-
-#undef NVLIST_TAKEV
-
-void *
-nvlist_takev_binary(nvlist_t *nvl, size_t *sizep, const char *namefmt,
- va_list nameap)
-{
- va_list cnameap;
- nvpair_t *nvp;
- void *value;
-
- va_copy(cnameap, nameap);
- nvp = nvlist_findv(nvl, NV_TYPE_BINARY, namefmt, cnameap);
- va_end(cnameap);
- if (nvp == NULL)
- nvlist_report_missing(NV_TYPE_BINARY, namefmt, nameap);
-
- value = (void *)(intptr_t)nvpair_get_binary(nvp, sizep);
- nvlist_remove_nvpair(nvl, nvp);
- nvpair_free_structure(nvp);
- return (value);
-}
-
-void
-nvlist_remove_nvpair(nvlist_t *nvl, nvpair_t *nvp)
-{
-
- NVLIST_ASSERT(nvl);
- NVPAIR_ASSERT(nvp);
- PJDLOG_ASSERT(nvpair_nvlist(nvp) == nvl);
-
- nvpair_remove(&nvl->nvl_head, nvp, nvl);
-}
-
-void
-nvlist_free(nvlist_t *nvl, const char *name)
-{
-
- nvlist_freef(nvl, "%s", name);
-}
-
-#define NVLIST_FREE(type) \
-void \
-nvlist_free_##type(nvlist_t *nvl, const char *name) \
-{ \
- \
- nvlist_freef_##type(nvl, "%s", name); \
-}
-
-NVLIST_FREE(null)
-NVLIST_FREE(bool)
-NVLIST_FREE(number)
-NVLIST_FREE(string)
-NVLIST_FREE(nvlist)
-NVLIST_FREE(descriptor)
-NVLIST_FREE(binary)
-
-#undef NVLIST_FREE
-
-void
-nvlist_freef(nvlist_t *nvl, const char *namefmt, ...)
-{
- va_list nameap;
-
- va_start(nameap, namefmt);
- nvlist_freev(nvl, namefmt, nameap);
- va_end(nameap);
-}
-
-#define NVLIST_FREEF(type) \
-void \
-nvlist_freef_##type(nvlist_t *nvl, const char *namefmt, ...) \
-{ \
- va_list nameap; \
- \
- va_start(nameap, namefmt); \
- nvlist_freev_##type(nvl, namefmt, nameap); \
- va_end(nameap); \
-}
-
-NVLIST_FREEF(null)
-NVLIST_FREEF(bool)
-NVLIST_FREEF(number)
-NVLIST_FREEF(string)
-NVLIST_FREEF(nvlist)
-NVLIST_FREEF(descriptor)
-NVLIST_FREEF(binary)
-
-#undef NVLIST_FREEF
-
-void
-nvlist_freev(nvlist_t *nvl, const char *namefmt, va_list nameap)
-{
-
- nvlist_freev_type(nvl, NV_TYPE_NONE, namefmt, nameap);
-}
-
-#define NVLIST_FREEV(type, TYPE) \
-void \
-nvlist_freev_##type(nvlist_t *nvl, const char *namefmt, va_list nameap) \
-{ \
- \
- nvlist_freev_type(nvl, NV_TYPE_##TYPE, namefmt, nameap); \
-}
-
-NVLIST_FREEV(null, NULL)
-NVLIST_FREEV(bool, BOOL)
-NVLIST_FREEV(number, NUMBER)
-NVLIST_FREEV(string, STRING)
-NVLIST_FREEV(nvlist, NVLIST)
-NVLIST_FREEV(descriptor, DESCRIPTOR)
-NVLIST_FREEV(binary, BINARY)
-#undef NVLIST_FREEV
-
-void
-nvlist_free_nvpair(nvlist_t *nvl, nvpair_t *nvp)
-{
-
- NVLIST_ASSERT(nvl);
- NVPAIR_ASSERT(nvp);
- PJDLOG_ASSERT(nvpair_nvlist(nvp) == nvl);
-
- nvlist_remove_nvpair(nvl, nvp);
- nvpair_free(nvp);
-}
diff --git a/lib/libnv/nvlist_impl.h b/lib/libnv/nvlist_impl.h
deleted file mode 100644
index ef32dea..0000000
--- a/lib/libnv/nvlist_impl.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*-
- * Copyright (c) 2013 The FreeBSD Foundation
- * All rights reserved.
- *
- * This software was developed by Pawel Jakub Dawidek under sponsorship from
- * the FreeBSD Foundation.
- *
- * 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 AUTHORS 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 AUTHORS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-#ifndef _NVLIST_IMPL_H_
-#define _NVLIST_IMPL_H_
-
-#include <stdint.h>
-
-#include "nv.h"
-
-void *nvlist_xpack(const nvlist_t *nvl, int64_t *fdidxp, size_t *sizep);
-nvlist_t *nvlist_xunpack(const void *buf, size_t size, const int *fds,
- size_t nfds);
-
-nvpair_t *nvlist_get_nvpair_parent(const nvlist_t *nvl);
-const unsigned char *nvlist_unpack_header(nvlist_t *nvl,
- const unsigned char *ptr, size_t nfds, bool *isbep, size_t *leftp);
-
-#endif /* !_NVLIST_IMPL_H_ */
diff --git a/lib/libnv/nvpair.c b/lib/libnv/nvpair.c
deleted file mode 100644
index 4f0bd72..0000000
--- a/lib/libnv/nvpair.c
+++ /dev/null
@@ -1,1282 +0,0 @@
-/*-
- * Copyright (c) 2009-2013 The FreeBSD Foundation
- * All rights reserved.
- *
- * This software was developed by Pawel Jakub Dawidek under sponsorship from
- * the FreeBSD Foundation.
- *
- * 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 AUTHORS 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 AUTHORS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/param.h>
-#include <sys/endian.h>
-#include <sys/queue.h>
-
-#include <errno.h>
-#include <fcntl.h>
-#include <stdarg.h>
-#include <stdbool.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#ifdef HAVE_PJDLOG
-#include <pjdlog.h>
-#endif
-
-#include "common_impl.h"
-#include "nv.h"
-#include "nv_impl.h"
-#include "nvlist_impl.h"
-#include "nvpair_impl.h"
-
-#ifndef HAVE_PJDLOG
-#include <assert.h>
-#define PJDLOG_ASSERT(...) assert(__VA_ARGS__)
-#define PJDLOG_RASSERT(expr, ...) assert(expr)
-#define PJDLOG_ABORT(...) abort()
-#endif
-
-#define NVPAIR_MAGIC 0x6e7670 /* "nvp" */
-struct nvpair {
- int nvp_magic;
- char *nvp_name;
- int nvp_type;
- uint64_t nvp_data;
- size_t nvp_datasize;
- nvlist_t *nvp_list;
- TAILQ_ENTRY(nvpair) nvp_next;
-};
-
-#define NVPAIR_ASSERT(nvp) do { \
- PJDLOG_ASSERT((nvp) != NULL); \
- PJDLOG_ASSERT((nvp)->nvp_magic == NVPAIR_MAGIC); \
-} while (0)
-
-struct nvpair_header {
- uint8_t nvph_type;
- uint16_t nvph_namesize;
- uint64_t nvph_datasize;
-} __packed;
-
-
-void
-nvpair_assert(const nvpair_t *nvp)
-{
-
- NVPAIR_ASSERT(nvp);
-}
-
-nvlist_t *
-nvpair_nvlist(const nvpair_t *nvp)
-{
-
- NVPAIR_ASSERT(nvp);
-
- return (nvp->nvp_list);
-}
-
-nvpair_t *
-nvpair_next(const nvpair_t *nvp)
-{
-
- NVPAIR_ASSERT(nvp);
- PJDLOG_ASSERT(nvp->nvp_list != NULL);
-
- return (TAILQ_NEXT(nvp, nvp_next));
-}
-
-nvpair_t *
-nvpair_prev(const nvpair_t *nvp)
-{
-
- NVPAIR_ASSERT(nvp);
- PJDLOG_ASSERT(nvp->nvp_list != NULL);
-
- return (TAILQ_PREV(nvp, nvl_head, nvp_next));
-}
-
-void
-nvpair_insert(struct nvl_head *head, nvpair_t *nvp, nvlist_t *nvl)
-{
-
- NVPAIR_ASSERT(nvp);
- PJDLOG_ASSERT(nvp->nvp_list == NULL);
- PJDLOG_ASSERT(!nvlist_exists(nvl, nvpair_name(nvp)));
-
- TAILQ_INSERT_TAIL(head, nvp, nvp_next);
- nvp->nvp_list = nvl;
-}
-
-static void
-nvpair_remove_nvlist(nvpair_t *nvp)
-{
- nvlist_t *nvl;
-
- /* XXX: DECONST is bad, mkay? */
- nvl = __DECONST(nvlist_t *, nvpair_get_nvlist(nvp));
- PJDLOG_ASSERT(nvl != NULL);
- nvlist_set_parent(nvl, NULL);
-}
-
-void
-nvpair_remove(struct nvl_head *head, nvpair_t *nvp, const nvlist_t *nvl)
-{
-
- NVPAIR_ASSERT(nvp);
- PJDLOG_ASSERT(nvp->nvp_list == nvl);
-
- if (nvpair_type(nvp) == NV_TYPE_NVLIST)
- nvpair_remove_nvlist(nvp);
-
- TAILQ_REMOVE(head, nvp, nvp_next);
- nvp->nvp_list = NULL;
-}
-
-nvpair_t *
-nvpair_clone(const nvpair_t *nvp)
-{
- nvpair_t *newnvp;
- const char *name;
- const void *data;
- size_t datasize;
-
- NVPAIR_ASSERT(nvp);
-
- name = nvpair_name(nvp);
-
- switch (nvpair_type(nvp)) {
- case NV_TYPE_NULL:
- newnvp = nvpair_create_null(name);
- break;
- case NV_TYPE_BOOL:
- newnvp = nvpair_create_bool(name, nvpair_get_bool(nvp));
- break;
- case NV_TYPE_NUMBER:
- newnvp = nvpair_create_number(name, nvpair_get_number(nvp));
- break;
- case NV_TYPE_STRING:
- newnvp = nvpair_create_string(name, nvpair_get_string(nvp));
- break;
- case NV_TYPE_NVLIST:
- newnvp = nvpair_create_nvlist(name, nvpair_get_nvlist(nvp));
- break;
- case NV_TYPE_DESCRIPTOR:
- newnvp = nvpair_create_descriptor(name,
- nvpair_get_descriptor(nvp));
- break;
- case NV_TYPE_BINARY:
- data = nvpair_get_binary(nvp, &datasize);
- newnvp = nvpair_create_binary(name, data, datasize);
- break;
- default:
- PJDLOG_ABORT("Unknown type: %d.", nvpair_type(nvp));
- }
-
- return (newnvp);
-}
-
-size_t
-nvpair_header_size(void)
-{
-
- return (sizeof(struct nvpair_header));
-}
-
-size_t
-nvpair_size(const nvpair_t *nvp)
-{
-
- NVPAIR_ASSERT(nvp);
-
- return (nvp->nvp_datasize);
-}
-
-unsigned char *
-nvpair_pack_header(const nvpair_t *nvp, unsigned char *ptr, size_t *leftp)
-{
- struct nvpair_header nvphdr;
- size_t namesize;
-
- NVPAIR_ASSERT(nvp);
-
- nvphdr.nvph_type = nvp->nvp_type;
- namesize = strlen(nvp->nvp_name) + 1;
- PJDLOG_ASSERT(namesize > 0 && namesize <= UINT16_MAX);
- nvphdr.nvph_namesize = namesize;
- nvphdr.nvph_datasize = nvp->nvp_datasize;
- PJDLOG_ASSERT(*leftp >= sizeof(nvphdr));
- memcpy(ptr, &nvphdr, sizeof(nvphdr));
- ptr += sizeof(nvphdr);
- *leftp -= sizeof(nvphdr);
-
- PJDLOG_ASSERT(*leftp >= namesize);
- memcpy(ptr, nvp->nvp_name, namesize);
- ptr += namesize;
- *leftp -= namesize;
-
- return (ptr);
-}
-
-unsigned char *
-nvpair_pack_null(const nvpair_t *nvp, unsigned char *ptr,
- size_t *leftp __unused)
-{
-
- NVPAIR_ASSERT(nvp);
- PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_NULL);
-
- return (ptr);
-}
-
-unsigned char *
-nvpair_pack_bool(const nvpair_t *nvp, unsigned char *ptr, size_t *leftp)
-{
- uint8_t value;
-
- NVPAIR_ASSERT(nvp);
- PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_BOOL);
-
- value = (uint8_t)nvp->nvp_data;
-
- PJDLOG_ASSERT(*leftp >= sizeof(value));
- memcpy(ptr, &value, sizeof(value));
- ptr += sizeof(value);
- *leftp -= sizeof(value);
-
- return (ptr);
-}
-
-unsigned char *
-nvpair_pack_number(const nvpair_t *nvp, unsigned char *ptr, size_t *leftp)
-{
- uint64_t value;
-
- NVPAIR_ASSERT(nvp);
- PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_NUMBER);
-
- value = (uint64_t)nvp->nvp_data;
-
- PJDLOG_ASSERT(*leftp >= sizeof(value));
- memcpy(ptr, &value, sizeof(value));
- ptr += sizeof(value);
- *leftp -= sizeof(value);
-
- return (ptr);
-}
-
-unsigned char *
-nvpair_pack_string(const nvpair_t *nvp, unsigned char *ptr, size_t *leftp)
-{
-
- NVPAIR_ASSERT(nvp);
- PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_STRING);
-
- PJDLOG_ASSERT(*leftp >= nvp->nvp_datasize);
- memcpy(ptr, (const void *)(intptr_t)nvp->nvp_data, nvp->nvp_datasize);
- ptr += nvp->nvp_datasize;
- *leftp -= nvp->nvp_datasize;
-
- return (ptr);
-}
-
-unsigned char *
-nvpair_pack_nvlist_up(unsigned char *ptr, size_t *leftp)
-{
- struct nvpair_header nvphdr;
- size_t namesize;
- const char *name = "";
-
- namesize = 1;
- nvphdr.nvph_type = NV_TYPE_NVLIST_UP;
- nvphdr.nvph_namesize = namesize;
- nvphdr.nvph_datasize = 0;
- PJDLOG_ASSERT(*leftp >= sizeof(nvphdr));
- memcpy(ptr, &nvphdr, sizeof(nvphdr));
- ptr += sizeof(nvphdr);
- *leftp -= sizeof(nvphdr);
-
- PJDLOG_ASSERT(*leftp >= namesize);
- memcpy(ptr, name, namesize);
- ptr += namesize;
- *leftp -= namesize;
-
- return (ptr);
-}
-
-unsigned char *
-nvpair_pack_descriptor(const nvpair_t *nvp, unsigned char *ptr, int64_t *fdidxp,
- size_t *leftp)
-{
- int64_t value;
-
- NVPAIR_ASSERT(nvp);
- PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_DESCRIPTOR);
-
- value = (int64_t)nvp->nvp_data;
- if (value != -1) {
- /*
- * If there is a real descriptor here, we change its number
- * to position in the array of descriptors send via control
- * message.
- */
- PJDLOG_ASSERT(fdidxp != NULL);
-
- value = *fdidxp;
- (*fdidxp)++;
- }
-
- PJDLOG_ASSERT(*leftp >= sizeof(value));
- memcpy(ptr, &value, sizeof(value));
- ptr += sizeof(value);
- *leftp -= sizeof(value);
-
- return (ptr);
-}
-
-unsigned char *
-nvpair_pack_binary(const nvpair_t *nvp, unsigned char *ptr, size_t *leftp)
-{
-
- NVPAIR_ASSERT(nvp);
- PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_BINARY);
-
- PJDLOG_ASSERT(*leftp >= nvp->nvp_datasize);
- memcpy(ptr, (const void *)(intptr_t)nvp->nvp_data, nvp->nvp_datasize);
- ptr += nvp->nvp_datasize;
- *leftp -= nvp->nvp_datasize;
-
- return (ptr);
-}
-
-void
-nvpair_init_datasize(nvpair_t *nvp)
-{
-
- NVPAIR_ASSERT(nvp);
-
- if (nvp->nvp_type == NV_TYPE_NVLIST) {
- if (nvp->nvp_data == 0) {
- nvp->nvp_datasize = 0;
- } else {
- nvp->nvp_datasize =
- nvlist_size((const nvlist_t *)(intptr_t)nvp->nvp_data);
- }
- }
-}
-
-const unsigned char *
-nvpair_unpack_header(bool isbe, nvpair_t *nvp, const unsigned char *ptr,
- size_t *leftp)
-{
- struct nvpair_header nvphdr;
-
- if (*leftp < sizeof(nvphdr))
- goto failed;
-
- memcpy(&nvphdr, ptr, sizeof(nvphdr));
- ptr += sizeof(nvphdr);
- *leftp -= sizeof(nvphdr);
-
-#if NV_TYPE_FIRST > 0
- if (nvphdr.nvph_type < NV_TYPE_FIRST)
- goto failed;
-#endif
- if (nvphdr.nvph_type > NV_TYPE_LAST &&
- nvphdr.nvph_type != NV_TYPE_NVLIST_UP) {
- goto failed;
- }
-
-#if BYTE_ORDER == BIG_ENDIAN
- if (!isbe) {
- nvphdr.nvph_namesize = le16toh(nvphdr.nvph_namesize);
- nvphdr.nvph_datasize = le64toh(nvphdr.nvph_datasize);
- }
-#else
- if (isbe) {
- nvphdr.nvph_namesize = be16toh(nvphdr.nvph_namesize);
- nvphdr.nvph_datasize = be64toh(nvphdr.nvph_datasize);
- }
-#endif
-
- if (nvphdr.nvph_namesize > NV_NAME_MAX)
- goto failed;
- if (*leftp < nvphdr.nvph_namesize)
- goto failed;
- if (nvphdr.nvph_namesize < 1)
- goto failed;
- if (strnlen((const char *)ptr, nvphdr.nvph_namesize) !=
- (size_t)(nvphdr.nvph_namesize - 1)) {
- goto failed;
- }
-
- memcpy(nvp->nvp_name, ptr, nvphdr.nvph_namesize);
- ptr += nvphdr.nvph_namesize;
- *leftp -= nvphdr.nvph_namesize;
-
- if (*leftp < nvphdr.nvph_datasize)
- goto failed;
-
- nvp->nvp_type = nvphdr.nvph_type;
- nvp->nvp_data = 0;
- nvp->nvp_datasize = nvphdr.nvph_datasize;
-
- return (ptr);
-failed:
- errno = EINVAL;
- return (NULL);
-}
-
-const unsigned char *
-nvpair_unpack_null(bool isbe __unused, nvpair_t *nvp, const unsigned char *ptr,
- size_t *leftp __unused)
-{
-
- PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_NULL);
-
- if (nvp->nvp_datasize != 0) {
- errno = EINVAL;
- return (NULL);
- }
-
- return (ptr);
-}
-
-const unsigned char *
-nvpair_unpack_bool(bool isbe __unused, nvpair_t *nvp, const unsigned char *ptr,
- size_t *leftp)
-{
- uint8_t value;
-
- PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_BOOL);
-
- if (nvp->nvp_datasize != sizeof(value)) {
- errno = EINVAL;
- return (NULL);
- }
- if (*leftp < sizeof(value)) {
- errno = EINVAL;
- return (NULL);
- }
-
- memcpy(&value, ptr, sizeof(value));
- ptr += sizeof(value);
- *leftp -= sizeof(value);
-
- if (value != 0 && value != 1) {
- errno = EINVAL;
- return (NULL);
- }
-
- nvp->nvp_data = (uint64_t)value;
-
- return (ptr);
-}
-
-const unsigned char *
-nvpair_unpack_number(bool isbe, nvpair_t *nvp, const unsigned char *ptr,
- size_t *leftp)
-{
-
- PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_NUMBER);
-
- if (nvp->nvp_datasize != sizeof(uint64_t)) {
- errno = EINVAL;
- return (NULL);
- }
- if (*leftp < sizeof(uint64_t)) {
- errno = EINVAL;
- return (NULL);
- }
-
- if (isbe)
- nvp->nvp_data = be64dec(ptr);
- else
- nvp->nvp_data = le64dec(ptr);
- ptr += sizeof(uint64_t);
- *leftp -= sizeof(uint64_t);
-
- return (ptr);
-}
-
-const unsigned char *
-nvpair_unpack_string(bool isbe __unused, nvpair_t *nvp,
- const unsigned char *ptr, size_t *leftp)
-{
-
- PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_STRING);
-
- if (*leftp < nvp->nvp_datasize || nvp->nvp_datasize == 0) {
- errno = EINVAL;
- return (NULL);
- }
-
- if (strnlen((const char *)ptr, nvp->nvp_datasize) !=
- nvp->nvp_datasize - 1) {
- errno = EINVAL;
- return (NULL);
- }
-
- nvp->nvp_data = (uint64_t)(uintptr_t)strdup((const char *)ptr);
- if (nvp->nvp_data == 0)
- return (NULL);
-
- ptr += nvp->nvp_datasize;
- *leftp -= nvp->nvp_datasize;
-
- return (ptr);
-}
-
-const unsigned char *
-nvpair_unpack_nvlist(bool isbe __unused, nvpair_t *nvp,
- const unsigned char *ptr, size_t *leftp, size_t nfds, nvlist_t **child)
-{
- nvlist_t *value;
-
- PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_NVLIST);
-
- if (*leftp < nvp->nvp_datasize || nvp->nvp_datasize == 0) {
- errno = EINVAL;
- return (NULL);
- }
-
- value = nvlist_create(0);
- if (value == NULL)
- return (NULL);
-
- ptr = nvlist_unpack_header(value, ptr, nfds, NULL, leftp);
- if (ptr == NULL)
- return (NULL);
-
- nvp->nvp_data = (uint64_t)(uintptr_t)value;
- *child = value;
-
- return (ptr);
-}
-
-const unsigned char *
-nvpair_unpack_descriptor(bool isbe, nvpair_t *nvp, const unsigned char *ptr,
- size_t *leftp, const int *fds, size_t nfds)
-{
- int64_t idx;
-
- PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_DESCRIPTOR);
-
- if (nvp->nvp_datasize != sizeof(idx)) {
- errno = EINVAL;
- return (NULL);
- }
- if (*leftp < sizeof(idx)) {
- errno = EINVAL;
- return (NULL);
- }
-
- if (isbe)
- idx = be64dec(ptr);
- else
- idx = le64dec(ptr);
-
- if (idx < 0) {
- errno = EINVAL;
- return (NULL);
- }
-
- if ((size_t)idx >= nfds) {
- errno = EINVAL;
- return (NULL);
- }
-
- nvp->nvp_data = (uint64_t)fds[idx];
-
- ptr += sizeof(idx);
- *leftp -= sizeof(idx);
-
- return (ptr);
-}
-
-const unsigned char *
-nvpair_unpack_binary(bool isbe __unused, nvpair_t *nvp,
- const unsigned char *ptr, size_t *leftp)
-{
- void *value;
-
- PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_BINARY);
-
- if (*leftp < nvp->nvp_datasize || nvp->nvp_datasize == 0) {
- errno = EINVAL;
- return (NULL);
- }
-
- value = malloc(nvp->nvp_datasize);
- if (value == NULL)
- return (NULL);
-
- memcpy(value, ptr, nvp->nvp_datasize);
- ptr += nvp->nvp_datasize;
- *leftp -= nvp->nvp_datasize;
-
- nvp->nvp_data = (uint64_t)(uintptr_t)value;
-
- return (ptr);
-}
-
-const unsigned char *
-nvpair_unpack(bool isbe, const unsigned char *ptr, size_t *leftp,
- nvpair_t **nvpp)
-{
- nvpair_t *nvp, *tmp;
-
- nvp = calloc(1, sizeof(*nvp) + NV_NAME_MAX);
- if (nvp == NULL)
- return (NULL);
- nvp->nvp_name = (char *)(nvp + 1);
-
- ptr = nvpair_unpack_header(isbe, nvp, ptr, leftp);
- if (ptr == NULL)
- goto failed;
- tmp = realloc(nvp, sizeof(*nvp) + strlen(nvp->nvp_name) + 1);
- if (tmp == NULL)
- goto failed;
- nvp = tmp;
-
- /* Update nvp_name after realloc(). */
- nvp->nvp_name = (char *)(nvp + 1);
- nvp->nvp_data = 0x00;
- nvp->nvp_magic = NVPAIR_MAGIC;
- *nvpp = nvp;
- return (ptr);
-failed:
- free(nvp);
- return (NULL);
-}
-
-int
-nvpair_type(const nvpair_t *nvp)
-{
-
- NVPAIR_ASSERT(nvp);
-
- return (nvp->nvp_type);
-}
-
-const char *
-nvpair_name(const nvpair_t *nvp)
-{
-
- NVPAIR_ASSERT(nvp);
-
- return (nvp->nvp_name);
-}
-
-static nvpair_t *
-nvpair_allocv(int type, uint64_t data, size_t datasize, const char *namefmt,
- va_list nameap)
-{
- nvpair_t *nvp;
- char *name;
- int namelen;
-
- PJDLOG_ASSERT(type >= NV_TYPE_FIRST && type <= NV_TYPE_LAST);
-
- namelen = vasprintf(&name, namefmt, nameap);
- if (namelen < 0)
- return (NULL);
-
- PJDLOG_ASSERT(namelen > 0);
- if (namelen >= NV_NAME_MAX) {
- free(name);
- errno = ENAMETOOLONG;
- return (NULL);
- }
-
- nvp = calloc(1, sizeof(*nvp) + namelen + 1);
- if (nvp != NULL) {
- nvp->nvp_name = (char *)(nvp + 1);
- memcpy(nvp->nvp_name, name, namelen + 1);
- nvp->nvp_type = type;
- nvp->nvp_data = data;
- nvp->nvp_datasize = datasize;
- nvp->nvp_magic = NVPAIR_MAGIC;
- }
- free(name);
-
- return (nvp);
-};
-
-nvpair_t *
-nvpair_create_null(const char *name)
-{
-
- return (nvpair_createf_null("%s", name));
-}
-
-nvpair_t *
-nvpair_create_bool(const char *name, bool value)
-{
-
- return (nvpair_createf_bool(value, "%s", name));
-}
-
-nvpair_t *
-nvpair_create_number(const char *name, uint64_t value)
-{
-
- return (nvpair_createf_number(value, "%s", name));
-}
-
-nvpair_t *
-nvpair_create_string(const char *name, const char *value)
-{
-
- return (nvpair_createf_string(value, "%s", name));
-}
-
-nvpair_t *
-nvpair_create_stringf(const char *name, const char *valuefmt, ...)
-{
- va_list valueap;
- nvpair_t *nvp;
-
- va_start(valueap, valuefmt);
- nvp = nvpair_create_stringv(name, valuefmt, valueap);
- va_end(valueap);
-
- return (nvp);
-}
-
-nvpair_t *
-nvpair_create_stringv(const char *name, const char *valuefmt, va_list valueap)
-{
- nvpair_t *nvp;
- char *str;
- int len;
-
- len = vasprintf(&str, valuefmt, valueap);
- if (len < 0)
- return (NULL);
- nvp = nvpair_create_string(name, str);
- if (nvp == NULL)
- free(str);
- return (nvp);
-}
-
-nvpair_t *
-nvpair_create_nvlist(const char *name, const nvlist_t *value)
-{
-
- return (nvpair_createf_nvlist(value, "%s", name));
-}
-
-nvpair_t *
-nvpair_create_descriptor(const char *name, int value)
-{
-
- return (nvpair_createf_descriptor(value, "%s", name));
-}
-
-nvpair_t *
-nvpair_create_binary(const char *name, const void *value, size_t size)
-{
-
- return (nvpair_createf_binary(value, size, "%s", name));
-}
-
-nvpair_t *
-nvpair_createf_null(const char *namefmt, ...)
-{
- va_list nameap;
- nvpair_t *nvp;
-
- va_start(nameap, namefmt);
- nvp = nvpair_createv_null(namefmt, nameap);
- va_end(nameap);
-
- return (nvp);
-}
-
-nvpair_t *
-nvpair_createf_bool(bool value, const char *namefmt, ...)
-{
- va_list nameap;
- nvpair_t *nvp;
-
- va_start(nameap, namefmt);
- nvp = nvpair_createv_bool(value, namefmt, nameap);
- va_end(nameap);
-
- return (nvp);
-}
-
-nvpair_t *
-nvpair_createf_number(uint64_t value, const char *namefmt, ...)
-{
- va_list nameap;
- nvpair_t *nvp;
-
- va_start(nameap, namefmt);
- nvp = nvpair_createv_number(value, namefmt, nameap);
- va_end(nameap);
-
- return (nvp);
-}
-
-nvpair_t *
-nvpair_createf_string(const char *value, const char *namefmt, ...)
-{
- va_list nameap;
- nvpair_t *nvp;
-
- va_start(nameap, namefmt);
- nvp = nvpair_createv_string(value, namefmt, nameap);
- va_end(nameap);
-
- return (nvp);
-}
-
-nvpair_t *
-nvpair_createf_nvlist(const nvlist_t *value, const char *namefmt, ...)
-{
- va_list nameap;
- nvpair_t *nvp;
-
- va_start(nameap, namefmt);
- nvp = nvpair_createv_nvlist(value, namefmt, nameap);
- va_end(nameap);
-
- return (nvp);
-}
-
-nvpair_t *
-nvpair_createf_descriptor(int value, const char *namefmt, ...)
-{
- va_list nameap;
- nvpair_t *nvp;
-
- va_start(nameap, namefmt);
- nvp = nvpair_createv_descriptor(value, namefmt, nameap);
- va_end(nameap);
-
- return (nvp);
-}
-
-nvpair_t *
-nvpair_createf_binary(const void *value, size_t size, const char *namefmt, ...)
-{
- va_list nameap;
- nvpair_t *nvp;
-
- va_start(nameap, namefmt);
- nvp = nvpair_createv_binary(value, size, namefmt, nameap);
- va_end(nameap);
-
- return (nvp);
-}
-
-nvpair_t *
-nvpair_createv_null(const char *namefmt, va_list nameap)
-{
-
- return (nvpair_allocv(NV_TYPE_NULL, 0, 0, namefmt, nameap));
-}
-
-nvpair_t *
-nvpair_createv_bool(bool value, const char *namefmt, va_list nameap)
-{
-
- return (nvpair_allocv(NV_TYPE_BOOL, value ? 1 : 0, sizeof(uint8_t),
- namefmt, nameap));
-}
-
-nvpair_t *
-nvpair_createv_number(uint64_t value, const char *namefmt, va_list nameap)
-{
-
- return (nvpair_allocv(NV_TYPE_NUMBER, value, sizeof(value), namefmt,
- nameap));
-}
-
-nvpair_t *
-nvpair_createv_string(const char *value, const char *namefmt, va_list nameap)
-{
- nvpair_t *nvp;
- size_t size;
- char *data;
-
- if (value == NULL) {
- errno = EINVAL;
- return (NULL);
- }
-
- data = strdup(value);
- if (data == NULL)
- return (NULL);
- size = strlen(value) + 1;
-
- nvp = nvpair_allocv(NV_TYPE_STRING, (uint64_t)(uintptr_t)data, size,
- namefmt, nameap);
- if (nvp == NULL)
- free(data);
-
- return (nvp);
-}
-
-nvpair_t *
-nvpair_createv_nvlist(const nvlist_t *value, const char *namefmt,
- va_list nameap)
-{
- nvlist_t *nvl;
- nvpair_t *nvp;
-
- if (value == NULL) {
- errno = EINVAL;
- return (NULL);
- }
-
- nvl = nvlist_clone(value);
- if (nvl == NULL)
- return (NULL);
-
- nvp = nvpair_allocv(NV_TYPE_NVLIST, (uint64_t)(uintptr_t)nvl, 0,
- namefmt, nameap);
- if (nvp == NULL)
- nvlist_destroy(nvl);
- else
- nvlist_set_parent(nvl, nvp);
-
- return (nvp);
-}
-
-nvpair_t *
-nvpair_createv_descriptor(int value, const char *namefmt, va_list nameap)
-{
- nvpair_t *nvp;
-
- if (value < 0 || !fd_is_valid(value)) {
- errno = EBADF;
- return (NULL);
- }
-
- value = fcntl(value, F_DUPFD_CLOEXEC, 0);
- if (value < 0)
- return (NULL);
-
- nvp = nvpair_allocv(NV_TYPE_DESCRIPTOR, (uint64_t)value,
- sizeof(int64_t), namefmt, nameap);
- if (nvp == NULL)
- close(value);
-
- return (nvp);
-}
-
-nvpair_t *
-nvpair_createv_binary(const void *value, size_t size, const char *namefmt,
- va_list nameap)
-{
- nvpair_t *nvp;
- void *data;
-
- if (value == NULL || size == 0) {
- errno = EINVAL;
- return (NULL);
- }
-
- data = malloc(size);
- if (data == NULL)
- return (NULL);
- memcpy(data, value, size);
-
- nvp = nvpair_allocv(NV_TYPE_BINARY, (uint64_t)(uintptr_t)data, size,
- namefmt, nameap);
- if (nvp == NULL)
- free(data);
-
- return (nvp);
-}
-
-nvpair_t *
-nvpair_move_string(const char *name, char *value)
-{
-
- return (nvpair_movef_string(value, "%s", name));
-}
-
-nvpair_t *
-nvpair_move_nvlist(const char *name, nvlist_t *value)
-{
-
- return (nvpair_movef_nvlist(value, "%s", name));
-}
-
-nvpair_t *
-nvpair_move_descriptor(const char *name, int value)
-{
-
- return (nvpair_movef_descriptor(value, "%s", name));
-}
-
-nvpair_t *
-nvpair_move_binary(const char *name, void *value, size_t size)
-{
-
- return (nvpair_movef_binary(value, size, "%s", name));
-}
-
-nvpair_t *
-nvpair_movef_string(char *value, const char *namefmt, ...)
-{
- va_list nameap;
- nvpair_t *nvp;
-
- va_start(nameap, namefmt);
- nvp = nvpair_movev_string(value, namefmt, nameap);
- va_end(nameap);
-
- return (nvp);
-}
-
-nvpair_t *
-nvpair_movef_nvlist(nvlist_t *value, const char *namefmt, ...)
-{
- va_list nameap;
- nvpair_t *nvp;
-
- va_start(nameap, namefmt);
- nvp = nvpair_movev_nvlist(value, namefmt, nameap);
- va_end(nameap);
-
- return (nvp);
-}
-
-nvpair_t *
-nvpair_movef_descriptor(int value, const char *namefmt, ...)
-{
- va_list nameap;
- nvpair_t *nvp;
-
- va_start(nameap, namefmt);
- nvp = nvpair_movev_descriptor(value, namefmt, nameap);
- va_end(nameap);
-
- return (nvp);
-}
-
-nvpair_t *
-nvpair_movef_binary(void *value, size_t size, const char *namefmt, ...)
-{
- va_list nameap;
- nvpair_t *nvp;
-
- va_start(nameap, namefmt);
- nvp = nvpair_movev_binary(value, size, namefmt, nameap);
- va_end(nameap);
-
- return (nvp);
-}
-
-nvpair_t *
-nvpair_movev_string(char *value, const char *namefmt, va_list nameap)
-{
- nvpair_t *nvp;
-
- if (value == NULL) {
- errno = EINVAL;
- return (NULL);
- }
-
- nvp = nvpair_allocv(NV_TYPE_STRING, (uint64_t)(uintptr_t)value,
- strlen(value) + 1, namefmt, nameap);
- if (nvp == NULL)
- free(value);
-
- return (nvp);
-}
-
-nvpair_t *
-nvpair_movev_nvlist(nvlist_t *value, const char *namefmt, va_list nameap)
-{
- nvpair_t *nvp;
-
- if (value == NULL || nvlist_get_nvpair_parent(value) != NULL) {
- errno = EINVAL;
- return (NULL);
- }
-
- nvp = nvpair_allocv(NV_TYPE_NVLIST, (uint64_t)(uintptr_t)value, 0,
- namefmt, nameap);
- if (nvp == NULL)
- nvlist_destroy(value);
- else
- nvlist_set_parent(value, nvp);
-
- return (nvp);
-}
-
-nvpair_t *
-nvpair_movev_descriptor(int value, const char *namefmt, va_list nameap)
-{
-
- if (value < 0 || !fd_is_valid(value)) {
- errno = EBADF;
- return (NULL);
- }
-
- return (nvpair_allocv(NV_TYPE_DESCRIPTOR, (uint64_t)value,
- sizeof(int64_t), namefmt, nameap));
-}
-
-nvpair_t *
-nvpair_movev_binary(void *value, size_t size, const char *namefmt,
- va_list nameap)
-{
-
- if (value == NULL || size == 0) {
- errno = EINVAL;
- return (NULL);
- }
-
- return (nvpair_allocv(NV_TYPE_BINARY, (uint64_t)(uintptr_t)value, size,
- namefmt, nameap));
-}
-
-bool
-nvpair_get_bool(const nvpair_t *nvp)
-{
-
- NVPAIR_ASSERT(nvp);
-
- return (nvp->nvp_data == 1);
-}
-
-uint64_t
-nvpair_get_number(const nvpair_t *nvp)
-{
-
- NVPAIR_ASSERT(nvp);
-
- return (nvp->nvp_data);
-}
-
-const char *
-nvpair_get_string(const nvpair_t *nvp)
-{
-
- NVPAIR_ASSERT(nvp);
- PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_STRING);
-
- return ((const char *)(intptr_t)nvp->nvp_data);
-}
-
-const nvlist_t *
-nvpair_get_nvlist(const nvpair_t *nvp)
-{
-
- NVPAIR_ASSERT(nvp);
- PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_NVLIST);
-
- return ((const nvlist_t *)(intptr_t)nvp->nvp_data);
-}
-
-int
-nvpair_get_descriptor(const nvpair_t *nvp)
-{
-
- NVPAIR_ASSERT(nvp);
- PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_DESCRIPTOR);
-
- return ((int)nvp->nvp_data);
-}
-
-const void *
-nvpair_get_binary(const nvpair_t *nvp, size_t *sizep)
-{
-
- NVPAIR_ASSERT(nvp);
- PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_BINARY);
-
- if (sizep != NULL)
- *sizep = nvp->nvp_datasize;
- return ((const void *)(intptr_t)nvp->nvp_data);
-}
-
-void
-nvpair_free(nvpair_t *nvp)
-{
-
- NVPAIR_ASSERT(nvp);
- PJDLOG_ASSERT(nvp->nvp_list == NULL);
-
- nvp->nvp_magic = 0;
- switch (nvp->nvp_type) {
- case NV_TYPE_DESCRIPTOR:
- close((int)nvp->nvp_data);
- break;
- case NV_TYPE_NVLIST:
- nvlist_destroy((nvlist_t *)(intptr_t)nvp->nvp_data);
- break;
- case NV_TYPE_STRING:
- free((char *)(intptr_t)nvp->nvp_data);
- break;
- case NV_TYPE_BINARY:
- free((void *)(intptr_t)nvp->nvp_data);
- break;
- }
- free(nvp);
-}
-
-void
-nvpair_free_structure(nvpair_t *nvp)
-{
-
- NVPAIR_ASSERT(nvp);
- PJDLOG_ASSERT(nvp->nvp_list == NULL);
-
- nvp->nvp_magic = 0;
- free(nvp);
-}
-
-const char *
-nvpair_type_string(int type)
-{
-
- switch (type) {
- case NV_TYPE_NULL:
- return ("NULL");
- case NV_TYPE_BOOL:
- return ("BOOL");
- case NV_TYPE_NUMBER:
- return ("NUMBER");
- case NV_TYPE_STRING:
- return ("STRING");
- case NV_TYPE_NVLIST:
- return ("NVLIST");
- case NV_TYPE_DESCRIPTOR:
- return ("DESCRIPTOR");
- case NV_TYPE_BINARY:
- return ("BINARY");
- default:
- return ("<UNKNOWN>");
- }
-}
diff --git a/lib/libnv/nvpair_impl.h b/lib/libnv/nvpair_impl.h
deleted file mode 100644
index a72000b..0000000
--- a/lib/libnv/nvpair_impl.h
+++ /dev/null
@@ -1,92 +0,0 @@
-/*-
- * Copyright (c) 2009-2013 The FreeBSD Foundation
- * All rights reserved.
- *
- * This software was developed by Pawel Jakub Dawidek under sponsorship from
- * the FreeBSD Foundation.
- *
- * 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 AUTHORS 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 AUTHORS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-#ifndef _NVPAIR_IMPL_H_
-#define _NVPAIR_IMPL_H_
-
-#include <sys/queue.h>
-
-#include <stdint.h>
-
-#include "nv.h"
-
-TAILQ_HEAD(nvl_head, nvpair);
-
-void nvpair_assert(const nvpair_t *nvp);
-nvlist_t *nvpair_nvlist(const nvpair_t *nvp);
-nvpair_t *nvpair_next(const nvpair_t *nvp);
-nvpair_t *nvpair_prev(const nvpair_t *nvp);
-void nvpair_insert(struct nvl_head *head, nvpair_t *nvp, nvlist_t *nvl);
-void nvpair_remove(struct nvl_head *head, nvpair_t *nvp, const nvlist_t *nvl);
-size_t nvpair_header_size(void);
-size_t nvpair_size(const nvpair_t *nvp);
-const unsigned char *nvpair_unpack(bool isbe, const unsigned char *ptr,
- size_t *leftp, nvpair_t **nvpp);
-void nvpair_free_structure(nvpair_t *nvp);
-void nvpair_init_datasize(nvpair_t *nvp);
-const char *nvpair_type_string(int type);
-
-/* Pack functions. */
-unsigned char *nvpair_pack_header(const nvpair_t *nvp, unsigned char *ptr,
- size_t *leftp);
-unsigned char *nvpair_pack_null(const nvpair_t *nvp, unsigned char *ptr,
- size_t *leftp);
-unsigned char *nvpair_pack_bool(const nvpair_t *nvp, unsigned char *ptr,
- size_t *leftp);
-unsigned char *nvpair_pack_number(const nvpair_t *nvp, unsigned char *ptr,
- size_t *leftp);
-unsigned char *nvpair_pack_string(const nvpair_t *nvp, unsigned char *ptr,
- size_t *leftp);
-unsigned char *nvpair_pack_descriptor(const nvpair_t *nvp, unsigned char *ptr,
- int64_t *fdidxp, size_t *leftp);
-unsigned char *nvpair_pack_binary(const nvpair_t *nvp, unsigned char *ptr,
- size_t *leftp);
-unsigned char *nvpair_pack_nvlist_up(unsigned char *ptr, size_t *leftp);
-
-/* Unpack data functions. */
-const unsigned char *nvpair_unpack_header(bool isbe, nvpair_t *nvp,
- const unsigned char *ptr, size_t *leftp);
-const unsigned char *nvpair_unpack_null(bool isbe, nvpair_t *nvp,
- const unsigned char *ptr, size_t *leftp);
-const unsigned char *nvpair_unpack_bool(bool isbe, nvpair_t *nvp,
- const unsigned char *ptr, size_t *leftp);
-const unsigned char *nvpair_unpack_number(bool isbe, nvpair_t *nvp,
- const unsigned char *ptr, size_t *leftp);
-const unsigned char *nvpair_unpack_string(bool isbe, nvpair_t *nvp,
- const unsigned char *ptr, size_t *leftp);
-const unsigned char *nvpair_unpack_nvlist(bool isbe, nvpair_t *nvp,
- const unsigned char *ptr, size_t *leftp, size_t nvlist, nvlist_t **child);
-const unsigned char *nvpair_unpack_descriptor(bool isbe, nvpair_t *nvp,
- const unsigned char *ptr, size_t *leftp, const int *fds, size_t nfds);
-const unsigned char *nvpair_unpack_binary(bool isbe, nvpair_t *nvp,
- const unsigned char *ptr, size_t *leftp);
-
-#endif /* !_NVPAIR_IMPL_H_ */
diff --git a/lib/libnv/tests/Makefile b/lib/libnv/tests/Makefile
index df10549..7fc8d91 100644
--- a/lib/libnv/tests/Makefile
+++ b/lib/libnv/tests/Makefile
@@ -2,6 +2,10 @@
TESTSDIR= ${TESTSBASE}/lib/libnv
+ATF_TESTS_CXX= \
+ dnv_tests \
+ nv_tests \
+
TAP_TESTS_C+= nvlist_add_test
TAP_TESTS_C+= nvlist_exists_test
TAP_TESTS_C+= nvlist_free_test
@@ -9,9 +13,8 @@ TAP_TESTS_C+= nvlist_get_test
TAP_TESTS_C+= nvlist_move_test
TAP_TESTS_C+= nvlist_send_recv_test
-DPADD+= ${LIBNV}
-LDADD+= -lnv
+LIBADD+= nv
-WARNS?= 6
+WARNS?= 3
.include <bsd.test.mk>
diff --git a/lib/libnv/tests/dnv_tests.cc b/lib/libnv/tests/dnv_tests.cc
new file mode 100644
index 0000000..2f92d9d
--- /dev/null
+++ b/lib/libnv/tests/dnv_tests.cc
@@ -0,0 +1,567 @@
+/*-
+ * Copyright (c) 2014-2015 Sandvine Inc. All rights reserved.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <atf-c++.hpp>
+#include <dnv.h>
+#include <nv.h>
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_get_bool__present);
+ATF_TEST_CASE_BODY(dnvlist_get_bool__present)
+{
+ nvlist_t *nvl;
+ const char *key;
+ bool value;
+
+ nvl = nvlist_create(0);
+
+ key = "name";
+ value = true;
+ nvlist_add_bool(nvl, key, value);
+
+ ATF_REQUIRE_EQ(dnvlist_get_bool(nvl, key, false), value);
+ ATF_REQUIRE_EQ(dnvlist_get_bool(nvl, "name", false), value);
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_get_bool__default_value);
+ATF_TEST_CASE_BODY(dnvlist_get_bool__default_value)
+{
+ nvlist_t *nvl;
+ const char *key;
+
+ key = "123";
+ nvl = nvlist_create(0);
+
+ ATF_REQUIRE_EQ(dnvlist_get_bool(nvl, key, false), false);
+ ATF_REQUIRE_EQ(dnvlist_get_bool(nvl, "123", true), true);
+
+ nvlist_add_bool(nvl, key, true);
+
+ ATF_REQUIRE_EQ(dnvlist_get_bool(nvl, "otherkey", true), true);
+ ATF_REQUIRE_EQ(dnvlist_get_bool(nvl, "12c", false), false);
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_get_number__present);
+ATF_TEST_CASE_BODY(dnvlist_get_number__present)
+{
+ nvlist_t *nvl;
+ const char *key;
+ uint64_t value;
+
+ nvl = nvlist_create(0);
+
+ key = "key";
+ value = 48952;
+ nvlist_add_number(nvl, key, value);
+
+ ATF_REQUIRE_EQ(dnvlist_get_number(nvl, key, 19), value);
+ ATF_REQUIRE_EQ(dnvlist_get_number(nvl, "key", 65), value);
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_get_number__default_value);
+ATF_TEST_CASE_BODY(dnvlist_get_number__default_value)
+{
+ nvlist_t *nvl;
+ const char *key;
+
+ key = "123";
+ nvl = nvlist_create(0);
+
+ ATF_REQUIRE_EQ(dnvlist_get_number(nvl, key, 5), 5);
+ ATF_REQUIRE_EQ(dnvlist_get_number(nvl, "1234", 5), 5);
+
+ nvlist_add_number(nvl, key, 24841);
+
+ ATF_REQUIRE_EQ(dnvlist_get_number(nvl, "1234", 5641), 5641);
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_get_string__present);
+ATF_TEST_CASE_BODY(dnvlist_get_string__present)
+{
+ nvlist_t *nvl;
+ const char *key;
+ const char *value, *actual_value;
+
+ nvl = nvlist_create(0);
+
+ key = "string";
+ value = "fjdojfdi";
+ nvlist_add_string(nvl, key, value);
+
+ ATF_REQUIRE_EQ(strcmp(dnvlist_get_string(nvl, key, "g"), value), 0);
+
+ actual_value = dnvlist_get_string(nvl, key, "rs");
+ ATF_REQUIRE_EQ(strcmp(actual_value, value), 0);
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_get_string__default_value);
+ATF_TEST_CASE_BODY(dnvlist_get_string__default_value)
+{
+ nvlist_t *nvl;
+ const char *key;
+ const char *actual_value;
+
+ key = "123";
+ nvl = nvlist_create(0);
+
+ ATF_REQUIRE_EQ(strcmp(dnvlist_get_string(nvl, key, "bar"), "bar"), 0);
+
+ actual_value = dnvlist_get_string(nvl, key, "d");
+ ATF_REQUIRE_EQ(strcmp(actual_value, "d"), 0);
+
+ nvlist_add_string(nvl, key, "cxhweh");
+
+ ATF_REQUIRE_EQ(strcmp(dnvlist_get_string(nvl, "hthth", "fd"), "fd"), 0);
+ actual_value = dnvlist_get_string(nvl, "5", "5");
+ ATF_REQUIRE_EQ(strcmp("5", "5"), 0);
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_get_nvlist__present);
+ATF_TEST_CASE_BODY(dnvlist_get_nvlist__present)
+{
+ nvlist_t *nvl;
+ const char *key;
+ nvlist_t *value;
+ const nvlist_t *actual_value;
+
+ nvl = nvlist_create(0);
+
+ key = "nvlist";
+ value = nvlist_create(0);
+ nvlist_move_nvlist(nvl, key, value);
+
+ actual_value = dnvlist_get_nvlist(nvl, key, NULL);
+ ATF_REQUIRE(actual_value != NULL);
+ ATF_REQUIRE(nvlist_empty(actual_value));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_get_nvlist__default_value);
+ATF_TEST_CASE_BODY(dnvlist_get_nvlist__default_value)
+{
+ nvlist_t *nvl;
+ const char *key;
+ nvlist_t *dummy;
+
+ key = "123";
+ nvl = nvlist_create(0);
+ dummy = nvlist_create(0);
+
+ ATF_REQUIRE_EQ(dnvlist_get_nvlist(nvl, key, dummy), dummy);
+
+ nvlist_move_nvlist(nvl, key, nvlist_create(0));
+ ATF_REQUIRE_EQ(dnvlist_get_nvlist(nvl, "456", dummy), dummy);
+ ATF_REQUIRE_EQ(dnvlist_get_nvlist(nvl, "gh", dummy), dummy);
+
+ nvlist_destroy(nvl);
+}
+
+static void
+set_const_binary_value(const void *&value, size_t &size, const char *str)
+{
+
+ value = str;
+ size = strlen(str) + 1; /* +1 to include '\0' */
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_get_binary__present);
+ATF_TEST_CASE_BODY(dnvlist_get_binary__present)
+{
+ nvlist_t *nvl;
+ const char *k;
+ const void *value, *actual_value;
+ size_t value_size, actual_size;
+
+ nvl = nvlist_create(0);
+
+ k = "binary";
+ set_const_binary_value(value, value_size, "fjdojfdi");
+ nvlist_add_binary(nvl, k, value, value_size);
+
+ actual_value = dnvlist_get_binary(nvl, k, &actual_size, "g", 1);
+ ATF_REQUIRE_EQ(value_size, actual_size);
+ ATF_REQUIRE_EQ(memcmp(actual_value, value, actual_size), 0);
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_get_binary__default_value);
+ATF_TEST_CASE_BODY(dnvlist_get_binary__default_value)
+{
+ nvlist_t *nvl;
+ const char *key;
+ const void *default_value, *actual_value;
+ size_t default_size, actual_size;
+
+ key = "123";
+ nvl = nvlist_create(0);
+
+ set_const_binary_value(default_value, default_size, "bar");
+ actual_value = dnvlist_get_binary(nvl, key, &actual_size, default_value,
+ default_size);
+ ATF_REQUIRE_EQ(default_size, actual_size);
+ ATF_REQUIRE_EQ(memcmp(actual_value, default_value, actual_size), 0);
+
+ set_const_binary_value(default_value, default_size, "atf");
+ actual_value = dnvlist_get_binary(nvl, key, &actual_size, default_value,
+ default_size);
+ ATF_REQUIRE_EQ(default_size, actual_size);
+ ATF_REQUIRE_EQ(memcmp(actual_value, default_value, actual_size), 0);
+
+ nvlist_add_binary(nvl, key, "test", 4);
+
+ set_const_binary_value(default_value, default_size, "bthrg");
+ actual_value = dnvlist_get_binary(nvl, "k", &actual_size, default_value,
+ default_size);
+ ATF_REQUIRE_EQ(default_size, actual_size);
+ ATF_REQUIRE_EQ(memcmp(actual_value, default_value, actual_size), 0);
+
+ set_const_binary_value(default_value, default_size,
+ "rrhgrythtyrtgbrhgrtdsvdfbtjlkul");
+ actual_value = dnvlist_get_binary(nvl, "s", &actual_size, default_value,
+ default_size);
+ ATF_REQUIRE_EQ(default_size, actual_size);
+ ATF_REQUIRE_EQ(memcmp(actual_value, default_value, actual_size), 0);
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_take_bool__present);
+ATF_TEST_CASE_BODY(dnvlist_take_bool__present)
+{
+ nvlist_t *nvl;
+ const char *key;
+ bool value;
+
+ nvl = nvlist_create(0);
+
+ key = "name";
+ value = true;
+ nvlist_add_bool(nvl, key, value);
+
+ ATF_REQUIRE_EQ(dnvlist_take_bool(nvl, key, false), value);
+ ATF_REQUIRE(nvlist_empty(nvl));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_take_bool__empty);
+ATF_TEST_CASE_BODY(dnvlist_take_bool__empty)
+{
+ nvlist_t *nvl;
+
+ nvl = nvlist_create(0);
+
+ ATF_REQUIRE_EQ(dnvlist_take_bool(nvl, "123", false), false);
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_take_bool__default_value);
+ATF_TEST_CASE_BODY(dnvlist_take_bool__default_value)
+{
+ nvlist_t *nvl;
+
+ nvl = nvlist_create(0);
+ nvlist_add_bool(nvl, "key", true);
+
+ ATF_REQUIRE_EQ(dnvlist_take_bool(nvl, "otherkey", true), true);
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_take_number__present);
+ATF_TEST_CASE_BODY(dnvlist_take_number__present)
+{
+ nvlist_t *nvl;
+ const char *key;
+ uint64_t value;
+
+ nvl = nvlist_create(0);
+
+ key = "name";
+ value = 194154;
+ nvlist_add_number(nvl, key, value);
+
+ ATF_REQUIRE_EQ(dnvlist_take_number(nvl, key, 2), value);
+ ATF_REQUIRE(nvlist_empty(nvl));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_take_number__empty);
+ATF_TEST_CASE_BODY(dnvlist_take_number__empty)
+{
+ nvlist_t *nvl;
+
+ nvl = nvlist_create(0);
+
+ ATF_REQUIRE_EQ(dnvlist_take_number(nvl, "123", 126484), 126484);
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_take_number__default_value);
+ATF_TEST_CASE_BODY(dnvlist_take_number__default_value)
+{
+ nvlist_t *nvl;
+
+ nvl = nvlist_create(0);
+ nvlist_add_number(nvl, "key", 12);
+
+ ATF_REQUIRE_EQ(dnvlist_take_number(nvl, "otherkey", 13), 13);
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_take_string__present);
+ATF_TEST_CASE_BODY(dnvlist_take_string__present)
+{
+ nvlist_t *nvl;
+ const char *key;
+ const char *value;
+ char *default_val, *actual_val;
+
+ nvl = nvlist_create(0);
+
+ key = "name";
+ value = "wrowm";
+ default_val = strdup("default");
+ nvlist_add_string(nvl, key, value);
+
+ actual_val = dnvlist_take_string(nvl, key, default_val);
+ ATF_REQUIRE_EQ(strcmp(actual_val, value), 0);
+ ATF_REQUIRE(nvlist_empty(nvl));
+
+ free(actual_val);
+ free(default_val);
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_take_string__empty);
+ATF_TEST_CASE_BODY(dnvlist_take_string__empty)
+{
+ nvlist_t *nvl;
+ char *default_val, *actual_val;
+
+ nvl = nvlist_create(0);
+ default_val = strdup("");
+
+ actual_val = dnvlist_take_string(nvl, "123", default_val);
+ ATF_REQUIRE_EQ(strcmp(actual_val, default_val), 0);
+
+ free(actual_val);
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_take_string__default_value);
+ATF_TEST_CASE_BODY(dnvlist_take_string__default_value)
+{
+ nvlist_t *nvl;
+ char *default_val, *actual_val;
+
+ nvl = nvlist_create(0);
+ nvlist_add_string(nvl, "key", "foobar");
+ default_val = strdup("other");
+
+ actual_val = dnvlist_take_string(nvl, "otherkey", default_val);
+ ATF_REQUIRE_EQ(strcmp(actual_val, default_val), 0);
+
+ free(actual_val);
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_take_nvlist__present);
+ATF_TEST_CASE_BODY(dnvlist_take_nvlist__present)
+{
+ nvlist_t *nvl;
+ const char *key;
+ nvlist_t *value, *default_val, *actual_val;
+
+ nvl = nvlist_create(0);
+
+ key = "name";
+ value = nvlist_create(0);
+ default_val = nvlist_create(0);
+ nvlist_move_nvlist(nvl, key, value);
+
+ actual_val = dnvlist_take_nvlist(nvl, key, default_val);
+ ATF_REQUIRE_EQ(actual_val, value);
+ ATF_REQUIRE(nvlist_empty(nvl));
+
+ free(actual_val);
+ free(default_val);
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_take_nvlist__empty);
+ATF_TEST_CASE_BODY(dnvlist_take_nvlist__empty)
+{
+ nvlist_t *nvl, *actual_val;
+
+ nvl = nvlist_create(0);
+
+ actual_val = dnvlist_take_nvlist(nvl, "123", NULL);
+ ATF_REQUIRE_EQ(actual_val, static_cast<nvlist_t *>(NULL));
+
+ free(actual_val);
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_take_nvlist__default_value);
+ATF_TEST_CASE_BODY(dnvlist_take_nvlist__default_value)
+{
+ nvlist_t *nvl;
+ nvlist_t *default_val, *actual_val;
+
+ nvl = nvlist_create(0);
+ nvlist_move_nvlist(nvl, "key", nvlist_create(0));
+ default_val = nvlist_create(0);
+
+ actual_val = dnvlist_take_nvlist(nvl, "otherkey", default_val);
+ ATF_REQUIRE_EQ(actual_val, default_val);
+
+ free(actual_val);
+ nvlist_destroy(nvl);
+}
+
+static void
+set_binary_value(void *&value, size_t &size, const char *str)
+{
+
+ value = strdup(str);
+ size = strlen(str) + 1; /* +1 to include '\0' */
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_take_binary__present);
+ATF_TEST_CASE_BODY(dnvlist_take_binary__present)
+{
+ nvlist_t *nvl;
+ const char *key;
+ void *value, *default_val, *actual_val;
+ size_t value_size, default_size, actual_size;
+
+ nvl = nvlist_create(0);
+
+ key = "name";
+ set_binary_value(value, value_size, "fkdojvmo908");
+ set_binary_value(default_val, default_size, "16546");
+ nvlist_add_binary(nvl, key, value, value_size);
+
+ actual_val = dnvlist_take_binary(nvl, key, &actual_size, default_val,
+ default_size);
+ ATF_REQUIRE_EQ(value_size, actual_size);
+ ATF_REQUIRE_EQ(memcmp(actual_val, value, value_size), 0);
+ ATF_REQUIRE(nvlist_empty(nvl));
+
+ free(actual_val);
+ free(default_val);
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_take_binary__empty);
+ATF_TEST_CASE_BODY(dnvlist_take_binary__empty)
+{
+ nvlist_t *nvl;
+ void *default_val, *actual_val;
+ size_t default_size, actual_size;
+
+ nvl = nvlist_create(0);
+ set_binary_value(default_val, default_size, "\xa8\x89\x49\xff\xe2\x08");
+
+ actual_val = dnvlist_take_binary(nvl, "123", &actual_size, default_val,
+ default_size);
+ ATF_REQUIRE_EQ(default_size, actual_size);
+ ATF_REQUIRE_EQ(memcmp(actual_val, default_val, actual_size), 0);
+
+ free(actual_val);
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_take_binary__default_value);
+ATF_TEST_CASE_BODY(dnvlist_take_binary__default_value)
+{
+ nvlist_t *nvl;
+ void *default_val, *actual_val;
+ size_t default_size, actual_size;
+
+ nvl = nvlist_create(0);
+ nvlist_add_binary(nvl, "key", "foobar", 6);
+ set_binary_value(default_val, default_size, "vbhag");
+
+ actual_val = dnvlist_take_binary(nvl, "otherkey", &actual_size,
+ default_val, default_size);
+ ATF_REQUIRE_EQ(default_size, actual_size);
+ ATF_REQUIRE_EQ(memcmp(actual_val, default_val, default_size), 0);
+
+ free(actual_val);
+ nvlist_destroy(nvl);
+}
+
+ATF_INIT_TEST_CASES(tp)
+{
+ ATF_ADD_TEST_CASE(tp, dnvlist_get_bool__present);
+ ATF_ADD_TEST_CASE(tp, dnvlist_get_bool__default_value);
+ ATF_ADD_TEST_CASE(tp, dnvlist_get_number__present);
+ ATF_ADD_TEST_CASE(tp, dnvlist_get_number__default_value);
+ ATF_ADD_TEST_CASE(tp, dnvlist_get_string__present);
+ ATF_ADD_TEST_CASE(tp, dnvlist_get_string__default_value);
+ ATF_ADD_TEST_CASE(tp, dnvlist_get_nvlist__present);
+ ATF_ADD_TEST_CASE(tp, dnvlist_get_nvlist__default_value);
+ ATF_ADD_TEST_CASE(tp, dnvlist_get_binary__present);
+ ATF_ADD_TEST_CASE(tp, dnvlist_get_binary__default_value);
+
+ ATF_ADD_TEST_CASE(tp, dnvlist_take_bool__present);
+ ATF_ADD_TEST_CASE(tp, dnvlist_take_bool__empty);
+ ATF_ADD_TEST_CASE(tp, dnvlist_take_bool__default_value);
+ ATF_ADD_TEST_CASE(tp, dnvlist_take_number__present);
+ ATF_ADD_TEST_CASE(tp, dnvlist_take_number__empty);
+ ATF_ADD_TEST_CASE(tp, dnvlist_take_number__default_value);
+ ATF_ADD_TEST_CASE(tp, dnvlist_take_string__present);
+ ATF_ADD_TEST_CASE(tp, dnvlist_take_string__empty);
+ ATF_ADD_TEST_CASE(tp, dnvlist_take_string__default_value);
+ ATF_ADD_TEST_CASE(tp, dnvlist_take_nvlist__present);
+ ATF_ADD_TEST_CASE(tp, dnvlist_take_nvlist__empty);
+ ATF_ADD_TEST_CASE(tp, dnvlist_take_nvlist__default_value);
+ ATF_ADD_TEST_CASE(tp, dnvlist_take_binary__present);
+ ATF_ADD_TEST_CASE(tp, dnvlist_take_binary__empty);
+ ATF_ADD_TEST_CASE(tp, dnvlist_take_binary__default_value);
+}
diff --git a/lib/libnv/tests/nv_tests.cc b/lib/libnv/tests/nv_tests.cc
new file mode 100644
index 0000000..d779190
--- /dev/null
+++ b/lib/libnv/tests/nv_tests.cc
@@ -0,0 +1,1275 @@
+/*-
+ * Copyright (c) 2014-2015 Sandvine Inc. All rights reserved.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <atf-c++.hpp>
+#include <nv.h>
+
+#include <errno.h>
+#include <limits>
+#include <set>
+#include <sstream>
+#include <string>
+
+/*
+ * Test that a newly created nvlist has no errors, and is empty.
+ */
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_create__is_empty);
+ATF_TEST_CASE_BODY(nvlist_create__is_empty)
+{
+ nvlist_t *nvl;
+ int type;
+ void *it;
+
+ nvl = nvlist_create(0);
+
+ ATF_REQUIRE(nvl != NULL);
+
+ ATF_REQUIRE_EQ(nvlist_error(nvl), 0);
+ ATF_REQUIRE(nvlist_empty(nvl));
+
+ it = NULL;
+ ATF_REQUIRE_EQ(nvlist_next(nvl, &type, &it), static_cast<const char *>(NULL));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_add_null__single_insert);
+ATF_TEST_CASE_BODY(nvlist_add_null__single_insert)
+{
+ nvlist_t *nvl;
+ void *it;
+ const char *key;
+ int type;
+
+ key = "key";
+ nvl = nvlist_create(0);
+
+ ATF_REQUIRE(nvl != NULL);
+ ATF_REQUIRE(!nvlist_exists(nvl, key));
+
+ nvlist_add_null(nvl, key);
+
+ ATF_REQUIRE(!nvlist_empty(nvl));
+ ATF_REQUIRE(nvlist_exists(nvl, key));
+ ATF_REQUIRE(nvlist_exists_null(nvl, key));
+ ATF_REQUIRE(nvlist_exists_null(nvl, "key"));
+
+ /* Iterate over the nvlist; ensure that it has only our one key. */
+ it = NULL;
+ ATF_REQUIRE_EQ(strcmp(nvlist_next(nvl, &type, &it), key), 0);
+ ATF_REQUIRE_EQ(type, NV_TYPE_NULL);
+ ATF_REQUIRE_EQ(nvlist_next(nvl, &type,&it), static_cast<const char *>(NULL));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_add_bool__single_insert);
+ATF_TEST_CASE_BODY(nvlist_add_bool__single_insert)
+{
+ nvlist_t *nvl;
+ void *it;
+ const char *key;
+ int type;
+
+ key = "name";
+ nvl = nvlist_create(0);
+
+ ATF_REQUIRE(nvl != NULL);
+ ATF_REQUIRE(!nvlist_exists(nvl, key));
+
+ nvlist_add_bool(nvl, key, true);
+
+ ATF_REQUIRE(!nvlist_empty(nvl));
+ ATF_REQUIRE(nvlist_exists(nvl, key));
+ ATF_REQUIRE(nvlist_exists(nvl, "name"));
+ ATF_REQUIRE(nvlist_exists_bool(nvl, key));
+ ATF_REQUIRE(nvlist_exists_bool(nvl, "name"));
+ ATF_REQUIRE_EQ(nvlist_get_bool(nvl, key), true);
+
+ /* Iterate over the nvlist; ensure that it has only our one key. */
+ it = NULL;
+ ATF_REQUIRE_EQ(strcmp(nvlist_next(nvl, &type, &it), key), 0);
+ ATF_REQUIRE_EQ(type, NV_TYPE_BOOL);
+ ATF_REQUIRE_EQ(nvlist_next(nvl, &type,&it), static_cast<const char *>(NULL));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_add_number__single_insert);
+ATF_TEST_CASE_BODY(nvlist_add_number__single_insert)
+{
+ nvlist_t *nvl;
+ void *it;
+ const char *key;
+ uint64_t value;
+ int type;
+
+ key = "foo123";
+ value = 71965;
+ nvl = nvlist_create(0);
+
+ ATF_REQUIRE(nvl != NULL);
+ ATF_REQUIRE(!nvlist_exists(nvl, key));
+
+ nvlist_add_number(nvl, key, value);
+
+ ATF_REQUIRE(!nvlist_empty(nvl));
+ ATF_REQUIRE(nvlist_exists(nvl, key));
+ ATF_REQUIRE(nvlist_exists(nvl, "foo123"));
+ ATF_REQUIRE(nvlist_exists_number(nvl, key));
+ ATF_REQUIRE_EQ(nvlist_get_number(nvl, key), value);
+
+ /* Iterate over the nvlist; ensure that it has only our one key. */
+ it = NULL;
+ ATF_REQUIRE_EQ(strcmp(nvlist_next(nvl, &type, &it), key), 0);
+ ATF_REQUIRE_EQ(type, NV_TYPE_NUMBER);
+ ATF_REQUIRE_EQ(nvlist_next(nvl, &type,&it), static_cast<const char *>(NULL));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_add_string__single_insert);
+ATF_TEST_CASE_BODY(nvlist_add_string__single_insert)
+{
+ nvlist_t *nvl;
+ void *it;
+ const char *key;
+ const char *value;
+ int type;
+
+ key = "test";
+ value = "fgjdkgjdk";
+ nvl = nvlist_create(0);
+
+ ATF_REQUIRE(nvl != NULL);
+ ATF_REQUIRE(!nvlist_exists(nvl, key));
+
+ nvlist_add_string(nvl, key, value);
+
+ ATF_REQUIRE(!nvlist_empty(nvl));
+ ATF_REQUIRE(nvlist_exists(nvl, key));
+ ATF_REQUIRE(nvlist_exists(nvl, "test"));
+ ATF_REQUIRE(nvlist_exists_string(nvl, key));
+ ATF_REQUIRE(nvlist_exists_string(nvl, "test"));
+ ATF_REQUIRE_EQ(strcmp(nvlist_get_string(nvl, key), value), 0);
+
+ /* nvlist_add_* is required to clone the value, so check for that. */
+ ATF_REQUIRE(nvlist_get_string(nvl, key) != value);
+
+ /* Iterate over the nvlist; ensure that it has only our one key. */
+ it = NULL;
+ ATF_REQUIRE_EQ(strcmp(nvlist_next(nvl, &type, &it), key), 0);
+ ATF_REQUIRE_EQ(type, NV_TYPE_STRING);
+ ATF_REQUIRE_EQ(nvlist_next(nvl, &type,&it), static_cast<const char *>(NULL));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_add_nvlist__single_insert);
+ATF_TEST_CASE_BODY(nvlist_add_nvlist__single_insert)
+{
+ nvlist_t *nvl;
+ void *it;
+ const char *key, *subkey;
+ nvlist_t *sublist;
+ const nvlist_t *value;
+ int type;
+
+ key = "test";
+ subkey = "subkey";
+ sublist = nvlist_create(0);
+ nvl = nvlist_create(0);
+
+ ATF_REQUIRE(nvl != NULL);
+ ATF_REQUIRE(!nvlist_exists(nvl, key));
+
+ nvlist_add_null(sublist, subkey);
+ nvlist_add_nvlist(nvl, key, sublist);
+
+ ATF_REQUIRE(!nvlist_empty(nvl));
+ ATF_REQUIRE(nvlist_exists(nvl, key));
+ ATF_REQUIRE(nvlist_exists(nvl, "test"));
+ ATF_REQUIRE(nvlist_exists_nvlist(nvl, key));
+ ATF_REQUIRE(nvlist_exists_nvlist(nvl, "test"));
+
+ value = nvlist_get_nvlist(nvl, key);
+ ATF_REQUIRE(nvlist_exists_null(value, subkey));
+
+ /* nvlist_add_* is required to clone the value, so check for that. */
+ ATF_REQUIRE(sublist != value);
+
+ /* Iterate over the nvlist; ensure that it has only our one key. */
+ it = NULL;
+ ATF_REQUIRE_EQ(strcmp(nvlist_next(nvl, &type, &it), key), 0);
+ ATF_REQUIRE_EQ(type, NV_TYPE_NVLIST);
+ ATF_REQUIRE_EQ(nvlist_next(nvl, &type,&it), static_cast<const char *>(NULL));
+
+ nvlist_destroy(sublist);
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_add_nvlist__child_with_error);
+ATF_TEST_CASE_BODY(nvlist_add_nvlist__child_with_error)
+{
+ nvlist_t *nvl, *parent;
+
+ nvl = nvlist_create(0);
+ parent = nvlist_create(0);
+
+ nvlist_set_error(nvl, EBADF);
+ nvlist_add_nvlist(parent, "test", nvl);
+ ATF_REQUIRE_EQ(nvlist_error(parent), EBADF);
+
+ nvlist_destroy(nvl);
+ nvlist_destroy(parent);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_add_binary__single_insert);
+ATF_TEST_CASE_BODY(nvlist_add_binary__single_insert)
+{
+ nvlist_t *nvl;
+ void *it;
+ const char *key;
+ void *value;
+ const void *ret_value;
+ size_t value_size, ret_size;
+ int type;
+
+ key = "binary";
+ value_size = 13;
+ value = malloc(value_size);
+ memset(value, 0xa5, value_size);
+ nvl = nvlist_create(0);
+
+ ATF_REQUIRE(nvl != NULL);
+ ATF_REQUIRE(!nvlist_exists(nvl, key));
+
+ nvlist_add_binary(nvl, key, value, value_size);
+
+ ATF_REQUIRE(!nvlist_empty(nvl));
+ ATF_REQUIRE(nvlist_exists(nvl, key));
+ ATF_REQUIRE(nvlist_exists(nvl, "binary"));
+ ATF_REQUIRE(nvlist_exists_binary(nvl, key));
+ ATF_REQUIRE(nvlist_exists_binary(nvl, "binary"));
+
+ ret_value = nvlist_get_binary(nvl, key, &ret_size);
+ ATF_REQUIRE_EQ(value_size, ret_size);
+ ATF_REQUIRE_EQ(memcmp(value, ret_value, ret_size), 0);
+
+ /* nvlist_add_* is required to clone the value, so check for that. */
+ ATF_REQUIRE(value != ret_value);
+
+ /* Iterate over the nvlist; ensure that it has only our one key. */
+ it = NULL;
+ ATF_REQUIRE_EQ(strcmp(nvlist_next(nvl, &type, &it), key), 0);
+ ATF_REQUIRE_EQ(type, NV_TYPE_BINARY);
+ ATF_REQUIRE_EQ(nvlist_next(nvl, &type,&it), static_cast<const char *>(NULL));
+
+ nvlist_destroy(nvl);
+ free(value);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_clone__empty_nvlist);
+ATF_TEST_CASE_BODY(nvlist_clone__empty_nvlist)
+{
+ nvlist_t *nvl, *clone;
+
+ nvl = nvlist_create(0);
+ ATF_REQUIRE(nvl != NULL);
+
+ clone = nvlist_clone(nvl);
+ ATF_REQUIRE(clone != NULL);
+ ATF_REQUIRE(clone != nvl);
+ ATF_REQUIRE(nvlist_empty(clone));
+
+ nvlist_destroy(clone);
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_clone__nonempty_nvlist);
+ATF_TEST_CASE_BODY(nvlist_clone__nonempty_nvlist)
+{
+ nvlist_t *nvl, *clone;
+ const char *key;
+ void *it;
+ uint64_t value;
+ int type;
+
+ nvl = nvlist_create(0);
+ ATF_REQUIRE(nvl != NULL);
+
+ key = "testkey";
+ value = 684874;
+ nvlist_add_number(nvl, key, value);
+
+ clone = nvlist_clone(nvl);
+ ATF_REQUIRE(clone != NULL);
+ ATF_REQUIRE(clone != nvl);
+ ATF_REQUIRE(nvlist_exists_number(clone, key));
+ ATF_REQUIRE_EQ(nvlist_get_number(clone, key), value);
+
+ /* Iterate over the nvlist; ensure that it has only our one key. */
+ it = NULL;
+ ATF_REQUIRE_EQ(strcmp(nvlist_next(clone, &type, &it), key), 0);
+ ATF_REQUIRE_EQ(type, NV_TYPE_NUMBER);
+ ATF_REQUIRE_EQ(nvlist_next(clone, &type, &it), static_cast<const char *>(NULL));
+
+ nvlist_destroy(clone);
+ nvlist_destroy(nvl);
+}
+
+static const char * const test_subnvlist_key = "nvlist";
+
+static const char * const test_string_key = "string";
+static const char * const test_string_val = "59525";
+
+static nvlist_t*
+create_test_nvlist(void)
+{
+ nvlist_t *nvl, *sublist;
+
+ nvl = nvlist_create(0);
+ ATF_REQUIRE(nvl != NULL);
+
+ sublist = nvlist_create(0);
+ ATF_REQUIRE(sublist != NULL);
+
+ nvlist_add_string(sublist, test_string_key, test_string_val);
+ nvlist_move_nvlist(nvl, test_subnvlist_key, sublist);
+
+ return (nvl);
+}
+
+static void
+verify_test_nvlist(const nvlist_t *nvl)
+{
+ void *it;
+ const nvlist_t *value;
+ int type;
+
+ ATF_REQUIRE(nvlist_exists_nvlist(nvl, test_subnvlist_key));
+
+ value = nvlist_get_nvlist(nvl, test_subnvlist_key);
+
+ ATF_REQUIRE(nvlist_exists_string(value, test_string_key));
+ ATF_REQUIRE_EQ(strcmp(nvlist_get_string(value, test_string_key), test_string_val), 0);
+ ATF_REQUIRE(nvlist_get_string(value, test_string_key) != test_string_val);
+
+ /* Iterate over both nvlists; ensure that each has only the one key. */
+ it = NULL;
+ ATF_REQUIRE_EQ(strcmp(nvlist_next(value, &type, &it),
+ test_string_key), 0);
+ ATF_REQUIRE_EQ(type, NV_TYPE_STRING);
+ ATF_REQUIRE_EQ(nvlist_next(value, &type, &it), static_cast<const char *>(NULL));
+
+ it = NULL;
+ ATF_REQUIRE_EQ(strcmp(nvlist_next(nvl, &type, &it),
+ test_subnvlist_key), 0);
+ ATF_REQUIRE_EQ(type, NV_TYPE_NVLIST);
+ ATF_REQUIRE_EQ(nvlist_next(nvl, &type, &it), static_cast<const char *>(NULL));
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_clone__nested_nvlist);
+ATF_TEST_CASE_BODY(nvlist_clone__nested_nvlist)
+{
+ nvlist_t *nvl, *clone;
+
+ nvl = create_test_nvlist();
+ clone = nvlist_clone(nvl);
+
+ ATF_REQUIRE(clone != NULL);
+ ATF_REQUIRE(clone != nvl);
+ verify_test_nvlist(clone);
+
+ nvlist_destroy(clone);
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_clone__error_nvlist);
+ATF_TEST_CASE_BODY(nvlist_clone__error_nvlist)
+{
+ nvlist_t *nvl, *clone;
+
+ nvl = nvlist_create(0);
+ ATF_REQUIRE(nvl != NULL);
+
+ nvlist_set_error(nvl, ENOMEM);
+
+ clone = nvlist_clone(nvl);
+ ATF_REQUIRE(clone == NULL);
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_pack__empty_nvlist);
+ATF_TEST_CASE_BODY(nvlist_pack__empty_nvlist)
+{
+ nvlist_t *nvl, *unpacked;
+ void *packed;
+ size_t packed_size;
+
+ nvl = nvlist_create(0);
+ ATF_REQUIRE(nvl != NULL);
+
+ packed = nvlist_pack(nvl, &packed_size);
+ ATF_REQUIRE(packed != NULL);
+
+ unpacked = nvlist_unpack(packed, packed_size, 0);
+ ATF_REQUIRE(unpacked != NULL);
+ ATF_REQUIRE(unpacked != nvl);
+ ATF_REQUIRE(nvlist_empty(unpacked));
+
+ nvlist_destroy(unpacked);
+ nvlist_destroy(nvl);
+ free(packed);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_unpack__flags_nvlist);
+ATF_TEST_CASE_BODY(nvlist_unpack__flags_nvlist)
+{
+ nvlist_t *nvl, *unpacked;
+ void *packed;
+ size_t packed_size;
+
+ nvl = nvlist_create(NV_FLAG_NO_UNIQUE);
+ ATF_REQUIRE(nvl != NULL);
+
+ nvlist_add_bool(nvl, "name", true);
+ ATF_REQUIRE(!nvlist_empty(nvl));
+ ATF_REQUIRE(nvlist_exists_bool(nvl, "name"));
+
+ packed = nvlist_pack(nvl, &packed_size);
+ ATF_REQUIRE(packed != NULL);
+
+ unpacked = nvlist_unpack(packed, packed_size, 0);
+ ATF_REQUIRE(unpacked == NULL);
+
+ unpacked = nvlist_unpack(packed, packed_size, NV_FLAG_IGNORE_CASE);
+ ATF_REQUIRE(unpacked == NULL);
+
+ unpacked = nvlist_unpack(packed, packed_size, NV_FLAG_NO_UNIQUE);
+ ATF_REQUIRE(unpacked != NULL);
+ ATF_REQUIRE(unpacked != nvl);
+ ATF_REQUIRE(!nvlist_empty(unpacked));
+ ATF_REQUIRE(nvlist_exists_bool(unpacked, "name"));
+
+ nvlist_destroy(unpacked);
+ nvlist_destroy(nvl);
+ free(packed);
+}
+
+static void
+verify_null(const nvlist_t *nvl, int type)
+{
+
+ ATF_REQUIRE_EQ(type, NV_TYPE_NULL);
+}
+
+static void
+verify_number(const nvlist_t *nvl, const char *name, int type, uint64_t value)
+{
+
+ ATF_REQUIRE_EQ(type, NV_TYPE_NUMBER);
+ ATF_REQUIRE_EQ(nvlist_get_number(nvl, name), value);
+}
+
+static void
+verify_string(const nvlist_t *nvl, const char *name, int type,
+ const char * value)
+{
+
+ ATF_REQUIRE_EQ(type, NV_TYPE_STRING);
+ ATF_REQUIRE_EQ(strcmp(nvlist_get_string(nvl, name), value), 0);
+}
+
+static void
+verify_nvlist(const nvlist_t *nvl, const char *name, int type)
+{
+
+ ATF_REQUIRE_EQ(type, NV_TYPE_NVLIST);
+ verify_test_nvlist(nvlist_get_nvlist(nvl, name));
+}
+
+static void
+verify_binary(const nvlist_t *nvl, const char *name, int type,
+ const void * value, size_t size)
+{
+ const void *actual_value;
+ size_t actual_size;
+
+ ATF_REQUIRE_EQ(type, NV_TYPE_BINARY);
+ actual_value = nvlist_get_binary(nvl, name, &actual_size);
+ ATF_REQUIRE_EQ(size, actual_size);
+ ATF_REQUIRE_EQ(memcmp(value, actual_value, size), 0);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_pack__multiple_values);
+ATF_TEST_CASE_BODY(nvlist_pack__multiple_values)
+{
+ std::ostringstream msg;
+ std::set<std::string> keys_seen;
+ nvlist_t *nvl, *unpacked, *nvvalue;
+ const char *nullkey, *numkey, *strkey, *nvkey, *binkey, *name;
+ int numvalue;
+ const char * strvalue;
+ void *binvalue, *packed, *it;
+ size_t binsize, packed_size;
+ int type;
+
+ nvl = nvlist_create(0);
+
+ nullkey = "null";
+ nvlist_add_null(nvl, nullkey);
+
+ numkey = "number";
+ numvalue = 939853984;
+ nvlist_add_number(nvl, numkey, numvalue);
+
+ strkey = "string";
+ strvalue = "jfieutijf";
+ nvlist_add_string(nvl, strkey, strvalue);
+
+ nvkey = "nvlist";
+ nvvalue = create_test_nvlist();
+ nvlist_move_nvlist(nvl, nvkey, nvvalue);
+
+ binkey = "binary";
+ binsize = 4;
+ binvalue = malloc(binsize);
+ memset(binvalue, 'b', binsize);
+ nvlist_move_binary(nvl, binkey, binvalue, binsize);
+
+ packed = nvlist_pack(nvl, &packed_size);
+ ATF_REQUIRE(packed != NULL);
+
+ unpacked = nvlist_unpack(packed, packed_size, 0);
+ ATF_REQUIRE(unpacked != 0);
+
+ it = NULL;
+ while ((name = nvlist_next(unpacked, &type, &it)) != NULL) {
+ /* Ensure that we see every key only once. */
+ ATF_REQUIRE_EQ(keys_seen.count(name), 0);
+
+ if (strcmp(name, nullkey) == 0)
+ verify_null(unpacked, type);
+ else if (strcmp(name, numkey) == 0)
+ verify_number(unpacked, name, type, numvalue);
+ else if (strcmp(name, strkey) == 0)
+ verify_string(unpacked, name, type, strvalue);
+ else if (strcmp(name, nvkey) == 0)
+ verify_nvlist(unpacked, name, type);
+ else if (strcmp(name, binkey) == 0)
+ verify_binary(unpacked, name, type, binvalue, binsize);
+ else {
+ msg << "Unexpected key :'" << name << "'";
+ ATF_FAIL(msg.str().c_str());
+ }
+
+ keys_seen.insert(name);
+ }
+
+ /* Ensure that we saw every key. */
+ ATF_REQUIRE_EQ(keys_seen.size(), 5);
+
+ nvlist_destroy(nvl);
+ nvlist_destroy(unpacked);
+ free(packed);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_pack__error_nvlist);
+ATF_TEST_CASE_BODY(nvlist_pack__error_nvlist)
+{
+ nvlist_t *nvl;
+ void *packed;
+ size_t size;
+
+ nvl = nvlist_create(0);
+ ATF_REQUIRE(nvl != NULL);
+
+ nvlist_set_error(nvl, ENOMEM);
+
+ packed = nvlist_pack(nvl, &size);
+ ATF_REQUIRE(packed == NULL);
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_unpack__duplicate_key);
+ATF_TEST_CASE_BODY(nvlist_unpack__duplicate_key)
+{
+ nvlist_t *nvl, *unpacked;
+ const char *key1, *key2;
+ void *packed, *keypos;
+ size_t size, keylen;
+
+ nvl = nvlist_create(0);
+
+ key1 = "key1";
+ keylen = strlen(key1);
+ nvlist_add_number(nvl, key1, 5);
+
+ key2 = "key2";
+ ATF_REQUIRE_EQ(keylen, strlen(key2));
+ nvlist_add_number(nvl, key2, 10);
+
+ packed = nvlist_pack(nvl, &size);
+
+ /*
+ * Mangle the packed nvlist by replacing key1 with key2, creating a
+ * packed nvlist with a duplicate key.
+ */
+ keypos = memmem(packed, size, key1, keylen);
+ ATF_REQUIRE(keypos != NULL);
+ memcpy(keypos, key2, keylen);
+
+ unpacked = nvlist_unpack(packed, size, 0);
+ ATF_REQUIRE(nvlist_error(unpacked) != 0);
+
+ free(packed);
+ nvlist_destroy(nvl);
+ nvlist_destroy(unpacked);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_move_string__single_insert);
+ATF_TEST_CASE_BODY(nvlist_move_string__single_insert)
+{
+ nvlist_t *nvl;
+ const char *key;
+ char *value;
+
+ nvl = nvlist_create(0);
+ ATF_REQUIRE(nvl != NULL);
+
+ key = "testkey";
+ value = strdup("testval");
+ ATF_REQUIRE(value != NULL);
+
+ nvlist_move_string(nvl, key, value);
+ ATF_REQUIRE_EQ(nvlist_get_string(nvl, key), value);
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_move_nvlist__null_child);
+ATF_TEST_CASE_BODY(nvlist_move_nvlist__null_child)
+{
+ nvlist_t *parent;
+
+ parent = nvlist_create(0);
+
+ nvlist_move_nvlist(parent, "test", NULL);
+
+ ATF_REQUIRE(nvlist_error(parent) != 0);
+
+ nvlist_destroy(parent);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_move_nvlist__child_with_error);
+ATF_TEST_CASE_BODY(nvlist_move_nvlist__child_with_error)
+{
+ nvlist_t *nvl, *parent;
+
+ nvl = nvlist_create(0);
+ parent = nvlist_create(0);
+
+ nvlist_set_error(nvl, EBADF);
+ nvlist_move_nvlist(parent, "test", nvl);
+ ATF_REQUIRE_EQ(nvlist_error(parent), EBADF);
+
+ nvlist_destroy(parent);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_move_nvlist__single_insert);
+ATF_TEST_CASE_BODY(nvlist_move_nvlist__single_insert)
+{
+ nvlist_t *nvl;
+ const char *key;
+ nvlist_t *value;
+
+ nvl = nvlist_create(0);
+ ATF_REQUIRE(nvl != NULL);
+
+ key = "testkey";
+ value = nvlist_create(0);
+ ATF_REQUIRE(value != NULL);
+
+ nvlist_move_nvlist(nvl, key, value);
+ ATF_REQUIRE_EQ(nvlist_get_nvlist(nvl, key), value);
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_move_binary__single_insert);
+ATF_TEST_CASE_BODY(nvlist_move_binary__single_insert)
+{
+ nvlist_t *nvl;
+ const char *key;
+ void *value;
+ size_t size, actual_size;
+
+ nvl = nvlist_create(0);
+ ATF_REQUIRE(nvl != NULL);
+
+ key = "testkey";
+ size = 73;
+ value = malloc(size);
+ ATF_REQUIRE(value != NULL);
+
+ nvlist_move_binary(nvl, key, value, size);
+ ATF_REQUIRE_EQ(nvlist_get_binary(nvl, key, &actual_size), value);
+ ATF_REQUIRE_EQ(size, actual_size);
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_bool__single_remove);
+ATF_TEST_CASE_BODY(nvlist_take_bool__single_remove)
+{
+ nvlist_t *nvl;
+ const char *testkey;
+ bool testval;
+
+ nvl = nvlist_create(0);
+ ATF_REQUIRE(nvl != NULL);
+
+ testkey = "boolkey";
+ testval = false;
+ nvlist_add_bool(nvl, testkey, testval);
+
+ ATF_REQUIRE_EQ(nvlist_take_bool(nvl, testkey), testval);
+ ATF_REQUIRE(nvlist_empty(nvl));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_bool__other_keys_unchanged);
+ATF_TEST_CASE_BODY(nvlist_take_bool__other_keys_unchanged)
+{
+ nvlist_t *nvl;
+ const char *testkey, *otherkey1, *otherkey2;
+ bool testval, otherval1;
+ nvlist_t *otherval2;
+
+ nvl = nvlist_create(0);
+ ATF_REQUIRE(nvl != NULL);
+
+ testkey = "boolkey";
+ testval = true;
+ nvlist_add_bool(nvl, testkey, testval);
+
+ otherkey1 = "key1";
+ otherval1 = false;
+ nvlist_add_bool(nvl, otherkey1, otherval1);
+
+ otherkey2 = "key2";
+ otherval2 = create_test_nvlist();
+ nvlist_move_nvlist(nvl, otherkey2, otherval2);
+
+ ATF_REQUIRE_EQ(nvlist_take_bool(nvl, testkey), testval);
+
+ ATF_REQUIRE(nvlist_exists_bool(nvl, otherkey1));
+ ATF_REQUIRE_EQ(nvlist_get_bool(nvl, otherkey1), otherval1);
+
+ ATF_REQUIRE(nvlist_exists_nvlist(nvl, otherkey2));
+ verify_test_nvlist(nvlist_get_nvlist(nvl, otherkey2));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_number__single_remove);
+ATF_TEST_CASE_BODY(nvlist_take_number__single_remove)
+{
+ nvlist_t *nvl;
+ const char *testkey;
+ uint64_t testval;
+
+ nvl = nvlist_create(0);
+ ATF_REQUIRE(nvl != NULL);
+
+ testkey = "numkey";
+ testval = std::numeric_limits<uint64_t>::max();
+ nvlist_add_number(nvl, testkey, testval);
+
+ ATF_REQUIRE_EQ(nvlist_take_number(nvl, testkey), testval);
+ ATF_REQUIRE(nvlist_empty(nvl));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_number__other_keys_unchanged);
+ATF_TEST_CASE_BODY(nvlist_take_number__other_keys_unchanged)
+{
+ nvlist_t *nvl;
+ const char *testkey, *otherkey1, *otherkey2;
+ uint64_t testval, otherval1;
+ const char *otherval2;
+
+ nvl = nvlist_create(0);
+ ATF_REQUIRE(nvl != NULL);
+
+ otherkey1 = "key1";
+ otherval1 = 5;
+ nvlist_add_number(nvl, otherkey1, otherval1);
+
+ testkey = "numkey";
+ testval = 1654;
+ nvlist_add_number(nvl, testkey, testval);
+
+ otherkey2 = "key2";
+ otherval2 = "string";
+ nvlist_add_string(nvl, otherkey2, otherval2);
+
+ ATF_REQUIRE_EQ(nvlist_take_number(nvl, testkey), testval);
+
+ ATF_REQUIRE(nvlist_exists_number(nvl, otherkey1));
+ ATF_REQUIRE_EQ(nvlist_get_number(nvl, otherkey1), otherval1);
+
+ ATF_REQUIRE(nvlist_exists_string(nvl, otherkey2));
+ ATF_REQUIRE_EQ(strcmp(nvlist_get_string(nvl, otherkey2), otherval2), 0);
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_string__single_remove);
+ATF_TEST_CASE_BODY(nvlist_take_string__single_remove)
+{
+ nvlist_t *nvl;
+ const char *testkey;
+ const char *testval;
+
+ nvl = nvlist_create(0);
+ ATF_REQUIRE(nvl != NULL);
+
+ testkey = "numkey";
+ testval = "nvlist";
+ nvlist_add_string(nvl, testkey, testval);
+
+ ATF_REQUIRE_EQ(strcmp(nvlist_take_string(nvl, testkey), testval), 0);
+ ATF_REQUIRE(nvlist_empty(nvl));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_string__other_keys_unchanged);
+ATF_TEST_CASE_BODY(nvlist_take_string__other_keys_unchanged)
+{
+ nvlist_t *nvl;
+ const char *testkey, *otherkey1, *otherkey2;
+ const char *testval, *otherval1;
+ bool otherval2;
+
+ nvl = nvlist_create(0);
+ ATF_REQUIRE(nvl != NULL);
+
+ otherkey1 = "key1";
+ otherval1 = "fjdifjdk";
+ nvlist_add_string(nvl, otherkey1, otherval1);
+
+ otherkey2 = "key2";
+ otherval2 = true;
+ nvlist_add_bool(nvl, otherkey2, otherval2);
+
+ testkey = "strkey";
+ testval = "1654";
+ nvlist_add_string(nvl, testkey, testval);
+
+ ATF_REQUIRE_EQ(strcmp(nvlist_take_string(nvl, testkey), testval), 0);
+
+ ATF_REQUIRE(nvlist_exists_string(nvl, otherkey1));
+ ATF_REQUIRE_EQ(strcmp(nvlist_get_string(nvl, otherkey1), otherval1), 0);
+
+ ATF_REQUIRE(nvlist_exists_bool(nvl, otherkey2));
+ ATF_REQUIRE_EQ(nvlist_get_bool(nvl, otherkey2), otherval2);
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_nvlist__single_remove);
+ATF_TEST_CASE_BODY(nvlist_take_nvlist__single_remove)
+{
+ nvlist_t *nvl;
+ const char *testkey;
+ nvlist_t *testval;
+
+ nvl = nvlist_create(0);
+ ATF_REQUIRE(nvl != NULL);
+
+ testkey = "numkey";
+ testval = create_test_nvlist();
+ nvlist_move_nvlist(nvl, testkey, testval);
+
+ verify_test_nvlist(nvlist_take_nvlist(nvl, testkey));
+ ATF_REQUIRE(nvlist_empty(nvl));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_nvlist__other_keys_unchanged);
+ATF_TEST_CASE_BODY(nvlist_take_nvlist__other_keys_unchanged)
+{
+ nvlist_t *nvl;
+ const char *testkey, *otherkey1, *otherkey2;
+ nvlist_t *testval, *otherval1;
+
+ nvl = nvlist_create(0);
+ ATF_REQUIRE(nvl != NULL);
+
+ testkey = "strkey";
+ testval = create_test_nvlist();
+ nvlist_move_nvlist(nvl, testkey, testval);
+
+ otherkey1 = "key1";
+ otherval1 = nvlist_create(0);
+ nvlist_move_nvlist(nvl, otherkey1, otherval1);
+
+ otherkey2 = "key2";
+ nvlist_add_null(nvl, otherkey2);
+
+ verify_test_nvlist(nvlist_take_nvlist(nvl, testkey));
+
+ ATF_REQUIRE(nvlist_exists_nvlist(nvl, otherkey1));
+ ATF_REQUIRE(nvlist_empty(nvlist_get_nvlist(nvl, otherkey1)));
+
+ ATF_REQUIRE(nvlist_exists_null(nvl, otherkey2));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_binary__single_remove);
+ATF_TEST_CASE_BODY(nvlist_take_binary__single_remove)
+{
+ nvlist_t *nvl;
+ const char *testkey;
+ void *testval;
+ const void *actual_val;
+ size_t testsize, actual_size;
+
+ nvl = nvlist_create(0);
+ ATF_REQUIRE(nvl != NULL);
+
+ testkey = "numkey";
+ testsize = 457;
+ testval = malloc(testsize);
+ memset(testval, '5', testsize);
+ nvlist_move_binary(nvl, testkey, testval, testsize);
+
+ actual_val = nvlist_take_binary(nvl, testkey, &actual_size);
+ ATF_REQUIRE_EQ(testsize, actual_size);
+ ATF_REQUIRE_EQ(memcmp(actual_val, testval, testsize), 0);
+ ATF_REQUIRE(nvlist_empty(nvl));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_binary__other_keys_unchanged);
+ATF_TEST_CASE_BODY(nvlist_take_binary__other_keys_unchanged)
+{
+ nvlist_t *nvl;
+ const char *testkey, *otherkey1, *otherkey2;
+ const void *actual_value;
+ char testval[] = "gjiertj";
+ char otherval1[] = "fdreg";
+ size_t testsize, othersize, actual_size;
+ bool otherval2;
+
+ nvl = nvlist_create(0);
+ ATF_REQUIRE(nvl != NULL);
+
+ otherkey1 = "key1";
+ othersize = sizeof(otherval1);
+ nvlist_add_binary(nvl, otherkey1, otherval1, othersize);
+
+ otherkey2 = "key2";
+ otherval2 = true;
+ nvlist_add_bool(nvl, otherkey2, otherval2);
+
+ testkey = "strkey";
+ testsize = sizeof(testval);
+ nvlist_add_binary(nvl, testkey, testval, testsize);
+
+ actual_value = nvlist_take_binary(nvl, testkey, &actual_size);
+ ATF_REQUIRE_EQ(testsize, actual_size);
+ ATF_REQUIRE_EQ(memcmp(actual_value, testval, testsize), 0);
+
+ ATF_REQUIRE(nvlist_exists_binary(nvl, otherkey1));
+ actual_value = nvlist_get_binary(nvl, otherkey1, &actual_size);
+ ATF_REQUIRE_EQ(othersize, actual_size);
+ ATF_REQUIRE_EQ(memcmp(actual_value, otherval1, othersize), 0);
+
+ ATF_REQUIRE(nvlist_exists_bool(nvl, otherkey2));
+ ATF_REQUIRE_EQ(nvlist_get_bool(nvl, otherkey2), otherval2);
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free__single_null);
+ATF_TEST_CASE_BODY(nvlist_free__single_null)
+{
+ nvlist_t *nvl;
+ const char *key;
+
+ nvl = nvlist_create(0);
+ key = "test";
+ nvlist_add_null(nvl, key);
+
+ nvlist_free(nvl, key);
+ ATF_REQUIRE(nvlist_empty(nvl));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free__single_bool);
+ATF_TEST_CASE_BODY(nvlist_free__single_bool)
+{
+ nvlist_t *nvl;
+ const char *key;
+
+ nvl = nvlist_create(0);
+ key = "test";
+ nvlist_add_bool(nvl, key, true);
+
+ nvlist_free(nvl, key);
+ ATF_REQUIRE(nvlist_empty(nvl));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free__single_number);
+ATF_TEST_CASE_BODY(nvlist_free__single_number)
+{
+ nvlist_t *nvl;
+ const char *key;
+
+ nvl = nvlist_create(0);
+ key = "test";
+ nvlist_add_number(nvl, key, 584);
+
+ nvlist_free(nvl, key);
+ ATF_REQUIRE(nvlist_empty(nvl));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free__single_string);
+ATF_TEST_CASE_BODY(nvlist_free__single_string)
+{
+ nvlist_t *nvl;
+ const char *key;
+
+ nvl = nvlist_create(0);
+ key = "test";
+ nvlist_add_string(nvl, key, "gjkfkjd");
+
+ nvlist_free(nvl, key);
+ ATF_REQUIRE(nvlist_empty(nvl));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free__single_nvlist);
+ATF_TEST_CASE_BODY(nvlist_free__single_nvlist)
+{
+ nvlist_t *nvl;
+ const char *key;
+
+ nvl = nvlist_create(0);
+ key = "test";
+ nvlist_add_nvlist(nvl, key, nvlist_create(0));
+
+ nvlist_free(nvl, key);
+ ATF_REQUIRE(nvlist_empty(nvl));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free__single_binary);
+ATF_TEST_CASE_BODY(nvlist_free__single_binary)
+{
+ nvlist_t *nvl;
+ const char *key;
+
+ nvl = nvlist_create(0);
+ key = "test";
+ nvlist_add_binary(nvl, key, "jgjgfd", 6);
+
+ nvlist_free(nvl, key);
+ ATF_REQUIRE(nvlist_empty(nvl));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free_null__single_null);
+ATF_TEST_CASE_BODY(nvlist_free_null__single_null)
+{
+ nvlist_t *nvl;
+ const char *key;
+
+ nvl = nvlist_create(0);
+ key = "test";
+ nvlist_add_null(nvl, key);
+
+ nvlist_free_null(nvl, key);
+ ATF_REQUIRE(nvlist_empty(nvl));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free_bool__single_bool);
+ATF_TEST_CASE_BODY(nvlist_free_bool__single_bool)
+{
+ nvlist_t *nvl;
+ const char *key;
+
+ nvl = nvlist_create(0);
+ key = "test";
+ nvlist_add_bool(nvl, key, true);
+
+ nvlist_free_bool(nvl, key);
+ ATF_REQUIRE(nvlist_empty(nvl));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free_number__single_number);
+ATF_TEST_CASE_BODY(nvlist_free_number__single_number)
+{
+ nvlist_t *nvl;
+ const char *key;
+
+ nvl = nvlist_create(0);
+ key = "test";
+ nvlist_add_number(nvl, key, 584);
+
+ nvlist_free_number(nvl, key);
+ ATF_REQUIRE(nvlist_empty(nvl));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free_string__single_string);
+ATF_TEST_CASE_BODY(nvlist_free_string__single_string)
+{
+ nvlist_t *nvl;
+ const char *key;
+
+ nvl = nvlist_create(0);
+ key = "test";
+ nvlist_add_string(nvl, key, "gjkfkjd");
+
+ nvlist_free_string(nvl, key);
+ ATF_REQUIRE(nvlist_empty(nvl));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free_nvlist__single_nvlist);
+ATF_TEST_CASE_BODY(nvlist_free_nvlist__single_nvlist)
+{
+ nvlist_t *nvl;
+ const char *key;
+
+ nvl = nvlist_create(0);
+ key = "test";
+ nvlist_add_nvlist(nvl, key, nvlist_create(0));
+
+ nvlist_free_nvlist(nvl, key);
+ ATF_REQUIRE(nvlist_empty(nvl));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free_binary__single_binary);
+ATF_TEST_CASE_BODY(nvlist_free_binary__single_binary)
+{
+ nvlist_t *nvl;
+ const char *key;
+
+ nvl = nvlist_create(0);
+ key = "test";
+ nvlist_add_binary(nvl, key, "jgjgfd", 6);
+
+ nvlist_free_binary(nvl, key);
+ ATF_REQUIRE(nvlist_empty(nvl));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_INIT_TEST_CASES(tp)
+{
+ ATF_ADD_TEST_CASE(tp, nvlist_create__is_empty);
+ ATF_ADD_TEST_CASE(tp, nvlist_add_null__single_insert);
+ ATF_ADD_TEST_CASE(tp, nvlist_add_bool__single_insert);
+ ATF_ADD_TEST_CASE(tp, nvlist_add_number__single_insert);
+ ATF_ADD_TEST_CASE(tp, nvlist_add_string__single_insert);
+ ATF_ADD_TEST_CASE(tp, nvlist_add_nvlist__single_insert);
+ ATF_ADD_TEST_CASE(tp, nvlist_add_nvlist__child_with_error);
+ ATF_ADD_TEST_CASE(tp, nvlist_add_binary__single_insert);
+
+ ATF_ADD_TEST_CASE(tp, nvlist_clone__empty_nvlist);
+ ATF_ADD_TEST_CASE(tp, nvlist_clone__nonempty_nvlist);
+ ATF_ADD_TEST_CASE(tp, nvlist_clone__nested_nvlist);
+ ATF_ADD_TEST_CASE(tp, nvlist_clone__error_nvlist);
+
+ ATF_ADD_TEST_CASE(tp, nvlist_pack__empty_nvlist);
+ ATF_ADD_TEST_CASE(tp, nvlist_pack__multiple_values);
+ ATF_ADD_TEST_CASE(tp, nvlist_pack__error_nvlist);
+ ATF_ADD_TEST_CASE(tp, nvlist_unpack__duplicate_key);
+ ATF_ADD_TEST_CASE(tp, nvlist_unpack__flags_nvlist);
+
+ ATF_ADD_TEST_CASE(tp, nvlist_move_string__single_insert);
+ ATF_ADD_TEST_CASE(tp, nvlist_move_nvlist__single_insert);
+ ATF_ADD_TEST_CASE(tp, nvlist_move_nvlist__null_child);
+ ATF_ADD_TEST_CASE(tp, nvlist_move_nvlist__child_with_error);
+ ATF_ADD_TEST_CASE(tp, nvlist_move_binary__single_insert);
+
+ ATF_ADD_TEST_CASE(tp, nvlist_take_bool__single_remove);
+ ATF_ADD_TEST_CASE(tp, nvlist_take_bool__other_keys_unchanged);
+ ATF_ADD_TEST_CASE(tp, nvlist_take_number__single_remove);
+ ATF_ADD_TEST_CASE(tp, nvlist_take_number__other_keys_unchanged);
+ ATF_ADD_TEST_CASE(tp, nvlist_take_string__single_remove);
+ ATF_ADD_TEST_CASE(tp, nvlist_take_string__other_keys_unchanged);
+ ATF_ADD_TEST_CASE(tp, nvlist_take_nvlist__single_remove);
+ ATF_ADD_TEST_CASE(tp, nvlist_take_nvlist__other_keys_unchanged);
+ ATF_ADD_TEST_CASE(tp, nvlist_take_binary__single_remove);
+ ATF_ADD_TEST_CASE(tp, nvlist_take_binary__other_keys_unchanged);
+
+ ATF_ADD_TEST_CASE(tp, nvlist_free__single_null);
+ ATF_ADD_TEST_CASE(tp, nvlist_free__single_bool);
+ ATF_ADD_TEST_CASE(tp, nvlist_free__single_number);
+ ATF_ADD_TEST_CASE(tp, nvlist_free__single_string);
+ ATF_ADD_TEST_CASE(tp, nvlist_free__single_nvlist);
+ ATF_ADD_TEST_CASE(tp, nvlist_free__single_binary);
+
+ ATF_ADD_TEST_CASE(tp, nvlist_free_null__single_null);
+ ATF_ADD_TEST_CASE(tp, nvlist_free_bool__single_bool);
+ ATF_ADD_TEST_CASE(tp, nvlist_free_number__single_number);
+ ATF_ADD_TEST_CASE(tp, nvlist_free_string__single_string);
+ ATF_ADD_TEST_CASE(tp, nvlist_free_nvlist__single_nvlist);
+ ATF_ADD_TEST_CASE(tp, nvlist_free_binary__single_binary);
+}
diff --git a/lib/libnv/tests/nvlist_send_recv_test.c b/lib/libnv/tests/nvlist_send_recv_test.c
index c751bf7..50222fb 100644
--- a/lib/libnv/tests/nvlist_send_recv_test.c
+++ b/lib/libnv/tests/nvlist_send_recv_test.c
@@ -58,8 +58,10 @@ static void
child(int sock)
{
nvlist_t *nvl;
+ nvlist_t *empty;
nvl = nvlist_create(0);
+ empty = nvlist_create(0);
nvlist_add_bool(nvl, "nvlist/bool/true", true);
nvlist_add_bool(nvl, "nvlist/bool/false", false);
@@ -75,6 +77,7 @@ child(int sock)
nvlist_add_descriptor(nvl, "nvlist/descriptor/STDERR_FILENO", STDERR_FILENO);
nvlist_add_binary(nvl, "nvlist/binary/x", "x", 1);
nvlist_add_binary(nvl, "nvlist/binary/abcdefghijklmnopqrstuvwxyz", "abcdefghijklmnopqrstuvwxyz", sizeof("abcdefghijklmnopqrstuvwxyz"));
+ nvlist_move_nvlist(nvl, "nvlist/nvlist/empty", empty);
nvlist_add_nvlist(nvl, "nvlist/nvlist", nvl);
nvlist_send(sock, nvl);
@@ -86,13 +89,13 @@ static void
parent(int sock)
{
nvlist_t *nvl;
- const nvlist_t *cnvl;
+ const nvlist_t *cnvl, *empty;
const char *name, *cname;
void *cookie, *ccookie;
int type, ctype;
size_t size;
- nvl = nvlist_recv(sock);
+ nvl = nvlist_recv(sock, 0);
CHECK(nvlist_error(nvl) == 0);
if (nvlist_error(nvl) != 0)
err(1, "nvlist_recv() failed");
@@ -190,6 +193,13 @@ parent(int sock)
name = nvlist_next(nvl, &type, &cookie);
CHECK(name != NULL);
CHECK(type == NV_TYPE_NVLIST);
+ CHECK(strcmp(name, "nvlist/nvlist/empty") == 0);
+ cnvl = nvlist_get_nvlist(nvl, name);
+ CHECK(nvlist_empty(cnvl));
+
+ name = nvlist_next(nvl, &type, &cookie);
+ CHECK(name != NULL);
+ CHECK(type == NV_TYPE_NVLIST);
CHECK(strcmp(name, "nvlist/nvlist") == 0);
cnvl = nvlist_get_nvlist(nvl, name);
@@ -284,6 +294,13 @@ parent(int sock)
CHECK(size == sizeof("abcdefghijklmnopqrstuvwxyz"));
cname = nvlist_next(cnvl, &ctype, &ccookie);
+ CHECK(cname != NULL);
+ CHECK(ctype == NV_TYPE_NVLIST);
+ CHECK(strcmp(cname, "nvlist/nvlist/empty") == 0);
+ empty = nvlist_get_nvlist(cnvl, cname);
+ CHECK(nvlist_empty(empty));
+
+ cname = nvlist_next(cnvl, &ctype, &ccookie);
CHECK(cname == NULL);
name = nvlist_next(nvl, &type, &cookie);
@@ -296,7 +313,7 @@ main(void)
int status, socks[2];
pid_t pid;
- printf("1..126\n");
+ printf("1..134\n");
fflush(stdout);
if (socketpair(PF_UNIX, SOCK_STREAM, 0, socks) < 0)
diff --git a/lib/libopie/Makefile b/lib/libopie/Makefile
index e47e16d..e66e67a 100644
--- a/lib/libopie/Makefile
+++ b/lib/libopie/Makefile
@@ -27,8 +27,7 @@ CFLAGS+= -DINSECURE_OVERRIDE -DPATH_ACCESS_FILE=${ACCESSFILE}
WARNS?= 0
-DPADD= ${LIBMD}
-LDADD= -lmd
+LIBADD= md
MAN= ${OPIE_DIST}/opie.4 ${OPIE_DIST}/opiekeys.5 ${OPIE_DIST}/opieaccess.5
diff --git a/lib/libpam/libpam/tests/Makefile b/lib/libpam/libpam/tests/Makefile
index 2ad64e2..4532ace 100644
--- a/lib/libpam/libpam/tests/Makefile
+++ b/lib/libpam/libpam/tests/Makefile
@@ -13,7 +13,6 @@ SRCS.${test} = ${test}.c ${COMMONSRC}
CFLAGS +=-I${OPENPAM}/include -I${OPENPAM}/lib/libpam -I${OPENPAM}/t
WARNS ?= 6
-DPADD = ${LIBPAM}
-LDADD = ${MINUSLPAM}
+LIBADD = pam
.include <bsd.test.mk>
diff --git a/lib/libpam/modules/Makefile.inc b/lib/libpam/modules/Makefile.inc
index 085ab58..2da5a7b 100644
--- a/lib/libpam/modules/Makefile.inc
+++ b/lib/libpam/modules/Makefile.inc
@@ -14,8 +14,7 @@ CFLAGS+= -I${PAMDIR}/include -I${.CURDIR}/../../libpam
NO_PIC=
.else
SHLIB_NAME?= ${LIB}.so.${SHLIB_MAJOR}
-DPADD+= ${LIBPAM}
-LDADD+= -lpam
+LIBADD+= pam
.endif
.include "../Makefile.inc"
diff --git a/lib/libpam/modules/modules.inc b/lib/libpam/modules/modules.inc
index 66fc63c..02debf7 100644
--- a/lib/libpam/modules/modules.inc
+++ b/lib/libpam/modules/modules.inc
@@ -21,7 +21,9 @@ MODULES += pam_opie
MODULES += pam_opieaccess
MODULES += pam_passwdqc
MODULES += pam_permit
+.if ${MK_RADIUS_SUPPORT} != "no"
MODULES += pam_radius
+.endif
MODULES += pam_rhosts
MODULES += pam_rootok
MODULES += pam_securetty
diff --git a/lib/libpam/modules/pam_guest/pam_guest.8 b/lib/libpam/modules/pam_guest/pam_guest.8
index 0bd1755..0b858d6 100644
--- a/lib/libpam/modules/pam_guest/pam_guest.8
+++ b/lib/libpam/modules/pam_guest/pam_guest.8
@@ -82,8 +82,8 @@ password.
Requires the guest user to type in the guest account name as password.
.El
.Sh SEE ALSO
-.Xr pam_getenv 3 ,
.Xr pam_get_item 3 ,
+.Xr pam_getenv 3 ,
.Xr pam.conf 5 ,
.Xr pam 8
.Sh AUTHORS
diff --git a/lib/libpam/modules/pam_krb5/Makefile b/lib/libpam/modules/pam_krb5/Makefile
index 85f3421..97fd490 100644
--- a/lib/libpam/modules/pam_krb5/Makefile
+++ b/lib/libpam/modules/pam_krb5/Makefile
@@ -32,7 +32,6 @@ CFLAGS+=-D_FREEFALL_CONFIG
WARNS?= 3
.endif
-DPADD= ${LIBKRB5} ${LIBHX509} ${LIBASN1} ${LIBROKEN} ${LIBCOM_ERR} ${LIBCRYPT} ${LIBCRYPTO}
-LDADD= -lkrb5 -lhx509 -lasn1 -lroken -lcom_err -lcrypt -lcrypto
+LIBADD+= krb5
.include <bsd.lib.mk>
diff --git a/lib/libpam/modules/pam_ksu/Makefile b/lib/libpam/modules/pam_ksu/Makefile
index 9aa6a7e..26f3f85 100644
--- a/lib/libpam/modules/pam_ksu/Makefile
+++ b/lib/libpam/modules/pam_ksu/Makefile
@@ -28,7 +28,6 @@ LIB= pam_ksu
SRCS= pam_ksu.c
MAN= pam_ksu.8
-DPADD= ${LIBKRB5} ${LIBHX509} ${LIBASN1} ${LIBROKEN} ${LIBCOM_ERR} ${LIBCRYPT} ${LIBCRYPTO}
-LDADD= -lkrb5 -lhx509 -lasn1 -lroken -lcom_err -lcrypt -lcrypto
+LIBADD+= krb5
.include <bsd.lib.mk>
diff --git a/lib/libpam/modules/pam_nologin/Makefile b/lib/libpam/modules/pam_nologin/Makefile
index ba5a7d4..746e9e8 100644
--- a/lib/libpam/modules/pam_nologin/Makefile
+++ b/lib/libpam/modules/pam_nologin/Makefile
@@ -28,7 +28,6 @@ LIB= pam_nologin
SRCS= pam_nologin.c
MAN= pam_nologin.8
-DPADD= ${LIBUTIL}
-LDADD= -lutil
+LIBADD+= util
.include <bsd.lib.mk>
diff --git a/lib/libpam/modules/pam_opie/Makefile b/lib/libpam/modules/pam_opie/Makefile
index fbc1278..c2074bf 100644
--- a/lib/libpam/modules/pam_opie/Makefile
+++ b/lib/libpam/modules/pam_opie/Makefile
@@ -29,7 +29,6 @@ LIB= pam_opie
SRCS= pam_opie.c
MAN= pam_opie.8
-DPADD= ${LIBOPIE}
-LDADD= -lopie
+LIBADD+= opie
.include <bsd.lib.mk>
diff --git a/lib/libpam/modules/pam_opieaccess/Makefile b/lib/libpam/modules/pam_opieaccess/Makefile
index 1554a88..2e764cd 100644
--- a/lib/libpam/modules/pam_opieaccess/Makefile
+++ b/lib/libpam/modules/pam_opieaccess/Makefile
@@ -4,7 +4,6 @@ LIB= pam_opieaccess
SRCS= ${LIB}.c
MAN= pam_opieaccess.8
-DPADD= ${LIBOPIE}
-LDADD= -lopie
+LIBADD+= opie
.include <bsd.lib.mk>
diff --git a/lib/libpam/modules/pam_passwdqc/Makefile b/lib/libpam/modules/pam_passwdqc/Makefile
index c9cc30e..cd23642 100644
--- a/lib/libpam/modules/pam_passwdqc/Makefile
+++ b/lib/libpam/modules/pam_passwdqc/Makefile
@@ -10,8 +10,7 @@ MAN= pam_passwdqc.8
WARNS?= 2
CFLAGS+= -I${SRCDIR}
-DPADD= ${LIBCRYPT}
-LDADD= -lcrypt
+LIBADD+= crypt
.include <bsd.lib.mk>
diff --git a/lib/libpam/modules/pam_radius/Makefile b/lib/libpam/modules/pam_radius/Makefile
index 2fac833..a9a93e2 100644
--- a/lib/libpam/modules/pam_radius/Makefile
+++ b/lib/libpam/modules/pam_radius/Makefile
@@ -29,7 +29,6 @@ SRCS= pam_radius.c
MAN= pam_radius.8
WARNS?= 3
-DPADD= ${LIBRADIUS}
-LDADD= -lradius
+LIBADD+= radius
.include <bsd.lib.mk>
diff --git a/lib/libpam/modules/pam_radius/pam_radius.c b/lib/libpam/modules/pam_radius/pam_radius.c
index c5d4dd4..dcfde30 100644
--- a/lib/libpam/modules/pam_radius/pam_radius.c
+++ b/lib/libpam/modules/pam_radius/pam_radius.c
@@ -62,11 +62,11 @@ __FBSDID("$FreeBSD$");
#define PASSWORD_PROMPT "RADIUS Password:"
static int build_access_request(struct rad_handle *, const char *,
- const char *, const char *, const char *, const void *,
- size_t);
+ const char *, const char *, const char *, const char *,
+ const void *, size_t);
static int do_accept(pam_handle_t *, struct rad_handle *);
static int do_challenge(pam_handle_t *, struct rad_handle *,
- const char *, const char *, const char *);
+ const char *, const char *, const char *, const char *);
/*
* Construct an access request, but don't send it. Returns 0 on success,
@@ -75,7 +75,7 @@ static int do_challenge(pam_handle_t *, struct rad_handle *,
static int
build_access_request(struct rad_handle *radh, const char *user,
const char *pass, const char *nas_id, const char *nas_ipaddr,
- const void *state, size_t state_len)
+ const char *rhost, const void *state, size_t state_len)
{
int error;
char host[MAXHOSTNAMELEN];
@@ -121,8 +121,13 @@ build_access_request(struct rad_handle *radh, const char *user,
}
}
}
- if (state != NULL && rad_put_attr(radh, RAD_STATE, state,
- state_len) == -1) {
+ if (rhost != NULL &&
+ rad_put_string(radh, RAD_CALLING_STATION_ID, rhost) == -1) {
+ syslog(LOG_CRIT, "rad_put_string: %s", rad_strerror(radh));
+ return (-1);
+ }
+ if (state != NULL &&
+ rad_put_attr(radh, RAD_STATE, state, state_len) == -1) {
syslog(LOG_CRIT, "rad_put_attr: %s", rad_strerror(radh));
return (-1);
}
@@ -162,7 +167,7 @@ do_accept(pam_handle_t *pamh, struct rad_handle *radh)
static int
do_challenge(pam_handle_t *pamh, struct rad_handle *radh, const char *user,
- const char *nas_id, const char *nas_ipaddr)
+ const char *nas_id, const char *nas_ipaddr, const char *rhost)
{
int retval;
int attrtype;
@@ -230,7 +235,7 @@ do_challenge(pam_handle_t *pamh, struct rad_handle *radh, const char *user,
conv->appdata_ptr)) != PAM_SUCCESS)
return (retval);
if (build_access_request(radh, user, resp[num_msgs-1].resp, nas_id,
- nas_ipaddr, state, statelen) == -1)
+ nas_ipaddr, rhost, state, statelen) == -1)
return (PAM_SERVICE_ERR);
memset(resp[num_msgs-1].resp, 0, strlen(resp[num_msgs-1].resp));
free(resp[num_msgs-1].resp);
@@ -246,7 +251,7 @@ pam_sm_authenticate(pam_handle_t *pamh, int flags __unused,
{
struct rad_handle *radh;
const char *user, *pass;
- const void *tmpuser;
+ const void *rhost, *tmpuser;
const char *conf_file, *template_user, *nas_id, *nas_ipaddr;
int retval;
int e;
@@ -255,6 +260,7 @@ pam_sm_authenticate(pam_handle_t *pamh, int flags __unused,
template_user = openpam_get_option(pamh, PAM_OPT_TEMPLATE_USER);
nas_id = openpam_get_option(pamh, PAM_OPT_NAS_ID);
nas_ipaddr = openpam_get_option(pamh, PAM_OPT_NAS_IPADDR);
+ pam_get_item(pamh, PAM_RHOST, &rhost);
retval = pam_get_user(pamh, &user, NULL);
if (retval != PAM_SUCCESS)
@@ -284,8 +290,8 @@ pam_sm_authenticate(pam_handle_t *pamh, int flags __unused,
PAM_LOG("Radius config file read");
- if (build_access_request(radh, user, pass, nas_id, nas_ipaddr, NULL,
- 0) == -1) {
+ if (build_access_request(radh, user, pass, nas_id, nas_ipaddr, rhost,
+ NULL, 0) == -1) {
rad_close(radh);
return (PAM_SERVICE_ERR);
}
@@ -330,7 +336,7 @@ pam_sm_authenticate(pam_handle_t *pamh, int flags __unused,
case RAD_ACCESS_CHALLENGE:
retval = do_challenge(pamh, radh, user, nas_id,
- nas_ipaddr);
+ nas_ipaddr, rhost);
if (retval != PAM_SUCCESS) {
rad_close(radh);
return (retval);
diff --git a/lib/libpam/modules/pam_ssh/Makefile b/lib/libpam/modules/pam_ssh/Makefile
index 5643f32..b5ca478 100644
--- a/lib/libpam/modules/pam_ssh/Makefile
+++ b/lib/libpam/modules/pam_ssh/Makefile
@@ -13,9 +13,7 @@ SRCS+= roaming_dummy.c
WARNS?= 3
CFLAGS+= -I${SSHDIR} -include ssh_namespace.h
-DPADD= ${LIBSSH} ${LIBCRYPTO} ${LIBCRYPT}
-LDADD= ${LDSSH} -lcrypto -lcrypt
-USEPRIVATELIB= ssh
+LIBADD= ssh
.include <bsd.lib.mk>
diff --git a/lib/libpam/modules/pam_tacplus/Makefile b/lib/libpam/modules/pam_tacplus/Makefile
index 053812a..5d2a3f3 100644
--- a/lib/libpam/modules/pam_tacplus/Makefile
+++ b/lib/libpam/modules/pam_tacplus/Makefile
@@ -28,7 +28,6 @@ LIB= pam_tacplus
SRCS= pam_tacplus.c
MAN= pam_tacplus.8
-DPADD= ${LIBTACPLUS}
-LDADD= -ltacplus
+LIBADD+= tacplus
.include <bsd.lib.mk>
diff --git a/lib/libpam/modules/pam_unix/Makefile b/lib/libpam/modules/pam_unix/Makefile
index ea9e639..5330ae4 100644
--- a/lib/libpam/modules/pam_unix/Makefile
+++ b/lib/libpam/modules/pam_unix/Makefile
@@ -41,13 +41,11 @@ LIB= pam_unix
SRCS= pam_unix.c
MAN= pam_unix.8
-DPADD+= ${LIBUTIL} ${LIBCRYPT}
-LDADD+= -lutil -lcrypt
+LIBADD+= util crypt
.if ${MK_NIS} != "no"
CFLAGS+= -DYP
-DPADD+= ${LIBYPCLNT}
-LDADD+= -lypclnt
+LIBADD+= ypclnt
.endif
.include <bsd.lib.mk>
diff --git a/lib/libpcap/Makefile b/lib/libpcap/Makefile
index 11d7f73..c36b3ef 100644
--- a/lib/libpcap/Makefile
+++ b/lib/libpcap/Makefile
@@ -40,6 +40,7 @@ MAN= pcap.3 \
pcap_findalldevs.3 \
pcap_freecode.3 \
pcap_get_selectable_fd.3 \
+ pcap_get_tstamp_precision.3 \
pcap_geterr.3 \
pcap_inject.3 \
pcap_is_swapped.3 \
@@ -57,10 +58,12 @@ MAN= pcap.3 \
pcap_open_offline.3 \
pcap_set_buffer_size.3 \
pcap_set_datalink.3 \
+ pcap_set_immediate_mode.3 \
pcap_set_promisc.3 \
pcap_set_rfmon.3 \
pcap_set_snaplen.3 \
pcap_set_timeout.3 \
+ pcap_set_tstamp_precision.3 \
pcap_set_tstamp_type.3 \
pcap_setdirection.3 \
pcap_setfilter.3 \
diff --git a/lib/libpcap/config.h b/lib/libpcap/config.h
index 60cb448..4033b27 100644
--- a/lib/libpcap/config.h
+++ b/lib/libpcap/config.h
@@ -227,13 +227,13 @@
/* #undef LINUX_USB_MON_DEV */
/* if we need a pcap_parse wrapper around yyparse */
-#define NEED_YYPARSE_WRAPPER
+#define NEED_YYPARSE_WRAPPER 1
/* Define to 1 if netinet/ether.h declares `ether_hostton' */
/* #undef NETINET_ETHER_H_DECLARES_ETHER_HOSTTON */
/* Define to 1 if netinet/if_ether.h declares `ether_hostton' */
-#define NETINET_IF_ETHER_H_DECLARES_ETHER_HOSTTON
+#define NETINET_IF_ETHER_H_DECLARES_ETHER_HOSTTON /**/
/* do not use protochain */
/* #undef NO_PROTOCHAIN */
@@ -250,6 +250,9 @@
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME ""
+/* Define to the home page for this package. */
+#define PACKAGE_URL ""
+
/* Define to the version of this package. */
#define PACKAGE_VERSION ""
@@ -259,12 +262,18 @@
/* target host supports Bluetooth sniffing */
/* #undef PCAP_SUPPORT_BT */
+/* target host supports Bluetooth Monitor */
+/* #undef PCAP_SUPPORT_BT_MONITOR */
+
/* target host supports CAN sniffing */
/* #undef PCAP_SUPPORT_CAN */
/* target host supports canusb */
/* #undef PCAP_SUPPORT_CANUSB */
+/* support D-Bus sniffing */
+/* #undef PCAP_SUPPORT_DBUS */
+
/* target host supports netfilter sniffing */
/* #undef PCAP_SUPPORT_NETFILTER */
@@ -286,12 +295,14 @@
/* Enable parser debugging */
/* #undef YYDEBUG */
+/* Enable large inode numbers on Mac OS X 10.5. */
+#ifndef _DARWIN_USE_64_BIT_INODE
+# define _DARWIN_USE_64_BIT_INODE 1
+#endif
+
/* Number of bits in a file offset, on hosts where this is settable. */
/* #undef _FILE_OFFSET_BITS */
-/* needed on HP-UX */
-/* #undef _HPUX_SOURCE */
-
/* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */
/* #undef _LARGEFILE_SOURCE */
@@ -301,6 +312,9 @@
/* define on AIX to get certain functions */
/* #undef _SUN */
+/* define if your compiler allows __attribute__((format)) without a warning */
+#define __ATTRIBUTE___FORMAT_OK 1
+
/* to handle Ultrix compilers that don't support const in prototypes */
/* #undef const */
diff --git a/lib/libpjdlog/Makefile b/lib/libpjdlog/Makefile
index a80b629..e44f53b 100644
--- a/lib/libpjdlog/Makefile
+++ b/lib/libpjdlog/Makefile
@@ -13,8 +13,7 @@ SHLIB_MAJOR= 0
CFLAGS+=-I${.CURDIR}
-DPADD= ${LIBUTIL}
-LDADD= -lutil
+LIBADD= util
WARNS?= 6
diff --git a/lib/libpmc/libpmc.c b/lib/libpmc/libpmc.c
index 5282bb2..d9d7902 100644
--- a/lib/libpmc/libpmc.c
+++ b/lib/libpmc/libpmc.c
@@ -74,10 +74,18 @@ static int p6_allocate_pmc(enum pmc_event _pe, char *_ctrspec,
static int tsc_allocate_pmc(enum pmc_event _pe, char *_ctrspec,
struct pmc_op_pmcallocate *_pmc_config);
#endif
+#if defined(__arm__)
#if defined(__XSCALE__)
static int xscale_allocate_pmc(enum pmc_event _pe, char *_ctrspec,
struct pmc_op_pmcallocate *_pmc_config);
#endif
+static int armv7_allocate_pmc(enum pmc_event _pe, char *_ctrspec,
+ struct pmc_op_pmcallocate *_pmc_config);
+#endif
+#if defined(__aarch64__)
+static int arm64_allocate_pmc(enum pmc_event _pe, char *_ctrspec,
+ struct pmc_op_pmcallocate *_pmc_config);
+#endif
#if defined(__mips__)
static int mips_allocate_pmc(enum pmc_event _pe, char* ctrspec,
struct pmc_op_pmcallocate *_pmc_config);
@@ -153,11 +161,15 @@ PMC_CLASSDEP_TABLE(p4, P4);
PMC_CLASSDEP_TABLE(p5, P5);
PMC_CLASSDEP_TABLE(p6, P6);
PMC_CLASSDEP_TABLE(xscale, XSCALE);
+PMC_CLASSDEP_TABLE(armv7, ARMV7);
+PMC_CLASSDEP_TABLE(armv8, ARMV8);
PMC_CLASSDEP_TABLE(mips24k, MIPS24K);
+PMC_CLASSDEP_TABLE(mips74k, MIPS74K);
PMC_CLASSDEP_TABLE(octeon, OCTEON);
PMC_CLASSDEP_TABLE(ucf, UCF);
PMC_CLASSDEP_TABLE(ppc7450, PPC7450);
PMC_CLASSDEP_TABLE(ppc970, PPC970);
+PMC_CLASSDEP_TABLE(e500, E500);
static struct pmc_event_descr soft_event_table[PMC_EV_DYN_COUNT];
@@ -200,6 +212,12 @@ static const struct pmc_event_descr haswell_event_table[] =
__PMC_EV_ALIAS_HASWELL()
};
+static const struct pmc_event_descr haswell_xeon_event_table[] =
+{
+ __PMC_EV_ALIAS_HASWELL_XEON()
+};
+
+
static const struct pmc_event_descr ivybridge_event_table[] =
{
__PMC_EV_ALIAS_IVYBRIDGE()
@@ -250,6 +268,16 @@ static const struct pmc_event_descr westmereuc_event_table[] =
__PMC_EV_ALIAS_WESTMEREUC()
};
+static const struct pmc_event_descr cortex_a53_event_table[] =
+{
+ __PMC_EV_ALIAS_ARMV8_CORTEX_A53()
+};
+
+static const struct pmc_event_descr cortex_a57_event_table[] =
+{
+ __PMC_EV_ALIAS_ARMV8_CORTEX_A57()
+};
+
/*
* PMC_MDEP_TABLE(NAME, PRIMARYCLASS, ADDITIONAL_CLASSES...)
*
@@ -267,6 +295,7 @@ PMC_MDEP_TABLE(core2, IAP, PMC_CLASS_SOFT, PMC_CLASS_IAF, PMC_CLASS_TSC);
PMC_MDEP_TABLE(corei7, IAP, PMC_CLASS_SOFT, PMC_CLASS_IAF, PMC_CLASS_TSC, PMC_CLASS_UCF, PMC_CLASS_UCP);
PMC_MDEP_TABLE(nehalem_ex, IAP, PMC_CLASS_SOFT, PMC_CLASS_IAF, PMC_CLASS_TSC);
PMC_MDEP_TABLE(haswell, IAP, PMC_CLASS_SOFT, PMC_CLASS_IAF, PMC_CLASS_TSC, PMC_CLASS_UCF, PMC_CLASS_UCP);
+PMC_MDEP_TABLE(haswell_xeon, IAP, PMC_CLASS_SOFT, PMC_CLASS_IAF, PMC_CLASS_TSC, PMC_CLASS_UCF, PMC_CLASS_UCP);
PMC_MDEP_TABLE(ivybridge, IAP, PMC_CLASS_SOFT, PMC_CLASS_IAF, PMC_CLASS_TSC);
PMC_MDEP_TABLE(ivybridge_xeon, IAP, PMC_CLASS_SOFT, PMC_CLASS_IAF, PMC_CLASS_TSC);
PMC_MDEP_TABLE(sandybridge, IAP, PMC_CLASS_SOFT, PMC_CLASS_IAF, PMC_CLASS_TSC, PMC_CLASS_UCF, PMC_CLASS_UCP);
@@ -279,10 +308,15 @@ PMC_MDEP_TABLE(p4, P4, PMC_CLASS_SOFT, PMC_CLASS_TSC);
PMC_MDEP_TABLE(p5, P5, PMC_CLASS_SOFT, PMC_CLASS_TSC);
PMC_MDEP_TABLE(p6, P6, PMC_CLASS_SOFT, PMC_CLASS_TSC);
PMC_MDEP_TABLE(xscale, XSCALE, PMC_CLASS_SOFT, PMC_CLASS_XSCALE);
+PMC_MDEP_TABLE(armv7, ARMV7, PMC_CLASS_SOFT, PMC_CLASS_ARMV7);
+PMC_MDEP_TABLE(cortex_a53, ARMV8, PMC_CLASS_SOFT, PMC_CLASS_ARMV8);
+PMC_MDEP_TABLE(cortex_a57, ARMV8, PMC_CLASS_SOFT, PMC_CLASS_ARMV8);
PMC_MDEP_TABLE(mips24k, MIPS24K, PMC_CLASS_SOFT, PMC_CLASS_MIPS24K);
+PMC_MDEP_TABLE(mips74k, MIPS74K, PMC_CLASS_SOFT, PMC_CLASS_MIPS74K);
PMC_MDEP_TABLE(octeon, OCTEON, PMC_CLASS_SOFT, PMC_CLASS_OCTEON);
-PMC_MDEP_TABLE(ppc7450, PPC7450, PMC_CLASS_SOFT, PMC_CLASS_PPC7450);
-PMC_MDEP_TABLE(ppc970, PPC970, PMC_CLASS_SOFT, PMC_CLASS_PPC970);
+PMC_MDEP_TABLE(ppc7450, PPC7450, PMC_CLASS_SOFT, PMC_CLASS_PPC7450, PMC_CLASS_TSC);
+PMC_MDEP_TABLE(ppc970, PPC970, PMC_CLASS_SOFT, PMC_CLASS_PPC970, PMC_CLASS_TSC);
+PMC_MDEP_TABLE(e500, E500, PMC_CLASS_SOFT, PMC_CLASS_E500, PMC_CLASS_TSC);
PMC_MDEP_TABLE(generic, SOFT, PMC_CLASS_SOFT);
static const struct pmc_event_descr tsc_event_table[] =
@@ -312,6 +346,7 @@ PMC_CLASS_TABLE_DESC(core2, IAP, core2, iap);
PMC_CLASS_TABLE_DESC(corei7, IAP, corei7, iap);
PMC_CLASS_TABLE_DESC(nehalem_ex, IAP, nehalem_ex, iap);
PMC_CLASS_TABLE_DESC(haswell, IAP, haswell, iap);
+PMC_CLASS_TABLE_DESC(haswell_xeon, IAP, haswell_xeon, iap);
PMC_CLASS_TABLE_DESC(ivybridge, IAP, ivybridge, iap);
PMC_CLASS_TABLE_DESC(ivybridge_xeon, IAP, ivybridge_xeon, iap);
PMC_CLASS_TABLE_DESC(sandybridge, IAP, sandybridge, iap);
@@ -338,16 +373,25 @@ PMC_CLASS_TABLE_DESC(p6, P6, p6, p6);
#if defined(__i386__) || defined(__amd64__)
PMC_CLASS_TABLE_DESC(tsc, TSC, tsc, tsc);
#endif
+#if defined(__arm__)
#if defined(__XSCALE__)
PMC_CLASS_TABLE_DESC(xscale, XSCALE, xscale, xscale);
#endif
+PMC_CLASS_TABLE_DESC(armv7, ARMV7, armv7, armv7);
+#endif
+#if defined(__aarch64__)
+PMC_CLASS_TABLE_DESC(cortex_a53, ARMV8, cortex_a53, arm64);
+PMC_CLASS_TABLE_DESC(cortex_a57, ARMV8, cortex_a57, arm64);
+#endif
#if defined(__mips__)
PMC_CLASS_TABLE_DESC(mips24k, MIPS24K, mips24k, mips);
+PMC_CLASS_TABLE_DESC(mips74k, MIPS74K, mips74k, mips);
PMC_CLASS_TABLE_DESC(octeon, OCTEON, octeon, mips);
#endif /* __mips__ */
#if defined(__powerpc__)
PMC_CLASS_TABLE_DESC(ppc7450, PPC7450, ppc7450, powerpc);
PMC_CLASS_TABLE_DESC(ppc970, PPC970, ppc970, powerpc);
+PMC_CLASS_TABLE_DESC(e500, E500, e500, powerpc);
#endif
static struct pmc_class_descr soft_class_table_descr =
@@ -379,9 +423,14 @@ static const char * pmc_capability_names[] = {
__PMC_CAPS()
};
-static const char * pmc_class_names[] = {
+struct pmc_class_map {
+ enum pmc_class pm_class;
+ const char *pm_name;
+};
+
+static const struct pmc_class_map pmc_class_names[] = {
#undef __PMC_CLASS
-#define __PMC_CLASS(C) #C ,
+#define __PMC_CLASS(S,V,D) { .pm_class = PMC_CLASS_##S, .pm_name = #S } ,
__PMC_CLASSES()
};
@@ -626,6 +675,8 @@ static struct pmc_event_alias core2_aliases_without_iaf[] = {
#define nehalem_ex_aliases_without_iaf core2_aliases_without_iaf
#define haswell_aliases core2_aliases
#define haswell_aliases_without_iaf core2_aliases_without_iaf
+#define haswell_xeon_aliases core2_aliases
+#define haswell_xeon_aliases_without_iaf core2_aliases_without_iaf
#define ivybridge_aliases core2_aliases
#define ivybridge_aliases_without_iaf core2_aliases_without_iaf
#define ivybridge_xeon_aliases core2_aliases
@@ -896,7 +947,8 @@ iap_allocate_pmc(enum pmc_event pe, char *ctrspec,
n = pmc_parse_mask(iap_rsp_mask_sb_sbx_ib, p, &rsp);
} else
return (-1);
- } else if (cpu_info.pm_cputype == PMC_CPU_INTEL_HASWELL) {
+ } else if (cpu_info.pm_cputype == PMC_CPU_INTEL_HASWELL ||
+ cpu_info.pm_cputype == PMC_CPU_INTEL_HASWELL_XEON) {
if (KWPREFIXMATCH(p, IAP_KW_RSP "=")) {
n = pmc_parse_mask(iap_rsp_mask_haswell, p, &rsp);
} else
@@ -2360,6 +2412,7 @@ soft_allocate_pmc(enum pmc_event pe, char *ctrspec,
return (0);
}
+#if defined(__arm__)
#if defined(__XSCALE__)
static struct pmc_event_alias xscale_aliases[] = {
@@ -2383,6 +2436,45 @@ xscale_allocate_pmc(enum pmc_event pe, char *ctrspec __unused,
}
#endif
+static struct pmc_event_alias armv7_aliases[] = {
+ EV_ALIAS("dc-misses", "L1_DCACHE_REFILL"),
+ EV_ALIAS("ic-misses", "L1_ICACHE_REFILL"),
+ EV_ALIAS("instructions", "INSTR_EXECUTED"),
+ EV_ALIAS(NULL, NULL)
+};
+static int
+armv7_allocate_pmc(enum pmc_event pe, char *ctrspec __unused,
+ struct pmc_op_pmcallocate *pmc_config __unused)
+{
+ switch (pe) {
+ default:
+ break;
+ }
+
+ return (0);
+}
+#endif
+
+#if defined(__aarch64__)
+static struct pmc_event_alias cortex_a53_aliases[] = {
+ EV_ALIAS(NULL, NULL)
+};
+static struct pmc_event_alias cortex_a57_aliases[] = {
+ EV_ALIAS(NULL, NULL)
+};
+static int
+arm64_allocate_pmc(enum pmc_event pe, char *ctrspec __unused,
+ struct pmc_op_pmcallocate *pmc_config __unused)
+{
+ switch (pe) {
+ default:
+ break;
+ }
+
+ return (0);
+}
+#endif
+
#if defined(__mips__)
static struct pmc_event_alias mips24k_aliases[] = {
@@ -2392,6 +2484,13 @@ static struct pmc_event_alias mips24k_aliases[] = {
EV_ALIAS(NULL, NULL)
};
+static struct pmc_event_alias mips74k_aliases[] = {
+ EV_ALIAS("instructions", "INSTR_EXECUTED"),
+ EV_ALIAS("branches", "BRANCH_INSNS"),
+ EV_ALIAS("branch-mispredicts", "MISPREDICTED_BRANCH_INSNS"),
+ EV_ALIAS(NULL, NULL)
+};
+
static struct pmc_event_alias octeon_aliases[] = {
EV_ALIAS("instructions", "RET"),
EV_ALIAS("branches", "BR"),
@@ -2444,6 +2543,12 @@ static struct pmc_event_alias ppc970_aliases[] = {
EV_ALIAS(NULL, NULL)
};
+static struct pmc_event_alias e500_aliases[] = {
+ EV_ALIAS("instructions", "INSTR_COMPLETED"),
+ EV_ALIAS("cycles", "CYCLES"),
+ EV_ALIAS(NULL, NULL)
+};
+
#define POWERPC_KW_OS "os"
#define POWERPC_KW_USR "usr"
#define POWERPC_KW_ANYTHREAD "anythread"
@@ -2788,6 +2893,10 @@ pmc_event_names_of_class(enum pmc_class cl, const char ***eventnames,
ev = haswell_event_table;
count = PMC_EVENT_TABLE_SIZE(haswell);
break;
+ case PMC_CPU_INTEL_HASWELL_XEON:
+ ev = haswell_xeon_event_table;
+ count = PMC_EVENT_TABLE_SIZE(haswell_xeon);
+ break;
case PMC_CPU_INTEL_IVYBRIDGE:
ev = ivybridge_event_table;
count = PMC_EVENT_TABLE_SIZE(ivybridge);
@@ -2871,10 +2980,31 @@ pmc_event_names_of_class(enum pmc_class cl, const char ***eventnames,
ev = xscale_event_table;
count = PMC_EVENT_TABLE_SIZE(xscale);
break;
+ case PMC_CLASS_ARMV7:
+ ev = armv7_event_table;
+ count = PMC_EVENT_TABLE_SIZE(armv7);
+ break;
+ case PMC_CLASS_ARMV8:
+ switch (cpu_info.pm_cputype) {
+ default:
+ case PMC_CPU_ARMV8_CORTEX_A53:
+ ev = cortex_a53_event_table;
+ count = PMC_EVENT_TABLE_SIZE(cortex_a53);
+ break;
+ case PMC_CPU_ARMV8_CORTEX_A57:
+ ev = cortex_a57_event_table;
+ count = PMC_EVENT_TABLE_SIZE(cortex_a57);
+ break;
+ }
+ break;
case PMC_CLASS_MIPS24K:
ev = mips24k_event_table;
count = PMC_EVENT_TABLE_SIZE(mips24k);
break;
+ case PMC_CLASS_MIPS74K:
+ ev = mips74k_event_table;
+ count = PMC_EVENT_TABLE_SIZE(mips74k);
+ break;
case PMC_CLASS_OCTEON:
ev = octeon_event_table;
count = PMC_EVENT_TABLE_SIZE(octeon);
@@ -2887,6 +3017,10 @@ pmc_event_names_of_class(enum pmc_class cl, const char ***eventnames,
ev = ppc970_event_table;
count = PMC_EVENT_TABLE_SIZE(ppc970);
break;
+ case PMC_CLASS_E500:
+ ev = e500_event_table;
+ count = PMC_EVENT_TABLE_SIZE(e500);
+ break;
case PMC_CLASS_SOFT:
ev = soft_event_table;
count = soft_event_info.pm_nevent;
@@ -3115,6 +3249,9 @@ pmc_init(void)
pmc_class_table[n++] = &haswelluc_class_table_descr;
PMC_MDEP_INIT_INTEL_V2(haswell);
break;
+ case PMC_CPU_INTEL_HASWELL_XEON:
+ PMC_MDEP_INIT_INTEL_V2(haswell_xeon);
+ break;
case PMC_CPU_INTEL_IVYBRIDGE:
PMC_MDEP_INIT_INTEL_V2(ivybridge);
break;
@@ -3145,17 +3282,37 @@ pmc_init(void)
case PMC_CPU_GENERIC:
PMC_MDEP_INIT(generic);
break;
+#if defined(__arm__)
#if defined(__XSCALE__)
case PMC_CPU_INTEL_XSCALE:
PMC_MDEP_INIT(xscale);
pmc_class_table[n] = &xscale_class_table_descr;
break;
#endif
+ case PMC_CPU_ARMV7:
+ PMC_MDEP_INIT(armv7);
+ pmc_class_table[n] = &armv7_class_table_descr;
+ break;
+#endif
+#if defined(__aarch64__)
+ case PMC_CPU_ARMV8_CORTEX_A53:
+ PMC_MDEP_INIT(cortex_a53);
+ pmc_class_table[n] = &cortex_a53_class_table_descr;
+ break;
+ case PMC_CPU_ARMV8_CORTEX_A57:
+ PMC_MDEP_INIT(cortex_a57);
+ pmc_class_table[n] = &cortex_a57_class_table_descr;
+ break;
+#endif
#if defined(__mips__)
case PMC_CPU_MIPS_24K:
PMC_MDEP_INIT(mips24k);
pmc_class_table[n] = &mips24k_class_table_descr;
break;
+ case PMC_CPU_MIPS_74K:
+ PMC_MDEP_INIT(mips74k);
+ pmc_class_table[n] = &mips74k_class_table_descr;
+ break;
case PMC_CPU_MIPS_OCTEON:
PMC_MDEP_INIT(octeon);
pmc_class_table[n] = &octeon_class_table_descr;
@@ -3170,6 +3327,10 @@ pmc_init(void)
PMC_MDEP_INIT(ppc970);
pmc_class_table[n] = &ppc970_class_table_descr;
break;
+ case PMC_CPU_PPC_E500:
+ PMC_MDEP_INIT(e500);
+ pmc_class_table[n] = &e500_class_table_descr;
+ break;
#endif
default:
/*
@@ -3206,9 +3367,11 @@ pmc_name_of_capability(enum pmc_caps cap)
const char *
pmc_name_of_class(enum pmc_class pc)
{
- if ((int) pc >= PMC_CLASS_FIRST &&
- pc <= PMC_CLASS_LAST)
- return (pmc_class_names[pc]);
+ size_t n;
+
+ for (n = 0; n < PMC_TABLE_SIZE(pmc_class_names); n++)
+ if (pc == pmc_class_names[n].pm_class)
+ return (pmc_class_names[n].pm_name);
errno = EINVAL;
return (NULL);
@@ -3280,6 +3443,11 @@ _pmc_name_of_event(enum pmc_event pe, enum pmc_cputype cpu)
ev = haswell_event_table;
evfence = haswell_event_table + PMC_EVENT_TABLE_SIZE(haswell);
break;
+ case PMC_CPU_INTEL_HASWELL_XEON:
+ ev = haswell_xeon_event_table;
+ evfence = haswell_xeon_event_table + PMC_EVENT_TABLE_SIZE(haswell_xeon);
+ break;
+
case PMC_CPU_INTEL_IVYBRIDGE:
ev = ivybridge_event_table;
evfence = ivybridge_event_table + PMC_EVENT_TABLE_SIZE(ivybridge);
@@ -3346,9 +3514,28 @@ _pmc_name_of_event(enum pmc_event pe, enum pmc_cputype cpu)
} else if (pe >= PMC_EV_XSCALE_FIRST && pe <= PMC_EV_XSCALE_LAST) {
ev = xscale_event_table;
evfence = xscale_event_table + PMC_EVENT_TABLE_SIZE(xscale);
+ } else if (pe >= PMC_EV_ARMV7_FIRST && pe <= PMC_EV_ARMV7_LAST) {
+ ev = armv7_event_table;
+ evfence = armv7_event_table + PMC_EVENT_TABLE_SIZE(armv7);
+ } else if (pe >= PMC_EV_ARMV8_FIRST && pe <= PMC_EV_ARMV8_LAST) {
+ switch (cpu) {
+ case PMC_CPU_ARMV8_CORTEX_A53:
+ ev = cortex_a53_event_table;
+ evfence = cortex_a53_event_table + PMC_EVENT_TABLE_SIZE(cortex_a53);
+ break;
+ case PMC_CPU_ARMV8_CORTEX_A57:
+ ev = cortex_a57_event_table;
+ evfence = cortex_a57_event_table + PMC_EVENT_TABLE_SIZE(cortex_a57);
+ break;
+ default: /* Unknown CPU type. */
+ break;
+ }
} else if (pe >= PMC_EV_MIPS24K_FIRST && pe <= PMC_EV_MIPS24K_LAST) {
ev = mips24k_event_table;
evfence = mips24k_event_table + PMC_EVENT_TABLE_SIZE(mips24k);
+ } else if (pe >= PMC_EV_MIPS74K_FIRST && pe <= PMC_EV_MIPS74K_LAST) {
+ ev = mips74k_event_table;
+ evfence = mips74k_event_table + PMC_EVENT_TABLE_SIZE(mips74k);
} else if (pe >= PMC_EV_OCTEON_FIRST && pe <= PMC_EV_OCTEON_LAST) {
ev = octeon_event_table;
evfence = octeon_event_table + PMC_EVENT_TABLE_SIZE(octeon);
@@ -3358,6 +3545,9 @@ _pmc_name_of_event(enum pmc_event pe, enum pmc_cputype cpu)
} else if (pe >= PMC_EV_PPC970_FIRST && pe <= PMC_EV_PPC970_LAST) {
ev = ppc970_event_table;
evfence = ppc970_event_table + PMC_EVENT_TABLE_SIZE(ppc970);
+ } else if (pe >= PMC_EV_E500_FIRST && pe <= PMC_EV_E500_LAST) {
+ ev = e500_event_table;
+ evfence = e500_event_table + PMC_EVENT_TABLE_SIZE(e500);
} else if (pe == PMC_EV_TSC_TSC) {
ev = tsc_event_table;
evfence = tsc_event_table + PMC_EVENT_TABLE_SIZE(tsc);
diff --git a/lib/libpmc/pmc.3 b/lib/libpmc/pmc.3
index 8e6db48..f51285e 100644
--- a/lib/libpmc/pmc.3
+++ b/lib/libpmc/pmc.3
@@ -527,6 +527,7 @@ API is
.Xr pmc.core2 3 ,
.Xr pmc.haswell 3 ,
.Xr pmc.haswelluc 3 ,
+.Xr pmc.haswellxeon 3 ,
.Xr pmc.iaf 3 ,
.Xr pmc.ivybridge 3 ,
.Xr pmc.ivybridgexeon 3 ,
diff --git a/lib/libpmc/pmc.corei7.3 b/lib/libpmc/pmc.corei7.3
index 90d19df..ec31054 100644
--- a/lib/libpmc/pmc.corei7.3
+++ b/lib/libpmc/pmc.corei7.3
@@ -1549,18 +1549,18 @@ Counts number of segment register loads.
.Xr pmc 3 ,
.Xr pmc.atom 3 ,
.Xr pmc.core 3 ,
+.Xr pmc.corei7uc 3 ,
.Xr pmc.iaf 3 ,
-.Xr pmc.ucf 3 ,
.Xr pmc.k7 3 ,
.Xr pmc.k8 3 ,
.Xr pmc.p4 3 ,
.Xr pmc.p5 3 ,
.Xr pmc.p6 3 ,
-.Xr pmc.corei7uc 3 ,
-.Xr pmc.westmere 3 ,
-.Xr pmc.westmereuc 3 ,
.Xr pmc.soft 3 ,
.Xr pmc.tsc 3 ,
+.Xr pmc.ucf 3 ,
+.Xr pmc.westmere 3 ,
+.Xr pmc.westmereuc 3 ,
.Xr pmc_cpuinfo 3 ,
.Xr pmclog 3 ,
.Xr hwpmc 4
diff --git a/lib/libpmc/pmc.corei7uc.3 b/lib/libpmc/pmc.corei7uc.3
index 5b99113..3bcda1c 100644
--- a/lib/libpmc/pmc.corei7uc.3
+++ b/lib/libpmc/pmc.corei7uc.3
@@ -853,18 +853,18 @@ refreshed or needs to go into a power down mode.
.Xr pmc 3 ,
.Xr pmc.atom 3 ,
.Xr pmc.core 3 ,
+.Xr pmc.corei7 3 ,
.Xr pmc.iaf 3 ,
-.Xr pmc.ucf 3 ,
.Xr pmc.k7 3 ,
.Xr pmc.k8 3 ,
.Xr pmc.p4 3 ,
.Xr pmc.p5 3 ,
.Xr pmc.p6 3 ,
-.Xr pmc.corei7 3 ,
-.Xr pmc.westmere 3 ,
-.Xr pmc.westmereuc 3 ,
.Xr pmc.soft 3 ,
.Xr pmc.tsc 3 ,
+.Xr pmc.ucf 3 ,
+.Xr pmc.westmere 3 ,
+.Xr pmc.westmereuc 3 ,
.Xr pmc_cpuinfo 3 ,
.Xr pmclog 3 ,
.Xr hwpmc 4
diff --git a/lib/libpmc/pmc.haswell.3 b/lib/libpmc/pmc.haswell.3
index ace9c2a..a85f760 100644
--- a/lib/libpmc/pmc.haswell.3
+++ b/lib/libpmc/pmc.haswell.3
@@ -529,73 +529,60 @@ instruction.
.It Li ILD_STALL.IQ_FULL
.Pq Event 87H , Umask 04H
Stall cycles due to IQ is full.
-.It Li BR_INST_EXEC.COND
-.Pq Event 88H , Umask 01H
-Qualify conditional near branch instructions
-executed, but not necessarily retired.
+.It Li BR_INST_EXEC.NONTAKEN_COND
+.Pq Event 88H , Umask 41H
+Count conditional near branch instructions that were executed (but not
+necessarily retired) and not taken.
+.It Li BR_INST_EXEC.TAKEN_COND
+.Pq Event 88H , Umask 81H
+Count conditional near branch instructions that were executed (but not
+necessarily retired) and taken.
.It Li BR_INST_EXEC.DIRECT_JMP
-.Pq Event 88H , Umask 02H
-Qualify all unconditional near branch instructions
-excluding calls and indirect branches.
+.Pq Event 88H , Umask 82H
+Count all unconditional near branch instructions excluding calls and
+indirect branches.
.It Li BR_INST_EXEC.INDIRECT_JMP_NON_CALL_RET
-.Pq Event 88H , Umask 04H
-Qualify executed indirect near branch instructions
-that are not calls nor returns.
+.Pq Event 88H , Umask 84H
+Count executed indirect near branch instructions that are not calls nor
+returns.
.It Li BR_INST_EXEC.RETURN_NEAR
-.Pq Event 88H , Umask 08H
-Qualify indirect near branches that have a return
-mnemonic.
+.Pq Event 88H , Umask 88H
+Count indirect near branches that have a return mnemonic.
.It Li BR_INST_EXEC.DIRECT_NEAR_CALL
-.Pq Event 88H , Umask 10H
-Qualify unconditional near call branch instructions,
-excluding non call branch, executed.
+.Pq Event 88H , Umask 90H
+Count unconditional near call branch instructions, excluding non call
+branch, executed.
.It Li BR_INST_EXEC.INDIRECT_NEAR_CALL
-.Pq Event 88H , Umask 20H
-Qualify indirect near calls, including both register and
-memory indirect, executed.
-.It Li BR_INST_EXEC.NONTAKEN
-.Pq Event 88H , Umask 40H
-Qualify non-taken near branches executed.
-.It Li BR_INST_EXEC.TAKEN
-.Pq Event 88H , Umask 80H
-Qualify taken near branches executed. Must combine
-with 01H,02H, 04H, 08H, 10H, 20H.
+.Pq Event 88H , Umask A0H
+Count indirect near calls, including both register and memory indirect,
+executed.
.It Li BR_INST_EXEC.ALL_BRANCHES
.Pq Event 88H , Umask FFH
-Counts all near executed branches (not necessarily
-retired).
-.It Li BR_MISP_EXEC.COND
-.Pq Event 89H , Umask 01H
-Qualify conditional near branch instructions
-mispredicted.
+Counts all near executed branches (not necessarily retired).
+.It Li BR_MISP_EXEC.NONTAKEN_COND
+.Pq Event 89H , Umask 41H
+Count conditional near branch instructions mispredicted as nontaken.
+.It Li BR_MISP_EXEC.TAKEN_COND
+.Pq Event 89H , Umask 81H
+Count conditional near branch instructions mispredicted as taken.
.It Li BR_MISP_EXEC.INDIRECT_JMP_NON_CALL_RET
-.Pq Event 89H , Umask 04H
-Qualify mispredicted indirect near branch
-instructions that are not calls nor returns.
+.Pq Event 89H , Umask 84H
+Count mispredicted indirect near branch instructions that are not calls
+nor returns.
.It Li BR_MISP_EXEC.RETURN_NEAR
-.Pq Event 89H , Umask 08H
-Qualify mispredicted indirect near branches that
-have a return mnemonic.
+.Pq Event 89H , Umask 88H
+Count mispredicted indirect near branches that have a return mnemonic.
.It Li BR_MISP_EXEC.DIRECT_NEAR_CALL
-.Pq Event 89H , Umask 10H
-Qualify mispredicted unconditional near call branch
-instructions, excluding non call branch, executed.
+.Pq Event 89H , Umask 90H
+Count mispredicted unconditional near call branch instructions, excluding
+non call branch, executed.
.It Li BR_MISP_EXEC.INDIRECT_NEAR_CALL
-.Pq Event 89H , Umask 20H
-Qualify mispredicted indirect near calls, including
-both register and memory indirect, executed.
-.It Li BR_MISP_EXEC.NONTAKEN
-.Pq Event 89H , Umask 40H
-Qualify mispredicted non-taken near branches
-executed.
-.It Li BR_MISP_EXEC.TAKEN
-.Pq Event 89H , Umask 80H
-Qualify mispredicted taken near branches executed.
-Must combine with 01H,02H, 04H, 08H, 10H, 20H.
+.Pq Event 89H , Umask A0H
+Count mispredicted indirect near calls, including both register and memory
+indirect, executed.
.It Li BR_MISP_EXEC.ALL_BRANCHES
.Pq Event 89H , Umask FFH
-Counts all near executed branches (not necessarily
-retired).
+Counts all mispredicted near executed branches (not necessarily retired).
.It Li IDQ_UOPS_NOT_DELIVERED.CORE
.Pq Event 9CH , Umask 01H
Count number of non-delivered uops to RAT per
@@ -821,30 +808,24 @@ Count cases of saving new LBR records by hardware.
Randomly sampled loads whose latency is above a
user defined threshold. A small fraction of the overall
loads are sampled due to randomization.
-.It Li MEM_UOP_RETIRED.LOADS
-.Pq Event D0H , Umask 01H
-Qualify retired memory uops that are loads. Combine Supports PEBS and
-with umask 10H, 20H, 40H, 80H.
-.It Li MEM_UOP_RETIRED.STORES
-.Pq Event D0H , Umask 02H
-Qualify retired memory uops that are stores.
-Combine with umask 10H, 20H, 40H, 80H.
-.It Li MEM_UOP_RETIRED.STLB_MISS
-.Pq Event D0H , Umask 10H
-Qualify retired memory uops with STLB miss. Must
-combine with umask 01H, 02H, to produce counts.
-.It Li MEM_UOP_RETIRED.LOCK
-.Pq Event D0H , Umask 20H
-Qualify retired memory uops with lock. Must combine Supports PEBS and
-with umask 01H, 02H, to produce counts.
-.It Li MEM_UOP_RETIRED.SPLIT
-.Pq Event D0H , Umask 40H
-Qualify retired memory uops with line split. Must
-combine with umask 01H, 02H, to produce counts.
-.It Li MEM_UOP_RETIRED.ALL
-.Pq Event D0H , Umask 80H
-Qualify any retired memory uops. Must combine with Supports PEBS and
-umask 01H, 02H, to produce counts.
+.It Li MEM_UOPS_RETIRED.STLB_MISS_LOADS
+.Pq Event D0H , Umask 11H
+Count retired load uops that missed the STLB.
+.It Li MEM_UOPS_RETIRED.STLB_MISS_STORES
+.Pq Event D0H , Umask 12H
+Count retired store uops that missed the STLB.
+.It Li MEM_UOPS_RETIRED.SPLIT_LOADS
+.Pq Event D0H , Umask 41H
+Count retired load uops that were split across a cache line.
+.It Li MEM_UOPS_RETIRED.SPLIT_STORES
+.Pq Event D0H , Umask 42H
+Count retired store uops that were split across a cache line.
+.It Li MEM_UOPS_RETIRED.ALL_LOADS
+.Pq Event D0H , Umask 81H
+Count all retired load uops.
+.It Li MEM_UOPS_RETIRED.ALL_STORES
+.Pq Event D0H , Umask 82H
+Count all retired store uops.
.It Li MEM_LOAD_UOPS_RETIRED.L1_HIT
.Pq Event D1H , Umask 01H
Retired load uops with L1 cache hits as data sources.
@@ -936,25 +917,25 @@ Dirty L2 cache lines evicted by demand.
.Xr pmc 3 ,
.Xr pmc.atom 3 ,
.Xr pmc.core 3 ,
+.Xr pmc.corei7 3 ,
+.Xr pmc.corei7uc 3 ,
+.Xr pmc.haswelluc 3 ,
.Xr pmc.iaf 3 ,
-.Xr pmc.ucf 3 ,
+.Xr pmc.ivybridge 3 ,
+.Xr pmc.ivybridgexeon 3 ,
.Xr pmc.k7 3 ,
.Xr pmc.k8 3 ,
.Xr pmc.p4 3 ,
.Xr pmc.p5 3 ,
.Xr pmc.p6 3 ,
-.Xr pmc.corei7 3 ,
-.Xr pmc.corei7uc 3 ,
-.Xr pmc.haswelluc 3 ,
-.Xr pmc.ivybridge 3 ,
-.Xr pmc.ivybridgexeon 3 ,
.Xr pmc.sandybridge 3 ,
.Xr pmc.sandybridgeuc 3 ,
.Xr pmc.sandybridgexeon 3 ,
-.Xr pmc.westmere 3 ,
-.Xr pmc.westmereuc 3 ,
.Xr pmc.soft 3 ,
.Xr pmc.tsc 3 ,
+.Xr pmc.ucf 3 ,
+.Xr pmc.westmere 3 ,
+.Xr pmc.westmereuc 3 ,
.Xr pmc_cpuinfo 3 ,
.Xr pmclog 3 ,
.Xr hwpmc 4
diff --git a/lib/libpmc/pmc.haswellxeon.3 b/lib/libpmc/pmc.haswellxeon.3
new file mode 100644
index 0000000..7519030
--- /dev/null
+++ b/lib/libpmc/pmc.haswellxeon.3
@@ -0,0 +1,956 @@
+.\"
+.\" Copyright (c) 2013 Hiren Panchasara <hiren.panchasara@gmail.com>
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd November 21, 2014
+.Dt PMC.HASWELLXEON 3
+.Os
+.Sh NAME
+.Nm pmc.haswellxeon
+.Nd measurement events for
+.Tn Intel
+.Tn Haswell Xeon
+family CPUs
+.Sh LIBRARY
+.Lb libpmc
+.Sh SYNOPSIS
+.In pmc.h
+.Sh DESCRIPTION
+.Tn Intel
+.Tn "Haswell"
+CPUs contain PMCs conforming to version 2 of the
+.Tn Intel
+performance measurement architecture.
+These CPUs may contain up to two classes of PMCs:
+.Bl -tag -width "Li PMC_CLASS_IAP"
+.It Li PMC_CLASS_IAF
+Fixed-function counters that count only one hardware event per counter.
+.It Li PMC_CLASS_IAP
+Programmable counters that may be configured to count one of a defined
+set of hardware events.
+.El
+.Pp
+The number of PMCs available in each class and their widths need to be
+determined at run time by calling
+.Xr pmc_cpuinfo 3 .
+.Pp
+Intel Haswell Xeon PMCs are documented in
+.Rs
+.%B "Intel(R) 64 and IA-32 Architectures Software Developer's Manual"
+.%T "Combined Volumes: 1, 2A, 2B, 2C, 3A, 3B and 3C"
+.%N "Order Number: 325462-052US"
+.%D September 2014
+.%Q "Intel Corporation"
+.Re
+.Ss HASWELL FIXED FUNCTION PMCS
+These PMCs and their supported events are documented in
+.Xr pmc.iaf 3 .
+.Ss HASWELL PROGRAMMABLE PMCS
+The programmable PMCs support the following capabilities:
+.Bl -column "PMC_CAP_INTERRUPT" "Support"
+.It Em Capability Ta Em Support
+.It PMC_CAP_CASCADE Ta \&No
+.It PMC_CAP_EDGE Ta Yes
+.It PMC_CAP_INTERRUPT Ta Yes
+.It PMC_CAP_INVERT Ta Yes
+.It PMC_CAP_READ Ta Yes
+.It PMC_CAP_PRECISE Ta \&No
+.It PMC_CAP_SYSTEM Ta Yes
+.It PMC_CAP_TAGGING Ta \&No
+.It PMC_CAP_THRESHOLD Ta Yes
+.It PMC_CAP_USER Ta Yes
+.It PMC_CAP_WRITE Ta Yes
+.El
+.Ss Event Qualifiers
+Event specifiers for these PMCs support the following common
+qualifiers:
+.Bl -tag -width indent
+.It Li rsp= Ns Ar value
+Configure the Off-core Response bits.
+.Bl -tag -width indent
+.It Li DMND_DATA_RD
+Counts the number of demand and DCU prefetch data reads of full
+and partial cachelines as well as demand data page table entry
+cacheline reads. Does not count L2 data read prefetches or
+instruction fetches.
+.It Li REQ_DMND_RFO
+Counts the number of demand and DCU prefetch reads for ownership (RFO)
+requests generated by a write to data cacheline. Does not count L2 RFO
+prefetches.
+.It Li REQ_DMND_IFETCH
+Counts the number of demand and DCU prefetch instruction cacheline reads.
+Does not count L2 code read prefetches.
+.It Li REQ_WB
+Counts the number of writeback (modified to exclusive) transactions.
+.It Li REQ_PF_DATA_RD
+Counts the number of data cacheline reads generated by L2 prefetchers.
+.It Li REQ_PF_RFO
+Counts the number of RFO requests generated by L2 prefetchers.
+.It Li REQ_PF_IFETCH
+Counts the number of code reads generated by L2 prefetchers.
+.It Li REQ_PF_LLC_DATA_RD
+L2 prefetcher to L3 for loads.
+.It Li REQ_PF_LLC_RFO
+RFO requests generated by L2 prefetcher
+.It Li REQ_PF_LLC_IFETCH
+L2 prefetcher to L3 for instruction fetches.
+.It Li REQ_BUS_LOCKS
+Bus lock and split lock requests.
+.It Li REQ_STRM_ST
+Streaming store requests.
+.It Li REQ_OTHER
+Any other request that crosses IDI, including I/O.
+.It Li RES_ANY
+Catch all value for any response types.
+.It Li RES_SUPPLIER_NO_SUPP
+No Supplier Information available.
+.It Li RES_SUPPLIER_LLC_HITM
+M-state initial lookup stat in L3.
+.It Li RES_SUPPLIER_LLC_HITE
+E-state.
+.It Li RES_SUPPLIER_LLC_HITS
+S-state.
+.It Li RES_SUPPLIER_LLC_HITF
+F-state.
+.It Li RES_SUPPLIER_LOCAL
+Local DRAM Controller.
+.It Li RES_SNOOP_SNP_NONE
+No details on snoop-related information.
+.It Li RES_SNOOP_SNP_NO_NEEDED
+No snoop was needed to satisfy the request.
+.It Li RES_SNOOP_SNP_MISS
+A snoop was needed and it missed all snooped caches:
+-For LLC Hit, ReslHitl was returned by all cores
+-For LLC Miss, Rspl was returned by all sockets and data was returned from
+DRAM.
+.It Li RES_SNOOP_HIT_NO_FWD
+A snoop was needed and it hits in at least one snooped cache. Hit denotes a
+cache-line was valid before snoop effect. This includes:
+-Snoop Hit w/ Invalidation (LLC Hit, RFO)
+-Snoop Hit, Left Shared (LLC Hit/Miss, IFetch/Data_RD)
+-Snoop Hit w/ Invalidation and No Forward (LLC Miss, RFO Hit S)
+In the LLC Miss case, data is returned from DRAM.
+.It Li RES_SNOOP_HIT_FWD
+A snoop was needed and data was forwarded from a remote socket.
+This includes:
+-Snoop Forward Clean, Left Shared (LLC Hit/Miss, IFetch/Data_RD/RFT).
+.It Li RES_SNOOP_HITM
+A snoop was needed and it HitM-ed in local or remote cache. HitM denotes a
+cache-line was in modified state before effect as a results of snoop. This
+includes:
+-Snoop HitM w/ WB (LLC miss, IFetch/Data_RD)
+-Snoop Forward Modified w/ Invalidation (LLC Hit/Miss, RFO)
+-Snoop MtoS (LLC Hit, IFetch/Data_RD).
+.It Li RES_NON_DRAM
+Target was non-DRAM system address. This includes MMIO transactions.
+.El
+.It Li cmask= Ns Ar value
+Configure the PMC to increment only if the number of configured
+events measured in a cycle is greater than or equal to
+.Ar value .
+.It Li edge
+Configure the PMC to count the number of de-asserted to asserted
+transitions of the conditions expressed by the other qualifiers.
+If specified, the counter will increment only once whenever a
+condition becomes true, irrespective of the number of clocks during
+which the condition remains true.
+.It Li inv
+Invert the sense of comparison when the
+.Dq Li cmask
+qualifier is present, making the counter increment when the number of
+events per cycle is less than the value specified by the
+.Dq Li cmask
+qualifier.
+.It Li os
+Configure the PMC to count events happening at processor privilege
+level 0.
+.It Li usr
+Configure the PMC to count events occurring at privilege levels 1, 2
+or 3.
+.El
+.Pp
+If neither of the
+.Dq Li os
+or
+.Dq Li usr
+qualifiers are specified, the default is to enable both.
+.Ss Event Specifiers (Programmable PMCs)
+Haswell programmable PMCs support the following events:
+.Bl -tag -width indent
+.It Li LD_BLOCKS.STORE_FORWARD
+.Pq Event 03H , Umask 02H
+Loads blocked by overlapping with store buffer that
+cannot be forwarded.
+.It Li MISALIGN_MEM_REF.LOADS
+.Pq Event 05H , Umask 01H
+Speculative cache-line split load uops dispatched to
+L1D.
+.It Li MISALIGN_MEM_REF.STORES
+.Pq Event 05H , Umask 02H
+Speculative cache-line split Store-address uops
+dispatched to L1D.
+.It Li LD_BLOCKS_PARTIAL.ADDRESS_ALIAS
+.Pq Event 07H , Umask 01H
+False dependencies in MOB due to partial compare
+on address.
+.It Li DTLB_LOAD_MISSES.MISS_CAUSES_A_WALK
+.Pq Event 08H , Umask 01H
+Misses in all TLB levels that cause a page walk of any
+page size.
+.It Li DTLB_LOAD_MISSES.WALK_COMPLETED_4K
+.Pq Event 08H , Umask 02H
+Completed page walks due to demand load misses
+that caused 4K page walks in any TLB levels.
+.It Li DTLB_LOAD_MISSES.WALK_COMPLETED_2M_4K
+.Pq Event 08H , Umask 02H
+Completed page walks due to demand load misses
+that caused 2M/4M page walks in any TLB levels.
+.It Li DTLB_LOAD_MISSES.WALK_COMPLETED
+.Pq Event 08H , Umask 0EH
+Completed page walks in any TLB of any page size
+due to demand load misses
+.It Li DTLB_LOAD_MISSES.WALK_DURATION
+.Pq Event 08H , Umask 10H
+Cycle PMH is busy with a walk.
+.It Li DTLB_LOAD_MISSES.STLB_HIT_4K
+.Pq Event 08H , Umask 20H
+Load misses that missed DTLB but hit STLB (4K).
+.It Li DTLB_LOAD_MISSES.STLB_HIT_2M
+.Pq Event 08H , Umask 40H
+Load misses that missed DTLB but hit STLB (2M).
+.It Li DTLB_LOAD_MISSES.STLB_HIT
+.Pq Event 08H , Umask 60H
+Number of cache load STLB hits. No page walk.
+.It Li DTLB_LOAD_MISSES.PDE_CACHE_MISS
+.Pq Event 08H , Umask 80H
+DTLB demand load misses with low part of linear-to-
+physical address translation missed
+.It Li INT_MISC.RECOVERY_CYCLES
+.Pq Event 0DH , Umask 03H
+Cycles waiting to recover after Machine Clears
+except JEClear. Set Cmask= 1.
+.It Li UOPS_ISSUED.ANY
+.Pq Event 0EH , Umask 01H
+ncrements each cycle the # of Uops issued by the
+RAT to RS.
+Set Cmask = 1, Inv = 1, Any= 1to count stalled cycles
+of this core.
+.It Li UOPS_ISSUED.FLAGS_MERGE
+.Pq Event 0EH , Umask 10H
+Number of flags-merge uops allocated. Such uops
+adds delay.
+.It Li UOPS_ISSUED.SLOW_LEA
+.Pq Event 0EH , Umask 20H
+Number of slow LEA or similar uops allocated. Such
+uop has 3 sources (e.g. 2 sources + immediate)
+regardless if as a result of LEA instruction or not.
+.It Li UOPS_ISSUED.SiNGLE_MUL
+.Pq Event 0EH , Umask 40H
+Number of multiply packed/scalar single precision
+uops allocated.
+.It Li L2_RQSTS.DEMAND_DATA_RD_MISS
+.Pq Event 24H , Umask 21H
+Demand Data Read requests that missed L2, no
+rejects.
+.It Li L2_RQSTS.DEMAND_DATA_RD_HIT
+.Pq Event 24H , Umask 41H
+Demand Data Read requests that hit L2 cache.
+.It Li L2_RQSTS.ALL_DEMAND_DATA_RD
+.Pq Event 24H , Umask E1H
+Counts any demand and L1 HW prefetch data load
+requests to L2.
+.It Li L2_RQSTS.RFO_HIT
+.Pq Event 24H , Umask 42H
+Counts the number of store RFO requests that hit
+the L2 cache.
+.It Li L2_RQSTS.RFO_MISS
+.Pq Event 24H , Umask 22H
+Counts the number of store RFO requests that miss
+the L2 cache.
+.It Li L2_RQSTS.ALL_RFO
+.Pq Event 24H , Umask E2H
+Counts all L2 store RFO requests.
+.It Li L2_RQSTS.CODE_RD_HIT
+.Pq Event 24H , Umask 44H
+Number of instruction fetches that hit the L2 cache.
+.It Li L2_RQSTS.CODE_RD_MISS
+.Pq Event 24H , Umask 24H
+Number of instruction fetches that missed the L2
+cache.
+.It Li L2_RQSTS.ALL_DEMAND_MISS
+.Pq Event 24H , Umask 27H
+Demand requests that miss L2 cache.
+.It Li L2_RQSTS.ALL_DEMAND_REFERENCES
+.Pq Event 24H , Umask E7H
+Demand requests to L2 cache.
+.It Li L2_RQSTS.ALL_CODE_RD
+.Pq Event 24H , Umask E4H
+Counts all L2 code requests.
+.It Li L2_RQSTS.L2_PF_HIT
+.Pq Event 24H , Umask 50H
+Counts all L2 HW prefetcher requests that hit L2.
+.It Li L2_RQSTS.L2_PF_MISS
+.Pq Event 24H , Umask 30H
+Counts all L2 HW prefetcher requests that missed
+L2.
+.It Li L2_RQSTS.ALL_PF
+.Pq Event 24H , Umask F8H
+Counts all L2 HW prefetcher requests.
+.It Li L2_RQSTS.MISS
+.Pq Event 24H , Umask 3FH
+All requests that missed L2.
+.It Li L2_RQSTS.REFERENCES
+.Pq Event 24H , Umask FFH
+All requests to L2 cache.
+.It Li L2_DEMAND_RQSTS.WB_HIT
+.Pq Event 27H , Umask 50H
+Not rejected writebacks that hit L2 cache
+.It Li LONGEST_LAT_CACHE.REFERENCE
+.Pq Event 2EH , Umask 4FH
+This event counts requests originating from the core
+that reference a cache line in the last level cache.
+.It Li LONGEST_LAT_CACHE.MISS
+.Pq Event 2EH , Umask 41H
+This event counts each cache miss condition for
+references to the last level cache.
+.It Li CPU_CLK_UNHALTED.THREAD_P
+.Pq Event 3CH , Umask 00H
+Counts the number of thread cycles while the thread
+is not in a halt state. The thread enters the halt state
+when it is running the HLT instruction. The core
+frequency may change from time to time due to
+power or thermal throttling.
+.It Li CPU_CLK_THREAD_UNHALTED.REF_XCLK
+.Pq Event 3CH , Umask 01H
+Increments at the frequency of XCLK (100 MHz)
+when not halted.
+.It Li L1D_PEND_MISS.PENDING
+.Pq Event 48H , Umask 01H
+Increments the number of outstanding L1D misses
+every cycle. Set Cmaks = 1 and Edge =1 to count
+occurrences.
+.It Li DTLB_STORE_MISSES.MISS_CAUSES_A_WALK
+.Pq Event 49H , Umask 01H
+Miss in all TLB levels causes an page walk of any
+page size (4K/2M/4M/1G).
+.It Li DTLB_STORE_MISSES.WALK_COMPLETED_4K
+.Pq Event 49H , Umask 02H
+Completed page walks due to store misses in one or
+more TLB levels of 4K page structure.
+.It Li DTLB_STORE_MISSES.WALK_COMPLETED_2M_4M
+.Pq Event 49H , Umask 04H
+Completed page walks due to store misses in one or
+more TLB levels of 2M/4M page structure.
+.It Li DTLB_STORE_MISSES.WALK_COMPLETED
+.Pq Event 49H , Umask 0EH
+Completed page walks due to store miss in any TLB
+levels of any page size (4K/2M/4M/1G).
+.It Li DTLB_STORE_MISSES.WALK_DURATION
+.Pq Event 49H , Umask 10H
+Cycles PMH is busy with this walk.
+.It Li DTLB_STORE_MISSES.STLB_HIT_4K
+.Pq Event 49H , Umask 20H
+Store misses that missed DTLB but hit STLB (4K).
+.It Li DTLB_STORE_MISSES.STLB_HIT_2M
+.Pq Event 49H , Umask 40H
+Store misses that missed DTLB but hit STLB (2M).
+.It Li DTLB_STORE_MISSES.STLB_HIT
+.Pq Event 49H , Umask 60H
+Store operations that miss the first TLB level but hit
+the second and do not cause page walks.
+.It Li DTLB_STORE_MISSES.PDE_CACHE_MISS
+.Pq Event 49H , Umask 80H
+DTLB store misses with low part of linear-to-physical
+address translation missed.
+.It Li LOAD_HIT_PRE.SW_PF
+.Pq Event 4CH , Umask 01H
+Non-SW-prefetch load dispatches that hit fill buffer
+allocated for S/W prefetch.
+.It Li LOAD_HIT_PRE.HW_PF
+.Pq Event 4CH , Umask 02H
+Non-SW-prefetch load dispatches that hit fill buffer
+allocated for H/W prefetch.
+.It Li L1D.REPLACEMENT
+.Pq Event 51H , Umask 01H
+Counts the number of lines brought into the L1 data
+cache.
+.It Li MOVE_ELIMINATION.INT_NOT_ELIMINATED
+.Pq Event 58H , Umask 04H
+Number of integer Move Elimination candidate uops
+that were not eliminated.
+.It Li MOVE_ELIMINATION.SMID_NOT_ELIMINATED
+.Pq Event 58H , Umask 08H
+Number of SIMD Move Elimination candidate uops
+that were not eliminated.
+.It Li MOVE_ELIMINATION.INT_ELIMINATED
+.Pq Event 58H , Umask 01H
+Unhalted core cycles when the thread is in ring 0.
+.It Li MOVE_ELIMINATION.SMID_ELIMINATED
+.Pq Event 58H , Umask 02H
+Number of SIMD Move Elimination candidate uops
+that were eliminated.
+.It Li CPL_CYCLES.RING0
+.Pq Event 5CH , Umask 02H
+Unhalted core cycles when the thread is in ring 0.
+.It Li CPL_CYCLES.RING123
+.Pq Event 5CH , Umask 01H
+Unhalted core cycles when the thread is not in ring 0.
+.It Li RS_EVENTS.EMPTY_CYCLES
+.Pq Event 5EH , Umask 01H
+Cycles the RS is empty for the thread.
+.It Li OFFCORE_REQUESTS_OUTSTANDING.DEMAND_DATA_RD
+.Pq Event 60H , Umask 01H
+Offcore outstanding Demand Data Read transactions
+in SQ to uncore. Set Cmask=1 to count cycles.
+.It Li OFFCORE_REQUESTS_OUTSTANDING.DEMAND_CORE_RD
+.Pq Event 60H , Umask 02H
+Offcore outstanding Demand code Read transactions
+in SQ to uncore. Set Cmask=1 to count cycles.
+.It Li OFFCORE_REQUESTS_OUTSTANDING.DEMAND_RFO
+.Pq Event 60H , Umask 04H
+Offcore outstanding RFO store transactions in SQ to
+uncore. Set Cmask=1 to count cycles.
+.It Li OFFCORE_REQUESTS_OUTSTANDING.ALL_DATA_RD
+.Pq Event 60H , Umask 08H
+Offcore outstanding cacheable data read
+transactions in SQ to uncore. Set Cmask=1 to count
+cycles.
+.It Li LOCK_CYCLES.SPLIT_LOCK_UC_LOCK_DURATION
+.Pq Event 63H , Umask 01H
+Cycles in which the L1D and L2 are locked, due to a
+UC lock or split lock.
+.It Li LOCK_CYCLES.CACHE_LOCK_DURATION
+.Pq Event 63H , Umask 02H
+Cycles in which the L1D is locked.
+.It Li IDQ.EMPTY
+.Pq Event 79H , Umask 02H
+Counts cycles the IDQ is empty.
+.It Li IDQ.MITE_UOPS
+.Pq Event 79H , Umask 04H
+Increment each cycle # of uops delivered to IDQ from
+MITE path.
+Set Cmask = 1 to count cycles.
+.It Li IDQ.DSB_UOPS
+.Pq Event 79H , Umask 08H
+Increment each cycle. # of uops delivered to IDQ
+from DSB path.
+Set Cmask = 1 to count cycles.
+.It Li IDQ.MS_DSB_UOPS
+.Pq Event 79H , Umask 10H
+Increment each cycle # of uops delivered to IDQ
+when MS_busy by DSB. Set Cmask = 1 to count
+cycles. Add Edge=1 to count # of delivery.
+.It Li IDQ.MS_MITE_UOPS
+.Pq Event 79H , Umask 20H
+ncrement each cycle # of uops delivered to IDQ
+when MS_busy by MITE. Set Cmask = 1 to count
+cycles.
+.It Li IDQ.MS_UOPS
+.Pq Event 79H , Umask 30H
+Increment each cycle # of uops delivered to IDQ from
+MS by either DSB or MITE. Set Cmask = 1 to count
+cycles.
+.It Li IDQ.ALL_DSB_CYCLES_ANY_UOPS
+.Pq Event 79H , Umask 18H
+Counts cycles DSB is delivered at least one uops. Set
+Cmask = 1.
+.It Li IDQ.ALL_DSB_CYCLES_4_UOPS
+.Pq Event 79H , Umask 18H
+Counts cycles DSB is delivered four uops. Set Cmask
+=4.
+.It Li IDQ.ALL_MITE_CYCLES_ANY_UOPS
+.Pq Event 79H , Umask 24H
+Counts cycles MITE is delivered at least one uops. Set
+Cmask = 1.
+.It Li IDQ.ALL_MITE_CYCLES_4_UOPS
+.Pq Event 79H , Umask 24H
+Counts cycles MITE is delivered four uops. Set Cmask
+=4.
+.It Li IDQ.MITE_ALL_UOPS
+.Pq Event 79H , Umask 3CH
+# of uops delivered to IDQ from any path.
+.It Li ICACHE.MISSES
+.Pq Event 80H , Umask 02H
+Number of Instruction Cache, Streaming Buffer and
+Victim Cache Misses. Includes UC accesses.
+.It Li ITLB_MISSES.MISS_CAUSES_A_WALK
+.Pq Event 85H , Umask 01H
+Misses in ITLB that causes a page walk of any page
+size.
+.It Li ITLB_MISSES.WALK_COMPLETED_4K
+.Pq Event 85H , Umask 02H
+Completed page walks due to misses in ITLB 4K page
+entries.
+.It Li TLB_MISSES.WALK_COMPLETED_2M_4M
+.Pq Event 85H , Umask 04H
+Completed page walks due to misses in ITLB 2M/4M
+page entries.
+.It Li ITLB_MISSES.WALK_COMPLETED
+.Pq Event 85H , Umask 0EH
+Completed page walks in ITLB of any page size.
+.It Li ITLB_MISSES.WALK_DURATION
+.Pq Event 85H , Umask 10H
+Cycle PMH is busy with a walk.
+.It Li ITLB_MISSES.STLB_HIT_4K
+.Pq Event 85H , Umask 20H
+ITLB misses that hit STLB (4K).
+.It Li ITLB_MISSES.STLB_HIT_2M
+.Pq Event 85H , Umask 40H
+ITLB misses that hit STLB (2K).
+.It Li ITLB_MISSES.STLB_HIT
+.Pq Event 85H , Umask 60H
+TLB misses that hit STLB. No page walk.
+.It Li ILD_STALL.LCP
+.Pq Event 87H , Umask 01H
+Stalls caused by changing prefix length of the
+instruction.
+.It Li ILD_STALL.IQ_FULL
+.Pq Event 87H , Umask 04H
+Stall cycles due to IQ is full.
+.It Li BR_INST_EXEC.NONTAKEN_COND
+.Pq Event 88H , Umask 41H
+Count conditional near branch instructions that were executed (but not
+necessarily retired) and not taken.
+.It Li BR_INST_EXEC.TAKEN_COND
+.Pq Event 88H , Umask 81H
+Count conditional near branch instructions that were executed (but not
+necessarily retired) and taken.
+.It Li BR_INST_EXEC.DIRECT_JMP
+.Pq Event 88H , Umask 82H
+Count all unconditional near branch instructions excluding calls and
+indirect branches.
+.It Li BR_INST_EXEC.INDIRECT_JMP_NON_CALL_RET
+.Pq Event 88H , Umask 84H
+Count executed indirect near branch instructions that are not calls nor
+returns.
+.It Li BR_INST_EXEC.RETURN_NEAR
+.Pq Event 88H , Umask 88H
+Count indirect near branches that have a return mnemonic.
+.It Li BR_INST_EXEC.DIRECT_NEAR_CALL
+.Pq Event 88H , Umask 90H
+Count unconditional near call branch instructions, excluding non call
+branch, executed.
+.It Li BR_INST_EXEC.INDIRECT_NEAR_CALL
+.Pq Event 88H , Umask A0H
+Count indirect near calls, including both register and memory indirect,
+executed.
+.It Li BR_INST_EXEC.ALL_BRANCHES
+.Pq Event 88H , Umask FFH
+Counts all near executed branches (not necessarily retired).
+.It Li BR_MISP_EXEC.NONTAKEN_COND
+.Pq Event 89H , Umask 41H
+Count conditional near branch instructions mispredicted as nontaken.
+.It Li BR_MISP_EXEC.TAKEN_COND
+.Pq Event 89H , Umask 81H
+Count conditional near branch instructions mispredicted as taken.
+.It Li BR_MISP_EXEC.INDIRECT_JMP_NON_CALL_RET
+.Pq Event 89H , Umask 84H
+Count mispredicted indirect near branch instructions that are not calls
+nor returns.
+.It Li BR_MISP_EXEC.RETURN_NEAR
+.Pq Event 89H , Umask 88H
+Count mispredicted indirect near branches that have a return mnemonic.
+.It Li BR_MISP_EXEC.DIRECT_NEAR_CALL
+.Pq Event 89H , Umask 90H
+Count mispredicted unconditional near call branch instructions, excluding
+non call branch, executed.
+.It Li BR_MISP_EXEC.INDIRECT_NEAR_CALL
+.Pq Event 89H , Umask A0H
+Count mispredicted indirect near calls, including both register and memory
+indirect, executed.
+.It Li BR_MISP_EXEC.ALL_BRANCHES
+.Pq Event 89H , Umask FFH
+Counts all mispredicted near executed branches (not necessarily retired).
+.It Li IDQ_UOPS_NOT_DELIVERED.CORE
+.Pq Event 9CH , Umask 01H
+Count number of non-delivered uops to RAT per
+thread.
+.It Li UOPS_EXECUTED_PORT.PORT_0
+.Pq Event A1H , Umask 01H
+Cycles which a Uop is dispatched on port 0 in this
+thread.
+.It Li UOPS_EXECUTED_PORT.PORT_1
+.Pq Event A1H , Umask 02H
+Cycles which a Uop is dispatched on port 1 in this
+thread.
+.It Li UOPS_EXECUTED_PORT.PORT_2
+.Pq Event A1H , Umask 04H
+Cycles which a Uop is dispatched on port 2 in this
+thread.
+.It Li UOPS_EXECUTED_PORT.PORT_3
+.Pq Event A1H , Umask 08H
+Cycles which a Uop is dispatched on port 3 in this
+thread.
+.It Li UOPS_EXECUTED_PORT.PORT_4
+.Pq Event A1H , Umask 10H
+Cycles which a Uop is dispatched on port 4 in this
+thread.
+.It Li UOPS_EXECUTED_PORT.PORT_5
+.Pq Event A1H , Umask 20H
+Cycles which a Uop is dispatched on port 5 in this
+thread.
+.It Li UOPS_EXECUTED_PORT.PORT_6
+.Pq Event A1H , Umask 40H
+Cycles which a Uop is dispatched on port 6 in this
+thread.
+.It Li UOPS_EXECUTED_PORT.PORT_7
+.Pq Event A1H , Umask 80H
+Cycles which a Uop is dispatched on port 7 in this
+thread.
+.It Li RESOURCE_STALLS.ANY
+.Pq Event A2H , Umask 01H
+Cycles Allocation is stalled due to Resource Related
+reason.
+.It Li RESOURCE_STALLS.RS
+.Pq Event A2H , Umask 04H
+Cycles stalled due to no eligible RS entry available.
+.It Li RESOURCE_STALLS.SB
+.Pq Event A2H , Umask 08H
+Cycles stalled due to no store buffers available (not
+including draining form sync).
+.It Li RESOURCE_STALLS.ROB
+.Pq Event A2H , Umask 10H
+Cycles stalled due to re-order buffer full.
+.It Li CYCLE_ACTIVITY.CYCLES_L2_PENDING
+.Pq Event A3H , Umask 01H
+Cycles with pending L2 miss loads. Set Cmask=2 to
+count cycle.
+.It Li CYCLE_ACTIVITY.CYCLES_LDM_PENDING
+.Pq Event A3H , Umask 02H
+Cycles with pending memory loads. Set Cmask=2 to
+count cycle.
+.It Li CYCLE_ACTIVITY.STALLS_L2_PENDING
+.Pq Event A3H , Umask 05H
+Number of loads missed L2.
+.It Li CYCLE_ACTIVITY.CYCLES_L1D_PENDING
+.Pq Event A3H , Umask 08H
+Cycles with pending L1 cache miss loads. Set
+Cmask=8 to count cycle.
+.It Li ITLB.ITLB_FLUSH
+.Pq Event AEH , Umask 01H
+Counts the number of ITLB flushes, includes
+4k/2M/4M pages.
+.It Li OFFCORE_REQUESTS.DEMAND_DATA_RD
+.Pq Event B0H , Umask 01H
+Demand data read requests sent to uncore.
+.It Li OFFCORE_REQUESTS.DEMAND_CODE_RD
+.Pq Event B0H , Umask 02H
+Demand code read requests sent to uncore.
+.It Li OFFCORE_REQUESTS.DEMAND_RFO
+.Pq Event B0H , Umask 04H
+Demand RFO read requests sent to uncore, including
+regular RFOs, locks, ItoM.
+.It Li OFFCORE_REQUESTS.ALL_DATA_RD
+.Pq Event B0H , Umask 08H
+Data read requests sent to uncore (demand and
+prefetch).
+.It Li UOPS_EXECUTED.CORE
+.Pq Event B1H , Umask 02H
+Counts total number of uops to be executed per-core
+each cycle.
+.It Li OFF_CORE_RESPONSE_0
+.Pq Event B7H , Umask 01H
+Requires MSR 01A6H
+.It Li OFF_CORE_RESPONSE_1
+.Pq Event BBH , Umask 01H
+Requires MSR 01A7H
+.It Li PAGE_WALKER_LOADS.DTLB_L1
+.Pq Event BCH , Umask 11H
+Number of DTLB page walker loads that hit in the
+L1+FB.
+.It Li PAGE_WALKER_LOADS.ITLB_L1
+.Pq Event BCH , Umask 21H
+Number of ITLB page walker loads that hit in the
+L1+FB.
+.It Li PAGE_WALKER_LOADS.DTLB_L2
+.Pq Event BCH , Umask 12H
+Number of DTLB page walker loads that hit in the L2.
+.It Li PAGE_WALKER_LOADS.ITLB_L2
+.Pq Event BCH , Umask 22H
+Number of ITLB page walker loads that hit in the L2.
+.It Li PAGE_WALKER_LOADS.DTLB_L3
+.Pq Event BCH , Umask 14H
+Number of DTLB page walker loads that hit in the L3.
+.It Li PAGE_WALKER_LOADS.ITLB_L3
+.Pq Event BCH , Umask 24H
+Number of ITLB page walker loads that hit in the L3.
+.It Li PAGE_WALKER_LOADS.DTLB_MEMORY
+.Pq Event BCH , Umask 18H
+Number of DTLB page walker loads from memory.
+.It Li PAGE_WALKER_LOADS.ITLB_MEMORY
+.Pq Event BCH , Umask 28H
+Number of ITLB page walker loads from memory.
+.It Li TLB_FLUSH.DTLB_THREAD
+.Pq Event BDH , Umask 01H
+DTLB flush attempts of the thread-specific entries.
+.It Li TLB_FLUSH.STLB_ANY
+.Pq Event BDH , Umask 20H
+Count number of STLB flush attempts.
+.It Li INST_RETIRED.ANY_P
+.Pq Event C0H , Umask 00H
+Number of instructions at retirement.
+.It Li INST_RETIRED.ALL
+.Pq Event C0H , Umask 01H
+Precise instruction retired event with HW to reduce
+effect of PEBS shadow in IP distribution.
+.It Li OTHER_ASSISTS.AVX_TO_SSE
+.Pq Event C1H , Umask 08H
+Number of transitions from AVX-256 to legacy SSE
+when penalty applicable.
+.It Li OTHER_ASSISTS.SSE_TO_AVX
+.Pq Event C1H , Umask 10H
+Number of transitions from SSE to AVX-256 when
+penalty applicable.
+.It Li OTHER_ASSISTS.ANY_WB_ASSIST
+.Pq Event C1H , Umask 40H
+Number of microcode assists invoked by HW upon
+uop writeback.
+.It Li UOPS_RETIRED.ALL
+.Pq Event C2H , Umask 01H
+Counts the number of micro-ops retired, Use
+cmask=1 and invert to count active cycles or stalled
+cycles.
+.It Li UOPS_RETIRED.RETIRE_SLOTS
+.Pq Event C2H , Umask 02H
+Counts the number of retirement slots used each
+cycle.
+.It Li MACHINE_CLEARS.MEMORY_ORDERING
+.Pq Event C3H , Umask 02H
+Counts the number of machine clears due to memory
+order conflicts.
+.It Li MACHINE_CLEARS.SMC
+.Pq Event C3H , Umask 04H
+Number of self-modifying-code machine clears
+detected.
+.It Li MACHINE_CLEARS.MASKMOV
+.Pq Event C3H , Umask 20H
+Counts the number of executed AVX masked load
+operations that refer to an illegal address range with
+the mask bits set to 0.
+.It Li BR_INST_RETIRED.ALL_BRANCHES
+.Pq Event C4H , Umask 00H
+Branch instructions at retirement.
+.It Li BR_INST_RETIRED.CONDITIONAL
+.Pq Event C4H , Umask 01H
+Counts the number of conditional branch instructions Supports PEBS
+retired.
+.It Li BR_INST_RETIRED.NEAR_CALL
+.Pq Event C4H , Umask 02H
+Direct and indirect near call instructions retired.
+.It Li BR_INST_RETIRED.ALL_BRANCHES
+.Pq Event C4H , Umask 04H
+Counts the number of branch instructions retired.
+.It Li BR_INST_RETIRED.NEAR_RETURN
+.Pq Event C4H , Umask 08H
+Counts the number of near return instructions
+retired.
+.It Li BR_INST_RETIRED.NOT_TAKEN
+.Pq Event C4H , Umask 10H
+Counts the number of not taken branch instructions
+retired.
+ It Li BR_INST_RETIRED.NEAR_TAKEN
+.Pq Event C4H , Umask 20H
+Number of near taken branches retired.
+.It Li BR_INST_RETIRED.FAR_BRANCH
+.Pq Event C4H , Umask 40H
+Number of far branches retired.
+.It Li BR_MISP_RETIRED.ALL_BRANCHES
+.Pq Event C5H , Umask 00H
+Mispredicted branch instructions at retirement
+.It Li BR_MISP_RETIRED.CONDITIONAL
+.Pq Event C5H , Umask 01H
+Mispredicted conditional branch instructions retired.
+.It Li BR_MISP_RETIRED.CONDITIONAL
+.Pq Event C5H , Umask 04H
+Mispredicted macro branch instructions retired.
+.It Li FP_ASSIST.X87_OUTPUT
+.Pq Event CAH , Umask 02H
+Number of X87 FP assists due to Output values.
+.It Li FP_ASSIST.X87_INPUT
+.Pq Event CAH , Umask 04H
+Number of X87 FP assists due to input values.
+.It Li FP_ASSIST.SIMD_OUTPUT
+.Pq Event CAH , Umask 08H
+Number of SIMD FP assists due to Output values.
+.It Li FP_ASSIST.SIMD_INPUT
+.Pq Event CAH , Umask 10H
+Number of SIMD FP assists due to input values.
+.It Li FP_ASSIST.ANY
+.Pq Event CAH , Umask 1EH
+Cycles with any input/output SSE* or FP assists.
+.It Li ROB_MISC_EVENTS.LBR_INSERTS
+.Pq Event CCH , Umask 20H
+Count cases of saving new LBR records by hardware.
+.It Li MEM_TRANS_RETIRED.LOAD_LATENCY
+.Pq Event CDH , Umask 01H
+Randomly sampled loads whose latency is above a
+user defined threshold. A small fraction of the overall
+loads are sampled due to randomization.
+.It Li MEM_UOPS_RETIRED.STLB_MISS_LOADS
+.Pq Event D0H , Umask 11H
+Count retired load uops that missed the STLB.
+.It Li MEM_UOPS_RETIRED.STLB_MISS_STORES
+.Pq Event D0H , Umask 12H
+Count retired store uops that missed the STLB.
+.It Li MEM_UOPS_RETIRED.SPLIT_LOADS
+.Pq Event D0H , Umask 41H
+Count retired load uops that were split across a cache line.
+.It Li MEM_UOPS_RETIRED.SPLIT_STORES
+.Pq Event D0H , Umask 42H
+Count retired store uops that were split across a cache line.
+.It Li MEM_UOPS_RETIRED.ALL_LOADS
+.Pq Event D0H , Umask 81H
+Count all retired load uops.
+.It Li MEM_UOPS_RETIRED.ALL_STORES
+.Pq Event D0H , Umask 82H
+Count all retired store uops.
+.It Li MEM_LOAD_UOPS_RETIRED.L1_HIT
+.Pq Event D1H , Umask 01H
+Retired load uops with L1 cache hits as data sources.
+.It Li MEM_LOAD_UOPS_RETIRED.L2_HIT
+.Pq Event D1H , Umask 02H
+Retired load uops with L2 cache hits as data sources.
+.It Li MEM_LOAD_UOPS_RETIRED.LLC_HIT
+.Pq Event D1H , Umask 04H
+Retired load uops with LLC cache hits as data
+sources.
+.It Li MEM_LOAD_UOPS_RETIRED.L2_MISS
+.Pq Event D1H , Umask 10H
+Retired load uops missed L2. Unknown data source
+excluded.
+.It Li MEM_LOAD_UOPS_RETIRED.HIT_LFB
+.Pq Event D1H , Umask 40H
+Retired load uops which data sources were load uops
+missed L1 but hit FB due to preceding miss to the
+same cache line with data not ready.
+.It Li MEM_LOAD_UOPS_LLC_HIT_RETIRED.XSNP_MISS
+.Pq Event D2H , Umask 01H
+Retired load uops which data sources were LLC hit
+and cross-core snoop missed in on-pkg core cache.
+.It Li MEM_LOAD_UOPS_LLC_HIT_RETIRED.XSNP_HIT
+.Pq Event D2H , Umask 02H
+Retired load uops which data sources were LLC and
+cross-core snoop hits in on-pkg core cache.
+.It Li MEM_LOAD_UOPS_LLC_HIT_RETIRED.XSNP_HITM
+.Pq Event D2H , Umask 04H
+Retired load uops which data sources were HitM
+responses from shared LLC.
+.It Li MEM_LOAD_UOPS_LLC_HIT_RETIRED.XSNP_NONE
+.Pq Event D2H , Umask 08H
+Retired load uops which data sources were hits in
+LLC without snoops required.
+.It Li MEM_LOAD_UOPS_LLC_MISS_RETIRED.LOCAL_DRAM
+.Pq Event D3H , Umask 01H
+Retired load uops which data sources missed LLC but
+serviced from local dram.
+.It Li BACLEARS.ANY
+.Pq Event E6H , Umask 1FH
+Number of front end re-steers due to BPU
+misprediction.
+.It Li L2_TRANS.DEMAND_DATA_RD
+.Pq Event F0H , Umask 01H
+Demand Data Read requests that access L2 cache.
+.It Li L2_TRANS.RFO
+.Pq Event F0H , Umask 02H
+RFO requests that access L2 cache.
+.It Li L2_TRANS.CODE_RD
+.Pq Event F0H , Umask 04H
+L2 cache accesses when fetching instructions.
+.It Li L2_TRANS.ALL_PF
+.Pq Event F0H , Umask 08H
+Any MLC or LLC HW prefetch accessing L2, including
+rejects.
+.It Li L2_TRANS.L1D_WB
+.Pq Event F0H , Umask 10H
+L1D writebacks that access L2 cache.
+.It Li L2_TRANS.L2_FILL
+.Pq Event F0H , Umask 20H
+L2 fill requests that access L2 cache.
+.It Li L2_TRANS.L2_WB
+.Pq Event F0H , Umask 40H
+L2 writebacks that access L2 cache.
+.It Li L2_TRANS.ALL_REQUESTS
+.Pq Event F0H , Umask 80H
+Transactions accessing L2 pipe.
+.It Li L2_LINES_IN.I
+.Pq Event F1H , Umask 01H
+L2 cache lines in I state filling L2.
+.It Li L2_LINES_IN.S
+.Pq Event F1H , Umask 02H
+L2 cache lines in S state filling L2.
+.It Li L2_LINES_IN.E
+.Pq Event F1H , Umask 04H
+L2 cache lines in E state filling L2.
+.It Li L2_LINES_IN.ALL
+.Pq Event F1H , Umask 07H
+L2 cache lines filling L2.
+.It Li L2_LINES_OUT.DEMAND_CLEAN
+.Pq Event F2H , Umask 05H
+Clean L2 cache lines evicted by demand.
+.It Li L2_LINES_OUT.DEMAND_DIRTY
+.Pq Event F2H , Umask 06H
+Dirty L2 cache lines evicted by demand.
+.El
+.Sh SEE ALSO
+.Xr pmc 3 ,
+.Xr pmc.atom 3 ,
+.Xr pmc.core 3 ,
+.Xr pmc.iaf 3 ,
+.Xr pmc.ucf 3 ,
+.Xr pmc.k7 3 ,
+.Xr pmc.k8 3 ,
+.Xr pmc.p4 3 ,
+.Xr pmc.p5 3 ,
+.Xr pmc.p6 3 ,
+.Xr pmc.corei7 3 ,
+.Xr pmc.corei7uc 3 ,
+.Xr pmc.haswell 3 ,
+.Xr pmc.haswelluc 3 ,
+.Xr pmc.ivybridge 3 ,
+.Xr pmc.ivybridgexeon 3 ,
+.Xr pmc.sandybridge 3 ,
+.Xr pmc.sandybridgeuc 3 ,
+.Xr pmc.sandybridgexeon 3 ,
+.Xr pmc.westmere 3 ,
+.Xr pmc.westmereuc 3 ,
+.Xr pmc.soft 3 ,
+.Xr pmc.tsc 3 ,
+.Xr pmc_cpuinfo 3 ,
+.Xr pmclog 3 ,
+.Xr hwpmc 4
+.Sh HISTORY
+Support for the Haswell Xeon microarchitecture first appeared in
+.Fx 10.2 .
+.Sh AUTHORS
+The
+.Lb libpmc
+library was written by
+.An "Joseph Koshy"
+.Aq jkoshy@FreeBSD.org .
+The support for the Haswell Xeon
+microarchitecture was written by
+.An "Randall Stewart"
+.Aq rrs@FreeBSD.org .
diff --git a/lib/libpmc/pmc.ivybridge.3 b/lib/libpmc/pmc.ivybridge.3
index b8ad8e0..b693b30 100644
--- a/lib/libpmc/pmc.ivybridge.3
+++ b/lib/libpmc/pmc.ivybridge.3
@@ -449,80 +449,60 @@ Stalls caused by changing prefix length of the instruction.
.It Li ILD_STALL.IQ_FULL
.Pq Event 87H , Umask 04H
Stall cycles due to IQ is full.
-.It Li BR_INST_EXEC.COND
-.Pq Event 88H , Umask 01H
-Qualify conditional near branch instructions executed, but not necessarily
-retired.
-Must combine with umask 40H, 80H.
+.It Li BR_INST_EXEC.NONTAKEN_COND
+.Pq Event 88H , Umask 41H
+Count conditional near branch instructions that were executed (but not
+necessarily retired) and not taken.
+.It Li BR_INST_EXEC.TAKEN_COND
+.Pq Event 88H , Umask 81H
+Count conditional near branch instructions that were executed (but not
+necessarily retired) and taken.
.It Li BR_INST_EXEC.DIRECT_JMP
-.Pq Event 88H , Umask 02H
-Qualify all unconditional near branch instructions excluding calls and
+.Pq Event 88H , Umask 82H
+Count all unconditional near branch instructions excluding calls and
indirect branches.
-Must combine with umask 80H.
.It Li BR_INST_EXEC.INDIRECT_JMP_NON_CALL_RET
-.Pq Event 88H , Umask 04H
-Qualify executed indirect near branch instructions that are not calls nor
+.Pq Event 88H , Umask 84H
+Count executed indirect near branch instructions that are not calls nor
returns.
-Must combine with umask 80H.
.It Li BR_INST_EXEC.RETURN_NEAR
-.Pq Event 88H , Umask 08H
-Qualify indirect near branches that have a return mnemonic.
-Must combine with umask 80H.
+.Pq Event 88H , Umask 88H
+Count indirect near branches that have a return mnemonic.
.It Li BR_INST_EXEC.DIRECT_NEAR_CALL
-.Pq Event 88H , Umask 10H
-Qualify unconditional near call branch instructions, excluding non call
+.Pq Event 88H , Umask 90H
+Count unconditional near call branch instructions, excluding non call
branch, executed.
-Must combine with umask 80H.
.It Li BR_INST_EXEC.INDIRECT_NEAR_CALL
-.Pq Event 88H , Umask 20H
-Qualify indirect near calls, including both register and memory indirect,
+.Pq Event 88H , Umask A0H
+Count indirect near calls, including both register and memory indirect,
executed.
-Must combine with umask 80H.
-.It Li BR_INST_EXEC.NONTAKEN
-.Pq Event 88H , Umask 40H
-Qualify non-taken near branches executed.
-Applicable to umask 01H only.
-.It Li BR_INST_EXEC.TAKEN
-.Pq Event 88H , Umask 80H
-Qualify taken near branches executed. Must combine with 01H,02H, 04H, 08H,
-10H, 20H.
.It Li BR_INST_EXEC.ALL_BRANCHES
.Pq Event 88H , Umask FFH
Counts all near executed branches (not necessarily retired).
-.It Li BR_MISP_EXEC.COND
-.Pq Event 89H , Umask 01H
-Qualify conditional near branch instructions mispredicted.
-Must combine with umask 40H, 80H.
+.It Li BR_MISP_EXEC.NONTAKEN_COND
+.Pq Event 89H , Umask 41H
+Count conditional near branch instructions mispredicted as nontaken.
+.It Li BR_MISP_EXEC.TAKEN_COND
+.Pq Event 89H , Umask 81H
+Count conditional near branch instructions mispredicted as taken.
.It Li BR_MISP_EXEC.INDIRECT_JMP_NON_CALL_RET
-.Pq Event 89H , Umask 04H
-Qualify mispredicted indirect near branch instructions that are not calls
+.Pq Event 89H , Umask 84H
+Count mispredicted indirect near branch instructions that are not calls
nor returns.
-Must combine with umask 80H.
.It Li BR_MISP_EXEC.RETURN_NEAR
-.Pq Event 89H , Umask 08H
-Qualify mispredicted indirect near branches that have a return mnemonic.
-Must combine with umask 80H.
+.Pq Event 89H , Umask 88H
+Count mispredicted indirect near branches that have a return mnemonic.
.It Li BR_MISP_EXEC.DIRECT_NEAR_CALL
-.Pq Event 89H , Umask 10H
-Qualify mispredicted unconditional near call branch instructions, excluding
+.Pq Event 89H , Umask 90H
+Count mispredicted unconditional near call branch instructions, excluding
non call branch, executed.
-Must combine with umask 80H.
.It Li BR_MISP_EXEC.INDIRECT_NEAR_CALL
-.Pq Event 89H , Umask 20H
-Qualify mispredicted indirect near calls, including both register and memory
+.Pq Event 89H , Umask A0H
+Count mispredicted indirect near calls, including both register and memory
indirect, executed.
-Must combine with umask 80H.
-.It Li BR_MISP_EXEC.NONTAKEN
-.Pq Event 89H , Umask 40H
-Qualify mispredicted non-taken near branches executed.
-Applicable to umask 01H only.
-.It Li BR_MISP_EXEC.TAKEN
-.Pq Event 89H , Umask 80H
-Qualify mispredicted taken near branches executed. Must combine with
-01H,02H, 04H, 08H, 10H, 20H.
.It Li BR_MISP_EXEC.ALL_BRANCHES
.Pq Event 89H , Umask FFH
-Counts all near executed branches (not necessarily retired).
+Counts all mispredicted near executed branches (not necessarily retired).
.It Li IDQ_UOPS_NOT_DELIVERED.CORE
.Pq Event 9CH , Umask 01H
Count number of non-delivered uops to RAT per thread.
@@ -726,31 +706,24 @@ Specify threshold in MSR 0x3F6.
.Pq Event CDH , Umask 02H
Sample stores and collect precise store operation via PEBS record.
PMC3 only.
-.It Li MEM_UOP_RETIRED.LOADS
-.Pq Event D0H , Umask 01H
-Qualify retired memory uops that are loads. Combine with umask 10H, 20H,
-40H, 80H.
-Supports PEBS.
-.It Li MEM_UOP_RETIRED.STORES
-.Pq Event D0H , Umask 02H
-Qualify retired memory uops that are stores. Combine with umask 10H, 20H,
-40H, 80H.
-.It Li MEM_UOP_RETIRED.STLB_MISS
-.Pq Event D0H , Umask 10H
-Qualify retired memory uops with STLB miss. Must combine with umask 01H,
-02H, to produce counts.
-.It Li MEM_UOP_RETIRED.LOCK
-.Pq Event D0H , Umask 20H
-Qualify retired memory uops with lock. Must combine with umask 01H, 02H, to
-produce counts.
-.It Li MEM_UOP_RETIRED.SPLIT
-.Pq Event D0H , Umask 40H
-Qualify retired memory uops with line split. Must combine with umask 01H,
-02H, to produce counts.
-.It Li MEM_UOP_RETIRED.ALL
-.Pq Event D0H , Umask 80H
-Qualify any retired memory uops. Must combine with umask 01H, 02H, to
-produce counts.
+.It Li MEM_UOPS_RETIRED.STLB_MISS_LOADS
+.Pq Event D0H , Umask 11H
+Count retired load uops that missed the STLB.
+.It Li MEM_UOPS_RETIRED.STLB_MISS_STORES
+.Pq Event D0H , Umask 12H
+Count retired store uops that missed the STLB.
+.It Li MEM_UOPS_RETIRED.SPLIT_LOADS
+.Pq Event D0H , Umask 41H
+Count retired load uops that were split across a cache line.
+.It Li MEM_UOPS_RETIRED.SPLIT_STORES
+.Pq Event D0H , Umask 42H
+Count retired store uops that were split across a cache line.
+.It Li MEM_UOPS_RETIRED.ALL_LOADS
+.Pq Event D0H , Umask 81H
+Count all retired load uops.
+.It Li MEM_UOPS_RETIRED.ALL_STORES
+.Pq Event D0H , Umask 82H
+Count all retired store uops.
.It Li MEM_LOAD_UOPS_RETIRED.L1_HIT
.Pq Event D1H , Umask 01H
Retired load uops with L1 cache hits as data sources.
@@ -844,23 +817,23 @@ Dirty L2 cache lines evicted by the MLC prefetcher.
.Xr pmc 3 ,
.Xr pmc.atom 3 ,
.Xr pmc.core 3 ,
+.Xr pmc.corei7 3 ,
+.Xr pmc.corei7uc 3 ,
.Xr pmc.iaf 3 ,
-.Xr pmc.ucf 3 ,
+.Xr pmc.ivybridgexeon 3 ,
.Xr pmc.k7 3 ,
.Xr pmc.k8 3 ,
.Xr pmc.p4 3 ,
.Xr pmc.p5 3 ,
.Xr pmc.p6 3 ,
-.Xr pmc.corei7 3 ,
-.Xr pmc.corei7uc 3 ,
-.Xr pmc.ivybridgexeon 3 ,
.Xr pmc.sandybridge 3 ,
.Xr pmc.sandybridgeuc 3 ,
.Xr pmc.sandybridgexeon 3 ,
-.Xr pmc.westmere 3 ,
-.Xr pmc.westmereuc 3 ,
.Xr pmc.soft 3 ,
.Xr pmc.tsc 3 ,
+.Xr pmc.ucf 3 ,
+.Xr pmc.westmere 3 ,
+.Xr pmc.westmereuc 3 ,
.Xr pmc_cpuinfo 3 ,
.Xr pmclog 3 ,
.Xr hwpmc 4
diff --git a/lib/libpmc/pmc.ivybridgexeon.3 b/lib/libpmc/pmc.ivybridgexeon.3
index 3a5b709..2ee5b78 100644
--- a/lib/libpmc/pmc.ivybridgexeon.3
+++ b/lib/libpmc/pmc.ivybridgexeon.3
@@ -449,80 +449,60 @@ Stalls caused by changing prefix length of the instruction.
.It Li ILD_STALL.IQ_FULL
.Pq Event 87H , Umask 04H
Stall cycles due to IQ is full.
-.It Li BR_INST_EXEC.COND
-.Pq Event 88H , Umask 01H
-Qualify conditional near branch instructions executed, but not necessarily
-retired.
-Must combine with umask 40H, 80H.
+.It Li BR_INST_EXEC.NONTAKEN_COND
+.Pq Event 88H , Umask 41H
+Count conditional near branch instructions that were executed (but not
+necessarily retired) and not taken.
+.It Li BR_INST_EXEC.TAKEN_COND
+.Pq Event 88H , Umask 81H
+Count conditional near branch instructions that were executed (but not
+necessarily retired) and taken.
.It Li BR_INST_EXEC.DIRECT_JMP
-.Pq Event 88H , Umask 02H
-Qualify all unconditional near branch instructions excluding calls and
+.Pq Event 88H , Umask 82H
+Count all unconditional near branch instructions excluding calls and
indirect branches.
-Must combine with umask 80H.
.It Li BR_INST_EXEC.INDIRECT_JMP_NON_CALL_RET
-.Pq Event 88H , Umask 04H
-Qualify executed indirect near branch instructions that are not calls nor
+.Pq Event 88H , Umask 84H
+Count executed indirect near branch instructions that are not calls nor
returns.
-Must combine with umask 80H.
.It Li BR_INST_EXEC.RETURN_NEAR
-.Pq Event 88H , Umask 08H
-Qualify indirect near branches that have a return mnemonic.
-Must combine with umask 80H.
+.Pq Event 88H , Umask 88H
+Count indirect near branches that have a return mnemonic.
.It Li BR_INST_EXEC.DIRECT_NEAR_CALL
-.Pq Event 88H , Umask 10H
-Qualify unconditional near call branch instructions, excluding non call
+.Pq Event 88H , Umask 90H
+Count unconditional near call branch instructions, excluding non call
branch, executed.
-Must combine with umask 80H.
.It Li BR_INST_EXEC.INDIRECT_NEAR_CALL
-.Pq Event 88H , Umask 20H
-Qualify indirect near calls, including both register and memory indirect,
+.Pq Event 88H , Umask A0H
+Count indirect near calls, including both register and memory indirect,
executed.
-Must combine with umask 80H.
-.It Li BR_INST_EXEC.NONTAKEN
-.Pq Event 88H , Umask 40H
-Qualify non-taken near branches executed.
-Applicable to umask 01H only.
-.It Li BR_INST_EXEC.TAKEN
-.Pq Event 88H , Umask 80H
-Qualify taken near branches executed. Must combine with 01H,02H, 04H, 08H,
-10H, 20H.
.It Li BR_INST_EXEC.ALL_BRANCHES
.Pq Event 88H , Umask FFH
Counts all near executed branches (not necessarily retired).
-.It Li BR_MISP_EXEC.COND
-.Pq Event 89H , Umask 01H
-Qualify conditional near branch instructions mispredicted.
-Must combine with umask 40H, 80H.
+.It Li BR_MISP_EXEC.NONTAKEN_COND
+.Pq Event 89H , Umask 41H
+Count conditional near branch instructions mispredicted as nontaken.
+.It Li BR_MISP_EXEC.TAKEN_COND
+.Pq Event 89H , Umask 81H
+Count conditional near branch instructions mispredicted as taken.
.It Li BR_MISP_EXEC.INDIRECT_JMP_NON_CALL_RET
-.Pq Event 89H , Umask 04H
-Qualify mispredicted indirect near branch instructions that are not calls
+.Pq Event 89H , Umask 84H
+Count mispredicted indirect near branch instructions that are not calls
nor returns.
-Must combine with umask 80H.
.It Li BR_MISP_EXEC.RETURN_NEAR
-.Pq Event 89H , Umask 08H
-Qualify mispredicted indirect near branches that have a return mnemonic.
-Must combine with umask 80H.
+.Pq Event 89H , Umask 88H
+Count mispredicted indirect near branches that have a return mnemonic.
.It Li BR_MISP_EXEC.DIRECT_NEAR_CALL
-.Pq Event 89H , Umask 10H
-Qualify mispredicted unconditional near call branch instructions, excluding
+.Pq Event 89H , Umask 90H
+Count mispredicted unconditional near call branch instructions, excluding
non call branch, executed.
-Must combine with umask 80H.
.It Li BR_MISP_EXEC.INDIRECT_NEAR_CALL
-.Pq Event 89H , Umask 20H
-Qualify mispredicted indirect near calls, including both register and memory
+.Pq Event 89H , Umask A0H
+Count mispredicted indirect near calls, including both register and memory
indirect, executed.
-Must combine with umask 80H.
-.It Li BR_MISP_EXEC.NONTAKEN
-.Pq Event 89H , Umask 40H
-Qualify mispredicted non-taken near branches executed.
-Applicable to umask 01H only.
-.It Li BR_MISP_EXEC.TAKEN
-.Pq Event 89H , Umask 80H
-Qualify mispredicted taken near branches executed. Must combine with
-01H,02H, 04H, 08H, 10H, 20H.
.It Li BR_MISP_EXEC.ALL_BRANCHES
.Pq Event 89H , Umask FFH
-Counts all near executed branches (not necessarily retired).
+Counts all mispredicted near executed branches (not necessarily retired).
.It Li IDQ_UOPS_NOT_DELIVERED.CORE
.Pq Event 9CH , Umask 01H
Count number of non-delivered uops to RAT per thread.
@@ -738,31 +718,24 @@ Specify threshold in MSR 0x3F6.
.Pq Event CDH , Umask 02H
Sample stores and collect precise store operation via PEBS record.
PMC3 only.
-.It Li MEM_UOP_RETIRED.LOADS
-.Pq Event D0H , Umask 01H
-Qualify retired memory uops that are loads. Combine with umask 10H, 20H,
-40H, 80H.
-Supports PEBS.
-.It Li MEM_UOP_RETIRED.STORES
-.Pq Event D0H , Umask 02H
-Qualify retired memory uops that are stores. Combine with umask 10H, 20H,
-40H, 80H.
-.It Li MEM_UOP_RETIRED.STLB_MISS
-.Pq Event D0H , Umask 10H
-Qualify retired memory uops with STLB miss. Must combine with umask 01H,
-02H, to produce counts.
-.It Li MEM_UOP_RETIRED.LOCK
-.Pq Event D0H , Umask 20H
-Qualify retired memory uops with lock. Must combine with umask 01H, 02H, to
-produce counts.
-.It Li MEM_UOP_RETIRED.SPLIT
-.Pq Event D0H , Umask 40H
-Qualify retired memory uops with line split. Must combine with umask 01H,
-02H, to produce counts.
-.It Li MEM_UOP_RETIRED.ALL
-.Pq Event D0H , Umask 80H
-Qualify any retired memory uops. Must combine with umask 01H, 02H, to
-produce counts.
+.It Li MEM_UOPS_RETIRED.STLB_MISS_LOADS
+.Pq Event D0H , Umask 11H
+Count retired load uops that missed the STLB.
+.It Li MEM_UOPS_RETIRED.STLB_MISS_STORES
+.Pq Event D0H , Umask 12H
+Count retired store uops that missed the STLB.
+.It Li MEM_UOPS_RETIRED.SPLIT_LOADS
+.Pq Event D0H , Umask 41H
+Count retired load uops that were split across a cache line.
+.It Li MEM_UOPS_RETIRED.SPLIT_STORES
+.Pq Event D0H , Umask 42H
+Count retired store uops that were split across a cache line.
+.It Li MEM_UOPS_RETIRED.ALL_LOADS
+.Pq Event D0H , Umask 81H
+Count all retired load uops.
+.It Li MEM_UOPS_RETIRED.ALL_STORES
+.Pq Event D0H , Umask 82H
+Count all retired store uops.
.It Li MEM_LOAD_UOPS_RETIRED.L1_HIT
.Pq Event D1H , Umask 01H
Retired load uops with L1 cache hits as data sources.
@@ -874,23 +847,23 @@ Dirty L2 cache lines filling the L2.
.Xr pmc 3 ,
.Xr pmc.atom 3 ,
.Xr pmc.core 3 ,
+.Xr pmc.corei7 3 ,
+.Xr pmc.corei7uc 3 ,
.Xr pmc.iaf 3 ,
-.Xr pmc.ucf 3 ,
+.Xr pmc.ivybridge 3 ,
.Xr pmc.k7 3 ,
.Xr pmc.k8 3 ,
.Xr pmc.p4 3 ,
.Xr pmc.p5 3 ,
.Xr pmc.p6 3 ,
-.Xr pmc.corei7 3 ,
-.Xr pmc.corei7uc 3 ,
-.Xr pmc.ivybridge 3 ,
.Xr pmc.sandybridge 3 ,
.Xr pmc.sandybridgeuc 3 ,
.Xr pmc.sandybridgexeon 3 ,
-.Xr pmc.westmere 3 ,
-.Xr pmc.westmereuc 3 ,
.Xr pmc.soft 3 ,
.Xr pmc.tsc 3 ,
+.Xr pmc.ucf 3 ,
+.Xr pmc.westmere 3 ,
+.Xr pmc.westmereuc 3 ,
.Xr pmc_cpuinfo 3 ,
.Xr pmclog 3 ,
.Xr hwpmc 4
diff --git a/lib/libpmc/pmc.sandybridge.3 b/lib/libpmc/pmc.sandybridge.3
index 0b8f6b2..0e219ae 100644
--- a/lib/libpmc/pmc.sandybridge.3
+++ b/lib/libpmc/pmc.sandybridge.3
@@ -497,80 +497,60 @@ Stalls caused by changing prefix length of the instruction.
.It Li ILD_STALL.IQ_FULL
.Pq Event 87H, Umask 04H
Stall cycles due to IQ is full.
-.It Li BR_INST_EXEC.COND
-.Pq Event 88H, Umask 01H
-Qualify conditional near branch instructions executed, but not necessarily
-retired.
-Must combine with umask 40H, 80H
+.It Li BR_INST_EXEC.NONTAKEN_COND
+.Pq Event 88H , Umask 41H
+Count conditional near branch instructions that were executed (but not
+necessarily retired) and not taken.
+.It Li BR_INST_EXEC.TAKEN_COND
+.Pq Event 88H , Umask 81H
+Count conditional near branch instructions that were executed (but not
+necessarily retired) and taken.
.It Li BR_INST_EXEC.DIRECT_JMP
-.Pq Event 88H, Umask 02H
-Qualify all unconditional near branch instructions excluding calls and indirect
-branches.
-Must combine with umask 80H
+.Pq Event 88H , Umask 82H
+Count all unconditional near branch instructions excluding calls and
+indirect branches.
.It Li BR_INST_EXEC.INDIRECT_JMP_NON_CALL_RET
-.Pq Event 88H, Umask 04H
-Qualify executed indirect near branch instructions that are not calls nor
+.Pq Event 88H , Umask 84H
+Count executed indirect near branch instructions that are not calls nor
returns.
-Must combine with umask 80H
.It Li BR_INST_EXEC.RETURN_NEAR
-.Pq Event 88H, Umask 08H
-Qualify indirect near branches that have a return mnemonic.
-Must combine with umask 80H
+.Pq Event 88H , Umask 88H
+Count indirect near branches that have a return mnemonic.
.It Li BR_INST_EXEC.DIRECT_NEAR_CALL
-.Pq Event 88H, Umask 10H
-Qualify unconditional near call branch instructions, excluding non call branch,
-executed.
-Must combine with umask 80H
+.Pq Event 88H , Umask 90H
+Count unconditional near call branch instructions, excluding non call
+branch, executed.
.It Li BR_INST_EXEC.INDIRECT_NEAR_CALL
-.Pq Event 88H, Umask 20H
-Qualify indirect near calls, including both register and memory indirect,
+.Pq Event 88H , Umask A0H
+Count indirect near calls, including both register and memory indirect,
executed.
-Must combine with umask 80H
-.It Li BR_INST_EXEC.NONTAKEN
-.Pq Event 88H, Umask 40H
-Qualify non-taken near branches executed.
-Applicable to umask 01H only
-.It Li BR_INST_EXEC.TAKEN
-.Pq Event 88H, Umask 80H
-Qualify taken near branches executed.
-Must combine with 01H,02H, 04H, 08H, 10H, 20H
-.It Li BR_INST_EXE.ALL_BRANCHES
-.Pq Event 88H, Umask FFH
+.It Li BR_INST_EXEC.ALL_BRANCHES
+.Pq Event 88H , Umask FFH
Counts all near executed branches (not necessarily retired).
-.It Li BR_MISP_EXEC.COND
-.Pq Event 89H, Umask 01H
-Qualify conditional near branch instructions mispredicted.
-Must combine with umask 40H, 80H
+.It Li BR_MISP_EXEC.NONTAKEN_COND
+.Pq Event 89H , Umask 41H
+Count conditional near branch instructions mispredicted as nontaken.
+.It Li BR_MISP_EXEC.TAKEN_COND
+.Pq Event 89H , Umask 81H
+Count conditional near branch instructions mispredicted as taken.
.It Li BR_MISP_EXEC.INDIRECT_JMP_NON_CALL_RET
-.Pq Event 89H, Umask 04H
-Qualify mispredicted indirect near branch instructions that are not calls nor
-returns.
-Must combine with umask 80H
+.Pq Event 89H , Umask 84H
+Count mispredicted indirect near branch instructions that are not calls
+nor returns.
.It Li BR_MISP_EXEC.RETURN_NEAR
-.Pq Event 89H, Umask 08H
-Qualify mispredicted indirect near branches that have a return mnemonic.
-Must combine with umask 80H
+.Pq Event 89H , Umask 88H
+Count mispredicted indirect near branches that have a return mnemonic.
.It Li BR_MISP_EXEC.DIRECT_NEAR_CALL
-.Pq Event 89H, Umask 10H
-Qualify mispredicted unconditional near call branch instructions, excluding non
-call branch, executed.
-Must combine with umask 80H
+.Pq Event 89H , Umask 90H
+Count mispredicted unconditional near call branch instructions, excluding
+non call branch, executed.
.It Li BR_MISP_EXEC.INDIRECT_NEAR_CALL
-.Pq Event 89H, Umask 20H
-Qualify mispredicted indirect near calls, including both register and memory
+.Pq Event 89H , Umask A0H
+Count mispredicted indirect near calls, including both register and memory
indirect, executed.
-Must combine with umask 80H
-.It Li BR_MISP_EXEC.NONTAKEN
-.Pq Event 89H, Umask 40H
-Qualify mispredicted non-taken near branches executed.
-Applicable to umask 01H only
-.It Li BR_MISP_EXEC.TAKEN
-.Pq Event 89H, Umask 80H
-Qualify mispredicted taken near branches executed.
-Must combine with 01H,02H, 04H, 08H, 10H, 20H
.It Li BR_MISP_EXEC.ALL_BRANCHES
-.Pq Event 89H, Umask FFH
-Counts all near executed branches (not necessarily retired).
+.Pq Event 89H , Umask FFH
+Counts all mispredicted near executed branches (not necessarily retired).
.It Li IDQ_UOPS_NOT_DELIVERED.CORE
.Pq Event 9CH, Umask 01H
Count number of non-delivered uops to RAT per thread.
diff --git a/lib/libpmc/pmc.sandybridgexeon.3 b/lib/libpmc/pmc.sandybridgexeon.3
index 9a80f78..b334c16 100644
--- a/lib/libpmc/pmc.sandybridgexeon.3
+++ b/lib/libpmc/pmc.sandybridgexeon.3
@@ -543,73 +543,60 @@ instruction.
.It Li ILD_STALL.IQ_FULL
.Pq Event 87H , Umask 04H
Stall cycles due to IQ is full.
-.It Li BR_INST_EXEC.COND
-.Pq Event 88H , Umask 01H
-Qualify conditional near branch instructions
-executed, but not necessarily retired.
+.It Li BR_INST_EXEC.NONTAKEN_COND
+.Pq Event 88H , Umask 41H
+Count conditional near branch instructions that were executed (but not
+necessarily retired) and not taken.
+.It Li BR_INST_EXEC.TAKEN_COND
+.Pq Event 88H , Umask 81H
+Count conditional near branch instructions that were executed (but not
+necessarily retired) and taken.
.It Li BR_INST_EXEC.DIRECT_JMP
-.Pq Event 88H , Umask 02H
-Qualify all unconditional near branch instructions
-excluding calls and indirect branches.
+.Pq Event 88H , Umask 82H
+Count all unconditional near branch instructions excluding calls and
+indirect branches.
.It Li BR_INST_EXEC.INDIRECT_JMP_NON_CALL_RET
-.Pq Event 88H , Umask 04H
-Qualify executed indirect near branch instructions
-that are not calls nor returns.
+.Pq Event 88H , Umask 84H
+Count executed indirect near branch instructions that are not calls nor
+returns.
.It Li BR_INST_EXEC.RETURN_NEAR
-.Pq Event 88H , Umask 08H
-Qualify indirect near branches that have a return
-mnemonic.
+.Pq Event 88H , Umask 88H
+Count indirect near branches that have a return mnemonic.
.It Li BR_INST_EXEC.DIRECT_NEAR_CALL
-.Pq Event 88H , Umask 10H
-Qualify unconditional near call branch instructions,
-excluding non call branch, executed.
+.Pq Event 88H , Umask 90H
+Count unconditional near call branch instructions, excluding non call
+branch, executed.
.It Li BR_INST_EXEC.INDIRECT_NEAR_CALL
-.Pq Event 88H , Umask 20H
-Qualify indirect near calls, including both register
-and memory indirect, executed.
-.It Li BR_INST_EXEC.NONTAKEN
-.Pq Event 88H , Umask 40H
-Qualify non-taken near branches executed.
-.It Li BR_INST_EXEC.TAKEN
-.Pq Event 88H , Umask 80H
-Qualify taken near branches executed. Must
-combine with 01H,02H, 04H, 08H, 10H, 20H.
-.It Li BR_INST_EXE.ALL_BRANCHES
+.Pq Event 88H , Umask A0H
+Count indirect near calls, including both register and memory indirect,
+executed.
+.It Li BR_INST_EXEC.ALL_BRANCHES
.Pq Event 88H , Umask FFH
-Counts all near executed branches (not necessarily
-retired).
-.It Li BR_MISP_EXEC.COND
-.Pq Event 89H , Umask 01H
-Qualify conditional near branch instructions
-mispredicted.
+Counts all near executed branches (not necessarily retired).
+.It Li BR_MISP_EXEC.NONTAKEN_COND
+.Pq Event 89H , Umask 41H
+Count conditional near branch instructions mispredicted as nontaken.
+.It Li BR_MISP_EXEC.TAKEN_COND
+.Pq Event 89H , Umask 81H
+Count conditional near branch instructions mispredicted as taken.
.It Li BR_MISP_EXEC.INDIRECT_JMP_NON_CALL_RET
-.Pq Event 89H , Umask 04H
-Qualify mispredicted indirect near branch
-instructions that are not calls nor returns.
+.Pq Event 89H , Umask 84H
+Count mispredicted indirect near branch instructions that are not calls
+nor returns.
.It Li BR_MISP_EXEC.RETURN_NEAR
-.Pq Event 89H , Umask 08H
-Qualify mispredicted indirect near branches that
-have a return mnemonic.
+.Pq Event 89H , Umask 88H
+Count mispredicted indirect near branches that have a return mnemonic.
.It Li BR_MISP_EXEC.DIRECT_NEAR_CALL
-.Pq Event 89H , Umask 10H
-Qualify mispredicted unconditional near call branch
-instructions, excluding non call branch, executed.
+.Pq Event 89H , Umask 90H
+Count mispredicted unconditional near call branch instructions, excluding
+non call branch, executed.
.It Li BR_MISP_EXEC.INDIRECT_NEAR_CALL
-.Pq Event 89H , Umask 20H
-Qualify mispredicted indirect near calls, including
-both register and memory indirect, executed.
-.It Li BR_MISP_EXEC.NONTAKEN
-.Pq Event 89H , Umask 40H
-Qualify mispredicted non-taken near branches
-executed,.
-.It Li BR_MISP_EXEC.TAKEN
-.Pq Event 89H , Umask 80H
-Qualify mispredicted taken near branches executed.
-Must combine with 01H,02H, 04H, 08H, 10H, 20H
+.Pq Event 89H , Umask A0H
+Count mispredicted indirect near calls, including both register and memory
+indirect, executed.
.It Li BR_MISP_EXEC.ALL_BRANCHES
.Pq Event 89H , Umask FFH
-Counts all near executed branches (not necessarily
-retired).
+Counts all mispredicted near executed branches (not necessarily retired).
.It Li IDQ_UOPS_NOT_DELIVERED.CORE
.Pq Event 9CH , Umask 01H
Count number of non-delivered uops to RAT per
@@ -987,23 +974,24 @@ Split locks in SQ.
.Xr pmc 3 ,
.Xr pmc.atom 3 ,
.Xr pmc.core 3 ,
+.Xr pmc.corei7 3 ,
+.Xr pmc.corei7uc 3 ,
+.Xr pmc.haswelluc 3 ,
.Xr pmc.iaf 3 ,
-.Xr pmc.ucf 3 ,
+.Xr pmc.ivybridge 3 ,
+.Xr pmc.ivybridgexeon 3 ,
.Xr pmc.k7 3 ,
.Xr pmc.k8 3 ,
.Xr pmc.p4 3 ,
.Xr pmc.p5 3 ,
.Xr pmc.p6 3 ,
-.Xr pmc.corei7 3 ,
-.Xr pmc.corei7uc 3 ,
-.Xr pmc.ivybridge 3 ,
-.Xr pmc.ivybridgexeon 3 ,
.Xr pmc.sandybridge 3 ,
.Xr pmc.sandybridgeuc 3 ,
-.Xr pmc.westmere 3 ,
-.Xr pmc.westmereuc 3 ,
.Xr pmc.soft 3 ,
.Xr pmc.tsc 3 ,
+.Xr pmc.ucf 3 ,
+.Xr pmc.westmere 3 ,
+.Xr pmc.westmereuc 3 ,
.Xr pmc_cpuinfo 3 ,
.Xr pmclog 3 ,
.Xr hwpmc 4
diff --git a/lib/libpmc/pmc.soft.3 b/lib/libpmc/pmc.soft.3
index 5d331e2..ec53206 100644
--- a/lib/libpmc/pmc.soft.3
+++ b/lib/libpmc/pmc.soft.3
@@ -76,17 +76,17 @@ Write page fault.
.Xr pmc 3 ,
.Xr pmc.atom 3 ,
.Xr pmc.core 3 ,
+.Xr pmc.corei7 3 ,
+.Xr pmc.corei7uc 3 ,
.Xr pmc.iaf 3 ,
-.Xr pmc.ucf 3 ,
.Xr pmc.k7 3 ,
.Xr pmc.k8 3 ,
.Xr pmc.p4 3 ,
.Xr pmc.p5 3 ,
.Xr pmc.p6 3 ,
-.Xr pmc.corei7 3 ,
-.Xr pmc.corei7uc 3 ,
-.Xr pmc.westmereuc 3 ,
.Xr pmc.tsc 3 ,
+.Xr pmc.ucf 3 ,
+.Xr pmc.westmereuc 3 ,
.Xr pmc_cpuinfo 3 ,
.Xr pmclog 3 ,
.Xr hwpmc 4
diff --git a/lib/libpmc/pmc.ucf.3 b/lib/libpmc/pmc.ucf.3
index 6b02786..bdbb200 100644
--- a/lib/libpmc/pmc.ucf.3
+++ b/lib/libpmc/pmc.ucf.3
@@ -86,18 +86,18 @@ offset C0H under device number 0 and Function 0.
.Xr pmc.atom 3 ,
.Xr pmc.core 3 ,
.Xr pmc.core2 3 ,
+.Xr pmc.corei7 3 ,
+.Xr pmc.corei7uc 3 ,
.Xr pmc.iaf 3 ,
.Xr pmc.k7 3 ,
.Xr pmc.k8 3 ,
.Xr pmc.p4 3 ,
.Xr pmc.p5 3 ,
.Xr pmc.p6 3 ,
-.Xr pmc.corei7 3 ,
-.Xr pmc.corei7uc 3 ,
-.Xr pmc.westmere 3 ,
-.Xr pmc.westmereuc 3 ,
.Xr pmc.soft 3 ,
.Xr pmc.tsc 3 ,
+.Xr pmc.westmere 3 ,
+.Xr pmc.westmereuc 3 ,
.Xr pmc_cpuinfo 3 ,
.Xr pmclog 3 ,
.Xr hwpmc 4
diff --git a/lib/libpmc/pmc.westmere.3 b/lib/libpmc/pmc.westmere.3
index 6bfdf39..3668460 100644
--- a/lib/libpmc/pmc.westmere.3
+++ b/lib/libpmc/pmc.westmere.3
@@ -1371,18 +1371,18 @@ Counts number of SID integer 64 bit shift or move operations.
.Xr pmc 3 ,
.Xr pmc.atom 3 ,
.Xr pmc.core 3 ,
+.Xr pmc.corei7 3 ,
+.Xr pmc.corei7uc 3 ,
.Xr pmc.iaf 3 ,
-.Xr pmc.ucf 3 ,
.Xr pmc.k7 3 ,
.Xr pmc.k8 3 ,
.Xr pmc.p4 3 ,
.Xr pmc.p5 3 ,
.Xr pmc.p6 3 ,
-.Xr pmc.corei7 3 ,
-.Xr pmc.corei7uc 3 ,
-.Xr pmc.westmereuc 3 ,
.Xr pmc.soft 3 ,
.Xr pmc.tsc 3 ,
+.Xr pmc.ucf 3 ,
+.Xr pmc.westmereuc 3 ,
.Xr pmc_cpuinfo 3 ,
.Xr pmclog 3 ,
.Xr hwpmc 4
diff --git a/lib/libpmc/pmc.westmereuc.3 b/lib/libpmc/pmc.westmereuc.3
index 2f260c2..23319cf 100644
--- a/lib/libpmc/pmc.westmereuc.3
+++ b/lib/libpmc/pmc.westmereuc.3
@@ -1056,18 +1056,18 @@ disabled.
.Xr pmc 3 ,
.Xr pmc.atom 3 ,
.Xr pmc.core 3 ,
+.Xr pmc.corei7 3 ,
+.Xr pmc.corei7uc 3 ,
.Xr pmc.iaf 3 ,
-.Xr pmc.ucf 3 ,
.Xr pmc.k7 3 ,
.Xr pmc.k8 3 ,
.Xr pmc.p4 3 ,
.Xr pmc.p5 3 ,
.Xr pmc.p6 3 ,
-.Xr pmc.corei7 3 ,
-.Xr pmc.corei7uc 3 ,
-.Xr pmc.westmere 3 ,
.Xr pmc.soft 3 ,
.Xr pmc.tsc 3 ,
+.Xr pmc.ucf 3 ,
+.Xr pmc.westmere 3 ,
.Xr pmc_cpuinfo 3 ,
.Xr pmclog 3 ,
.Xr hwpmc 4
diff --git a/lib/libpmc/pmc.xscale.3 b/lib/libpmc/pmc.xscale.3
index 5a496b9..d5766e3 100644
--- a/lib/libpmc/pmc.xscale.3
+++ b/lib/libpmc/pmc.xscale.3
@@ -132,9 +132,9 @@ and the underlying hardware events used.
.El
.Sh SEE ALSO
.Xr pmc 3 ,
+.Xr pmc.soft 3 ,
.Xr pmc_cpuinfo 3 ,
.Xr pmclog 3 ,
-.Xr pmc.soft 3 ,
.Xr hwpmc 4
.Sh HISTORY
The
diff --git a/lib/libpmc/pmc_capabilities.3 b/lib/libpmc/pmc_capabilities.3
index 8c5916e..c0df754 100644
--- a/lib/libpmc/pmc_capabilities.3
+++ b/lib/libpmc/pmc_capabilities.3
@@ -223,8 +223,8 @@ The argument to the function was invalid.
.Xr pmc_allocate 3 ,
.Xr pmc_get_driver_stats 3 ,
.Xr pmc_name_of_capability 3 ,
-.Xr pmc_name_of_cputype 3 ,
.Xr pmc_name_of_class 3 ,
+.Xr pmc_name_of_cputype 3 ,
.Xr pmc_name_of_event 3 ,
.Xr pmc_name_of_mode 3 ,
.Xr hwpmc 4
diff --git a/lib/libproc/Makefile b/lib/libproc/Makefile
index bfb9492..3feddb5 100644
--- a/lib/libproc/Makefile
+++ b/lib/libproc/Makefile
@@ -16,20 +16,20 @@ INCS= libproc.h
CFLAGS+= -I${.CURDIR}
# avoid cyclic dependency
CFLAGS+= -I${.CURDIR:H}/librtld_db
+GENDIRDEPS_FILTER+= Nlib/librtld_db
.if ${MK_CXX} == "no"
CFLAGS+= -DNO_CXA_DEMANGLE
.elif ${MK_LIBCPLUSPLUS} != "no"
-LDADD+= -lcxxrt
-DPADD+= ${LIBCXXRT}
+LIBADD+= cxxrt
.else
-LDADD+= -lsupc++
-DPADD+= ${LIBSTDCPLUSPLUS}
+LIBADD+= supcplusplus
.endif
+LIBADD+= elf rtld_db util
+
.if ${MK_CDDL} != "no"
-LDADD+= -lctf
-DPADD+= ${LIBCTF}
+LIBADD+= ctf
IGNORE_PRAGMA= YES
CFLAGS+= -I${.CURDIR}/../../cddl/contrib/opensolaris/lib/libctf/common \
-I${.CURDIR}/../../sys/cddl/contrib/opensolaris/uts/common \
diff --git a/lib/libproc/Makefile.depend b/lib/libproc/Makefile.depend
index 46c4714..9d42af4 100644
--- a/lib/libproc/Makefile.depend
+++ b/lib/libproc/Makefile.depend
@@ -3,6 +3,7 @@
DEP_RELDIR := ${_PARSEDIR:S,${SRCTOP}/,,}
DIRDEPS = \
+ cddl/lib/libctf \
gnu/lib/csu \
gnu/lib/libgcc \
include \
diff --git a/lib/libproc/proc_bkpt.c b/lib/libproc/proc_bkpt.c
index fe6ed4a..1e4a6cc 100644
--- a/lib/libproc/proc_bkpt.c
+++ b/lib/libproc/proc_bkpt.c
@@ -51,6 +51,9 @@ __FBSDID("$FreeBSD$");
#elif defined(__powerpc__)
#define BREAKPOINT_INSTR 0x7fe00008 /* trap */
#define BREAKPOINT_INSTR_SZ 4
+#elif defined(__arm__)
+#define BREAKPOINT_INSTR 0xe7ffffff /* bkpt */
+#define BREAKPOINT_INSTR_SZ 4
#else
#error "Add support for your architecture"
#endif
diff --git a/lib/libproc/proc_regs.c b/lib/libproc/proc_regs.c
index 145c8fe..35d8d38 100644
--- a/lib/libproc/proc_regs.c
+++ b/lib/libproc/proc_regs.c
@@ -56,6 +56,8 @@ proc_regget(struct proc_handle *phdl, proc_reg_t reg, unsigned long *regvalue)
case REG_PC:
#if defined(__amd64__)
*regvalue = regs.r_rip;
+#elif defined(__arm__)
+ *regvalue = regs.r_pc;
#elif defined(__i386__)
*regvalue = regs.r_eip;
#elif defined(__mips__)
@@ -67,6 +69,8 @@ proc_regget(struct proc_handle *phdl, proc_reg_t reg, unsigned long *regvalue)
case REG_SP:
#if defined(__amd64__)
*regvalue = regs.r_rsp;
+#elif defined(__arm__)
+ *regvalue = regs.r_sp;
#elif defined(__i386__)
*regvalue = regs.r_esp;
#elif defined(__mips__)
@@ -99,6 +103,8 @@ proc_regset(struct proc_handle *phdl, proc_reg_t reg, unsigned long regvalue)
case REG_PC:
#if defined(__amd64__)
regs.r_rip = regvalue;
+#elif defined(__arm__)
+ regs.r_pc = regvalue;
#elif defined(__i386__)
regs.r_eip = regvalue;
#elif defined(__mips__)
@@ -110,6 +116,8 @@ proc_regset(struct proc_handle *phdl, proc_reg_t reg, unsigned long regvalue)
case REG_SP:
#if defined(__amd64__)
regs.r_rsp = regvalue;
+#elif defined(__arm__)
+ regs.r_sp = regvalue;
#elif defined(__i386__)
regs.r_esp = regvalue;
#elif defined(__mips__)
diff --git a/lib/libproc/proc_sym.c b/lib/libproc/proc_sym.c
index 766ff73..dd52638 100644
--- a/lib/libproc/proc_sym.c
+++ b/lib/libproc/proc_sym.c
@@ -82,6 +82,21 @@ fail:
strlcpy(buf, symbol, len);
}
+static int
+find_dbg_obj(const char *path)
+{
+ int fd;
+ char dbg_path[PATH_MAX];
+
+ snprintf(dbg_path, sizeof(dbg_path),
+ "/usr/lib/debug/%s.debug", path);
+ fd = open(dbg_path, O_RDONLY);
+ if (fd >= 0)
+ return (fd);
+ else
+ return (open(path, O_RDONLY));
+}
+
static void
proc_rdl2prmap(rd_loadobj_t *rdl, prmap_t *map)
{
@@ -153,9 +168,12 @@ proc_iter_objs(struct proc_handle *p, proc_map_f *func, void *cd)
prmap_t map;
char path[MAXPATHLEN];
char last[MAXPATHLEN];
+ int error;
if (p->nobjs == 0)
return (-1);
+
+ error = 0;
memset(last, 0, sizeof(last));
for (i = 0; i < p->nobjs; i++) {
rdl = &p->rdobjs[i];
@@ -169,11 +187,11 @@ proc_iter_objs(struct proc_handle *p, proc_map_f *func, void *cd)
*/
if (strcmp(path, last) == 0)
continue;
- (*func)(cd, &map, path);
+ if ((error = (*func)(cd, &map, path)) != 0)
+ break;
strlcpy(last, path, sizeof(last));
}
-
- return (0);
+ return (error);
}
prmap_t *
@@ -292,7 +310,7 @@ proc_addr2sym(struct proc_handle *p, uintptr_t addr, char *name,
if ((map = proc_addr2map(p, addr)) == NULL)
return (-1);
- if ((fd = open(map->pr_mapname, O_RDONLY, 0)) < 0) {
+ if ((fd = find_dbg_obj(map->pr_mapname)) < 0) {
DPRINTF("ERROR: open %s failed", map->pr_mapname);
goto err0;
}
@@ -335,8 +353,8 @@ proc_addr2sym(struct proc_handle *p, uintptr_t addr, char *name,
goto out;
error = lookup_addr(e, symtabscn, symtabstridx, off, addr, &s, symcopy);
- if (error == 0)
- goto out;
+ if (error != 0)
+ goto err2;
out:
demangle(s, name, namesz);
@@ -440,7 +458,7 @@ proc_name2sym(struct proc_handle *p, const char *object, const char *symbol,
DPRINTFX("ERROR: couldn't find object %s", object);
goto err0;
}
- if ((fd = open(map->pr_mapname, O_RDONLY, 0)) < 0) {
+ if ((fd = find_dbg_obj(map->pr_mapname)) < 0) {
DPRINTF("ERROR: open %s failed", map->pr_mapname);
goto err0;
}
@@ -501,13 +519,16 @@ ctf_file_t *
proc_name2ctf(struct proc_handle *p, const char *name)
{
#ifndef NO_CTF
+ ctf_file_t *ctf;
prmap_t *map;
int error;
if ((map = proc_name2map(p, name)) == NULL)
return (NULL);
- return (ctf_open(map->pr_mapname, &error));
+ ctf = ctf_open(map->pr_mapname, &error);
+ free(map);
+ return (ctf);
#else
(void)p;
(void)name;
@@ -533,7 +554,7 @@ proc_iter_symbyaddr(struct proc_handle *p, const char *object, int which,
if ((map = proc_name2map(p, object)) == NULL)
return (-1);
- if ((fd = open(map->pr_mapname, O_RDONLY)) < 0) {
+ if ((fd = find_dbg_obj(map->pr_mapname)) < 0) {
DPRINTF("ERROR: open %s failed", map->pr_mapname);
goto err0;
}
@@ -596,7 +617,8 @@ proc_iter_symbyaddr(struct proc_handle *p, const char *object, int which,
s = elf_strptr(e, stridx, sym.st_name);
if (ehdr.e_type != ET_EXEC)
sym.st_value += map->pr_vaddr;
- (*func)(cd, &sym, s);
+ if ((error = (*func)(cd, &sym, s)) != 0)
+ goto err2;
}
error = 0;
err2:
diff --git a/lib/libproc/tests/proc_test.c b/lib/libproc/tests/proc_test.c
index 0242b5b..dbaace8 100644
--- a/lib/libproc/tests/proc_test.c
+++ b/lib/libproc/tests/proc_test.c
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2014 Mark Johnston <markj@FreeBSD.org>
+ * Copyright (c) 2014, 2015 Mark Johnston <markj@FreeBSD.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -295,6 +295,43 @@ ATF_TC_BODY(symbol_lookup, tc)
proc_free(phdl);
}
+ATF_TC(symbol_lookup_fail);
+ATF_TC_HEAD(symbol_lookup_fail, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Verify that proc_addr2sym() returns an error when given an offset "
+ "that it cannot resolve.");
+}
+ATF_TC_BODY(symbol_lookup_fail, tc)
+{
+ char symname[32];
+ GElf_Sym sym;
+ struct proc_handle *phdl;
+ prmap_t *map;
+ int error;
+
+ phdl = start_prog(tc, false);
+
+ /* Initialize the rtld_db handle. */
+ (void)proc_rdagent(phdl);
+
+ map = proc_obj2map(phdl, target_prog_file);
+ ATF_REQUIRE_MSG(map != NULL, "failed to look up map for '%s'",
+ target_prog_file);
+
+ /*
+ * We shouldn't be able to find symbols at the beginning of a mapped
+ * file.
+ */
+ error = proc_addr2sym(phdl, map->pr_vaddr, symname, sizeof(symname),
+ &sym);
+ ATF_REQUIRE_MSG(error != 0, "unexpectedly found a symbol");
+
+ ATF_CHECK_EQ_MSG(proc_continue(phdl), 0, "failed to resume execution");
+
+ proc_free(phdl);
+}
+
ATF_TC(signal_forward);
ATF_TC_HEAD(signal_forward, tc)
{
@@ -343,6 +380,7 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp, map_alias_name2map);
ATF_TP_ADD_TC(tp, map_alias_name2sym);
ATF_TP_ADD_TC(tp, symbol_lookup);
+ ATF_TP_ADD_TC(tp, symbol_lookup_fail);
ATF_TP_ADD_TC(tp, signal_forward);
return (atf_no_error());
diff --git a/lib/libprocstat/Makefile b/lib/libprocstat/Makefile
index 32c7daa..fc71dbc 100644
--- a/lib/libprocstat/Makefile
+++ b/lib/libprocstat/Makefile
@@ -19,10 +19,39 @@ INCS= libprocstat.h
CFLAGS+= -I. -I${.CURDIR} -D_KVM_VNODE
SHLIB_MAJOR= 1
-DPADD= ${LIBELF} ${LIBKVM} ${LIBUTIL}
-LDADD= -lelf -lkvm -lutil
+LIBADD= elf kvm util
MAN= libprocstat.3
+MLINKS+=libprocstat.3 procstat_close.3 \
+ libprocstat.3 procstat_freeargv.3 \
+ libprocstat.3 procstat_freeauxv.3 \
+ libprocstat.3 procstat_freeenvv.3 \
+ libprocstat.3 procstat_freefiles.3 \
+ libprocstat.3 procstat_freegroups.3 \
+ libprocstat.3 procstat_freekstack.3 \
+ libprocstat.3 procstat_freeprocs.3 \
+ libprocstat.3 procstat_freevmmap.3 \
+ libprocstat.3 procstat_get_pipe_info.3 \
+ libprocstat.3 procstat_get_pts_info.3 \
+ libprocstat.3 procstat_get_sem_info.3 \
+ libprocstat.3 procstat_get_shm_info.3 \
+ libprocstat.3 procstat_get_socket_info.3 \
+ libprocstat.3 procstat_get_vnode_info.3 \
+ libprocstat.3 procstat_getargv.3 \
+ libprocstat.3 procstat_getauxv.3 \
+ libprocstat.3 procstat_getenvv.3 \
+ libprocstat.3 procstat_getfiles.3 \
+ libprocstat.3 procstat_getgroups.3 \
+ libprocstat.3 procstat_getkstack.3 \
+ libprocstat.3 procstat_getosrel.3 \
+ libprocstat.3 procstat_getpathname.3 \
+ libprocstat.3 procstat_getprocs.3 \
+ libprocstat.3 procstat_getrlimit.3 \
+ libprocstat.3 procstat_getumask.3 \
+ libprocstat.3 procstat_getvmmap.3 \
+ libprocstat.3 procstat_open_core.3 \
+ libprocstat.3 procstat_open_kvm.3 \
+ libprocstat.3 procstat_open_sysctl.3
# XXX This is a hack.
.if ${MK_CDDL} != "no"
diff --git a/lib/libprocstat/libprocstat.3 b/lib/libprocstat/libprocstat.3
index 1c1f811..e8be41c 100644
--- a/lib/libprocstat/libprocstat.3
+++ b/lib/libprocstat/libprocstat.3
@@ -24,25 +24,11 @@
.\"
.\" $FreeBSD$
.\"
-.Dd May 3, 2013
+.Dd May 18, 2015
.Dt LIBPROCSTAT 3
.Os
.Sh NAME
-.Nm procstat_open_core ,
-.Nm procstat_open_kvm ,
-.Nm procstat_open_sysctl ,
.Nm procstat_close ,
-.Nm procstat_getargv ,
-.Nm procstat_getauxv ,
-.Nm procstat_getenvv ,
-.Nm procstat_getfiles ,
-.Nm procstat_getgroups ,
-.Nm procstat_getkstack ,
-.Nm procstat_getosrel ,
-.Nm procstat_getpathname ,
-.Nm procstat_getprocs ,
-.Nm procstat_getumask ,
-.Nm procstat_getvmmap ,
.Nm procstat_freeargv ,
.Nm procstat_freeauxv ,
.Nm procstat_freeenvv ,
@@ -56,7 +42,22 @@
.Nm procstat_get_sem_info ,
.Nm procstat_get_shm_info ,
.Nm procstat_get_socket_info ,
-.Nm procstat_get_vnode_info
+.Nm procstat_get_vnode_info ,
+.Nm procstat_getargv ,
+.Nm procstat_getauxv ,
+.Nm procstat_getenvv ,
+.Nm procstat_getfiles ,
+.Nm procstat_getgroups ,
+.Nm procstat_getkstack ,
+.Nm procstat_getosrel ,
+.Nm procstat_getpathname ,
+.Nm procstat_getprocs ,
+.Nm procstat_getrlimit ,
+.Nm procstat_getumask ,
+.Nm procstat_getvmmap ,
+.Nm procstat_open_core ,
+.Nm procstat_open_kvm ,
+.Nm procstat_open_sysctl
.Nd library interface for file and process information retrieval
.Sh LIBRARY
.Lb libprocstat
@@ -175,17 +176,24 @@
.Fa "struct kinfo_proc *kp"
.Fa "unsigned int *count"
.Fc
+.Ft "struct kinfo_kstack *"
+.Fo procstat_getkstack
+.Fa "struct procstat *procstat"
+.Fa "struct kinfo_proc *kp"
+.Fa "unsigned int *count"
+.Fc
.Ft int
.Fo procstat_getosrel
.Fa "struct procstat *procstat"
.Fa "struct kinfo_proc *kp"
.Fa "int *osrelp"
.Fc
-.Ft "struct kinfo_kstack *"
-.Fo procstat_getkstack
+.Ft "int"
+.Fo procstat_getpathname
.Fa "struct procstat *procstat"
.Fa "struct kinfo_proc *kp"
-.Fa "unsigned int *count"
+.Fa "char *pathname"
+.Fa "size_t maxlen"
.Fc
.Ft "struct kinfo_proc *"
.Fo procstat_getprocs
@@ -195,13 +203,6 @@
.Fa "unsigned int *count"
.Fc
.Ft "int"
-.Fo procstat_getpathname
-.Fa "struct procstat *procstat"
-.Fa "struct kinfo_proc *kp"
-.Fa "char *pathname"
-.Fa "size_t maxlen"
-.Fc
-.Ft "int"
.Fo procstat_getrlimit
.Fa "struct procstat *procstat"
.Fa "struct kinfo_proc *kp"
diff --git a/lib/libprocstat/udf.c b/lib/libprocstat/udf.c
index 5d9310e..90c369c 100644
--- a/lib/libprocstat/udf.c
+++ b/lib/libprocstat/udf.c
@@ -30,7 +30,6 @@ __FBSDID("$FreeBSD$");
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/vnode.h>
-#include <sys/buf.h>
#define _KERNEL
#include <sys/mount.h>
#undef _KERNEL
diff --git a/lib/libradius/Makefile b/lib/libradius/Makefile
index 2b769d9..42f5def 100644
--- a/lib/libradius/Makefile
+++ b/lib/libradius/Makefile
@@ -70,13 +70,11 @@ MLINKS+=libradius.3 rad_acct_open.3 \
WARNS?= 3
-.if ${MK_OPENSSL} == "no"
-DPADD= ${LIBMD}
-LDADD= -lmd
-.else
-DPADD= ${LIBCRYPTO}
-LDADD= -lcrypto
+.if ${MK_OPENSSL} != "no"
+LIBADD+= crypto
CFLAGS+= -DWITH_SSL
+.else
+LIBADD+= md
.endif
.include <bsd.lib.mk>
diff --git a/lib/librpcsec_gss/Makefile b/lib/librpcsec_gss/Makefile
index 67a7963..c3e76844 100644
--- a/lib/librpcsec_gss/Makefile
+++ b/lib/librpcsec_gss/Makefile
@@ -5,8 +5,7 @@ SHLIB_MAJOR= 1
SRCS+= rpcsec_gss.c rpcsec_gss_prot.c rpcsec_gss_conf.c rpcsec_gss_misc.c \
svc_rpcsec_gss.c
-DPADD+= ${LIBGSSAPI}
-LDADD+= -lgssapi
+LIBADD= gssapi
VERSION_DEF= ${.CURDIR}/../libc/Versions.def
SYMBOL_MAPS= ${.CURDIR}/Symbol.map
diff --git a/lib/librpcsec_gss/Makefile.depend b/lib/librpcsec_gss/Makefile.depend
index fc5d471..89fa5df 100644
--- a/lib/librpcsec_gss/Makefile.depend
+++ b/lib/librpcsec_gss/Makefile.depend
@@ -3,7 +3,6 @@
DEP_RELDIR := ${_PARSEDIR:S,${SRCTOP}/,,}
DIRDEPS = \
- bin/cat.host \
gnu/lib/csu \
gnu/lib/libgcc \
include \
diff --git a/lib/librpcsec_gss/rpc_gss_get_error.3 b/lib/librpcsec_gss/rpc_gss_get_error.3
index eea77c7..a16c58e 100644
--- a/lib/librpcsec_gss/rpc_gss_get_error.3
+++ b/lib/librpcsec_gss/rpc_gss_get_error.3
@@ -44,8 +44,8 @@ Get details of the last RPCSEC_GSS error.
A pointer to a structure where the error details will be returned
.El
.Sh SEE ALSO
-.Xr rpc 3 ,
.Xr gssapi 3 ,
+.Xr rpc 3 ,
.Xr rpcset_gss 3
.Sh HISTORY
The
diff --git a/lib/librpcsec_gss/rpc_gss_get_mech_info.3 b/lib/librpcsec_gss/rpc_gss_get_mech_info.3
index 0bf6d45..8fcade3 100644
--- a/lib/librpcsec_gss/rpc_gss_get_mech_info.3
+++ b/lib/librpcsec_gss/rpc_gss_get_mech_info.3
@@ -54,8 +54,8 @@ a list of the supported qualities of protection is returned,
otherwise
.Dv NULL .
.Sh SEE ALSO
-.Xr rpc 3 ,
.Xr gssapi 3 ,
+.Xr rpc 3 ,
.Xr rpcset_gss 3
.Sh HISTORY
The
diff --git a/lib/librpcsec_gss/rpc_gss_get_mechanisms.3 b/lib/librpcsec_gss/rpc_gss_get_mechanisms.3
index 7c3bcca..224ab42 100644
--- a/lib/librpcsec_gss/rpc_gss_get_mechanisms.3
+++ b/lib/librpcsec_gss/rpc_gss_get_mechanisms.3
@@ -41,8 +41,8 @@ Return a
.Dv NULL
terminated list of installed security mechanisms.
.Sh SEE ALSO
-.Xr rpc 3 ,
.Xr gssapi 3 ,
+.Xr rpc 3 ,
.Xr rpcset_gss 3
.Sh HISTORY
The
diff --git a/lib/librpcsec_gss/rpc_gss_get_principal_name.3 b/lib/librpcsec_gss/rpc_gss_get_principal_name.3
index 286c09f..ba12835 100644
--- a/lib/librpcsec_gss/rpc_gss_get_principal_name.3
+++ b/lib/librpcsec_gss/rpc_gss_get_principal_name.3
@@ -67,9 +67,9 @@ if the principal was created or
.Dv FALSE
otherwise
.Sh SEE ALSO
-.Xr rpc 3 ,
-.Xr gssapi 3 ,
.Xr gss_export_name 3 ,
+.Xr gssapi 3 ,
+.Xr rpc 3 ,
.Xr rpcset_gss 3
.Sh HISTORY
The
diff --git a/lib/librpcsec_gss/rpc_gss_get_versions.3 b/lib/librpcsec_gss/rpc_gss_get_versions.3
index 9d79db4..725b2c0 100644
--- a/lib/librpcsec_gss/rpc_gss_get_versions.3
+++ b/lib/librpcsec_gss/rpc_gss_get_versions.3
@@ -50,8 +50,8 @@ The value of
is set to the lowest supported protocol version
.El
.Sh SEE ALSO
-.Xr rpc 3 ,
.Xr gssapi 3 ,
+.Xr rpc 3 ,
.Xr rpcset_gss 3
.Sh HISTORY
The
diff --git a/lib/librpcsec_gss/rpc_gss_getcred.3 b/lib/librpcsec_gss/rpc_gss_getcred.3
index 515bd99..3bb4b6d 100644
--- a/lib/librpcsec_gss/rpc_gss_getcred.3
+++ b/lib/librpcsec_gss/rpc_gss_getcred.3
@@ -70,8 +70,8 @@ if successful,
.Dv FALSE
otherwise.
.Sh SEE ALSO
-.Xr rpc 3 ,
.Xr gssapi 3 ,
+.Xr rpc 3 ,
.Xr rpc_gss_set_callback 3 ,
.Xr rpcset_gss 3
.Sh HISTORY
diff --git a/lib/librpcsec_gss/rpc_gss_is_installed.3 b/lib/librpcsec_gss/rpc_gss_is_installed.3
index 3d83b71..20df8bd 100644
--- a/lib/librpcsec_gss/rpc_gss_is_installed.3
+++ b/lib/librpcsec_gss/rpc_gss_is_installed.3
@@ -51,8 +51,8 @@ if the mechanism is installed,
.Dv FALSE
otherwise.
.Sh SEE ALSO
-.Xr rpc 3 ,
.Xr gssapi 3 ,
+.Xr rpc 3 ,
.Xr rpcset_gss 3
.Sh HISTORY
The
diff --git a/lib/librpcsec_gss/rpc_gss_max_data_length.3 b/lib/librpcsec_gss/rpc_gss_max_data_length.3
index 57cf673..6438ab8 100644
--- a/lib/librpcsec_gss/rpc_gss_max_data_length.3
+++ b/lib/librpcsec_gss/rpc_gss_max_data_length.3
@@ -50,8 +50,8 @@ Maximum packet size of the underlying transport protocol
.Sh RETURN VALUES
The maximum message size that can be encoded
.Sh SEE ALSO
-.Xr rpc 3 ,
.Xr gssapi 3 ,
+.Xr rpc 3 ,
.Xr rpcset_gss 3
.Sh HISTORY
The
diff --git a/lib/librpcsec_gss/rpc_gss_mech_to_oid.3 b/lib/librpcsec_gss/rpc_gss_mech_to_oid.3
index 1156325..6268880 100644
--- a/lib/librpcsec_gss/rpc_gss_mech_to_oid.3
+++ b/lib/librpcsec_gss/rpc_gss_mech_to_oid.3
@@ -54,8 +54,8 @@ If the mechanism is found,
is returned, otherwise
.Dv FALSE .
.Sh SEE ALSO
-.Xr rpc 3 ,
.Xr gssapi 3 ,
+.Xr rpc 3 ,
.Xr rpcset_gss 3
.Sh HISTORY
The
diff --git a/lib/librpcsec_gss/rpc_gss_oid_to_mech.3 b/lib/librpcsec_gss/rpc_gss_oid_to_mech.3
index 8ab8340..175e361 100644
--- a/lib/librpcsec_gss/rpc_gss_oid_to_mech.3
+++ b/lib/librpcsec_gss/rpc_gss_oid_to_mech.3
@@ -54,8 +54,8 @@ If the mechanism is found,
is returned, otherwise
.Dv FALSE .
.Sh SEE ALSO
-.Xr rpc 3 ,
.Xr gssapi 3 ,
+.Xr rpc 3 ,
.Xr rpcset_gss 3
.Sh HISTORY
The
diff --git a/lib/librpcsec_gss/rpc_gss_qop_to_num.3 b/lib/librpcsec_gss/rpc_gss_qop_to_num.3
index bb8b50a..4041e80 100644
--- a/lib/librpcsec_gss/rpc_gss_qop_to_num.3
+++ b/lib/librpcsec_gss/rpc_gss_qop_to_num.3
@@ -56,8 +56,8 @@ If the value is found,
is returned, otherwise
.Dv FALSE .
.Sh SEE ALSO
-.Xr rpc 3 ,
.Xr gssapi 3 ,
+.Xr rpc 3 ,
.Xr rpcset_gss 3
.Sh HISTORY
The
diff --git a/lib/librpcsec_gss/rpc_gss_seccreate.3 b/lib/librpcsec_gss/rpc_gss_seccreate.3
index 37e9efd..7e9bc34 100644
--- a/lib/librpcsec_gss/rpc_gss_seccreate.3
+++ b/lib/librpcsec_gss/rpc_gss_seccreate.3
@@ -96,11 +96,11 @@ To use this security context for subsequent RPC calls, set
.Va clnt->cl_auth
to this value.
.Sh SEE ALSO
-.Xr rpc 3 ,
.Xr gssapi 3 ,
+.Xr rpc 3 ,
+.Xr rpcset_gss 3 ,
.Xr mech 5 ,
-.Xr qop 5 ,
-.Xr rpcset_gss 3
+.Xr qop 5
.Sh HISTORY
The
.Nm
diff --git a/lib/librpcsec_gss/rpc_gss_set_callback.3 b/lib/librpcsec_gss/rpc_gss_set_callback.3
index 2d202a5..54f3f51 100644
--- a/lib/librpcsec_gss/rpc_gss_set_callback.3
+++ b/lib/librpcsec_gss/rpc_gss_set_callback.3
@@ -93,9 +93,9 @@ if the callback was registered successfully or
.Dv FALSE
otherwise
.Sh SEE ALSO
-.Xr rpc 3 ,
.Xr gssapi 3 ,
-.Xr rpc_gss_getcred 3
+.Xr rpc 3 ,
+.Xr rpc_gss_getcred 3 ,
.Xr rpcset_gss 3
.Sh HISTORY
The
diff --git a/lib/librpcsec_gss/rpc_gss_set_defaults.3 b/lib/librpcsec_gss/rpc_gss_set_defaults.3
index dcef9da..983d2c0 100644
--- a/lib/librpcsec_gss/rpc_gss_set_defaults.3
+++ b/lib/librpcsec_gss/rpc_gss_set_defaults.3
@@ -56,8 +56,8 @@ Returns
.Dv TRUE
if the values were set
.Sh SEE ALSO
-.Xr rpc 3 ,
.Xr gssapi 3 ,
+.Xr rpc 3 ,
.Xr rpcset_gss 3
.Sh HISTORY
The
diff --git a/lib/librpcsec_gss/rpc_gss_set_svc_name.3 b/lib/librpcsec_gss/rpc_gss_set_svc_name.3
index 97f1dee..44b15c7 100644
--- a/lib/librpcsec_gss/rpc_gss_set_svc_name.3
+++ b/lib/librpcsec_gss/rpc_gss_set_svc_name.3
@@ -72,9 +72,9 @@ if the service principal was registered or
.Dv FALSE
otherwise.
.Sh SEE ALSO
-.Xr rpc 3 ,
-.Xr gssapi 3 ,
.Xr gss_acquire_cred 3 ,
+.Xr gssapi 3 ,
+.Xr rpc 3 ,
.Xr rpcset_gss 3
.Sh HISTORY
The
diff --git a/lib/librpcsec_gss/rpc_gss_svc_max_data_length.3 b/lib/librpcsec_gss/rpc_gss_svc_max_data_length.3
index 24eeae9..59ee837 100644
--- a/lib/librpcsec_gss/rpc_gss_svc_max_data_length.3
+++ b/lib/librpcsec_gss/rpc_gss_svc_max_data_length.3
@@ -50,8 +50,8 @@ Maximum packet size of the underlying transport protocol
.Sh RETURN VALUES
The maximum message size that can be encoded
.Sh SEE ALSO
-.Xr rpc 3 ,
.Xr gssapi 3 ,
+.Xr rpc 3 ,
.Xr rpcset_gss 3
.Sh HISTORY
The
diff --git a/lib/librpcsec_gss/rpcsec_gss.3 b/lib/librpcsec_gss/rpcsec_gss.3
index d3120a6..966a1e0 100644
--- a/lib/librpcsec_gss/rpcsec_gss.3
+++ b/lib/librpcsec_gss/rpcsec_gss.3
@@ -214,12 +214,12 @@ Create a client principal name from various strings
Calculate maximum server message sizes.
.El
.Sh SEE ALSO
-.Xr rpc 3 ,
-.Xr gssapi 3 ,
.Xr gss_export_name 3 ,
+.Xr gssapi 3 ,
+.Xr rpc 3 ,
+.Xr rpcset_gss 3 ,
.Xr mech 5 ,
-.Xr qop 5 ,
-.Xr rpcset_gss 3
+.Xr qop 5
.Sh HISTORY
The
.Nm
diff --git a/lib/librt/Makefile b/lib/librt/Makefile
index bd6ec07..5696610 100644
--- a/lib/librt/Makefile
+++ b/lib/librt/Makefile
@@ -9,8 +9,7 @@ CFLAGS+=-I${.CURDIR}/../libc/include -I${.CURDIR}
CFLAGS+=-fexceptions
.endif
CFLAGS+=-Winline -Wall
-DPADD= ${LIBPTHREAD}
-LDADD= -lpthread
+LIBADD= pthread
WARNS?= 2
@@ -20,6 +19,8 @@ PRECIOUSLIB=
VERSION_MAP= ${.CURDIR}/Version.map
-.include <bsd.arch.inc.mk>
+.if ${MK_TESTS} != "no"
+SUBDIR+= tests
+.endif
.include <bsd.lib.mk>
diff --git a/lib/librt/Makefile.amd64 b/lib/librt/Makefile.amd64
deleted file mode 100644
index dd0f5b0..0000000
--- a/lib/librt/Makefile.amd64
+++ /dev/null
@@ -1,6 +0,0 @@
-# $FreeBSD$
-
-.if ${MK_TESTS} != "no"
-SUBDIR+= tests
-.endif
-
diff --git a/lib/librt/Makefile.i386 b/lib/librt/Makefile.i386
deleted file mode 100644
index dd0f5b0..0000000
--- a/lib/librt/Makefile.i386
+++ /dev/null
@@ -1,6 +0,0 @@
-# $FreeBSD$
-
-.if ${MK_TESTS} != "no"
-SUBDIR+= tests
-.endif
-
diff --git a/lib/librt/tests/Makefile b/lib/librt/tests/Makefile
index 224f52e..95c5259 100644
--- a/lib/librt/tests/Makefile
+++ b/lib/librt/tests/Makefile
@@ -6,8 +6,7 @@ TESTSRC= ${SRCTOP}/contrib/netbsd-tests/lib/librt
TESTSDIR= ${TESTSBASE}/lib/librt
-DPADD+= ${LIBRT}
-LDADD+= -lrt
+LIBADD= rt
NETBSD_ATF_TESTS_C= sched_test
NETBSD_ATF_TESTS_C+= sem_test
diff --git a/lib/librtld_db/librtld_db.3 b/lib/librtld_db/librtld_db.3
index 211ce79..f310abf 100644
--- a/lib/librtld_db/librtld_db.3
+++ b/lib/librtld_db/librtld_db.3
@@ -167,8 +167,8 @@ You can get the error string using
.Xr ld 1 ,
.Xr ld-elf.so.1 1 ,
.Xr ld.so 1 ,
-.Xr libproc 3 ,
-.Xr rtld 1
+.Xr rtld 1 ,
+.Xr libproc 3
.Sh HISTORY
The
.Nm librtld_db
diff --git a/lib/libsdp/search.c b/lib/libsdp/search.c
index 868fbe5..fa2a92d 100644
--- a/lib/libsdp/search.c
+++ b/lib/libsdp/search.c
@@ -32,6 +32,7 @@
#include <sys/uio.h>
#include <netinet/in.h>
#include <arpa/inet.h>
+#define L2CAP_SOCKET_CHECKED
#include <bluetooth.h>
#include <errno.h>
#include <stdio.h>
diff --git a/lib/libsdp/service.c b/lib/libsdp/service.c
index 2667966..53c8909 100644
--- a/lib/libsdp/service.c
+++ b/lib/libsdp/service.c
@@ -32,6 +32,7 @@
#include <sys/uio.h>
#include <netinet/in.h>
#include <arpa/inet.h>
+#define L2CAP_SOCKET_CHECKED
#include <bluetooth.h>
#include <errno.h>
#include <string.h>
diff --git a/lib/libsdp/session.c b/lib/libsdp/session.c
index a31f327..a74ce5f 100644
--- a/lib/libsdp/session.c
+++ b/lib/libsdp/session.c
@@ -28,7 +28,7 @@
* $Id: session.c,v 1.2 2003/09/04 22:12:13 max Exp $
* $FreeBSD$
*/
-
+#define L2CAP_SOCKET_CHECKED
#include <bluetooth.h>
#include <errno.h>
#include <stdlib.h>
@@ -62,6 +62,9 @@ sdp_open(bdaddr_t const *l, bdaddr_t const *r)
sa.l2cap_len = sizeof(sa);
sa.l2cap_family = AF_BLUETOOTH;
sa.l2cap_psm = 0;
+ sa.l2cap_cid = 0;
+ sa.l2cap_bdaddr_type = BDADDR_BREDR;
+
memcpy(&sa.l2cap_bdaddr, l, sizeof(sa.l2cap_bdaddr));
if (bind(ss->s, (struct sockaddr *) &sa, sizeof(sa)) < 0) {
ss->error = errno;
diff --git a/lib/libsdp/util.c b/lib/libsdp/util.c
index b996bd2..5ef4a1d 100644
--- a/lib/libsdp/util.c
+++ b/lib/libsdp/util.c
@@ -30,6 +30,7 @@
*/
#include <netinet/in.h>
+#define L2CAP_SOCKET_CHECKED
#include <bluetooth.h>
#include <stdio.h>
#include <sdp.h>
diff --git a/lib/libsmb/Makefile b/lib/libsmb/Makefile
index ea7327b..b63754b 100644
--- a/lib/libsmb/Makefile
+++ b/lib/libsmb/Makefile
@@ -7,8 +7,7 @@ CONTRIBDIR= ${.CURDIR}/../../contrib/smbfs
LIB= smb
SHLIB_MAJOR= 4
-DPADD= ${LIBKICONV}
-LDADD= -lkiconv
+LIBADD= kiconv
SRCS= rcfile.c ctx.c cfopt.c subr.c nls.c rap.c mbuf.c rq.c file.c \
print.c \
diff --git a/lib/libsqlite3/Makefile b/lib/libsqlite3/Makefile
new file mode 100644
index 0000000..2db85fb
--- /dev/null
+++ b/lib/libsqlite3/Makefile
@@ -0,0 +1,39 @@
+# $FreeBSD$
+
+PRIVATELIB= yes
+LIB= sqlite3
+SHLIB_MAJOR?= 0
+LIBADD+= pthread
+
+SRCS= sqlite3.c
+
+SQLITE= ${.CURDIR}/../../contrib/sqlite3
+.PATH: ${SQLITE}
+
+WARNS= 3
+CFLAGS+= -I${SQLITE} \
+ -DSTDC_HEADERS=1 \
+ -DHAVE_SYS_TYPES_H=1 \
+ -DHAVE_SYS_STAT_H=1 \
+ -DUSE_PREAD=1 \
+ -DHAVE_STDLIB_H=1 \
+ -DHAVE_STRING_H=1 \
+ -DHAVE_MEMORY_H=1 \
+ -DHAVE_STRINGS_H=1 \
+ -DHAVE_INTTYPES_H=1 \
+ -DHAVE_STDINT_H=1 \
+ -DHAVE_UNISTD_H=1 \
+ -DHAVE_DLFCN_H=1 \
+ -DHAVE_USLEEP=1 \
+ -DHAVE_LOCALTIME_R=1 \
+ -DHAVE_GMTIME_R=1 \
+ -DHAVE_DECL_STRERROR_R=1 \
+ -DHAVE_STRERROR_R=1 \
+ -DHAVE_POSIX_FALLOCATE=1 \
+ -D_REENTRANT=1 \
+ -DSQLITE_THREADSAFE=1 \
+ -DSQLITE_ENABLE_FTS3 \
+ -DSQLITE_ENABLE_FTS4 \
+ -DSQLITE_ENABLE_RTREE
+
+.include <bsd.lib.mk>
diff --git a/lib/libsqlite3/Makefile.depend b/lib/libsqlite3/Makefile.depend
new file mode 100644
index 0000000..37acbe0
--- /dev/null
+++ b/lib/libsqlite3/Makefile.depend
@@ -0,0 +1,21 @@
+# Autogenerated - do NOT edit!
+
+DEP_RELDIR := ${_PARSEDIR:S,${SRCTOP}/,,}
+
+DIRDEPS = \
+ gnu/lib/csu \
+ gnu/lib/libgcc \
+ include \
+ include/xlocale \
+ lib/${CSU_DIR} \
+ lib/libc \
+ lib/libcompiler_rt \
+ lib/libthr \
+ usr.bin/xinstall.host \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif
diff --git a/lib/libstand/Makefile b/lib/libstand/Makefile
index e57407f..2ee2921 100644
--- a/lib/libstand/Makefile
+++ b/lib/libstand/Makefile
@@ -11,6 +11,9 @@ MK_SSP= no
.include <src.opts.mk>
+LIBSTAND_SRC= ${.CURDIR}
+LIBC_SRC= ${LIBSTAND_SRC}/../libc
+
LIB= stand
NO_PIC=
INCS= stand.h
@@ -19,7 +22,7 @@ MAN= libstand.3
WARNS?= 0
CFLAGS+= -ffreestanding -Wformat
-CFLAGS+= -I${.CURDIR}
+CFLAGS+= -I${LIBSTAND_SRC}
.if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64"
CFLAGS+= -mno-mmx -mno-3dnow -mno-sse -mno-sse2 -mno-sse3 -msoft-float
@@ -28,7 +31,7 @@ CFLAGS+= -mno-mmx -mno-3dnow -mno-sse -mno-sse2 -mno-sse3 -msoft-float
CFLAGS.gcc+= -mpreferred-stack-boundary=2
.endif
.if ${MACHINE_CPUARCH} == "amd64"
-CFLAGS+= -fPIC
+CFLAGS+= -fPIC -mno-red-zone
.endif
.if ${MACHINE} == "pc98"
CFLAGS+= -Os
@@ -39,6 +42,9 @@ CFLAGS+= -msoft-float -D_STANDALONE -DNETIF_DEBUG
.if ${MACHINE_CPUARCH} == "arm"
CFLAGS+= -msoft-float -D_STANDALONE
.endif
+.if ${MACHINE_CPUARCH} == "aarch64"
+CFLAGS+= -D_STANDALONE -mgeneral-regs-only
+.endif
.if ${MACHINE_CPUARCH} == "mips"
CFLAGS+= -G0 -fno-pic -mno-abicalls
.endif
@@ -51,55 +57,54 @@ SRCS+= gzguts.h zutil.h __main.c assert.c bcd.c bswap.c environment.c getopt.c g
# private (pruned) versions of libc string functions
SRCS+= strcasecmp.c
-.PATH: ${.CURDIR}/../libc/net
+.PATH: ${LIBC_SRC}/net
SRCS+= ntoh.c
# string functions from libc
-.PATH: ${.CURDIR}/../libc/string
+.PATH: ${LIBC_SRC}/string
SRCS+= bcmp.c bcopy.c bzero.c ffs.c memccpy.c memchr.c memcmp.c memcpy.c \
memmove.c memset.c qdivrem.c strcat.c strchr.c strcmp.c strcpy.c \
strcspn.c strlen.c strncat.c strncmp.c strncpy.c strpbrk.c \
strrchr.c strsep.c strspn.c strstr.c strtok.c swab.c
.if ${MACHINE_CPUARCH} == "arm"
-.PATH: ${.CURDIR}/../libc/arm/gen
+.PATH: ${LIBC_SRC}/arm/gen
# Compiler support functions
-.PATH: ${.CURDIR}/../../contrib/compiler-rt/lib/
+.PATH: ${LIBSTAND_SRC}/../../contrib/compiler-rt/lib/builtins/
# __clzsi2 and ctzsi2 for various builtin functions
SRCS+= clzsi2.c ctzsi2.c
# Divide and modulus functions called by the compiler
SRCS+= divmoddi4.c divmodsi4.c divdi3.c divsi3.c moddi3.c modsi3.c
SRCS+= udivmoddi4.c udivmodsi4.c udivdi3.c udivsi3.c umoddi3.c umodsi3.c
-.PATH: ${.CURDIR}/../../contrib/compiler-rt/lib/arm/
+.PATH: ${LIBSTAND_SRC}/../../contrib/compiler-rt/lib/builtins/arm/
SRCS+= aeabi_idivmod.S aeabi_ldivmod.S aeabi_uidivmod.S aeabi_uldivmod.S
SRCS+= aeabi_memcmp.S aeabi_memcpy.S aeabi_memmove.S aeabi_memset.S
+.endif
+.if ${MACHINE_CPUARCH} == "aarch64"
+.PATH: ${LIBC_SRC}/aarch64/gen
.endif
+
.if ${MACHINE_CPUARCH} == "powerpc"
-.PATH: ${.CURDIR}/../libc/quad
+.PATH: ${LIBC_SRC}/quad
SRCS+= ashldi3.c ashrdi3.c
-.PATH: ${.CURDIR}/../libc/powerpc/gen
SRCS+= syncicache.c
.endif
# uuid functions from libc
-.PATH: ${.CURDIR}/../libc/uuid
+.PATH: ${LIBC_SRC}/uuid
SRCS+= uuid_equal.c uuid_is_nil.c
# _setjmp/_longjmp
-.if ${MACHINE_ARCH} == "powerpc64"
-.PATH: ${.CURDIR}/powerpc
-.else
-.PATH: ${.CURDIR}/${MACHINE_CPUARCH}
-.endif
+.PATH: ${LIBSTAND_SRC}/${MACHINE_CPUARCH}
SRCS+= _setjmp.S
# decompression functionality from libbz2
# NOTE: to actually test this functionality after libbz2 upgrade compile
# loader(8) with LOADER_BZIP2_SUPPORT defined
-.PATH: ${.CURDIR}/../../contrib/bzip2
+.PATH: ${LIBSTAND_SRC}/../../contrib/bzip2
CFLAGS+= -DBZ_NO_STDIO -DBZ_NO_COMPRESS
SRCS+= libstand_bzlib_private.h
@@ -108,7 +113,8 @@ SRCS+= _${file}
CLEANFILES+= _${file}
_${file}: ${file}
- sed "s|bzlib_private\.h|libstand_bzlib_private.h|" ${.ALLSRC} > ${.TARGET}
+ sed "s|bzlib_private\.h|libstand_bzlib_private.h|" \
+ ${.ALLSRC} > ${.TARGET}
.endfor
CLEANFILES+= libstand_bzlib_private.h
@@ -117,8 +123,8 @@ libstand_bzlib_private.h: bzlib_private.h
${.ALLSRC} > ${.TARGET}
# decompression functionality from libz
-.PATH: ${.CURDIR}/../libz
-CFLAGS+=-DHAVE_MEMCPY -I${.CURDIR}/../libz
+.PATH: ${LIBSTAND_SRC}/../libz
+CFLAGS+=-DHAVE_MEMCPY -I${LIBSTAND_SRC}/../libz
SRCS+= adler32.c crc32.c libstand_zutil.h libstand_gzguts.h
.for file in infback.c inffast.c inflate.c inftrees.c zutil.c
@@ -163,4 +169,3 @@ SRCS+= nandfs.c
.endif
.include <bsd.lib.mk>
-
diff --git a/lib/libstand/cd9660.c b/lib/libstand/cd9660.c
index c6bcef2..09cc7f8 100644
--- a/lib/libstand/cd9660.c
+++ b/lib/libstand/cd9660.c
@@ -151,9 +151,14 @@ susp_lookup_record(struct open_file *f, const char *identifier,
return (NULL);
p = susp_buffer + isonum_733(shc->offset);
end = p + isonum_733(shc->length);
- } else
+ } else {
/* Ignore this record and skip to the next. */
p += isonum_711(sh->length);
+
+ /* Avoid infinite loops with corrupted file systems */
+ if (isonum_711(sh->length) == 0)
+ return (NULL);
+ }
}
return (NULL);
}
@@ -281,7 +286,7 @@ cd9660_open(const char *path, struct open_file *f)
buf = malloc(buf_size = ISO_DEFAULT_BLOCK_SIZE);
vd = buf;
for (bno = 16;; bno++) {
- twiddle();
+ twiddle(1);
rc = f->f_dev->dv_strategy(f->f_devdata, F_READ, cdb2devb(bno),
ISO_DEFAULT_BLOCK_SIZE, buf, &read);
if (rc)
@@ -314,7 +319,7 @@ cd9660_open(const char *path, struct open_file *f)
while (off < dsize) {
if ((off % ISO_DEFAULT_BLOCK_SIZE) == 0) {
- twiddle();
+ twiddle(1);
rc = f->f_dev->dv_strategy
(f->f_devdata, F_READ,
cdb2devb(bno + boff),
@@ -374,7 +379,7 @@ cd9660_open(const char *path, struct open_file *f)
/* Check for Rock Ridge since we didn't in the loop above. */
bno = isonum_733(rec.extent) + isonum_711(rec.ext_attr_length);
- twiddle();
+ twiddle(1);
rc = f->f_dev->dv_strategy(f->f_devdata, F_READ, cdb2devb(bno),
ISO_DEFAULT_BLOCK_SIZE, buf, &read);
if (rc)
@@ -431,7 +436,7 @@ buf_read_file(struct open_file *f, char **buf_p, size_t *size_p)
if (fp->f_buf == (char *)0)
fp->f_buf = malloc(ISO_DEFAULT_BLOCK_SIZE);
- twiddle();
+ twiddle(16);
rc = f->f_dev->dv_strategy(f->f_devdata, F_READ,
cdb2devb(blkno), ISO_DEFAULT_BLOCK_SIZE, fp->f_buf, &read);
if (rc)
diff --git a/lib/libstand/dosfs.c b/lib/libstand/dosfs.c
index 72205a2..b75d752 100644
--- a/lib/libstand/dosfs.c
+++ b/lib/libstand/dosfs.c
@@ -786,7 +786,8 @@ static int
ioget(struct open_file *fd, u_int lsec, void *buf, u_int nsec)
{
int err;
-
+
+ twiddle(1);
if ((err = (fd->f_dev->dv_strategy)(fd->f_devdata, F_READ, lsec,
secbyt(nsec), buf, NULL)))
return(err);
diff --git a/lib/libstand/ext2fs.c b/lib/libstand/ext2fs.c
index e0afb3e..d0b91e0 100644
--- a/lib/libstand/ext2fs.c
+++ b/lib/libstand/ext2fs.c
@@ -353,7 +353,7 @@ ext2fs_open(const char *upath, struct open_file *f)
/* allocate space and read super block */
fs = (struct ext2fs *)malloc(sizeof(*fs));
fp->f_fs = fs;
- twiddle();
+ twiddle(1);
error = (f->f_dev->dv_strategy)(f->f_devdata, F_READ,
EXT2_SBLOCK, EXT2_SBSIZE, (char *)fs, &buf_size);
if (error)
@@ -395,7 +395,7 @@ ext2fs_open(const char *upath, struct open_file *f)
len = blkgrps * fs->fs_bsize;
fp->f_bg = malloc(len);
- twiddle();
+ twiddle(1);
error = (f->f_dev->dv_strategy)(f->f_devdata, F_READ,
EXT2_SBLOCK + EXT2_SBSIZE / DEV_BSIZE, len,
(char *)fp->f_bg, &buf_size);
@@ -507,7 +507,7 @@ ext2fs_open(const char *upath, struct open_file *f)
if (error)
goto out;
- twiddle();
+ twiddle(1);
error = (f->f_dev->dv_strategy)(f->f_devdata,
F_READ, fsb_to_db(fs, disk_block),
fs->fs_bsize, buf, &buf_size);
@@ -568,7 +568,7 @@ read_inode(ino_t inumber, struct open_file *f)
* Read inode and save it.
*/
buf = malloc(fs->fs_bsize);
- twiddle();
+ twiddle(1);
error = (f->f_dev->dv_strategy)(f->f_devdata, F_READ,
ino_to_db(fs, fp->f_bg, inumber), fs->fs_bsize, buf, &rsize);
if (error)
@@ -665,7 +665,7 @@ block_map(struct open_file *f, daddr_t file_block, daddr_t *disk_block_p)
if (fp->f_blk[level] == (char *)0)
fp->f_blk[level] =
malloc(fs->fs_bsize);
- twiddle();
+ twiddle(1);
error = (f->f_dev->dv_strategy)(f->f_devdata, F_READ,
fsb_to_db(fp->f_fs, ind_block_num), fs->fs_bsize,
fp->f_blk[level], &fp->f_blksize[level]);
@@ -723,7 +723,7 @@ buf_read_file(struct open_file *f, char **buf_p, size_t *size_p)
bzero(fp->f_buf, block_size);
fp->f_buf_size = block_size;
} else {
- twiddle();
+ twiddle(4);
error = (f->f_dev->dv_strategy)(f->f_devdata, F_READ,
fsb_to_db(fs, disk_block), block_size,
fp->f_buf, &fp->f_buf_size);
diff --git a/lib/libstand/libstand.3 b/lib/libstand/libstand.3
index b42c8b5..42289c1 100644
--- a/lib/libstand/libstand.3
+++ b/lib/libstand/libstand.3
@@ -288,7 +288,7 @@ Thus
printf(
.Qq reg=%b\en ,
3,
-.Qq \e10\e2BITTWO\e1BITONE\en
+.Qq \e10\e2BITTWO\e1BITONE
);
.Ed
.Pp
diff --git a/lib/libstand/nandfs.c b/lib/libstand/nandfs.c
index 713dc12..b8c51e3 100644
--- a/lib/libstand/nandfs.c
+++ b/lib/libstand/nandfs.c
@@ -921,7 +921,7 @@ nandfs_bmap_lookup(struct nandfs *fs, struct nandfs_node *node,
return (0);
}
- twiddle();
+ twiddle(1);
NANDFS_DEBUG("calling get_map with %jx\n", ind_block_num);
map = nandfs_get_map(fs, node, ind_block_num, phys);
if (map == NULL)
diff --git a/lib/libstand/nfs.c b/lib/libstand/nfs.c
index adb0a11..a0b726c 100644
--- a/lib/libstand/nfs.c
+++ b/lib/libstand/nfs.c
@@ -662,7 +662,7 @@ nfs_read(struct open_file *f, void *buf, size_t size, size_t *resid)
(int)fp->off);
#endif
while ((int)size > 0) {
- twiddle();
+ twiddle(16);
cc = nfs_readdata(fp, fp->off, (void *)addr, size);
/* XXX maybe should retry on certain errors */
if (cc == -1) {
@@ -1311,7 +1311,7 @@ nfs_read(struct open_file *f, void *buf, size_t size, size_t *resid)
(int)fp->off);
#endif
while ((int)size > 0) {
- twiddle();
+ twiddle(16);
cc = nfs_readdata(fp, fp->off, (void *)addr, size);
/* XXX maybe should retry on certain errors */
if (cc == -1) {
diff --git a/lib/libstand/powerpc/_setjmp.S b/lib/libstand/powerpc/_setjmp.S
index 3884b11..7c7c24b 100644
--- a/lib/libstand/powerpc/_setjmp.S
+++ b/lib/libstand/powerpc/_setjmp.S
@@ -42,7 +42,7 @@
#define JMP_xer 24*REGWIDTH
#define JMP_sig 25*REGWIDTH
-ASENTRY_NOPROF(setjmp)
+ASENTRY_NOPROF(_setjmp)
ST_REG 31, JMP_r31(3)
/* r1, r2, r14-r30 */
ST_REG 1, JMP_r1 (3)
@@ -79,7 +79,7 @@ ASENTRY_NOPROF(setjmp)
.extern sigsetmask
-ASENTRY_NOPROF(longjmp)
+ASENTRY_NOPROF(_longjmp)
LD_REG 31, JMP_r31(3)
/* r1, r2, r14-r30 */
LD_REG 1, JMP_r1 (3)
diff --git a/lib/libstand/powerpc/syncicache.c b/lib/libstand/powerpc/syncicache.c
new file mode 100644
index 0000000..434dcec
--- /dev/null
+++ b/lib/libstand/powerpc/syncicache.c
@@ -0,0 +1,103 @@
+/*-
+ * Copyright (C) 1995-1997, 1999 Wolfgang Solfrank.
+ * Copyright (C) 1995-1997, 1999 TooLs GmbH.
+ * 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. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by TooLs GmbH.
+ * 4. The name of TooLs GmbH may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``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 TOOLS GMBH 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.
+ *
+ * $NetBSD: syncicache.c,v 1.2 1999/05/05 12:36:40 tsubai Exp $
+ */
+
+#ifndef lint
+static const char rcsid[] =
+ "$FreeBSD$";
+#endif /* not lint */
+
+#include <sys/param.h>
+#if defined(_KERNEL) || defined(_STANDALONE)
+#include <sys/time.h>
+#include <sys/proc.h>
+#include <vm/vm.h>
+#endif
+#include <sys/sysctl.h>
+
+#include <machine/cpu.h>
+#include <machine/md_var.h>
+
+#ifdef _STANDALONE
+int cacheline_size = 32;
+#endif
+
+#if !defined(_KERNEL) && !defined(_STANDALONE)
+#include <stdlib.h>
+
+int cacheline_size = 0;
+
+static void getcachelinesize(void);
+
+static void
+getcachelinesize()
+{
+ static int cachemib[] = { CTL_MACHDEP, CPU_CACHELINE };
+ int clen;
+
+ clen = sizeof(cacheline_size);
+
+ if (sysctl(cachemib, sizeof(cachemib) / sizeof(cachemib[0]),
+ &cacheline_size, &clen, NULL, 0) < 0 || !cacheline_size) {
+ abort();
+ }
+}
+#endif
+
+void
+__syncicache(void *from, int len)
+{
+ int l, off;
+ char *p;
+
+#if !defined(_KERNEL) && !defined(_STANDALONE)
+ if (!cacheline_size)
+ getcachelinesize();
+#endif
+
+ off = (u_int)from & (cacheline_size - 1);
+ l = len += off;
+ p = (char *)from - off;
+
+ do {
+ __asm __volatile ("dcbst 0,%0" :: "r"(p));
+ p += cacheline_size;
+ } while ((l -= cacheline_size) > 0);
+ __asm __volatile ("sync");
+ p = (char *)from - off;
+ do {
+ __asm __volatile ("icbi 0,%0" :: "r"(p));
+ p += cacheline_size;
+ } while ((len -= cacheline_size) > 0);
+ __asm __volatile ("sync; isync");
+}
+
diff --git a/lib/libstand/printf.c b/lib/libstand/printf.c
index 157b327..fef5341 100644
--- a/lib/libstand/printf.c
+++ b/lib/libstand/printf.c
@@ -187,7 +187,7 @@ ksprintn(char *nbuf, uintmax_t num, int base, int *lenp, int upper)
* the next characters (up to a control character, i.e. a character <= 32),
* give the name of the register. Thus:
*
- * kvprintf("reg=%b\n", 3, "\10\2BITTWO\1BITONE\n");
+ * kvprintf("reg=%b\n", 3, "\10\2BITTWO\1BITONE");
*
* would produce output:
*
@@ -500,7 +500,7 @@ number:
while (percent < fmt)
PCHAR(*percent++);
/*
- * Since we ignore an formatting argument it is no
+ * Since we ignore a formatting argument it is no
* longer safe to obey the remaining formatting
* arguments as the arguments will no longer match
* the format specs.
diff --git a/lib/libstand/read.c b/lib/libstand/read.c
index 4c67dbe..a984dbe 100644
--- a/lib/libstand/read.c
+++ b/lib/libstand/read.c
@@ -77,7 +77,7 @@ read(int fd, void *dest, size_t bcount)
return (-1);
}
if (f->f_flags & F_RAW) {
- twiddle();
+ twiddle(4);
errno = (f->f_dev->dv_strategy)(f->f_devdata, F_READ,
btodb(f->f_offset), bcount, dest, &resid);
if (errno)
diff --git a/lib/libstand/stand.h b/lib/libstand/stand.h
index bcd146a..22ee319 100644
--- a/lib/libstand/stand.h
+++ b/lib/libstand/stand.h
@@ -242,7 +242,8 @@ extern int sprintf(char *buf, const char *cfmt, ...) __printflike(2, 3);
extern int snprintf(char *buf, size_t size, const char *cfmt, ...) __printflike(3, 4);
extern void vsprintf(char *buf, const char *cfmt, __va_list);
-extern void twiddle(void);
+extern void twiddle(u_int callerdiv);
+extern void twiddle_divisor(u_int globaldiv);
extern void ngets(char *, int);
#define gets(x) ngets((x), 0)
diff --git a/lib/libstand/tftp.c b/lib/libstand/tftp.c
index e3983c3..6527c4e 100644
--- a/lib/libstand/tftp.c
+++ b/lib/libstand/tftp.c
@@ -447,14 +447,12 @@ tftp_read(struct open_file *f, void *addr, size_t size,
size_t *resid /* out */)
{
struct tftp_handle *tftpfile;
- static int tc = 0;
tftpfile = (struct tftp_handle *) f->f_fsdata;
while (size > 0) {
int needblock, count;
- if (!(tc++ % 16))
- twiddle();
+ twiddle(32);
needblock = tftpfile->off / tftpfile->tftp_blksize + 1;
diff --git a/lib/libstand/twiddle.c b/lib/libstand/twiddle.c
index e0a4c08..96ebbbe 100644
--- a/lib/libstand/twiddle.c
+++ b/lib/libstand/twiddle.c
@@ -42,11 +42,28 @@ __FBSDID("$FreeBSD$");
/* Extra functions from NetBSD standalone printf.c */
+static u_int globaldiv;
+
void
-twiddle()
+twiddle(u_int callerdiv)
{
- static int pos;
+ static u_int callercnt, globalcnt, pos;
+
+ callercnt++;
+ if (callerdiv > 1 && (callercnt % callerdiv) != 0)
+ return;
+
+ globalcnt++;
+ if (globaldiv > 1 && (globalcnt % globaldiv) != 0)
+ return;
putchar("|/-\\"[pos++ & 3]);
putchar('\b');
}
+
+void
+twiddle_divisor(u_int gdiv)
+{
+
+ globaldiv = gdiv;
+}
diff --git a/lib/libstand/ufs.c b/lib/libstand/ufs.c
index b6f7815..928a1d1 100644
--- a/lib/libstand/ufs.c
+++ b/lib/libstand/ufs.c
@@ -155,7 +155,7 @@ read_inode(inumber, f)
* Read inode and save it.
*/
buf = malloc(fs->fs_bsize);
- twiddle();
+ twiddle(1);
rc = (f->f_dev->dv_strategy)(f->f_devdata, F_READ,
fsbtodb(fs, ino_to_fsba(fs, inumber)), fs->fs_bsize,
buf, &rsize);
@@ -265,7 +265,7 @@ block_map(f, file_block, disk_block_p)
if (fp->f_blk[level] == (char *)0)
fp->f_blk[level] =
malloc(fs->fs_bsize);
- twiddle();
+ twiddle(1);
rc = (f->f_dev->dv_strategy)(f->f_devdata, F_READ,
fsbtodb(fp->f_fs, ind_block_num),
fs->fs_bsize,
@@ -346,7 +346,7 @@ buf_write_file(f, buf_p, size_p)
if (fp->f_buf == (char *)0)
fp->f_buf = malloc(fs->fs_bsize);
- twiddle();
+ twiddle(4);
rc = (f->f_dev->dv_strategy)(f->f_devdata, F_READ,
fsbtodb(fs, disk_block),
block_size, fp->f_buf, &fp->f_buf_size);
@@ -365,7 +365,7 @@ buf_write_file(f, buf_p, size_p)
* Write the block out to storage.
*/
- twiddle();
+ twiddle(4);
rc = (f->f_dev->dv_strategy)(f->f_devdata, F_WRITE,
fsbtodb(fs, disk_block),
block_size, fp->f_buf, &fp->f_buf_size);
@@ -406,7 +406,7 @@ buf_read_file(f, buf_p, size_p)
bzero(fp->f_buf, block_size);
fp->f_buf_size = block_size;
} else {
- twiddle();
+ twiddle(4);
rc = (f->f_dev->dv_strategy)(f->f_devdata, F_READ,
fsbtodb(fs, disk_block),
block_size, fp->f_buf, &fp->f_buf_size);
@@ -515,7 +515,7 @@ ufs_open(upath, f)
/* allocate space and read super block */
fs = malloc(SBLOCKSIZE);
fp->f_fs = fs;
- twiddle();
+ twiddle(1);
/*
* Try reading the superblock in each of its possible locations.
*/
@@ -649,7 +649,7 @@ ufs_open(upath, f)
if (rc)
goto out;
- twiddle();
+ twiddle(1);
rc = (f->f_dev->dv_strategy)(f->f_devdata,
F_READ, fsbtodb(fs, disk_block),
fs->fs_bsize, buf, &buf_size);
diff --git a/lib/libstand/write.c b/lib/libstand/write.c
index dccdb8b..9e02f08 100644
--- a/lib/libstand/write.c
+++ b/lib/libstand/write.c
@@ -80,7 +80,7 @@ write(fd, dest, bcount)
return (-1);
}
if (f->f_flags & F_RAW) {
- twiddle();
+ twiddle(4);
errno = (f->f_dev->dv_strategy)(f->f_devdata, F_WRITE,
btodb(f->f_offset), bcount, dest, &resid);
if (errno)
diff --git a/lib/libstdthreads/Makefile b/lib/libstdthreads/Makefile
index 544eeb0..8daee58 100644
--- a/lib/libstdthreads/Makefile
+++ b/lib/libstdthreads/Makefile
@@ -32,8 +32,7 @@ MLINKS= thrd_create.3 call_once.3 \
thrd_create.3 tss_get.3 \
thrd_create.3 tss_set.3
-DPADD= ${LIBPTHREAD}
-LDADD= -lpthread
+LIBADD= pthread
VERSION_DEF= ${.CURDIR}/../libc/Versions.def
SYMBOL_MAPS= ${.CURDIR}/Symbol.map
diff --git a/lib/libstdthreads/Makefile.depend b/lib/libstdthreads/Makefile.depend
index 3b39ad7..37acbe0 100644
--- a/lib/libstdthreads/Makefile.depend
+++ b/lib/libstdthreads/Makefile.depend
@@ -3,7 +3,6 @@
DEP_RELDIR := ${_PARSEDIR:S,${SRCTOP}/,,}
DIRDEPS = \
- bin/cat.host \
gnu/lib/csu \
gnu/lib/libgcc \
include \
diff --git a/lib/libstdthreads/mtx.c b/lib/libstdthreads/mtx.c
index 6c9166d..f38fbae 100644
--- a/lib/libstdthreads/mtx.c
+++ b/lib/libstdthreads/mtx.c
@@ -96,7 +96,7 @@ int
mtx_trylock(mtx_t *mtx)
{
- switch (pthread_mutex_lock(mtx)) {
+ switch (pthread_mutex_trylock(mtx)) {
case 0:
return (thrd_success);
case EBUSY:
diff --git a/lib/libstdthreads/thrd.c b/lib/libstdthreads/thrd.c
index f0ce55a..b0e36ef 100644
--- a/lib/libstdthreads/thrd.c
+++ b/lib/libstdthreads/thrd.c
@@ -108,7 +108,8 @@ thrd_join(thrd_t thr, int *res)
if (pthread_join(thr, &value_ptr) != 0)
return (thrd_error);
- *res = (intptr_t)value_ptr;
+ if (res != NULL)
+ *res = (intptr_t)value_ptr;
return (thrd_success);
}
diff --git a/lib/libtacplus/Makefile b/lib/libtacplus/Makefile
index 798c949..01345e1 100644
--- a/lib/libtacplus/Makefile
+++ b/lib/libtacplus/Makefile
@@ -28,8 +28,7 @@ LIB= tacplus
SRCS= taclib.c
INCS= taclib.h
CFLAGS+= -Wall
-DPADD= ${LIBMD}
-LDADD= -lmd
+LIBADD= md
SHLIB_MAJOR= 5
MAN= libtacplus.3 tacplus.conf.5
diff --git a/lib/libthr/Makefile b/lib/libthr/Makefile
index 5cbd0aa..1717672 100644
--- a/lib/libthr/Makefile
+++ b/lib/libthr/Makefile
@@ -40,13 +40,14 @@ MAN= libthr.3
# enable extra internal consistancy checks
CFLAGS+=-D_PTHREADS_INVARIANTS
-#CFLAGS+=-g
PRECIOUSLIB=
.PATH: ${.CURDIR}/arch/${MACHINE_CPUARCH}/${MACHINE_CPUARCH}
+.if exists(${.CURDIR}/arch/${MACHINE_CPUARCH}/Makefile.inc)
.include "${.CURDIR}/arch/${MACHINE_CPUARCH}/Makefile.inc"
+.endif
.include "${.CURDIR}/sys/Makefile.inc"
.include "${.CURDIR}/thread/Makefile.inc"
@@ -60,10 +61,8 @@ SYMLINKS+=lib${LIB}.so ${LIBDIR}/libpthread.so
SYMLINKS+=lib${LIB}_p.a ${LIBDIR}/libpthread_p.a
.endif
-.if ${MK_SYSCALL_COMPAT} != "no"
-CFLAGS+=-DSYSCALL_COMPAT
+.if ${MK_TESTS} != "no"
+SUBDIR+= tests
.endif
-.include <bsd.arch.inc.mk>
-
.include <bsd.lib.mk>
diff --git a/lib/libthr/Makefile.amd64 b/lib/libthr/Makefile.amd64
deleted file mode 100644
index dd0f5b0..0000000
--- a/lib/libthr/Makefile.amd64
+++ /dev/null
@@ -1,6 +0,0 @@
-# $FreeBSD$
-
-.if ${MK_TESTS} != "no"
-SUBDIR+= tests
-.endif
-
diff --git a/lib/libthr/Makefile.i386 b/lib/libthr/Makefile.i386
deleted file mode 100644
index dd0f5b0..0000000
--- a/lib/libthr/Makefile.i386
+++ /dev/null
@@ -1,6 +0,0 @@
-# $FreeBSD$
-
-.if ${MK_TESTS} != "no"
-SUBDIR+= tests
-.endif
-
diff --git a/lib/libthr/arch/aarch64/Makefile.inc b/lib/libthr/arch/aarch64/Makefile.inc
new file mode 100644
index 0000000..b720e3d
--- /dev/null
+++ b/lib/libthr/arch/aarch64/Makefile.inc
@@ -0,0 +1,2 @@
+# $FreeBSD$
+
diff --git a/lib/libc/powerpc64/gen/getcontextx.c b/lib/libthr/arch/aarch64/include/pthread_md.h
index 54f8513..14c1893 100644
--- a/lib/libc/powerpc64/gen/getcontextx.c
+++ b/lib/libthr/arch/aarch64/include/pthread_md.h
@@ -1,7 +1,11 @@
-/*
- * Copyright (c) 2011 Konstantin Belousov <kib@FreeBSD.org>
+/*-
+ * Copyright (c) 2005 David Xu <davidxu@freebsd.org>.
+ * Copyright (c) 2014 the FreeBSD Foundation
* All rights reserved.
*
+ * Portions of this software were developed by Andrew Turner
+ * under sponsorship from the FreeBSD Foundation
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -22,55 +26,59 @@
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+/*
+ * Machine-dependent thread prototypes/definitions.
+ */
+#ifndef _PTHREAD_MD_H_
+#define _PTHREAD_MD_H_
#include <sys/types.h>
-#include <sys/ucontext.h>
-#include <errno.h>
-#include <stdlib.h>
+#include <machine/sysarch.h>
+#include <stddef.h>
-int
-__getcontextx_size(void)
-{
+#define CPU_SPINWAIT
+#define DTV_OFFSET offsetof(struct tcb, tcb_dtv)
- return (sizeof(ucontext_t));
-}
+/*
+ * Variant I tcb. The structure layout is fixed, don't blindly
+ * change it.
+ */
+struct tcb {
+ void *tcb_dtv;
+ struct pthread *tcb_thread;
+};
-int
-__fillcontextx2(char *ctx)
+/* Called from the thread to set its private data. */
+static __inline void
+_tcb_set(struct tcb *tcb)
{
- return (0);
+ __asm __volatile("msr tpidr_el0, %x0" :: "r" (tcb));
}
-int
-__fillcontextx(char *ctx)
+/*
+ * Get the current tcb.
+ */
+static __inline struct tcb *
+_tcb_get(void)
{
- ucontext_t *ucp;
+ struct tcb *tcb;
- ucp = (ucontext_t *)ctx;
- return (getcontext(ucp));
+ __asm __volatile("mrs %x0, tpidr_el0" : "=r" (tcb));
+ return (tcb);
}
-__weak_reference(__getcontextx, getcontextx);
+extern struct pthread *_thr_initial;
-ucontext_t *
-__getcontextx(void)
+static __inline struct pthread *
+_get_curthread(void)
{
- char *ctx;
- int error;
- ctx = malloc(__getcontextx_size());
- if (ctx == NULL)
- return (NULL);
- if (__fillcontextx(ctx) == -1) {
- error = errno;
- free(ctx);
- errno = error;
- return (NULL);
- }
- return ((ucontext_t *)ctx);
+ return (_tcb_get()->tcb_thread);
}
+
+#endif /* _PTHREAD_MD_H_ */
diff --git a/lib/libthr/arch/amd64/Makefile.inc b/lib/libthr/arch/amd64/Makefile.inc
index e6d99ec..797618d 100644
--- a/lib/libthr/arch/amd64/Makefile.inc
+++ b/lib/libthr/arch/amd64/Makefile.inc
@@ -1,3 +1,3 @@
#$FreeBSD$
-SRCS+= pthread_md.c _umtx_op_err.S
+SRCS+= _umtx_op_err.S
diff --git a/lib/libthr/arch/amd64/amd64/pthread_md.c b/lib/libthr/arch/amd64/amd64/pthread_md.c
deleted file mode 100644
index b661657..0000000
--- a/lib/libthr/arch/amd64/amd64/pthread_md.c
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (c) 2003 Daniel Eischen <deischen@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. Neither the name of the author 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 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.
- *
- * $FreeBSD$
- */
-
-#include <sys/types.h>
-#include <rtld_tls.h>
-
-#include "pthread_md.h"
-
-/*
- * The constructors.
- */
-struct tcb *
-_tcb_ctor(struct pthread *thread, int initial)
-{
- struct tcb *tcb;
-
- if (initial)
- __asm __volatile("movq %%fs:0, %0" : "=r" (tcb));
- else
- tcb = _rtld_allocate_tls(NULL, sizeof(struct tcb), 16);
- if (tcb)
- tcb->tcb_thread = thread;
- return (tcb);
-}
-
-void
-_tcb_dtor(struct tcb *tcb)
-{
- _rtld_free_tls(tcb, sizeof(struct tcb), 16);
-}
diff --git a/lib/libthr/arch/amd64/include/pthread_md.h b/lib/libthr/arch/amd64/include/pthread_md.h
index 0ebea2e..e4a0dd2 100644
--- a/lib/libthr/arch/amd64/include/pthread_md.h
+++ b/lib/libthr/arch/amd64/include/pthread_md.h
@@ -77,9 +77,6 @@ struct tcb {
__result; \
})
-struct tcb *_tcb_ctor(struct pthread *, int);
-void _tcb_dtor(struct tcb *tcb);
-
static __inline void
_tcb_set(struct tcb *tcb)
{
diff --git a/lib/libthr/arch/arm/Makefile.inc b/lib/libthr/arch/arm/Makefile.inc
deleted file mode 100644
index 2ee2247..0000000
--- a/lib/libthr/arch/arm/Makefile.inc
+++ /dev/null
@@ -1,3 +0,0 @@
-# $FreeBSD$
-
-SRCS+= pthread_md.c
diff --git a/lib/libthr/arch/arm/arm/pthread_md.c b/lib/libthr/arch/arm/arm/pthread_md.c
deleted file mode 100644
index 028f06c..0000000
--- a/lib/libthr/arch/arm/arm/pthread_md.c
+++ /dev/null
@@ -1,53 +0,0 @@
-/*-
- * Copyright (C) 2005 David Xu <davidxu@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. Neither the name of the author 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 AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-#include <stdlib.h>
-#include <sys/types.h>
-#include <rtld_tls.h>
-
-#include "pthread_md.h"
-
-struct tcb *
-_tcb_ctor(struct pthread *thread, int initial)
-{
- struct tcb *tcb;
-
- tcb = _rtld_allocate_tls((initial) ? _tcb_get() : NULL,
- sizeof(struct tcb), 16);
- if (tcb)
- tcb->tcb_thread = thread;
-
- return (tcb);
-}
-
-void
-_tcb_dtor(struct tcb *tcb)
-{
-
- _rtld_free_tls(tcb, sizeof(struct tcb), 16);
-}
diff --git a/lib/libthr/arch/arm/include/pthread_md.h b/lib/libthr/arch/arm/include/pthread_md.h
index 3c3dd6d..9a6b523 100644
--- a/lib/libthr/arch/arm/include/pthread_md.h
+++ b/lib/libthr/arch/arm/include/pthread_md.h
@@ -47,12 +47,6 @@ struct tcb {
struct pthread *tcb_thread; /* our hook */
};
-/*
- * The tcb constructors.
- */
-struct tcb *_tcb_ctor(struct pthread *, int);
-void _tcb_dtor(struct tcb *);
-
/* Called from the thread to set its private data. */
static __inline void
_tcb_set(struct tcb *tcb)
diff --git a/lib/libthr/arch/i386/Makefile.inc b/lib/libthr/arch/i386/Makefile.inc
index 01290d5..bdab0bc 100644
--- a/lib/libthr/arch/i386/Makefile.inc
+++ b/lib/libthr/arch/i386/Makefile.inc
@@ -1,3 +1,3 @@
# $FreeBSD$
-SRCS+= pthread_md.c _umtx_op_err.S
+SRCS+= _umtx_op_err.S
diff --git a/lib/libthr/arch/i386/i386/pthread_md.c b/lib/libthr/arch/i386/i386/pthread_md.c
deleted file mode 100644
index a8b31d5..0000000
--- a/lib/libthr/arch/i386/i386/pthread_md.c
+++ /dev/null
@@ -1,57 +0,0 @@
-/*-
- * Copyright (C) 2003 David Xu <davidxu@freebsd.org>
- * Copyright (c) 2001,2003 Daniel Eischen <deischen@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. Neither the name of the author 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 AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-#include <sys/types.h>
-#include <machine/segments.h>
-#include <machine/sysarch.h>
-#include <string.h>
-#include <rtld_tls.h>
-
-#include "pthread_md.h"
-
-struct tcb *
-_tcb_ctor(struct pthread *thread, int initial)
-{
- struct tcb *tcb;
-
- if (initial)
- __asm __volatile("movl %%gs:0, %0" : "=r" (tcb));
- else
- tcb = _rtld_allocate_tls(NULL, sizeof(struct tcb), 16);
- if (tcb)
- tcb->tcb_thread = thread;
- return (tcb);
-}
-
-void
-_tcb_dtor(struct tcb *tcb)
-{
-
- _rtld_free_tls(tcb, sizeof(struct tcb), 16);
-}
diff --git a/lib/libthr/arch/i386/include/pthread_md.h b/lib/libthr/arch/i386/include/pthread_md.h
index c160aa4..ba7b75c 100644
--- a/lib/libthr/arch/i386/include/pthread_md.h
+++ b/lib/libthr/arch/i386/include/pthread_md.h
@@ -76,12 +76,6 @@ struct tcb {
__result; \
})
-/*
- * The constructors.
- */
-struct tcb *_tcb_ctor(struct pthread *, int);
-void _tcb_dtor(struct tcb *tcb);
-
/* Called from the thread to set its private data. */
static __inline void
_tcb_set(struct tcb *tcb)
diff --git a/lib/libthr/arch/mips/Makefile.inc b/lib/libthr/arch/mips/Makefile.inc
deleted file mode 100644
index 2ee2247..0000000
--- a/lib/libthr/arch/mips/Makefile.inc
+++ /dev/null
@@ -1,3 +0,0 @@
-# $FreeBSD$
-
-SRCS+= pthread_md.c
diff --git a/lib/libthr/arch/mips/include/pthread_md.h b/lib/libthr/arch/mips/include/pthread_md.h
index 19c9f38..32af964 100644
--- a/lib/libthr/arch/mips/include/pthread_md.h
+++ b/lib/libthr/arch/mips/include/pthread_md.h
@@ -50,12 +50,6 @@ struct tcb {
struct pthread *tcb_thread;
};
-/*
- * The tcb constructors.
- */
-struct tcb *_tcb_ctor(struct pthread *, int);
-void _tcb_dtor(struct tcb *);
-
/* Called from the thread to set its private data. */
static __inline void
_tcb_set(struct tcb *tcb)
diff --git a/lib/libthr/arch/mips/mips/pthread_md.c b/lib/libthr/arch/mips/mips/pthread_md.c
deleted file mode 100644
index e596edc..0000000
--- a/lib/libthr/arch/mips/mips/pthread_md.c
+++ /dev/null
@@ -1,59 +0,0 @@
-/*-
- * Copyright (C) 2005 David Xu <davidxu@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. Neither the name of the author 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 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.
- *
- * from: src/lib/libthr/arch/arm/arm/pthread_md.c,v 1.2 2005/10/29 13:40:31 davidxu
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <stdlib.h>
-#include <sys/types.h>
-#include <rtld_tls.h>
-#include <strings.h>
-
-#include <machine/sysarch.h>
-
-#include "pthread_md.h"
-
-struct tcb *
-_tcb_ctor(struct pthread *thread, int initial)
-{
- struct tcb *tcb;
-
- tcb = _rtld_allocate_tls((initial) ? _tcb_get() : NULL,
- sizeof(struct tcb), 16);
- if (tcb)
- tcb->tcb_thread = thread;
-
- return (tcb);
-}
-
-void
-_tcb_dtor(struct tcb *tcb)
-{
-
- _rtld_free_tls(tcb, sizeof(struct tcb), 16);
-}
diff --git a/lib/libthr/arch/powerpc/Makefile.inc b/lib/libthr/arch/powerpc/Makefile.inc
deleted file mode 100644
index 2ee2247..0000000
--- a/lib/libthr/arch/powerpc/Makefile.inc
+++ /dev/null
@@ -1,3 +0,0 @@
-# $FreeBSD$
-
-SRCS+= pthread_md.c
diff --git a/lib/libthr/arch/powerpc/include/pthread_md.h b/lib/libthr/arch/powerpc/include/pthread_md.h
index 91102b4..544ee1c 100644
--- a/lib/libthr/arch/powerpc/include/pthread_md.h
+++ b/lib/libthr/arch/powerpc/include/pthread_md.h
@@ -55,29 +55,26 @@ struct tcb {
struct pthread *tcb_thread;
};
-struct tcb *_tcb_ctor(struct pthread *, int);
-void _tcb_dtor(struct tcb *);
-
static __inline void
_tcb_set(struct tcb *tcb)
{
#ifdef __powerpc64__
- register uint8_t *_tp __asm__("%r13");
+ __asm __volatile("mr 13,%0" ::
+ "r"((uint8_t *)tcb + TP_OFFSET));
#else
- register uint8_t *_tp __asm__("%r2");
-#endif
-
- __asm __volatile("mr %0,%1" : "=r"(_tp) :
+ __asm __volatile("mr 2,%0" ::
"r"((uint8_t *)tcb + TP_OFFSET));
+#endif
}
static __inline struct tcb *
_tcb_get(void)
{
+ register uint8_t *_tp;
#ifdef __powerpc64__
- register uint8_t *_tp __asm__("%r13");
+ __asm __volatile("mr %0,13" : "=r"(_tp));
#else
- register uint8_t *_tp __asm__("%r2");
+ __asm __volatile("mr %0,2" : "=r"(_tp));
#endif
return ((struct tcb *)(_tp - TP_OFFSET));
diff --git a/lib/libthr/arch/powerpc/powerpc/pthread_md.c b/lib/libthr/arch/powerpc/powerpc/pthread_md.c
deleted file mode 100644
index 66f043e..0000000
--- a/lib/libthr/arch/powerpc/powerpc/pthread_md.c
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (c) 2003 Daniel Eischen <deischen@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. Neither the name of the author 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 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.
- *
- * $FreeBSD$
- */
-
-#include <sys/types.h>
-#include <rtld_tls.h>
-
-#include "pthread_md.h"
-
-/*
- * The constructors.
- */
-struct tcb *
-_tcb_ctor(struct pthread *thread, int initial)
-{
- struct tcb *tcb;
-
- tcb = _rtld_allocate_tls((initial) ? _tcb_get() : NULL,
- sizeof(struct tcb), 1);
- if (tcb)
- tcb->tcb_thread = thread;
- return (tcb);
-
-}
-
-void
-_tcb_dtor(struct tcb *tcb)
-{
- _rtld_free_tls(tcb, sizeof(struct tcb), 1);
-}
diff --git a/lib/libthr/arch/sparc64/Makefile.inc b/lib/libthr/arch/sparc64/Makefile.inc
index 88586b4..bdab0bc 100644
--- a/lib/libthr/arch/sparc64/Makefile.inc
+++ b/lib/libthr/arch/sparc64/Makefile.inc
@@ -1,3 +1,3 @@
# $FreeBSD$
-SRCS+= _umtx_op_err.S pthread_md.c
+SRCS+= _umtx_op_err.S
diff --git a/lib/libthr/arch/sparc64/include/pthread_md.h b/lib/libthr/arch/sparc64/include/pthread_md.h
index 7ee9654..35d8405 100644
--- a/lib/libthr/arch/sparc64/include/pthread_md.h
+++ b/lib/libthr/arch/sparc64/include/pthread_md.h
@@ -50,12 +50,6 @@ struct tcb {
void *tcb_spare[1];
};
-/*
- * The tcb constructors.
- */
-struct tcb *_tcb_ctor(struct pthread *, int);
-void _tcb_dtor(struct tcb *);
-
/* Called from the thread to set its private data. */
static __inline void
_tcb_set(struct tcb *tcb)
diff --git a/lib/libthr/libthr.3 b/lib/libthr/libthr.3
index 4b636ce..8108e2f 100644
--- a/lib/libthr/libthr.3
+++ b/lib/libthr/libthr.3
@@ -1,5 +1,5 @@
.\" Copyright (c) 2005 Robert N. M. Watson
-.\" Copyright (c) 2014 The FreeBSD Foundation, Inc.
+.\" Copyright (c) 2014,2015 The FreeBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" Part of this documentation was written by
@@ -29,7 +29,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd September 26, 2014
+.Dd February 12, 2015
.Dt LIBTHR 3
.Os
.Sh NAME
@@ -200,45 +200,25 @@ Bigger values reduce the frequency of the FIFO discipline.
The value must be between 0 and 255.
.El
.Sh INTERACTION WITH RUN-TIME LINKER
-The
+On load,
.Nm
-library must appear before
-.Li libc
-in the global order of depended objects.
-.Pp
-Loading
-.Nm
-with the
-.Xr dlopen 3
-call in the process after the program binary is activated
-is not supported, and causes miscellaneous and hard-to-diagnose misbehaviour.
-This is due to
-.Nm
-interposing several important
-.Li libc
-symbols to provide thread-safe services.
-In particular,
-.Dv errno
-and the locking stubs from
-.Li libc
-are affected.
-This requirement is currently not enforced.
-.Pp
-If the program loads any modules at run-time, and those modules may require
-threading services, the main program binary must be linked with
-.Li libpthread ,
-even if it does not require any services from the library.
+installs interposing handlers into the hooks exported by
+.Li libc .
+The interposers provide real locking implementation instead of the
+stubs for single-threaded processes in
+.Li ,
+cancellation support and some modifications to the signal operations.
.Pp
.Nm
cannot be unloaded; the
.Xr dlclose 3
function does not perform any action when called with a handle for
.Nm .
-One of the reasons is that the interposing of
+One of the reasons is that the internal interposing of
.Li libc
functions cannot be undone.
.Sh SIGNALS
-The implementation also interposes the user-installed
+The implementation interposes the user-installed
.Xr signal 3
handlers.
This interposing is done to postpone signal delivery to threads which
diff --git a/lib/libthr/pthread.map b/lib/libthr/pthread.map
index bbbd930e..0903989 100644
--- a/lib/libthr/pthread.map
+++ b/lib/libthr/pthread.map
@@ -6,22 +6,6 @@
* Use the same naming scheme as libc.
*/
FBSD_1.0 {
- __error;
- accept;
- aio_suspend;
- close;
- connect;
- creat;
- execve;
- fcntl;
- fork;
- fsync;
- msync;
- nanosleep;
- open;
- pause;
- poll;
- pselect;
pthread_atfork;
pthread_barrier_destroy;
pthread_barrier_init;
@@ -139,30 +123,6 @@ FBSD_1.0 {
pthread_testcancel;
pthread_timedjoin_np;
pthread_yield;
- raise;
- read;
- readv;
- recvfrom;
- recvmsg;
- select;
- sendmsg;
- sendto;
- sigaction;
- sigprocmask;
- sigsuspend;
- sigwait;
- sigwaitinfo;
- sigtimedwait;
- sleep;
- system;
- tcdrain;
- usleep;
- wait;
- wait3;
- wait4;
- waitpid;
- write;
- writev;
};
/*
@@ -170,28 +130,6 @@ FBSD_1.0 {
* These are not part of our application ABI.
*/
FBSDprivate_1.0 {
- ___creat;
- ___pause;
- ___pselect;
- ___sigwait;
- ___sleep;
- ___system;
- ___tcdrain;
- ___usleep;
- ___wait;
- ___waitpid;
- __accept;
- __accept4;
- __aio_suspend;
- __close;
- __connect;
- __fcntl;
- __fsync;
- __msync;
- __nanosleep;
- __open;
- __openat;
- __poll;
__pthread_cond_timedwait;
__pthread_cond_wait;
__pthread_cxa_finalize;
@@ -199,21 +137,6 @@ FBSDprivate_1.0 {
__pthread_mutex_lock;
__pthread_mutex_timedlock;
__pthread_mutex_trylock;
- __read;
- __readv;
- __recvfrom;
- __recvmsg;
- __select;
- __sendmsg;
- __sendto;
- __sigsuspend;
- __sigtimedwait;
- __sigwaitinfo;
- __wait3;
- __wait4;
- __write;
- __writev;
- _fork;
_pthread_atfork;
_pthread_barrier_destroy;
_pthread_barrier_init;
@@ -345,18 +268,6 @@ FBSDprivate_1.0 {
_pthread_testcancel;
_pthread_timedjoin_np;
_pthread_yield;
- _raise;
- _setcontext;
- _sigaction;
- _sigprocmask;
- _sigsuspend;
- _sigtimedwait;
- _sigwait;
- _sigwaitinfo;
- _spinlock;
- _spinlock_debug;
- _spinunlock;
- _swapcontext;
/* Debugger needs these. */
_libthr_debug;
@@ -404,12 +315,5 @@ FBSD_1.1 {
};
FBSD_1.2 {
- openat;
pthread_getthreadid_np;
- setcontext;
- swapcontext;
-};
-
-FBSD_1.3 {
- accept4;
};
diff --git a/lib/libthr/sys/thr_error.c b/lib/libthr/sys/thr_error.c
index 45295c5..852588a 100644
--- a/lib/libthr/sys/thr_error.c
+++ b/lib/libthr/sys/thr_error.c
@@ -42,8 +42,9 @@
#undef errno
extern int errno;
+__weak_reference(__error_threaded, __error);
int *
-__error(void)
+__error_threaded(void)
{
struct pthread *curthread;
diff --git a/lib/libthr/tests/Makefile b/lib/libthr/tests/Makefile
index 50f07f0..11cf0e7 100644
--- a/lib/libthr/tests/Makefile
+++ b/lib/libthr/tests/Makefile
@@ -25,7 +25,9 @@ NETBSD_ATF_TESTS_C+= sigmask_test
NETBSD_ATF_TESTS_C+= sigsuspend_test
NETBSD_ATF_TESTS_C+= siglongjmp_test
NETBSD_ATF_TESTS_C+= sleep_test
+.if ${MACHINE} != "arm64" # ARM64TODO: Missing makecontext
NETBSD_ATF_TESTS_C+= swapcontext_test
+.endif
NETBSD_ATF_TESTS_SH= atexit_test
NETBSD_ATF_TESTS_SH+= cancel_test
diff --git a/lib/libthr/thread/Makefile.inc b/lib/libthr/thread/Makefile.inc
index ddde6e9..1a7c63d 100644
--- a/lib/libthr/thread/Makefile.inc
+++ b/lib/libthr/thread/Makefile.inc
@@ -14,6 +14,7 @@ SRCS+= \
thr_cond.c \
thr_condattr.c \
thr_create.c \
+ thr_ctrdtr.c \
thr_detach.c \
thr_equal.c \
thr_event.c \
diff --git a/lib/libthr/thread/thr_barrier.c b/lib/libthr/thread/thr_barrier.c
index 86f880e..10b6346 100644
--- a/lib/libthr/thread/thr_barrier.c
+++ b/lib/libthr/thread/thr_barrier.c
@@ -86,16 +86,13 @@ _pthread_barrier_init(pthread_barrier_t *barrier,
if (barrier == NULL || count <= 0)
return (EINVAL);
- bar = malloc(sizeof(struct pthread_barrier));
+ bar = calloc(1, sizeof(struct pthread_barrier));
if (bar == NULL)
return (ENOMEM);
_thr_umutex_init(&bar->b_lock);
_thr_ucond_init(&bar->b_cv);
- bar->b_cycle = 0;
- bar->b_waiters = 0;
bar->b_count = count;
- bar->b_refcount = 0;
*barrier = bar;
return (0);
diff --git a/lib/libthr/thread/thr_clean.c b/lib/libthr/thread/thr_clean.c
index dc5b0c7..f200726 100644
--- a/lib/libthr/thread/thr_clean.c
+++ b/lib/libthr/thread/thr_clean.c
@@ -84,7 +84,7 @@ _pthread_cleanup_push(void (*routine) (void *), void *arg)
curthread->unwind_disabled = 1;
#endif
if ((newbuf = (struct pthread_cleanup *)
- malloc(sizeof(struct _pthread_cleanup_info))) != NULL) {
+ malloc(sizeof(struct pthread_cleanup))) != NULL) {
newbuf->routine = routine;
newbuf->routine_arg = arg;
newbuf->onheap = 1;
diff --git a/lib/libthr/thread/thr_create.c b/lib/libthr/thread/thr_create.c
index a41b33f..df3509d 100644
--- a/lib/libthr/thread/thr_create.c
+++ b/lib/libthr/thread/thr_create.c
@@ -40,6 +40,7 @@
#include <pthread_np.h>
#include "un-namespace.h"
+#include "libc_private.h"
#include "thr_private.h"
static int create_stack(struct pthread_attr *pattr);
@@ -66,8 +67,11 @@ _pthread_create(pthread_t * thread, const pthread_attr_t * attr,
/*
* Tell libc and others now they need lock to protect their data.
*/
- if (_thr_isthreaded() == 0 && _thr_setthreaded(1))
- return (EAGAIN);
+ if (_thr_isthreaded() == 0) {
+ _malloc_first_thread();
+ if (_thr_setthreaded(1))
+ return (EAGAIN);
+ }
curthread = _get_curthread();
if ((new_thread = _thr_alloc(curthread)) == NULL)
diff --git a/lib/libthr/arch/sparc64/sparc64/pthread_md.c b/lib/libthr/thread/thr_ctrdtr.c
index e1d439a..9d4301e 100644
--- a/lib/libthr/arch/sparc64/sparc64/pthread_md.c
+++ b/lib/libthr/thread/thr_ctrdtr.c
@@ -32,7 +32,7 @@ __FBSDID("$FreeBSD$");
#include <sys/types.h>
#include <rtld_tls.h>
-#include "pthread_md.h"
+#include "thr_private.h"
struct tcb *
_tcb_ctor(struct pthread *thread, int initial)
diff --git a/lib/libthr/thread/thr_fork.c b/lib/libthr/thread/thr_fork.c
index fc87688..7dc8ca8 100644
--- a/lib/libthr/thread/thr_fork.c
+++ b/lib/libthr/thread/thr_fork.c
@@ -128,12 +128,10 @@ __pthread_cxa_finalize(struct dl_phdr_info *phdr_info)
_thr_sigact_unload(phdr_info);
}
-__weak_reference(_fork, fork);
-
-pid_t _fork(void);
+__weak_reference(__thr_fork, _fork);
pid_t
-_fork(void)
+__thr_fork(void)
{
struct pthread *curthread;
struct pthread_atfork *af;
diff --git a/lib/libthr/thread/thr_init.c b/lib/libthr/thread/thr_init.c
index 6d6a532..9a1a67a 100644
--- a/lib/libthr/thread/thr_init.c
+++ b/lib/libthr/thread/thr_init.c
@@ -37,6 +37,7 @@
#include <sys/types.h>
#include <sys/signalvar.h>
#include <sys/ioctl.h>
+#include <sys/link_elf.h>
#include <sys/resource.h>
#include <sys/sysctl.h>
#include <sys/ttycom.h>
@@ -302,7 +303,7 @@ _thread_init_hack(void)
void
_libpthread_init(struct pthread *curthread)
{
- int fd, first = 0;
+ int fd, first, dlopened;
/* Check if this function has already been called: */
if ((_thr_initial != NULL) && (curthread == NULL))
@@ -316,6 +317,7 @@ _libpthread_init(struct pthread *curthread)
if (sizeof(jmp_table) != (sizeof(pthread_func_t) * PJT_MAX * 2))
PANIC("Thread jump table not properly initialized");
memcpy(__thr_jtable, jmp_table, sizeof(jmp_table));
+ __thr_interpose_libc();
/*
* Check for the special case of this process running as
@@ -349,7 +351,10 @@ _libpthread_init(struct pthread *curthread)
if (curthread == NULL)
PANIC("Can't allocate initial thread");
init_main_thread(curthread);
+ } else {
+ first = 0;
}
+
/*
* Add the thread to the thread list queue.
*/
@@ -361,7 +366,8 @@ _libpthread_init(struct pthread *curthread)
if (first) {
_thr_initial = curthread;
- _thr_signal_init();
+ dlopened = _rtld_is_dlopened(&_thread_autoinit_dummy_decl) != 0;
+ _thr_signal_init(dlopened);
if (_thread_event_mask & TD_CREATE)
_thr_report_creation(curthread, curthread);
/*
diff --git a/lib/libthr/thread/thr_mutex.c b/lib/libthr/thread/thr_mutex.c
index 61ff077..26e8776 100644
--- a/lib/libthr/thread/thr_mutex.c
+++ b/lib/libthr/thread/thr_mutex.c
@@ -633,7 +633,7 @@ mutex_unlock_common(struct pthread_mutex *m, int cv, int *mtx_defer)
{
struct pthread *curthread = _get_curthread();
uint32_t id;
- int defered;
+ int defered, error;
if (__predict_false(m <= THR_MUTEX_DESTROYED)) {
if (m == THR_MUTEX_DESTROYED)
@@ -647,6 +647,7 @@ mutex_unlock_common(struct pthread_mutex *m, int cv, int *mtx_defer)
if (__predict_false(m->m_owner != curthread))
return (EPERM);
+ error = 0;
id = TID(curthread);
if (__predict_false(
PMUTEX_TYPE(m->m_flags) == PTHREAD_MUTEX_RECURSIVE &&
@@ -660,7 +661,7 @@ mutex_unlock_common(struct pthread_mutex *m, int cv, int *mtx_defer)
defered = 0;
DEQUEUE_MUTEX(curthread, m);
- _thr_umutex_unlock2(&m->m_lock, id, mtx_defer);
+ error = _thr_umutex_unlock2(&m->m_lock, id, mtx_defer);
if (mtx_defer == NULL && defered) {
_thr_wake_all(curthread->defer_waiters,
@@ -670,7 +671,7 @@ mutex_unlock_common(struct pthread_mutex *m, int cv, int *mtx_defer)
}
if (!cv && m->m_flags & PMUTEX_FLAG_PRIVATE)
THR_CRITICAL_LEAVE(curthread);
- return (0);
+ return (error);
}
int
diff --git a/lib/libthr/thread/thr_printf.c b/lib/libthr/thread/thr_printf.c
index 7d32ae7..a64b446 100644
--- a/lib/libthr/thread/thr_printf.c
+++ b/lib/libthr/thread/thr_printf.c
@@ -31,6 +31,7 @@
#include <unistd.h>
#include <pthread.h>
+#include "libc_private.h"
#include "thr_private.h"
static void pchar(int fd, char c);
diff --git a/lib/libthr/thread/thr_private.h b/lib/libthr/thread/thr_private.h
index c6651cd..ed24c38 100644
--- a/lib/libthr/thread/thr_private.h
+++ b/lib/libthr/thread/thr_private.h
@@ -337,7 +337,7 @@ struct pthread_key {
/*
* lwpid_t is 32bit but kernel thr API exports tid as long type
- * in very earily date.
+ * to preserve the ABI for M:N model in very early date (r131431).
*/
#define TID(thread) ((uint32_t) ((thread)->tid))
@@ -763,7 +763,7 @@ void _thr_cancel_leave(struct pthread *, int) __hidden;
void _thr_testcancel(struct pthread *) __hidden;
void _thr_signal_block(struct pthread *) __hidden;
void _thr_signal_unblock(struct pthread *) __hidden;
-void _thr_signal_init(void) __hidden;
+void _thr_signal_init(int) __hidden;
void _thr_signal_deinit(void) __hidden;
int _thr_send_sig(struct pthread *, int sig) __hidden;
void _thr_list_init(void) __hidden;
@@ -839,7 +839,6 @@ int __sys_close(int);
int __sys_fork(void);
pid_t __sys_getpid(void);
ssize_t __sys_read(int, void *, size_t);
-ssize_t __sys_write(int, const void *, size_t);
void __sys_exit(int);
#endif
@@ -906,12 +905,36 @@ int _sleepq_remove(struct sleepqueue *, struct pthread *) __hidden;
void _sleepq_drop(struct sleepqueue *,
void (*cb)(struct pthread *, void *arg), void *) __hidden;
+int _pthread_mutex_init_calloc_cb(pthread_mutex_t *mutex,
+ void *(calloc_cb)(size_t, size_t));
+
struct dl_phdr_info;
void __pthread_cxa_finalize(struct dl_phdr_info *phdr_info);
void _thr_tsd_unload(struct dl_phdr_info *phdr_info) __hidden;
void _thr_sigact_unload(struct dl_phdr_info *phdr_info) __hidden;
void _thr_stack_fix_protection(struct pthread *thrd);
+int *__error_threaded(void) __hidden;
+void __thr_interpose_libc(void) __hidden;
+pid_t __thr_fork(void);
+int __thr_setcontext(const ucontext_t *ucp);
+int __thr_sigaction(int sig, const struct sigaction *act,
+ struct sigaction *oact) __hidden;
+int __thr_sigprocmask(int how, const sigset_t *set, sigset_t *oset);
+int __thr_sigsuspend(const sigset_t * set);
+int __thr_sigtimedwait(const sigset_t *set, siginfo_t *info,
+ const struct timespec * timeout);
+int __thr_sigwait(const sigset_t *set, int *sig);
+int __thr_sigwaitinfo(const sigset_t *set, siginfo_t *info);
+int __thr_swapcontext(ucontext_t *oucp, const ucontext_t *ucp);
+
+struct _spinlock;
+void __thr_spinunlock(struct _spinlock *lck);
+void __thr_spinlock(struct _spinlock *lck);
+
+struct tcb *_tcb_ctor(struct pthread *, int);
+void _tcb_dtor(struct tcb *);
+
__END_DECLS
#endif /* !_THR_PRIVATE_H */
diff --git a/lib/libthr/thread/thr_sig.c b/lib/libthr/thread/thr_sig.c
index 57c9406..11a131c 100644
--- a/lib/libthr/thread/thr_sig.c
+++ b/lib/libthr/thread/thr_sig.c
@@ -38,6 +38,7 @@
#include "un-namespace.h"
#include "libc_private.h"
+#include "libc_private.h"
#include "thr_private.h"
/* #define DEBUG_SIGNAL */
@@ -54,24 +55,23 @@ struct usigaction {
static struct usigaction _thr_sigact[_SIG_MAXSIG];
+static inline struct usigaction *
+__libc_sigaction_slot(int signo)
+{
+
+ return (&_thr_sigact[signo - 1]);
+}
+
static void thr_sighandler(int, siginfo_t *, void *);
static void handle_signal(struct sigaction *, int, siginfo_t *, ucontext_t *);
static void check_deferred_signal(struct pthread *);
static void check_suspend(struct pthread *);
static void check_cancel(struct pthread *curthread, ucontext_t *ucp);
-int ___pause(void);
-int _raise(int);
-int __sigtimedwait(const sigset_t *set, siginfo_t *info,
- const struct timespec * timeout);
int _sigtimedwait(const sigset_t *set, siginfo_t *info,
const struct timespec * timeout);
-int __sigwaitinfo(const sigset_t *set, siginfo_t *info);
int _sigwaitinfo(const sigset_t *set, siginfo_t *info);
-int ___sigwait(const sigset_t *set, int *sig);
int _sigwait(const sigset_t *set, int *sig);
-int __sigsuspend(const sigset_t *sigmask);
-int _sigaction(int, const struct sigaction *, struct sigaction *);
int _setcontext(const ucontext_t *);
int _swapcontext(ucontext_t *, const ucontext_t *);
@@ -143,8 +143,8 @@ sigcancel_handler(int sig __unused,
errno = err;
}
-typedef void (*ohandler)(int sig, int code,
- struct sigcontext *scp, char *addr, __sighandler_t *catcher);
+typedef void (*ohandler)(int sig, int code, struct sigcontext *scp,
+ char *addr, __sighandler_t *catcher);
/*
* The signal handler wrapper is entered with all signal masked.
@@ -152,15 +152,19 @@ typedef void (*ohandler)(int sig, int code,
static void
thr_sighandler(int sig, siginfo_t *info, void *_ucp)
{
- struct pthread *curthread = _get_curthread();
- ucontext_t *ucp = _ucp;
+ struct pthread *curthread;
+ ucontext_t *ucp;
struct sigaction act;
+ struct usigaction *usa;
int err;
err = errno;
- _thr_rwl_rdlock(&_thr_sigact[sig-1].lock);
- act = _thr_sigact[sig-1].sigact;
- _thr_rwl_unlock(&_thr_sigact[sig-1].lock);
+ curthread = _get_curthread();
+ ucp = _ucp;
+ usa = __libc_sigaction_slot(sig);
+ _thr_rwl_rdlock(&usa->lock);
+ act = usa->sigact;
+ _thr_rwl_unlock(&usa->lock);
errno = err;
curthread->deferred_run = 0;
@@ -234,12 +238,12 @@ handle_signal(struct sigaction *actp, int sig, siginfo_t *info, ucontext_t *ucp)
* so after setjmps() returns once more, the user code may need to
* re-set cancel_enable flag by calling pthread_setcancelstate().
*/
- if ((actp->sa_flags & SA_SIGINFO) != 0)
- (*(sigfunc))(sig, info, ucp);
- else {
- ((ohandler)(*sigfunc))(
- sig, info->si_code, (struct sigcontext *)ucp,
- info->si_addr, (__sighandler_t *)sigfunc);
+ if ((actp->sa_flags & SA_SIGINFO) != 0) {
+ sigfunc(sig, info, ucp);
+ } else {
+ ((ohandler)sigfunc)(sig, info->si_code,
+ (struct sigcontext *)ucp, info->si_addr,
+ (__sighandler_t *)sigfunc);
}
err = errno;
@@ -395,9 +399,34 @@ check_suspend(struct pthread *curthread)
}
void
-_thr_signal_init(void)
+_thr_signal_init(int dlopened)
{
- struct sigaction act;
+ struct sigaction act, nact, oact;
+ struct usigaction *usa;
+ sigset_t oldset;
+ int sig, error;
+
+ if (dlopened) {
+ __sys_sigprocmask(SIG_SETMASK, &_thr_maskset, &oldset);
+ for (sig = 1; sig <= _SIG_MAXSIG; sig++) {
+ if (sig == SIGCANCEL)
+ continue;
+ error = __sys_sigaction(sig, NULL, &oact);
+ if (error == -1 || oact.sa_handler == SIG_DFL ||
+ oact.sa_handler == SIG_IGN)
+ continue;
+ usa = __libc_sigaction_slot(sig);
+ usa->sigact = oact;
+ nact = oact;
+ remove_thr_signals(&usa->sigact.sa_mask);
+ nact.sa_flags &= ~SA_NODEFER;
+ nact.sa_flags |= SA_SIGINFO;
+ nact.sa_sigaction = thr_sighandler;
+ nact.sa_mask = _thr_maskset;
+ (void)__sys_sigaction(sig, &nact, NULL);
+ }
+ __sys_sigprocmask(SIG_SETMASK, &oldset, NULL);
+ }
/* Install SIGCANCEL handler. */
SIGFILLSET(act.sa_mask);
@@ -418,18 +447,20 @@ _thr_sigact_unload(struct dl_phdr_info *phdr_info)
struct pthread *curthread = _get_curthread();
struct urwlock *rwlp;
struct sigaction *actp;
+ struct usigaction *usa;
struct sigaction kact;
void (*handler)(int);
int sig;
_thr_signal_block(curthread);
for (sig = 1; sig <= _SIG_MAXSIG; sig++) {
- actp = &_thr_sigact[sig-1].sigact;
+ usa = __libc_sigaction_slot(sig);
+ actp = &usa->sigact;
retry:
handler = actp->sa_handler;
if (handler != SIG_DFL && handler != SIG_IGN &&
__elf_phdr_match_addr(phdr_info, handler)) {
- rwlp = &_thr_sigact[sig-1].lock;
+ rwlp = &usa->lock;
_thr_rwl_wrlock(rwlp);
if (handler != actp->sa_handler) {
_thr_rwl_unlock(rwlp);
@@ -455,7 +486,7 @@ _thr_signal_prefork(void)
int i;
for (i = 1; i <= _SIG_MAXSIG; ++i)
- _thr_rwl_rdlock(&_thr_sigact[i-1].lock);
+ _thr_rwl_rdlock(&__libc_sigaction_slot(i)->lock);
}
void
@@ -464,7 +495,7 @@ _thr_signal_postfork(void)
int i;
for (i = 1; i <= _SIG_MAXSIG; ++i)
- _thr_rwl_unlock(&_thr_sigact[i-1].lock);
+ _thr_rwl_unlock(&__libc_sigaction_slot(i)->lock);
}
void
@@ -472,8 +503,10 @@ _thr_signal_postfork_child(void)
{
int i;
- for (i = 1; i <= _SIG_MAXSIG; ++i)
- bzero(&_thr_sigact[i-1].lock, sizeof(struct urwlock));
+ for (i = 1; i <= _SIG_MAXSIG; ++i) {
+ bzero(&__libc_sigaction_slot(i) -> lock,
+ sizeof(struct urwlock));
+ }
}
void
@@ -481,84 +514,64 @@ _thr_signal_deinit(void)
{
}
-__weak_reference(___pause, pause);
-
-int
-___pause(void)
-{
- sigset_t oset;
-
- if (_sigprocmask(SIG_BLOCK, NULL, &oset) == -1)
- return (-1);
- return (__sigsuspend(&oset));
-}
-
-__weak_reference(_raise, raise);
-
-int
-_raise(int sig)
-{
- return _thr_send_sig(_get_curthread(), sig);
-}
-
-__weak_reference(_sigaction, sigaction);
-
int
-_sigaction(int sig, const struct sigaction * act, struct sigaction * oact)
+__thr_sigaction(int sig, const struct sigaction *act, struct sigaction *oact)
{
struct sigaction newact, oldact, oldact2;
sigset_t oldset;
- int ret = 0, err = 0;
+ struct usigaction *usa;
+ int ret, err;
if (!_SIG_VALID(sig) || sig == SIGCANCEL) {
errno = EINVAL;
return (-1);
}
- if (act)
- newact = *act;
+ ret = 0;
+ err = 0;
+ usa = __libc_sigaction_slot(sig);
__sys_sigprocmask(SIG_SETMASK, &_thr_maskset, &oldset);
- _thr_rwl_wrlock(&_thr_sigact[sig-1].lock);
+ _thr_rwl_wrlock(&usa->lock);
if (act != NULL) {
- oldact2 = _thr_sigact[sig-1].sigact;
+ oldact2 = usa->sigact;
+ newact = *act;
/*
* if a new sig handler is SIG_DFL or SIG_IGN,
- * don't remove old handler from _thr_sigact[],
+ * don't remove old handler from __libc_sigact[],
* so deferred signals still can use the handlers,
* multiple threads invoking sigaction itself is
* a race condition, so it is not a problem.
*/
if (newact.sa_handler != SIG_DFL &&
newact.sa_handler != SIG_IGN) {
- _thr_sigact[sig-1].sigact = newact;
- remove_thr_signals(
- &_thr_sigact[sig-1].sigact.sa_mask);
+ usa->sigact = newact;
+ remove_thr_signals(&usa->sigact.sa_mask);
newact.sa_flags &= ~SA_NODEFER;
newact.sa_flags |= SA_SIGINFO;
newact.sa_sigaction = thr_sighandler;
newact.sa_mask = _thr_maskset; /* mask all signals */
}
- if ((ret = __sys_sigaction(sig, &newact, &oldact))) {
+ ret = __sys_sigaction(sig, &newact, &oldact);
+ if (ret == -1) {
err = errno;
- _thr_sigact[sig-1].sigact = oldact2;
+ usa->sigact = oldact2;
}
} else if (oact != NULL) {
ret = __sys_sigaction(sig, NULL, &oldact);
err = errno;
}
- if (oldact.sa_handler != SIG_DFL &&
- oldact.sa_handler != SIG_IGN) {
+ if (oldact.sa_handler != SIG_DFL && oldact.sa_handler != SIG_IGN) {
if (act != NULL)
oldact = oldact2;
else if (oact != NULL)
- oldact = _thr_sigact[sig-1].sigact;
+ oldact = usa->sigact;
}
- _thr_rwl_unlock(&_thr_sigact[sig-1].lock);
+ _thr_rwl_unlock(&usa->lock);
__sys_sigprocmask(SIG_SETMASK, &oldset, NULL);
if (ret == 0) {
@@ -570,10 +583,8 @@ _sigaction(int sig, const struct sigaction * act, struct sigaction * oact)
return (ret);
}
-__weak_reference(_sigprocmask, sigprocmask);
-
int
-_sigprocmask(int how, const sigset_t *set, sigset_t *oset)
+__thr_sigprocmask(int how, const sigset_t *set, sigset_t *oset)
{
const sigset_t *p = set;
sigset_t newset;
@@ -593,13 +604,12 @@ __weak_reference(_pthread_sigmask, pthread_sigmask);
int
_pthread_sigmask(int how, const sigset_t *set, sigset_t *oset)
{
- if (_sigprocmask(how, set, oset))
+
+ if (__thr_sigprocmask(how, set, oset))
return (errno);
return (0);
}
-__weak_reference(__sigsuspend, sigsuspend);
-
int
_sigsuspend(const sigset_t * set)
{
@@ -609,7 +619,7 @@ _sigsuspend(const sigset_t * set)
}
int
-__sigsuspend(const sigset_t * set)
+__thr_sigsuspend(const sigset_t * set)
{
struct pthread *curthread;
sigset_t newset;
@@ -633,10 +643,6 @@ __sigsuspend(const sigset_t * set)
return (ret);
}
-__weak_reference(___sigwait, sigwait);
-__weak_reference(__sigtimedwait, sigtimedwait);
-__weak_reference(__sigwaitinfo, sigwaitinfo);
-
int
_sigtimedwait(const sigset_t *set, siginfo_t *info,
const struct timespec * timeout)
@@ -653,8 +659,8 @@ _sigtimedwait(const sigset_t *set, siginfo_t *info,
* it is not canceled.
*/
int
-__sigtimedwait(const sigset_t *set, siginfo_t *info,
- const struct timespec * timeout)
+__thr_sigtimedwait(const sigset_t *set, siginfo_t *info,
+ const struct timespec * timeout)
{
struct pthread *curthread = _get_curthread();
sigset_t newset;
@@ -681,7 +687,7 @@ _sigwaitinfo(const sigset_t *set, siginfo_t *info)
* it is not canceled.
*/
int
-__sigwaitinfo(const sigset_t *set, siginfo_t *info)
+__thr_sigwaitinfo(const sigset_t *set, siginfo_t *info)
{
struct pthread *curthread = _get_curthread();
sigset_t newset;
@@ -707,7 +713,7 @@ _sigwait(const sigset_t *set, int *sig)
* it is not canceled.
*/
int
-___sigwait(const sigset_t *set, int *sig)
+__thr_sigwait(const sigset_t *set, int *sig)
{
struct pthread *curthread = _get_curthread();
sigset_t newset;
@@ -721,9 +727,8 @@ ___sigwait(const sigset_t *set, int *sig)
return (ret);
}
-__weak_reference(_setcontext, setcontext);
int
-_setcontext(const ucontext_t *ucp)
+__thr_setcontext(const ucontext_t *ucp)
{
ucontext_t uc;
@@ -735,12 +740,11 @@ _setcontext(const ucontext_t *ucp)
return __sys_setcontext(ucp);
(void) memcpy(&uc, ucp, sizeof(uc));
SIGDELSET(uc.uc_sigmask, SIGCANCEL);
- return __sys_setcontext(&uc);
+ return (__sys_setcontext(&uc));
}
-__weak_reference(_swapcontext, swapcontext);
int
-_swapcontext(ucontext_t *oucp, const ucontext_t *ucp)
+__thr_swapcontext(ucontext_t *oucp, const ucontext_t *ucp)
{
ucontext_t uc;
@@ -753,5 +757,5 @@ _swapcontext(ucontext_t *oucp, const ucontext_t *ucp)
SIGDELSET(uc.uc_sigmask, SIGCANCEL);
ucp = &uc;
}
- return __sys_swapcontext(oucp, ucp);
+ return (__sys_swapcontext(oucp, ucp));
}
diff --git a/lib/libthr/thread/thr_spec.c b/lib/libthr/thread/thr_spec.c
index 46a6105..b53c4b7 100644
--- a/lib/libthr/thread/thr_spec.c
+++ b/lib/libthr/thread/thr_spec.c
@@ -30,6 +30,7 @@
*/
#include "namespace.h"
+#include <sys/mman.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
@@ -40,7 +41,6 @@
#include "thr_private.h"
-/* Static variables: */
struct pthread_key _thread_keytable[PTHREAD_KEYS_MAX];
__weak_reference(_pthread_key_create, pthread_key_create);
@@ -50,7 +50,7 @@ __weak_reference(_pthread_setspecific, pthread_setspecific);
int
-_pthread_key_create(pthread_key_t *key, void (*destructor) (void *))
+_pthread_key_create(pthread_key_t *key, void (*destructor)(void *))
{
struct pthread *curthread;
int i;
@@ -59,7 +59,6 @@ _pthread_key_create(pthread_key_t *key, void (*destructor) (void *))
curthread = _get_curthread();
- /* Lock the key table: */
THR_LOCK_ACQUIRE(curthread, &_keytable_lock);
for (i = 0; i < PTHREAD_KEYS_MAX; i++) {
@@ -68,14 +67,12 @@ _pthread_key_create(pthread_key_t *key, void (*destructor) (void *))
_thread_keytable[i].destructor = destructor;
_thread_keytable[i].seqno++;
- /* Unlock the key table: */
THR_LOCK_RELEASE(curthread, &_keytable_lock);
*key = i + 1;
return (0);
}
}
- /* Unlock the key table: */
THR_LOCK_RELEASE(curthread, &_keytable_lock);
return (EAGAIN);
}
@@ -83,44 +80,40 @@ _pthread_key_create(pthread_key_t *key, void (*destructor) (void *))
int
_pthread_key_delete(pthread_key_t userkey)
{
- struct pthread *curthread = _get_curthread();
- int key = userkey - 1;
- int ret = 0;
-
- if ((unsigned int)key < PTHREAD_KEYS_MAX) {
- /* Lock the key table: */
- THR_LOCK_ACQUIRE(curthread, &_keytable_lock);
-
- if (_thread_keytable[key].allocated)
- _thread_keytable[key].allocated = 0;
- else
- ret = EINVAL;
+ struct pthread *curthread;
+ int key, ret;
- /* Unlock the key table: */
- THR_LOCK_RELEASE(curthread, &_keytable_lock);
- } else
+ key = userkey - 1;
+ if ((unsigned int)key >= PTHREAD_KEYS_MAX)
+ return (EINVAL);
+ curthread = _get_curthread();
+ THR_LOCK_ACQUIRE(curthread, &_keytable_lock);
+ if (_thread_keytable[key].allocated) {
+ _thread_keytable[key].allocated = 0;
+ ret = 0;
+ } else {
ret = EINVAL;
+ }
+ THR_LOCK_RELEASE(curthread, &_keytable_lock);
return (ret);
}
void
_thread_cleanupspecific(void)
{
- struct pthread *curthread = _get_curthread();
- void (*destructor)( void *);
- const void *data = NULL;
- int key;
- int i;
+ struct pthread *curthread;
+ void (*destructor)(void *);
+ const void *data;
+ int i, key;
+ curthread = _get_curthread();
if (curthread->specific == NULL)
return;
-
- /* Lock the key table: */
THR_LOCK_ACQUIRE(curthread, &_keytable_lock);
- for (i = 0; (i < PTHREAD_DESTRUCTOR_ITERATIONS) &&
- (curthread->specific_data_count > 0); i++) {
- for (key = 0; (key < PTHREAD_KEYS_MAX) &&
- (curthread->specific_data_count > 0); key++) {
+ for (i = 0; i < PTHREAD_DESTRUCTOR_ITERATIONS &&
+ curthread->specific_data_count > 0; i++) {
+ for (key = 0; key < PTHREAD_KEYS_MAX &&
+ curthread->specific_data_count > 0; key++) {
destructor = NULL;
if (_thread_keytable[key].allocated &&
@@ -128,31 +121,29 @@ _thread_cleanupspecific(void)
if (curthread->specific[key].seqno ==
_thread_keytable[key].seqno) {
data = curthread->specific[key].data;
- destructor = _thread_keytable[key].destructor;
+ destructor = _thread_keytable[key].
+ destructor;
}
curthread->specific[key].data = NULL;
curthread->specific_data_count--;
- }
- else if (curthread->specific[key].data != NULL) {
+ } else if (curthread->specific[key].data != NULL) {
/*
- * This can happen if the key is deleted via
- * pthread_key_delete without first setting the value
- * to NULL in all threads. POSIX says that the
- * destructor is not invoked in this case.
+ * This can happen if the key is
+ * deleted via pthread_key_delete
+ * without first setting the value to
+ * NULL in all threads. POSIX says
+ * that the destructor is not invoked
+ * in this case.
*/
curthread->specific[key].data = NULL;
curthread->specific_data_count--;
}
/*
- * If there is a destructor, call it
- * with the key table entry unlocked:
+ * If there is a destructor, call it with the
+ * key table entry unlocked.
*/
if (destructor != NULL) {
- /*
- * Don't hold the lock while calling the
- * destructor:
- */
THR_LOCK_RELEASE(curthread, &_keytable_lock);
destructor(__DECONST(void *, data));
THR_LOCK_ACQUIRE(curthread, &_keytable_lock);
@@ -160,102 +151,92 @@ _thread_cleanupspecific(void)
}
}
THR_LOCK_RELEASE(curthread, &_keytable_lock);
- free(curthread->specific);
+ munmap(curthread->specific, PTHREAD_KEYS_MAX * sizeof(struct
+ pthread_specific_elem));
curthread->specific = NULL;
- if (curthread->specific_data_count > 0)
+ if (curthread->specific_data_count > 0) {
stderr_debug("Thread %p has exited with leftover "
"thread-specific data after %d destructor iterations\n",
curthread, PTHREAD_DESTRUCTOR_ITERATIONS);
-}
-
-static inline struct pthread_specific_elem *
-pthread_key_allocate_data(void)
-{
- struct pthread_specific_elem *new_data;
-
- new_data = (struct pthread_specific_elem *)
- calloc(1, sizeof(struct pthread_specific_elem) * PTHREAD_KEYS_MAX);
- return (new_data);
+ }
}
int
_pthread_setspecific(pthread_key_t userkey, const void *value)
{
- struct pthread *pthread;
- pthread_key_t key = userkey - 1;
- int ret = 0;
+ struct pthread *pthread;
+ void *tmp;
+ pthread_key_t key;
- /* Point to the running thread: */
- pthread = _get_curthread();
+ key = userkey - 1;
+ if ((unsigned int)key >= PTHREAD_KEYS_MAX ||
+ !_thread_keytable[key].allocated)
+ return (EINVAL);
- if ((pthread->specific) ||
- (pthread->specific = pthread_key_allocate_data())) {
- if ((unsigned int)key < PTHREAD_KEYS_MAX) {
- if (_thread_keytable[key].allocated) {
- if (pthread->specific[key].data == NULL) {
- if (value != NULL)
- pthread->specific_data_count++;
- } else if (value == NULL)
- pthread->specific_data_count--;
- pthread->specific[key].data = value;
- pthread->specific[key].seqno =
- _thread_keytable[key].seqno;
- ret = 0;
- } else
- ret = EINVAL;
- } else
- ret = EINVAL;
- } else
- ret = ENOMEM;
- return (ret);
+ pthread = _get_curthread();
+ if (pthread->specific == NULL) {
+ tmp = mmap(NULL, PTHREAD_KEYS_MAX *
+ sizeof(struct pthread_specific_elem),
+ PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
+ if (tmp == MAP_FAILED)
+ return (ENOMEM);
+ pthread->specific = tmp;
+ }
+ if (pthread->specific[key].data == NULL) {
+ if (value != NULL)
+ pthread->specific_data_count++;
+ } else if (value == NULL)
+ pthread->specific_data_count--;
+ pthread->specific[key].data = value;
+ pthread->specific[key].seqno = _thread_keytable[key].seqno;
+ return (0);
}
void *
_pthread_getspecific(pthread_key_t userkey)
{
- struct pthread *pthread;
- pthread_key_t key = userkey - 1;
- const void *data;
+ struct pthread *pthread;
+ const void *data;
+ pthread_key_t key;
- /* Point to the running thread: */
- pthread = _get_curthread();
+ /* Check if there is specific data. */
+ key = userkey - 1;
+ if ((unsigned int)key >= PTHREAD_KEYS_MAX)
+ return (NULL);
- /* Check if there is specific data: */
- if (pthread->specific != NULL && (unsigned int)key < PTHREAD_KEYS_MAX) {
- /* Check if this key has been used before: */
- if (_thread_keytable[key].allocated &&
- (pthread->specific[key].seqno == _thread_keytable[key].seqno)) {
- /* Return the value: */
- data = pthread->specific[key].data;
- } else {
- /*
- * This key has not been used before, so return NULL
- * instead:
- */
- data = NULL;
- }
- } else
- /* No specific data has been created, so just return NULL: */
+ pthread = _get_curthread();
+ /* Check if this key has been used before. */
+ if (_thread_keytable[key].allocated && pthread->specific != NULL &&
+ pthread->specific[key].seqno == _thread_keytable[key].seqno) {
+ /* Return the value: */
+ data = pthread->specific[key].data;
+ } else {
+ /*
+ * This key has not been used before, so return NULL
+ * instead.
+ */
data = NULL;
+ }
return (__DECONST(void *, data));
}
void
_thr_tsd_unload(struct dl_phdr_info *phdr_info)
{
- struct pthread *curthread = _get_curthread();
+ struct pthread *curthread;
void (*destructor)(void *);
int key;
+ curthread = _get_curthread();
THR_LOCK_ACQUIRE(curthread, &_keytable_lock);
for (key = 0; key < PTHREAD_KEYS_MAX; key++) {
- if (_thread_keytable[key].allocated) {
- destructor = _thread_keytable[key].destructor;
- if (destructor != NULL) {
- if (__elf_phdr_match_addr(phdr_info, destructor))
- _thread_keytable[key].destructor = NULL;
- }
- }
+ if (!_thread_keytable[key].allocated)
+ continue;
+ destructor = _thread_keytable[key].destructor;
+ if (destructor == NULL)
+ continue;
+ if (__elf_phdr_match_addr(phdr_info, destructor))
+ _thread_keytable[key].destructor = NULL;
}
THR_LOCK_RELEASE(curthread, &_keytable_lock);
}
diff --git a/lib/libthr/thread/thr_spinlock.c b/lib/libthr/thread/thr_spinlock.c
index ecc8067..380d10d 100644
--- a/lib/libthr/thread/thr_spinlock.c
+++ b/lib/libthr/thread/thr_spinlock.c
@@ -61,7 +61,7 @@ static void init_spinlock(spinlock_t *lck);
*/
void
-_spinunlock(spinlock_t *lck)
+__thr_spinunlock(spinlock_t *lck)
{
struct spinlock_extra *_extra;
@@ -70,7 +70,7 @@ _spinunlock(spinlock_t *lck)
}
void
-_spinlock(spinlock_t *lck)
+__thr_spinlock(spinlock_t *lck)
{
struct spinlock_extra *_extra;
@@ -84,12 +84,6 @@ _spinlock(spinlock_t *lck)
THR_UMUTEX_LOCK(_get_curthread(), &_extra->lock);
}
-void
-_spinlock_debug(spinlock_t *lck, char *fname __unused, int lineno __unused)
-{
- _spinlock(lck);
-}
-
static void
init_spinlock(spinlock_t *lck)
{
diff --git a/lib/libthr/thread/thr_syscalls.c b/lib/libthr/thread/thr_syscalls.c
index 7a08302..7c05697 100644
--- a/lib/libthr/thread/thr_syscalls.c
+++ b/lib/libthr/thread/thr_syscalls.c
@@ -1,9 +1,13 @@
/*
+ * Copyright (c) 2014 The FreeBSD Foundation.
* Copyright (C) 2005 David Xu <davidxu@freebsd.org>.
* Copyright (c) 2003 Daniel Eischen <deischen@freebsd.org>.
* Copyright (C) 2000 Jason Evans <jasone@freebsd.org>.
* All rights reserved.
*
+ * Portions of this software were developed by Konstantin Belousov
+ * under sponsorship from the FreeBSD Foundation.
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -27,8 +31,6 @@
* 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$
*/
/*
@@ -61,6 +63,9 @@
*
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
#include "namespace.h"
#include <sys/types.h>
#include <sys/mman.h>
@@ -87,85 +92,11 @@
#include <pthread.h>
#include "un-namespace.h"
+#include "libc_private.h"
#include "thr_private.h"
-extern int __creat(const char *, mode_t);
-extern int __pselect(int, fd_set *, fd_set *, fd_set *,
- const struct timespec *, const sigset_t *);
-extern unsigned __sleep(unsigned int);
-extern int __system(const char *);
-extern int __tcdrain(int);
-extern int __usleep(useconds_t);
-extern pid_t __wait(int *);
-extern pid_t __waitpid(pid_t, int *, int);
-extern int __sys_aio_suspend(const struct aiocb * const[], int,
- const struct timespec *);
-extern int __sys_accept(int, struct sockaddr *, socklen_t *);
-extern int __sys_accept4(int, struct sockaddr *, socklen_t *, int);
-extern int __sys_connect(int, const struct sockaddr *, socklen_t);
-extern int __sys_fsync(int);
-extern int __sys_msync(void *, size_t, int);
-extern int __sys_pselect(int, fd_set *, fd_set *, fd_set *,
- const struct timespec *, const sigset_t *);
-extern int __sys_poll(struct pollfd *, unsigned, int);
-extern ssize_t __sys_recv(int, void *, size_t, int);
-extern ssize_t __sys_recvfrom(int, void *, size_t, int, struct sockaddr *, socklen_t *);
-extern ssize_t __sys_recvmsg(int, struct msghdr *, int);
-extern int __sys_select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
-extern int __sys_sendfile(int, int, off_t, size_t, struct sf_hdtr *,
- off_t *, int);
-extern ssize_t __sys_sendmsg(int, const struct msghdr *, int);
-extern ssize_t __sys_sendto(int, const void *,size_t, int, const struct sockaddr *, socklen_t);
-extern ssize_t __sys_readv(int, const struct iovec *, int);
-extern pid_t __sys_wait4(pid_t, int *, int, struct rusage *);
-extern ssize_t __sys_writev(int, const struct iovec *, int);
-
-int ___creat(const char *, mode_t);
-int ___pselect(int, fd_set *, fd_set *, fd_set *,
- const struct timespec *, const sigset_t *);
-unsigned ___sleep(unsigned);
-int ___system(const char *);
-int ___tcdrain(int);
-int ___usleep(useconds_t useconds);
-pid_t ___wait(int *);
-pid_t ___waitpid(pid_t, int *, int);
-int __accept(int, struct sockaddr *, socklen_t *);
-int __accept4(int, struct sockaddr *, socklen_t *, int);
-int __aio_suspend(const struct aiocb * const iocbs[], int,
- const struct timespec *);
-int __close(int);
-int __connect(int, const struct sockaddr *, socklen_t);
-int __fcntl(int, int,...);
-#ifdef SYSCALL_COMPAT
-extern int __fcntl_compat(int, int,...);
-#endif
-int __fsync(int);
-int __msync(void *, size_t, int);
-int __nanosleep(const struct timespec *, struct timespec *);
-int __open(const char *, int,...);
-int __openat(int, const char *, int,...);
-int __poll(struct pollfd *, unsigned int, int);
-ssize_t __read(int, void *buf, size_t);
-ssize_t __readv(int, const struct iovec *, int);
-ssize_t __recvfrom(int, void *, size_t, int f, struct sockaddr *, socklen_t *);
-ssize_t __recvmsg(int, struct msghdr *, int);
-int __select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
-ssize_t __sendmsg(int, const struct msghdr *, int);
-ssize_t __sendto(int, const void *, size_t, int,
- const struct sockaddr *, socklen_t);
-pid_t __wait3(int *, int, struct rusage *);
-pid_t __wait4(pid_t, int *, int, struct rusage *);
-ssize_t __write(int, const void *, size_t);
-ssize_t __writev(int, const struct iovec *, int);
-
-__weak_reference(__accept, accept);
-
-/*
- * Cancellation behavior:
- * If thread is canceled, no socket is created.
- */
-int
-__accept(int s, struct sockaddr *addr, socklen_t *addrlen)
+static int
+__thr_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
{
struct pthread *curthread;
int ret;
@@ -178,14 +109,12 @@ __accept(int s, struct sockaddr *addr, socklen_t *addrlen)
return (ret);
}
-__weak_reference(__accept4, accept4);
-
/*
* Cancellation behavior:
* If thread is canceled, no socket is created.
*/
-int
-__accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags)
+static int
+__thr_accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags)
{
struct pthread *curthread;
int ret;
@@ -198,15 +127,14 @@ __accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags)
return (ret);
}
-__weak_reference(__aio_suspend, aio_suspend);
-
-int
-__aio_suspend(const struct aiocb * const iocbs[], int niocb, const struct
+static int
+__thr_aio_suspend(const struct aiocb * const iocbs[], int niocb, const struct
timespec *timeout)
{
- struct pthread *curthread = _get_curthread();
+ struct pthread *curthread;
int ret;
+ curthread = _get_curthread();
_thr_cancel_enter(curthread);
ret = __sys_aio_suspend(iocbs, niocb, timeout);
_thr_cancel_leave(curthread, 1);
@@ -214,8 +142,6 @@ __aio_suspend(const struct aiocb * const iocbs[], int niocb, const struct
return (ret);
}
-__weak_reference(__close, close);
-
/*
* Cancellation behavior:
* According to manual of close(), the file descriptor is always deleted.
@@ -223,12 +149,13 @@ __weak_reference(__close, close);
* descriptor is always deleted despite whether the thread is canceled
* or not.
*/
-int
-__close(int fd)
+static int
+__thr_close(int fd)
{
- struct pthread *curthread = _get_curthread();
- int ret;
+ struct pthread *curthread;
+ int ret;
+ curthread = _get_curthread();
_thr_cancel_enter2(curthread, 0);
ret = __sys_close(fd);
_thr_cancel_leave(curthread, 1);
@@ -236,18 +163,17 @@ __close(int fd)
return (ret);
}
-__weak_reference(__connect, connect);
-
/*
* Cancellation behavior:
* If the thread is canceled, connection is not made.
*/
-int
-__connect(int fd, const struct sockaddr *name, socklen_t namelen)
+static int
+__thr_connect(int fd, const struct sockaddr *name, socklen_t namelen)
{
- struct pthread *curthread = _get_curthread();
+ struct pthread *curthread;
int ret;
+ curthread = _get_curthread();
_thr_cancel_enter(curthread);
ret = __sys_connect(fd, name, namelen);
_thr_cancel_leave(curthread, ret == -1);
@@ -255,27 +181,6 @@ __connect(int fd, const struct sockaddr *name, socklen_t namelen)
return (ret);
}
-__weak_reference(___creat, creat);
-
-/*
- * Cancellation behavior:
- * If thread is canceled, file is not created.
- */
-int
-___creat(const char *path, mode_t mode)
-{
- struct pthread *curthread = _get_curthread();
- int ret;
-
- _thr_cancel_enter(curthread);
- ret = __creat(path, mode);
- _thr_cancel_leave(curthread, ret == -1);
-
- return ret;
-}
-
-__weak_reference(__fcntl, fcntl);
-
/*
* Cancellation behavior:
* According to specification, only F_SETLKW is a cancellation point.
@@ -283,46 +188,38 @@ __weak_reference(__fcntl, fcntl);
* is failure, this means the function does not generate side effect
* if it is canceled.
*/
-int
-__fcntl(int fd, int cmd,...)
+static int
+__thr_fcntl(int fd, int cmd, ...)
{
- struct pthread *curthread = _get_curthread();
- int ret;
+ struct pthread *curthread;
+ int ret;
va_list ap;
+ curthread = _get_curthread();
va_start(ap, cmd);
if (cmd == F_OSETLKW || cmd == F_SETLKW) {
_thr_cancel_enter(curthread);
-#ifdef SYSCALL_COMPAT
- ret = __fcntl_compat(fd, cmd, va_arg(ap, void *));
-#else
ret = __sys_fcntl(fd, cmd, va_arg(ap, void *));
-#endif
_thr_cancel_leave(curthread, ret == -1);
} else {
-#ifdef SYSCALL_COMPAT
- ret = __fcntl_compat(fd, cmd, va_arg(ap, void *));
-#else
ret = __sys_fcntl(fd, cmd, va_arg(ap, void *));
-#endif
}
va_end(ap);
return (ret);
}
-__weak_reference(__fsync, fsync);
-
/*
* Cancellation behavior:
* Thread may be canceled after system call.
*/
-int
-__fsync(int fd)
+static int
+__thr_fsync(int fd)
{
- struct pthread *curthread = _get_curthread();
- int ret;
+ struct pthread *curthread;
+ int ret;
+ curthread = _get_curthread();
_thr_cancel_enter2(curthread, 0);
ret = __sys_fsync(fd);
_thr_cancel_leave(curthread, 1);
@@ -330,34 +227,32 @@ __fsync(int fd)
return (ret);
}
-__weak_reference(__msync, msync);
-
/*
* Cancellation behavior:
* Thread may be canceled after system call.
*/
-int
-__msync(void *addr, size_t len, int flags)
+static int
+__thr_msync(void *addr, size_t len, int flags)
{
- struct pthread *curthread = _get_curthread();
- int ret;
+ struct pthread *curthread;
+ int ret;
+ curthread = _get_curthread();
_thr_cancel_enter2(curthread, 0);
ret = __sys_msync(addr, len, flags);
_thr_cancel_leave(curthread, 1);
- return ret;
+ return (ret);
}
-__weak_reference(__nanosleep, nanosleep);
-
-int
-__nanosleep(const struct timespec *time_to_sleep,
+static int
+__thr_nanosleep(const struct timespec *time_to_sleep,
struct timespec *time_remaining)
{
- struct pthread *curthread = _get_curthread();
- int ret;
+ struct pthread *curthread;
+ int ret;
+ curthread = _get_curthread();
_thr_cancel_enter(curthread);
ret = __sys_nanosleep(time_to_sleep, time_remaining);
_thr_cancel_leave(curthread, 1);
@@ -365,99 +260,88 @@ __nanosleep(const struct timespec *time_to_sleep,
return (ret);
}
-__weak_reference(__open, open);
-
/*
* Cancellation behavior:
* If the thread is canceled, file is not opened.
*/
-int
-__open(const char *path, int flags,...)
+static int
+__thr_openat(int fd, const char *path, int flags, ...)
{
- struct pthread *curthread = _get_curthread();
- int ret;
- int mode = 0;
+ struct pthread *curthread;
+ int mode, ret;
va_list ap;
+
/* Check if the file is being created: */
- if (flags & O_CREAT) {
+ if ((flags & O_CREAT) != 0) {
/* Get the creation mode: */
va_start(ap, flags);
mode = va_arg(ap, int);
va_end(ap);
+ } else {
+ mode = 0;
}
+ curthread = _get_curthread();
_thr_cancel_enter(curthread);
- ret = __sys_open(path, flags, mode);
+ ret = __sys_openat(fd, path, flags, mode);
_thr_cancel_leave(curthread, ret == -1);
- return ret;
+ return (ret);
}
-__weak_reference(__openat, openat);
-
/*
* Cancellation behavior:
- * If the thread is canceled, file is not opened.
+ * Thread may be canceled at start, but if the system call returns something,
+ * the thread is not canceled.
*/
-int
-__openat(int fd, const char *path, int flags, ...)
+static int
+__thr_poll(struct pollfd *fds, unsigned int nfds, int timeout)
{
- struct pthread *curthread = _get_curthread();
- int ret;
- int mode = 0;
- va_list ap;
+ struct pthread *curthread;
+ int ret;
-
- /* Check if the file is being created: */
- if (flags & O_CREAT) {
- /* Get the creation mode: */
- va_start(ap, flags);
- mode = va_arg(ap, int);
- va_end(ap);
- }
-
+ curthread = _get_curthread();
_thr_cancel_enter(curthread);
- ret = __sys_openat(fd, path, flags, mode);
+ ret = __sys_poll(fds, nfds, timeout);
_thr_cancel_leave(curthread, ret == -1);
- return ret;
+ return (ret);
}
-__weak_reference(__poll, poll);
-
/*
* Cancellation behavior:
* Thread may be canceled at start, but if the system call returns something,
* the thread is not canceled.
*/
-int
-__poll(struct pollfd *fds, unsigned int nfds, int timeout)
+static int
+__thr_ppoll(struct pollfd pfd[], nfds_t nfds, const struct timespec *
+ timeout, const sigset_t *newsigmask)
{
- struct pthread *curthread = _get_curthread();
+ struct pthread *curthread;
int ret;
+ curthread = _get_curthread();
_thr_cancel_enter(curthread);
- ret = __sys_poll(fds, nfds, timeout);
+ ret = __sys_ppoll(pfd, nfds, timeout, newsigmask);
_thr_cancel_leave(curthread, ret == -1);
- return ret;
+ return (ret);
}
-__weak_reference(___pselect, pselect);
-
/*
* Cancellation behavior:
* Thread may be canceled at start, but if the system call returns something,
* the thread is not canceled.
*/
-int
-___pselect(int count, fd_set *rfds, fd_set *wfds, fd_set *efds,
+static int
+__thr_pselect(int count, fd_set *rfds, fd_set *wfds, fd_set *efds,
const struct timespec *timo, const sigset_t *mask)
{
- struct pthread *curthread = _get_curthread();
+ struct pthread *curthread;
int ret;
+ curthread = _get_curthread();
_thr_cancel_enter(curthread);
ret = __sys_pselect(count, rfds, wfds, efds, timo, mask);
_thr_cancel_leave(curthread, ret == -1);
@@ -465,321 +349,311 @@ ___pselect(int count, fd_set *rfds, fd_set *wfds, fd_set *efds,
return (ret);
}
-__weak_reference(__read, read);
+static int
+__thr_kevent(int kq, const struct kevent *changelist, int nchanges,
+ struct kevent *eventlist, int nevents, const struct timespec *timeout)
+{
+ struct pthread *curthread;
+ int ret;
+
+ if (nevents == 0) {
+ /*
+ * No blocking, do not make the call cancellable.
+ */
+ return (__sys_kevent(kq, changelist, nchanges, eventlist,
+ nevents, timeout));
+ }
+ curthread = _get_curthread();
+ _thr_cancel_enter(curthread);
+ ret = __sys_kevent(kq, changelist, nchanges, eventlist, nevents,
+ timeout);
+ _thr_cancel_leave(curthread, ret == -1 && nchanges == 0);
+
+ return (ret);
+}
/*
* Cancellation behavior:
* Thread may be canceled at start, but if the system call got some data,
* the thread is not canceled.
*/
-ssize_t
-__read(int fd, void *buf, size_t nbytes)
+static ssize_t
+__thr_read(int fd, void *buf, size_t nbytes)
{
- struct pthread *curthread = _get_curthread();
+ struct pthread *curthread;
ssize_t ret;
+ curthread = _get_curthread();
_thr_cancel_enter(curthread);
ret = __sys_read(fd, buf, nbytes);
_thr_cancel_leave(curthread, ret == -1);
- return ret;
+ return (ret);
}
-__weak_reference(__readv, readv);
-
/*
* Cancellation behavior:
* Thread may be canceled at start, but if the system call got some data,
* the thread is not canceled.
*/
-ssize_t
-__readv(int fd, const struct iovec *iov, int iovcnt)
+static ssize_t
+__thr_readv(int fd, const struct iovec *iov, int iovcnt)
{
- struct pthread *curthread = _get_curthread();
+ struct pthread *curthread;
ssize_t ret;
+ curthread = _get_curthread();
_thr_cancel_enter(curthread);
ret = __sys_readv(fd, iov, iovcnt);
_thr_cancel_leave(curthread, ret == -1);
- return ret;
+ return (ret);
}
-__weak_reference(__recvfrom, recvfrom);
-
/*
* Cancellation behavior:
* Thread may be canceled at start, but if the system call got some data,
* the thread is not canceled.
*/
-ssize_t
-__recvfrom(int s, void *b, size_t l, int f, struct sockaddr *from,
+static ssize_t
+__thr_recvfrom(int s, void *b, size_t l, int f, struct sockaddr *from,
socklen_t *fl)
{
- struct pthread *curthread = _get_curthread();
+ struct pthread *curthread;
ssize_t ret;
+ curthread = _get_curthread();
_thr_cancel_enter(curthread);
ret = __sys_recvfrom(s, b, l, f, from, fl);
_thr_cancel_leave(curthread, ret == -1);
return (ret);
}
-__weak_reference(__recvmsg, recvmsg);
-
/*
* Cancellation behavior:
* Thread may be canceled at start, but if the system call got some data,
* the thread is not canceled.
*/
-ssize_t
-__recvmsg(int s, struct msghdr *m, int f)
+static ssize_t
+__thr_recvmsg(int s, struct msghdr *m, int f)
{
- struct pthread *curthread = _get_curthread();
+ struct pthread *curthread;
ssize_t ret;
+ curthread = _get_curthread();
_thr_cancel_enter(curthread);
ret = __sys_recvmsg(s, m, f);
_thr_cancel_leave(curthread, ret == -1);
return (ret);
}
-__weak_reference(__select, select);
-
/*
* Cancellation behavior:
* Thread may be canceled at start, but if the system call returns something,
* the thread is not canceled.
*/
-int
-__select(int numfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
+static int
+__thr_select(int numfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
struct timeval *timeout)
{
- struct pthread *curthread = _get_curthread();
+ struct pthread *curthread;
int ret;
+ curthread = _get_curthread();
_thr_cancel_enter(curthread);
ret = __sys_select(numfds, readfds, writefds, exceptfds, timeout);
_thr_cancel_leave(curthread, ret == -1);
- return ret;
+ return (ret);
}
-__weak_reference(__sendmsg, sendmsg);
-
/*
* Cancellation behavior:
* Thread may be canceled at start, but if the system call sent
* data, the thread is not canceled.
*/
-ssize_t
-__sendmsg(int s, const struct msghdr *m, int f)
+static ssize_t
+__thr_sendmsg(int s, const struct msghdr *m, int f)
{
- struct pthread *curthread = _get_curthread();
+ struct pthread *curthread;
ssize_t ret;
+ curthread = _get_curthread();
_thr_cancel_enter(curthread);
ret = __sys_sendmsg(s, m, f);
_thr_cancel_leave(curthread, ret <= 0);
return (ret);
}
-__weak_reference(__sendto, sendto);
-
/*
* Cancellation behavior:
* Thread may be canceled at start, but if the system call sent some
* data, the thread is not canceled.
*/
-ssize_t
-__sendto(int s, const void *m, size_t l, int f, const struct sockaddr *t,
+static ssize_t
+__thr_sendto(int s, const void *m, size_t l, int f, const struct sockaddr *t,
socklen_t tl)
{
- struct pthread *curthread = _get_curthread();
+ struct pthread *curthread;
ssize_t ret;
+ curthread = _get_curthread();
_thr_cancel_enter(curthread);
ret = __sys_sendto(s, m, l, f, t, tl);
_thr_cancel_leave(curthread, ret <= 0);
return (ret);
}
-__weak_reference(___sleep, sleep);
-
-unsigned int
-___sleep(unsigned int seconds)
+static int
+__thr_system(const char *string)
{
- struct pthread *curthread = _get_curthread();
- unsigned int ret;
+ struct pthread *curthread;
+ int ret;
+ curthread = _get_curthread();
_thr_cancel_enter(curthread);
- ret = __sleep(seconds);
+ ret = __libc_system(string);
_thr_cancel_leave(curthread, 1);
-
return (ret);
}
-__weak_reference(___system, system);
-
-int
-___system(const char *string)
-{
- struct pthread *curthread = _get_curthread();
- int ret;
-
- _thr_cancel_enter(curthread);
- ret = __system(string);
- _thr_cancel_leave(curthread, 1);
-
- return ret;
-}
-
-__weak_reference(___tcdrain, tcdrain);
-
/*
* Cancellation behavior:
* If thread is canceled, the system call is not completed,
* this means not all bytes were drained.
*/
-int
-___tcdrain(int fd)
+static int
+__thr_tcdrain(int fd)
{
- struct pthread *curthread = _get_curthread();
- int ret;
+ struct pthread *curthread;
+ int ret;
+ curthread = _get_curthread();
_thr_cancel_enter(curthread);
- ret = __tcdrain(fd);
+ ret = __libc_tcdrain(fd);
_thr_cancel_leave(curthread, ret == -1);
return (ret);
}
-__weak_reference(___usleep, usleep);
-
-int
-___usleep(useconds_t useconds)
-{
- struct pthread *curthread = _get_curthread();
- int ret;
-
- _thr_cancel_enter(curthread);
- ret = __usleep(useconds);
- _thr_cancel_leave(curthread, 1);
-
- return (ret);
-}
-
-__weak_reference(___wait, wait);
-
/*
* Cancellation behavior:
* Thread may be canceled at start, but if the system call returns
* a child pid, the thread is not canceled.
*/
-pid_t
-___wait(int *istat)
+static pid_t
+__thr_wait4(pid_t pid, int *status, int options, struct rusage *rusage)
{
- struct pthread *curthread = _get_curthread();
- pid_t ret;
-
- _thr_cancel_enter(curthread);
- ret = __wait(istat);
- _thr_cancel_leave(curthread, ret <= 0);
-
- return ret;
-}
-
-__weak_reference(__wait3, wait3);
-
-/*
- * Cancellation behavior:
- * Thread may be canceled at start, but if the system call returns
- * a child pid, the thread is not canceled.
- */
-pid_t
-__wait3(int *status, int options, struct rusage *rusage)
-{
- struct pthread *curthread = _get_curthread();
+ struct pthread *curthread;
pid_t ret;
+ curthread = _get_curthread();
_thr_cancel_enter(curthread);
- ret = _wait4(WAIT_ANY, status, options, rusage);
+ ret = __sys_wait4(pid, status, options, rusage);
_thr_cancel_leave(curthread, ret <= 0);
-
return (ret);
}
-__weak_reference(__wait4, wait4);
-
/*
* Cancellation behavior:
* Thread may be canceled at start, but if the system call returns
* a child pid, the thread is not canceled.
*/
-pid_t
-__wait4(pid_t pid, int *status, int options, struct rusage *rusage)
+static pid_t
+__thr_wait6(idtype_t idtype, id_t id, int *status, int options,
+ struct __wrusage *ru, siginfo_t *infop)
{
- struct pthread *curthread = _get_curthread();
+ struct pthread *curthread;
pid_t ret;
+ curthread = _get_curthread();
_thr_cancel_enter(curthread);
- ret = __sys_wait4(pid, status, options, rusage);
- _thr_cancel_leave(curthread, ret <= 0);
-
- return ret;
-}
-
-__weak_reference(___waitpid, waitpid);
-
-/*
- * Cancellation behavior:
- * Thread may be canceled at start, but if the system call returns
- * a child pid, the thread is not canceled.
- */
-pid_t
-___waitpid(pid_t wpid, int *status, int options)
-{
- struct pthread *curthread = _get_curthread();
- pid_t ret;
-
- _thr_cancel_enter(curthread);
- ret = __waitpid(wpid, status, options);
+ ret = __sys_wait6(idtype, id, status, options, ru, infop);
_thr_cancel_leave(curthread, ret <= 0);
-
- return ret;
+ return (ret);
}
-__weak_reference(__write, write);
-
/*
* Cancellation behavior:
* Thread may be canceled at start, but if the thread wrote some data,
* it is not canceled.
*/
-ssize_t
-__write(int fd, const void *buf, size_t nbytes)
+static ssize_t
+__thr_write(int fd, const void *buf, size_t nbytes)
{
- struct pthread *curthread = _get_curthread();
+ struct pthread *curthread;
ssize_t ret;
+ curthread = _get_curthread();
_thr_cancel_enter(curthread);
ret = __sys_write(fd, buf, nbytes);
_thr_cancel_leave(curthread, (ret <= 0));
- return ret;
+ return (ret);
}
-__weak_reference(__writev, writev);
-
/*
* Cancellation behavior:
* Thread may be canceled at start, but if the thread wrote some data,
* it is not canceled.
*/
-ssize_t
-__writev(int fd, const struct iovec *iov, int iovcnt)
+static ssize_t
+__thr_writev(int fd, const struct iovec *iov, int iovcnt)
{
- struct pthread *curthread = _get_curthread();
+ struct pthread *curthread;
ssize_t ret;
+ curthread = _get_curthread();
_thr_cancel_enter(curthread);
ret = __sys_writev(fd, iov, iovcnt);
_thr_cancel_leave(curthread, (ret <= 0));
- return ret;
+ return (ret);
+}
+
+void
+__thr_interpose_libc(void)
+{
+
+ __set_error_selector(__error_threaded);
+#define SLOT(name) \
+ *(__libc_interposing_slot(INTERPOS_##name)) = \
+ (interpos_func_t)__thr_##name;
+ SLOT(accept);
+ SLOT(accept4);
+ SLOT(aio_suspend);
+ SLOT(close);
+ SLOT(connect);
+ SLOT(fcntl);
+ SLOT(fsync);
+ SLOT(fork);
+ SLOT(msync);
+ SLOT(nanosleep);
+ SLOT(openat);
+ SLOT(poll);
+ SLOT(pselect);
+ SLOT(read);
+ SLOT(readv);
+ SLOT(recvfrom);
+ SLOT(recvmsg);
+ SLOT(select);
+ SLOT(sendmsg);
+ SLOT(sendto);
+ SLOT(setcontext);
+ SLOT(sigaction);
+ SLOT(sigprocmask);
+ SLOT(sigsuspend);
+ SLOT(sigwait);
+ SLOT(sigtimedwait);
+ SLOT(sigwaitinfo);
+ SLOT(swapcontext);
+ SLOT(system);
+ SLOT(tcdrain);
+ SLOT(wait4);
+ SLOT(write);
+ SLOT(writev);
+ SLOT(spinlock);
+ SLOT(spinunlock);
+ SLOT(kevent);
+ SLOT(wait6);
+ SLOT(ppoll);
+#undef SLOT
+ *(__libc_interposing_slot(
+ INTERPOS__pthread_mutex_init_calloc_cb)) =
+ (interpos_func_t)_pthread_mutex_init_calloc_cb;
}
diff --git a/lib/libthread_db/arch/aarch64/libpthread_md.c b/lib/libthread_db/arch/aarch64/libpthread_md.c
new file mode 100644
index 0000000..75f4553
--- /dev/null
+++ b/lib/libthread_db/arch/aarch64/libpthread_md.c
@@ -0,0 +1,96 @@
+/*-
+ * Copyright (c) 2014-2015 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Andrew Turner under
+ * sponsorship from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <string.h>
+#include <thread_db.h>
+
+#include "libpthread_db.h"
+
+void abort(void);
+
+void
+pt_reg_to_ucontext(const struct reg *r, ucontext_t *uc)
+{
+ mcontext_t *mc = &uc->uc_mcontext;
+
+ memcpy(mc->mc_gpregs.gp_x, r->x, sizeof(mc->mc_gpregs.gp_x));
+ mc->mc_gpregs.gp_sp = r->sp;
+ mc->mc_gpregs.gp_lr = r->lr;
+ mc->mc_gpregs.gp_elr = r->elr;
+ mc->mc_gpregs.gp_spsr = r->spsr;
+}
+
+void
+pt_ucontext_to_reg(const ucontext_t *uc, struct reg *r)
+{
+ const mcontext_t *mc = &uc->uc_mcontext;
+
+ memcpy(r->x, mc->mc_gpregs.gp_x, sizeof(mc->mc_gpregs.gp_x));
+ r->sp = mc->mc_gpregs.gp_sp;
+ r->lr = mc->mc_gpregs.gp_lr;
+ r->elr = mc->mc_gpregs.gp_elr;
+ r->spsr = mc->mc_gpregs.gp_spsr;
+}
+
+void
+pt_fpreg_to_ucontext(const struct fpreg *r, ucontext_t *uc)
+{
+ mcontext_t *mc = &uc->uc_mcontext;
+
+ memcpy(&mc->mc_fpregs, r, sizeof(*r));
+ mc->mc_flags |= _MC_FP_VALID;
+}
+
+void
+pt_ucontext_to_fpreg(const ucontext_t *uc, struct fpreg *r)
+{
+ const mcontext_t *mc = &uc->uc_mcontext;
+
+ if (mc->mc_flags & _MC_FP_VALID)
+ memcpy(r, &mc->mc_fpregs, sizeof(*r));
+ else
+ memset(r, 0, sizeof(*r));
+
+}
+
+void
+pt_md_init(void)
+{
+}
+
+int
+pt_reg_sstep(struct reg *reg __unused, int step __unused)
+{
+
+ return (0);
+}
diff --git a/lib/libthread_db/arch/i386/libpthread_md.c b/lib/libthread_db/arch/i386/libpthread_md.c
index d41865f..784c245 100644
--- a/lib/libthread_db/arch/i386/libpthread_md.c
+++ b/lib/libthread_db/arch/i386/libpthread_md.c
@@ -72,7 +72,7 @@ pt_ucontext_to_fpreg(const ucontext_t *uc, struct fpreg *r)
memcpy(r, &uc->uc_mcontext.mc_fpstate, sizeof(struct save87));
else {
int i;
- struct savexmm *sx = (struct savexmm *)&uc->uc_mcontext.mc_fpstate;
+ const struct savexmm *sx = (const struct savexmm *)&uc->uc_mcontext.mc_fpstate;
memcpy(&r->fpr_env, &sx->sv_env, sizeof(r->fpr_env));
for (i = 0; i < 8; ++i)
memcpy(&r->fpr_acc[i], &sx->sv_fp[i].fp_acc, 10);
diff --git a/lib/libucl/Makefile b/lib/libucl/Makefile
index 830c198..310e8b7 100644
--- a/lib/libucl/Makefile
+++ b/lib/libucl/Makefile
@@ -14,11 +14,16 @@ SRCS= ucl_emitter_streamline.c \
ucl_util.c \
xxhash.c
-.PATH: ${LIBUCL}/src
+.PATH: ${LIBUCL}/src \
+ ${LIBUCL}/include
+
+INCS= ucl.h
+LIBADD= m
WARNS= 1
CFLAGS+= -I${LIBUCL}/include \
-I${LIBUCL}/src \
- -I${LIBUCL}/uthash
+ -I${LIBUCL}/uthash \
+ -I${LIBUCL}/klib
.include <bsd.lib.mk>
diff --git a/lib/libufs/Makefile b/lib/libufs/Makefile
index 78832d8..24efd0c 100644
--- a/lib/libufs/Makefile
+++ b/lib/libufs/Makefile
@@ -21,7 +21,6 @@ MLINKS+= ufs_disk_close.3 ufs_disk_write.3
WARNS?= 2
-DEBUG_FLAGS = -g
CFLAGS+= -D_LIBUFS
.if defined(LIBUFS_DEBUG)
CFLAGS+= -D_LIBUFS_DEBUGGING
diff --git a/lib/libulog/Makefile b/lib/libulog/Makefile
index efbaece..fedd114 100644
--- a/lib/libulog/Makefile
+++ b/lib/libulog/Makefile
@@ -19,8 +19,7 @@ MLINKS+=ulog_login.3 ulog_login_pseudo.3 \
utempter_remove_added_record.3 removeFromUtmp.3 \
utempter_remove_record.3 removeLineFromUtmp.3
-DPADD= ${LIBMD}
-LDADD= -lmd
+LIBADD= md
VERSION_DEF= ${.CURDIR}/../libc/Versions.def
SYMBOL_MAPS= ${.CURDIR}/Symbol.map
diff --git a/lib/libunbound/Makefile b/lib/libunbound/Makefile
index aca3023..fb593f2 100644
--- a/lib/libunbound/Makefile
+++ b/lib/libunbound/Makefile
@@ -5,15 +5,15 @@ LDNSDIR= ${.CURDIR}/../../contrib/ldns
UNBOUNDDIR= ${.CURDIR}/../../contrib/unbound
# Hold my beer and watch this
-.PATH: ${UNBOUNDDIR} ${UNBOUNDDIR}/iterator ${UNBOUNDDIR}/ldns ${UNBOUNDDIR}/libunbound ${UNBOUNDDIR}/services ${UNBOUNDDIR}/services/cache ${UNBOUNDDIR}/util ${UNBOUNDDIR}/util/data ${UNBOUNDDIR}/util/storage ${UNBOUNDDIR}/validator
+.PATH: ${UNBOUNDDIR} ${UNBOUNDDIR}/dns64 ${UNBOUNDDIR}/iterator ${UNBOUNDDIR}/ldns ${UNBOUNDDIR}/libunbound ${UNBOUNDDIR}/services ${UNBOUNDDIR}/services/cache ${UNBOUNDDIR}/util ${UNBOUNDDIR}/util/data ${UNBOUNDDIR}/util/storage ${UNBOUNDDIR}/validator
LIB= unbound
PRIVATELIB=
-CFLAGS= -I${UNBOUNDDIR} -I${LDNSDIR} -I${.OBJDIR}
+CFLAGS= -I${UNBOUNDDIR} -I${LDNSDIR} -I${.OBJDIR}
SRCS= alloc.c autotrust.c config_file.c configlexer.l configparser.y \
- context.c dname.c dns.c dnstree.c fptr_wlist.c infra.c \
+ context.c dname.c dns.c dns64.c dnstree.c fptr_wlist.c infra.c \
iter_delegpt.c iter_donotq.c iter_fwd.c iter_hints.c iter_priv.c \
iter_resptype.c iter_scrub.c iter_utils.c iterator.c keyraw.c \
libunbound.c libworker.c listen_dnsport.c localzone.c locks.c log.c \
@@ -28,12 +28,11 @@ SRCS= alloc.c autotrust.c config_file.c configlexer.l configparser.y \
WARNS?= 3
-DPADD+= ${LIBSSL} ${LIBCRYPTO} ${LIBPTHREAD}
-LDADD+= -lssl -lcrypto -lpthread
+LIBADD= ssl crypto pthread
# Misnamed file in upstream source
configlexer.l: configlexer.lex
- cp -fp ${.ALLSRC} ${.TARGET}
+ ${CP} ${.ALLSRC} ${.TARGET}
CLEANFILES+= configlexer.l
# Symbol prefix for lex and yacc
diff --git a/lib/libusb/Makefile b/lib/libusb/Makefile
index 1ef85d4..24d97fd 100644
--- a/lib/libusb/Makefile
+++ b/lib/libusb/Makefile
@@ -19,8 +19,7 @@ PTHREAD_LIBS?= -lpthread
WARNS?= 2
-DPADD= ${LIBPTHREAD}
-LDADD= ${PTHREAD_LIBS}
+LIBADD= pthread
MLINKS+= libusb.3 usb.3
diff --git a/lib/libusb/libusb.3 b/lib/libusb/libusb.3
index 785c8c4..d00cb3f 100644
--- a/lib/libusb/libusb.3
+++ b/lib/libusb/libusb.3
@@ -42,9 +42,9 @@ The
.Nm
library contains interfaces for directly managing a usb device.
The current implementation supports v1.0 of the libusb API.
-.Sh LIBRARY INITIALISATION / DEINITIALISATION
+.Sh LIBRARY INITIALISATION AND DEINITIALISATION
.Ft int
-.Fn libusb_init libusb_context **ctx
+.Fn libusb_init "libusb_context **ctx"
This function initialises libusb.
It must be called at the beginning
of the program, before other libusb routines are used.
diff --git a/lib/libusb/libusb.h b/lib/libusb/libusb.h
index 7f8634f..ab20e92 100644
--- a/lib/libusb/libusb.h
+++ b/lib/libusb/libusb.h
@@ -128,6 +128,8 @@ enum libusb_standard_request {
LIBUSB_REQUEST_GET_INTERFACE = 0x0A,
LIBUSB_REQUEST_SET_INTERFACE = 0x0B,
LIBUSB_REQUEST_SYNCH_FRAME = 0x0C,
+ LIBUSB_REQUEST_SET_SEL = 0x30,
+ LIBUSB_REQUEST_SET_ISOCH_DELAY = 0x31,
};
enum libusb_request_type {
diff --git a/lib/libusb/libusb20.3 b/lib/libusb/libusb20.3
index f6004a5..590ff3c 100644
--- a/lib/libusb/libusb20.3
+++ b/lib/libusb/libusb20.3
@@ -1053,8 +1053,8 @@ This function does not return NULL.
.It Pa /dev/usb
.El
.Sh SEE ALSO
-.Xr usb 4 ,
.Xr libusb 3 ,
+.Xr usb 4 ,
.Xr usbconfig 8 ,
.Xr usbdump 8
.
diff --git a/lib/libusb/libusb20_desc.h b/lib/libusb/libusb20_desc.h
index 48e2715..c5f085f 100644
--- a/lib/libusb/libusb20_desc.h
+++ b/lib/libusb/libusb20_desc.h
@@ -481,6 +481,12 @@ enum libusb20_standard_request {
/** Set then report an endpoint's synchronization frame */
LIBUSB20_REQUEST_SYNCH_FRAME = 0x0C,
+
+ /** Set U1 and U2 system exit latency */
+ LIBUSB20_REQUEST_SET_SEL = 0x30,
+
+ /** Set isochronous delay */
+ LIBUSB20_REQUEST_SET_ISOCH_DELAY = 0x31,
};
/** \ingroup misc
diff --git a/lib/libutil/gr_util.c b/lib/libutil/gr_util.c
index 465efd9..b0b0b36f 100644
--- a/lib/libutil/gr_util.c
+++ b/lib/libutil/gr_util.c
@@ -351,8 +351,6 @@ gr_fini(void)
int
gr_equal(const struct group *gr1, const struct group *gr2)
{
- int gr1_ndx;
- int gr2_ndx;
/* Check that the non-member information is the same. */
if (gr1->gr_name == NULL || gr2->gr_name == NULL) {
@@ -368,7 +366,8 @@ gr_equal(const struct group *gr1, const struct group *gr2)
if (gr1->gr_gid != gr2->gr_gid)
return (false);
- /* Check all members in both groups.
+ /*
+ * Check all members in both groups.
* getgrnam can return gr_mem with a pointer to NULL.
* gr_dup and gr_add strip out this superfluous NULL, setting
* gr_mem to NULL for no members.
@@ -376,22 +375,18 @@ gr_equal(const struct group *gr1, const struct group *gr2)
if (gr1->gr_mem != NULL && gr2->gr_mem != NULL) {
int i;
- for (i = 0; gr1->gr_mem[i] != NULL; i++) {
+ for (i = 0;
+ gr1->gr_mem[i] != NULL && gr2->gr_mem[i] != NULL; i++) {
if (strcmp(gr1->gr_mem[i], gr2->gr_mem[i]) != 0)
return (false);
}
- }
- /* Count number of members in both structs */
- gr2_ndx = 0;
- if (gr2->gr_mem != NULL)
- for(; gr2->gr_mem[gr2_ndx] != NULL; gr2_ndx++)
- /* empty */;
- gr1_ndx = 0;
- if (gr1->gr_mem != NULL)
- for(; gr1->gr_mem[gr1_ndx] != NULL; gr1_ndx++)
- /* empty */;
- if (gr1_ndx != gr2_ndx)
+ if (gr1->gr_mem[i] != NULL || gr2->gr_mem[i] != NULL)
+ return (false);
+ } else if (gr1->gr_mem != NULL && gr1->gr_mem[0] != NULL) {
return (false);
+ } else if (gr2->gr_mem != NULL && gr2->gr_mem[0] != NULL) {
+ return (false);
+ }
return (true);
}
diff --git a/lib/libutil/quotafile.3 b/lib/libutil/quotafile.3
index 001a66c..362cf01 100644
--- a/lib/libutil/quotafile.3
+++ b/lib/libutil/quotafile.3
@@ -273,8 +273,8 @@ and set
to indicate the error.
.Sh SEE ALSO
.Xr quotactl 2 ,
-.Xr quota.user 5 ,
-.Xr quota.group 5
+.Xr quota.group 5 ,
+.Xr quota.user 5
.Sh HISTORY
The
.Nm quotafile
diff --git a/lib/libutil/tests/Makefile b/lib/libutil/tests/Makefile
index 31b6c54..36eb2ae 100644
--- a/lib/libutil/tests/Makefile
+++ b/lib/libutil/tests/Makefile
@@ -9,7 +9,6 @@ TAP_TESTS_C+= pidfile_test
TAP_TESTS_C+= trimdomain_test
TAP_TESTS_C+= trimdomain-nodomain_test
-DPADD+= ${LIBUTIL}
-LDADD+= -lutil
+LIBADD+= util
.include <bsd.test.mk>
diff --git a/lib/libvmmapi/Makefile b/lib/libvmmapi/Makefile
index 93d3c85..26cf86f 100644
--- a/lib/libvmmapi/Makefile
+++ b/lib/libvmmapi/Makefile
@@ -6,6 +6,8 @@ INCS= vmmapi.h
WARNS?= 2
+LIBADD= util
+
CFLAGS+= -I${.CURDIR}
.include <bsd.lib.mk>
diff --git a/lib/libvmmapi/vmmapi.c b/lib/libvmmapi/vmmapi.c
index 93955c7..1e6e627 100644
--- a/lib/libvmmapi/vmmapi.c
+++ b/lib/libvmmapi/vmmapi.c
@@ -40,6 +40,7 @@ __FBSDID("$FreeBSD$");
#include <machine/specialreg.h>
#include <machine/param.h>
+#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
@@ -368,14 +369,13 @@ vm_get_register(struct vmctx *ctx, int vcpu, int reg, uint64_t *ret_val)
}
int
-vm_run(struct vmctx *ctx, int vcpu, uint64_t rip, struct vm_exit *vmexit)
+vm_run(struct vmctx *ctx, int vcpu, struct vm_exit *vmexit)
{
int error;
struct vm_run vmrun;
bzero(&vmrun, sizeof(vmrun));
vmrun.cpuid = vcpu;
- vmrun.rip = rip;
error = ioctl(ctx->fd, VM_RUN, &vmrun);
bcopy(&vmrun.vm_exit, vmexit, sizeof(struct vm_exit));
@@ -399,36 +399,22 @@ vm_reinit(struct vmctx *ctx)
return (ioctl(ctx->fd, VM_REINIT, 0));
}
-static int
-vm_inject_exception_real(struct vmctx *ctx, int vcpu, int vector,
- int error_code, int error_code_valid)
+int
+vm_inject_exception(struct vmctx *ctx, int vcpu, int vector, int errcode_valid,
+ uint32_t errcode, int restart_instruction)
{
struct vm_exception exc;
- bzero(&exc, sizeof(exc));
exc.cpuid = vcpu;
exc.vector = vector;
- exc.error_code = error_code;
- exc.error_code_valid = error_code_valid;
+ exc.error_code = errcode;
+ exc.error_code_valid = errcode_valid;
+ exc.restart_instruction = restart_instruction;
return (ioctl(ctx->fd, VM_INJECT_EXCEPTION, &exc));
}
int
-vm_inject_exception(struct vmctx *ctx, int vcpu, int vector)
-{
-
- return (vm_inject_exception_real(ctx, vcpu, vector, 0, 0));
-}
-
-int
-vm_inject_exception2(struct vmctx *ctx, int vcpu, int vector, int errcode)
-{
-
- return (vm_inject_exception_real(ctx, vcpu, vector, errcode, 1));
-}
-
-int
vm_apicid2vcpu(struct vmctx *ctx, int apicid)
{
/*
@@ -973,9 +959,9 @@ vm_get_hpet_capabilities(struct vmctx *ctx, uint32_t *capabilities)
return (error);
}
-static int
-gla2gpa(struct vmctx *ctx, int vcpu, struct vm_guest_paging *paging,
- uint64_t gla, int prot, int *fault, uint64_t *gpa)
+int
+vm_gla2gpa(struct vmctx *ctx, int vcpu, struct vm_guest_paging *paging,
+ uint64_t gla, int prot, uint64_t *gpa, int *fault)
{
struct vm_gla2gpa gg;
int error;
@@ -1000,10 +986,12 @@ gla2gpa(struct vmctx *ctx, int vcpu, struct vm_guest_paging *paging,
int
vm_copy_setup(struct vmctx *ctx, int vcpu, struct vm_guest_paging *paging,
- uint64_t gla, size_t len, int prot, struct iovec *iov, int iovcnt)
+ uint64_t gla, size_t len, int prot, struct iovec *iov, int iovcnt,
+ int *fault)
{
+ void *va;
uint64_t gpa;
- int error, fault, i, n, off;
+ int error, i, n, off;
for (i = 0; i < iovcnt; i++) {
iov[i].iov_base = 0;
@@ -1012,16 +1000,18 @@ vm_copy_setup(struct vmctx *ctx, int vcpu, struct vm_guest_paging *paging,
while (len) {
assert(iovcnt > 0);
- error = gla2gpa(ctx, vcpu, paging, gla, prot, &fault, &gpa);
- if (error)
- return (-1);
- if (fault)
- return (1);
+ error = vm_gla2gpa(ctx, vcpu, paging, gla, prot, &gpa, fault);
+ if (error || *fault)
+ return (error);
off = gpa & PAGE_MASK;
n = min(len, PAGE_SIZE - off);
- iov->iov_base = (void *)gpa;
+ va = vm_map_gpa(ctx, gpa, n);
+ if (va == NULL)
+ return (EFAULT);
+
+ iov->iov_base = va;
iov->iov_len = n;
iov++;
iovcnt--;
@@ -1033,19 +1023,24 @@ vm_copy_setup(struct vmctx *ctx, int vcpu, struct vm_guest_paging *paging,
}
void
+vm_copy_teardown(struct vmctx *ctx, int vcpu, struct iovec *iov, int iovcnt)
+{
+
+ return;
+}
+
+void
vm_copyin(struct vmctx *ctx, int vcpu, struct iovec *iov, void *vp, size_t len)
{
const char *src;
char *dst;
- uint64_t gpa;
size_t n;
dst = vp;
while (len) {
assert(iov->iov_len);
- gpa = (uint64_t)iov->iov_base;
n = min(len, iov->iov_len);
- src = vm_map_gpa(ctx, gpa, n);
+ src = iov->iov_base;
bcopy(src, dst, n);
iov++;
@@ -1060,15 +1055,13 @@ vm_copyout(struct vmctx *ctx, int vcpu, const void *vp, struct iovec *iov,
{
const char *src;
char *dst;
- uint64_t gpa;
size_t n;
src = vp;
while (len) {
assert(iov->iov_len);
- gpa = (uint64_t)iov->iov_base;
n = min(len, iov->iov_len);
- dst = vm_map_gpa(ctx, gpa, n);
+ dst = iov->iov_base;
bcopy(src, dst, n);
iov++;
@@ -1146,3 +1139,63 @@ vm_set_intinfo(struct vmctx *ctx, int vcpu, uint64_t info1)
error = ioctl(ctx->fd, VM_SET_INTINFO, &vmii);
return (error);
}
+
+int
+vm_rtc_write(struct vmctx *ctx, int offset, uint8_t value)
+{
+ struct vm_rtc_data rtcdata;
+ int error;
+
+ bzero(&rtcdata, sizeof(struct vm_rtc_data));
+ rtcdata.offset = offset;
+ rtcdata.value = value;
+ error = ioctl(ctx->fd, VM_RTC_WRITE, &rtcdata);
+ return (error);
+}
+
+int
+vm_rtc_read(struct vmctx *ctx, int offset, uint8_t *retval)
+{
+ struct vm_rtc_data rtcdata;
+ int error;
+
+ bzero(&rtcdata, sizeof(struct vm_rtc_data));
+ rtcdata.offset = offset;
+ error = ioctl(ctx->fd, VM_RTC_READ, &rtcdata);
+ if (error == 0)
+ *retval = rtcdata.value;
+ return (error);
+}
+
+int
+vm_rtc_settime(struct vmctx *ctx, time_t secs)
+{
+ struct vm_rtc_time rtctime;
+ int error;
+
+ bzero(&rtctime, sizeof(struct vm_rtc_time));
+ rtctime.secs = secs;
+ error = ioctl(ctx->fd, VM_RTC_SETTIME, &rtctime);
+ return (error);
+}
+
+int
+vm_rtc_gettime(struct vmctx *ctx, time_t *secs)
+{
+ struct vm_rtc_time rtctime;
+ int error;
+
+ bzero(&rtctime, sizeof(struct vm_rtc_time));
+ error = ioctl(ctx->fd, VM_RTC_GETTIME, &rtctime);
+ if (error == 0)
+ *secs = rtctime.secs;
+ return (error);
+}
+
+int
+vm_restart_instruction(void *arg, int vcpu)
+{
+ struct vmctx *ctx = arg;
+
+ return (ioctl(ctx->fd, VM_RESTART_INSTRUCTION, &vcpu));
+}
diff --git a/lib/libvmmapi/vmmapi.h b/lib/libvmmapi/vmmapi.h
index fbb6ddd..d3ecdc4 100644
--- a/lib/libvmmapi/vmmapi.h
+++ b/lib/libvmmapi/vmmapi.h
@@ -32,6 +32,12 @@
#include <sys/param.h>
#include <sys/cpuset.h>
+/*
+ * API version for out-of-tree consumers like grub-bhyve for making compile
+ * time decisions.
+ */
+#define VMMAPI_VERSION 0101 /* 2 digit major followed by 2 digit minor */
+
struct iovec;
struct vmctx;
enum x2apic_state;
@@ -57,6 +63,8 @@ int vm_get_memory_seg(struct vmctx *ctx, vm_paddr_t gpa, size_t *ret_len,
int vm_setup_memory(struct vmctx *ctx, size_t len, enum vm_mmap_style s);
void *vm_map_gpa(struct vmctx *ctx, vm_paddr_t gaddr, size_t len);
int vm_get_gpa_pmap(struct vmctx *, uint64_t gpa, uint64_t *pte, int *num);
+int vm_gla2gpa(struct vmctx *, int vcpuid, struct vm_guest_paging *paging,
+ uint64_t gla, int prot, uint64_t *gpa, int *fault);
uint32_t vm_get_lowmem_limit(struct vmctx *ctx);
void vm_set_lowmem_limit(struct vmctx *ctx, uint32_t limit);
void vm_set_memflags(struct vmctx *ctx, int flags);
@@ -70,13 +78,12 @@ int vm_get_seg_desc(struct vmctx *ctx, int vcpu, int reg,
struct seg_desc *seg_desc);
int vm_set_register(struct vmctx *ctx, int vcpu, int reg, uint64_t val);
int vm_get_register(struct vmctx *ctx, int vcpu, int reg, uint64_t *retval);
-int vm_run(struct vmctx *ctx, int vcpu, uint64_t rip,
- struct vm_exit *ret_vmexit);
+int vm_run(struct vmctx *ctx, int vcpu, struct vm_exit *ret_vmexit);
int vm_suspend(struct vmctx *ctx, enum vm_suspend_how how);
int vm_reinit(struct vmctx *ctx);
int vm_apicid2vcpu(struct vmctx *ctx, int apicid);
-int vm_inject_exception(struct vmctx *ctx, int vcpu, int vec);
-int vm_inject_exception2(struct vmctx *ctx, int vcpu, int vec, int errcode);
+int vm_inject_exception(struct vmctx *ctx, int vcpu, int vector,
+ int errcode_valid, uint32_t errcode, int restart_instruction);
int vm_lapic_irq(struct vmctx *ctx, int vcpu, int vector);
int vm_lapic_local_irq(struct vmctx *ctx, int vcpu, int vector);
int vm_lapic_msi(struct vmctx *ctx, uint64_t addr, uint64_t msg);
@@ -124,14 +131,27 @@ int vm_get_hpet_capabilities(struct vmctx *ctx, uint32_t *capabilities);
/*
* Translate the GLA range [gla,gla+len) into GPA segments in 'iov'.
* The 'iovcnt' should be big enough to accomodate all GPA segments.
- * Returns 0 on success, 1 on a guest fault condition and -1 otherwise.
+ *
+ * retval fault Interpretation
+ * 0 0 Success
+ * 0 1 An exception was injected into the guest
+ * EFAULT N/A Error
*/
int vm_copy_setup(struct vmctx *ctx, int vcpu, struct vm_guest_paging *pg,
- uint64_t gla, size_t len, int prot, struct iovec *iov, int iovcnt);
+ uint64_t gla, size_t len, int prot, struct iovec *iov, int iovcnt,
+ int *fault);
void vm_copyin(struct vmctx *ctx, int vcpu, struct iovec *guest_iov,
void *host_dst, size_t len);
void vm_copyout(struct vmctx *ctx, int vcpu, const void *host_src,
struct iovec *guest_iov, size_t len);
+void vm_copy_teardown(struct vmctx *ctx, int vcpu, struct iovec *iov,
+ int iovcnt);
+
+/* RTC */
+int vm_rtc_write(struct vmctx *ctx, int offset, uint8_t value);
+int vm_rtc_read(struct vmctx *ctx, int offset, uint8_t *retval);
+int vm_rtc_settime(struct vmctx *ctx, time_t secs);
+int vm_rtc_gettime(struct vmctx *ctx, time_t *secs);
/* Reset vcpu register state */
int vcpu_reset(struct vmctx *ctx, int vcpu);
diff --git a/lib/libxo/Makefile b/lib/libxo/Makefile
index 644b71f..62fface 100644
--- a/lib/libxo/Makefile
+++ b/lib/libxo/Makefile
@@ -7,6 +7,8 @@ LIBXO= ${.CURDIR:H:H}/contrib/libxo
LIB= xo
SHLIB_MAJOR=0
+SHLIBDIR?= /lib
+
SRCS= libxo.c
CFLAGS+=-I${LIBXO}/libxo
@@ -19,10 +21,12 @@ MAN+= xo_attr.3 \
xo_create.3 \
xo_emit.3 \
xo_err.3 \
+ xo_error.3 \
xo_finish.3 \
xo_flush.3 \
xo_no_setlocale.3 \
xo_open_container.3 \
+ xo_open_marker.3 \
xo_open_list.3 \
xo_parse_args.3 \
xo_set_allocator.3 \
@@ -30,7 +34,51 @@ MAN+= xo_attr.3 \
xo_set_info.3 \
xo_set_options.3 \
xo_set_style.3 \
+ xo_set_version.3 \
xo_set_writer.3
MAN+= xo_format.5
+MLINKS= xo_attr.3 xo_attr_h.3 \
+ xo_attr.3 xo_attr_hv.3 \
+ xo_create.3 xo_create_to_file.3 \
+ xo_create.3 xo_destroy.3 \
+ xo_emit.3 xo_emit_h.3 \
+ xo_emit.3 xo_emit_hv.3 \
+ xo_err.3 xo_warn.3 \
+ xo_err.3 xo_warnx.3 \
+ xo_err.3 xo_warn_c.3 \
+ xo_err.3 xo_warn_hc.3 \
+ xo_err.3 xo_errc.3 \
+ xo_err.3 xo_errx.3 \
+ xo_err.3 xo_message.3 \
+ xo_err.3 xo_message_c.3 \
+ xo_err.3 xo_message_hc.3 \
+ xo_err.3 xo_message_hcv.3 \
+ xo_finish.3 xo_finish_h.3 \
+ xo_flush.3 xo_flush_h.3 \
+ xo_open_container.3 xo_open_container_h.3 \
+ xo_open_container.3 xo_open_container_hd.3 \
+ xo_open_container.3 xo_open_container_d.3 \
+ xo_open_container.3 xo_close_container.3 \
+ xo_open_container.3 xo_close_container_h.3 \
+ xo_open_container.3 xo_close_container_hd.3 \
+ xo_open_container.3 xo_close_container_d.3 \
+ xo_open_list.3 xo_open_list_h.3 \
+ xo_open_list.3 xo_open_list_hd.3 \
+ xo_open_list.3 xo_open_list_d.3 \
+ xo_open_list.3 xo_open_instance.3 \
+ xo_open_list.3 xo_open_instance_h.3 \
+ xo_open_list.3 xo_open_instance_hd.3 \
+ xo_open_list.3 xo_open_instance_d.3 \
+ xo_open_list.3 xo_close_instance.3 \
+ xo_open_list.3 xo_close_instance_h.3 \
+ xo_open_list.3 xo_close_instance_hd.3 \
+ xo_open_list.3 xo_close_instance_d.3 \
+ xo_open_list.3 xo_close_list.3 \
+ xo_open_list.3 xo_close_list_h.3 \
+ xo_open_list.3 xo_close_list_hd.3 \
+ xo_open_list.3 xo_close_list_d.3 \
+ xo_set_flags.3 xo_clear_flags.3 \
+ xo_set_style.3 xo_set_style_name.3
+
.include <bsd.lib.mk>
diff --git a/lib/msun/Makefile b/lib/msun/Makefile
index afb7067..094fcba 100644
--- a/lib/msun/Makefile
+++ b/lib/msun/Makefile
@@ -223,6 +223,8 @@ MLINKS+=trunc.3 truncf.3 trunc.3 truncl.3
.include <src.opts.mk>
-.include <bsd.arch.inc.mk>
+.if ${MK_TESTS} != "no"
+SUBDIR+= tests
+.endif
.include <bsd.lib.mk>
diff --git a/lib/msun/Makefile.amd64 b/lib/msun/Makefile.amd64
deleted file mode 100644
index dd0f5b0..0000000
--- a/lib/msun/Makefile.amd64
+++ /dev/null
@@ -1,6 +0,0 @@
-# $FreeBSD$
-
-.if ${MK_TESTS} != "no"
-SUBDIR+= tests
-.endif
-
diff --git a/lib/msun/Makefile.i386 b/lib/msun/Makefile.i386
deleted file mode 100644
index dd0f5b0..0000000
--- a/lib/msun/Makefile.i386
+++ /dev/null
@@ -1,6 +0,0 @@
-# $FreeBSD$
-
-.if ${MK_TESTS} != "no"
-SUBDIR+= tests
-.endif
-
diff --git a/lib/msun/aarch64/Makefile.inc b/lib/msun/aarch64/Makefile.inc
new file mode 100644
index 0000000..286a608
--- /dev/null
+++ b/lib/msun/aarch64/Makefile.inc
@@ -0,0 +1,4 @@
+# $FreeBSD$
+
+LDBL_PREC = 113
+
diff --git a/lib/msun/aarch64/fenv.c b/lib/msun/aarch64/fenv.c
new file mode 100644
index 0000000..4ec362f
--- /dev/null
+++ b/lib/msun/aarch64/fenv.c
@@ -0,0 +1,56 @@
+/*-
+ * Copyright (c) 2004 David Schultz <das@FreeBSD.ORG>
+ * Copyright (c) 2013 Andrew Turner <andrew@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$
+ */
+
+#define __fenv_static
+#include "fenv.h"
+
+/*
+ * Hopefully the system ID byte is immutable, so it's valid to use
+ * this as a default environment.
+ */
+const fenv_t __fe_dfl_env = 0;
+
+#ifdef __GNUC_GNU_INLINE__
+#error "This file must be compiled with C99 'inline' semantics"
+#endif
+
+extern inline int feclearexcept(int __excepts);
+extern inline int fegetexceptflag(fexcept_t *__flagp, int __excepts);
+extern inline int fesetexceptflag(const fexcept_t *__flagp, int __excepts);
+extern inline int feraiseexcept(int __excepts);
+extern inline int fetestexcept(int __excepts);
+extern inline int fegetround(void);
+extern inline int fesetround(int __round);
+extern inline int fegetenv(fenv_t *__envp);
+extern inline int feholdexcept(fenv_t *__envp);
+extern inline int fesetenv(const fenv_t *__envp);
+extern inline int feupdateenv(const fenv_t *__envp);
+extern inline int feenableexcept(int __mask);
+extern inline int fedisableexcept(int __mask);
+extern inline int fegetexcept(void);
diff --git a/lib/msun/aarch64/fenv.h b/lib/msun/aarch64/fenv.h
new file mode 100644
index 0000000..2bd2987
--- /dev/null
+++ b/lib/msun/aarch64/fenv.h
@@ -0,0 +1,246 @@
+/*-
+ * Copyright (c) 2004-2005 David Schultz <das@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$
+ */
+
+#ifndef _FENV_H_
+#define _FENV_H_
+
+#include <sys/_types.h>
+
+#ifndef __fenv_static
+#define __fenv_static static
+#endif
+
+typedef __uint64_t fenv_t;
+typedef __uint64_t fexcept_t;
+
+/* Exception flags */
+#define FE_INVALID 0x00000001
+#define FE_DIVBYZERO 0x00000002
+#define FE_OVERFLOW 0x00000004
+#define FE_UNDERFLOW 0x00000008
+#define FE_INEXACT 0x00000010
+#define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_INEXACT | \
+ FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW)
+
+/*
+ * Rounding modes
+ *
+ * We can't just use the hardware bit values here, because that would
+ * make FE_UPWARD and FE_DOWNWARD negative, which is not allowed.
+ */
+#define FE_TONEAREST 0x0
+#define FE_UPWARD 0x1
+#define FE_DOWNWARD 0x2
+#define FE_TOWARDZERO 0x3
+#define _ROUND_MASK (FE_TONEAREST | FE_DOWNWARD | \
+ FE_UPWARD | FE_TOWARDZERO)
+#define _ROUND_SHIFT 22
+
+__BEGIN_DECLS
+
+/* Default floating-point environment */
+extern const fenv_t __fe_dfl_env;
+#define FE_DFL_ENV (&__fe_dfl_env)
+
+/* We need to be able to map status flag positions to mask flag positions */
+#define _FPUSW_SHIFT 8
+#define _ENABLE_MASK (FE_ALL_EXCEPT << _FPUSW_SHIFT)
+
+#define __mrs_fpcr(__r) __asm __volatile("mrs %0, fpcr" : "=r" (__r))
+#define __msr_fpcr(__r) __asm __volatile("msr fpcr, %0" : : "r" (__r))
+
+#define __mrs_fpsr(__r) __asm __volatile("mrs %0, fpsr" : "=r" (__r))
+#define __msr_fpsr(__r) __asm __volatile("msr fpsr, %0" : : "r" (__r))
+
+__fenv_static __inline int
+feclearexcept(int __excepts)
+{
+ fexcept_t __r;
+
+ __mrs_fpsr(__r);
+ __r &= ~__excepts;
+ __msr_fpsr(__r);
+ return (0);
+}
+
+__fenv_static inline int
+fegetexceptflag(fexcept_t *__flagp, int __excepts)
+{
+ fexcept_t __r;
+
+ __mrs_fpsr(__r);
+ *__flagp = __r & __excepts;
+ return (0);
+}
+
+__fenv_static inline int
+fesetexceptflag(const fexcept_t *__flagp, int __excepts)
+{
+ fexcept_t __r;
+
+ __mrs_fpsr(__r);
+ __r &= ~__excepts;
+ __r |= *__flagp & __excepts;
+ __msr_fpsr(__r);
+ return (0);
+}
+
+__fenv_static inline int
+feraiseexcept(int __excepts)
+{
+ fexcept_t __r;
+
+ __mrs_fpsr(__r);
+ __r |= __excepts;
+ __msr_fpsr(__r);
+ return (0);
+}
+
+__fenv_static inline int
+fetestexcept(int __excepts)
+{
+ fexcept_t __r;
+
+ __mrs_fpsr(__r);
+ return (__r & __excepts);
+}
+
+__fenv_static inline int
+fegetround(void)
+{
+ fenv_t __r;
+
+ __mrs_fpcr(__r);
+ return ((__r >> _ROUND_SHIFT) & _ROUND_MASK);
+}
+
+__fenv_static inline int
+fesetround(int __round)
+{
+ fenv_t __r;
+
+ if (__round & ~_ROUND_MASK)
+ return (-1);
+ __mrs_fpcr(__r);
+ __r &= ~(_ROUND_MASK << _ROUND_SHIFT);
+ __r |= __round << _ROUND_SHIFT;
+ __msr_fpcr(__r);
+ return (0);
+}
+
+__fenv_static inline int
+fegetenv(fenv_t *__envp)
+{
+ fenv_t __r;
+
+ __mrs_fpcr(__r);
+ *__envp = __r & _ENABLE_MASK;
+
+ __mrs_fpsr(__r);
+ *__envp |= __r & (FE_ALL_EXCEPT | (_ROUND_MASK << _ROUND_SHIFT));
+
+ return (0);
+}
+
+__fenv_static inline int
+feholdexcept(fenv_t *__envp)
+{
+ fenv_t __r;
+
+ __mrs_fpcr(__r);
+ *__envp = __r & _ENABLE_MASK;
+ __r &= ~(_ENABLE_MASK);
+ __msr_fpcr(__r);
+
+ __mrs_fpsr(__r);
+ *__envp |= __r & (FE_ALL_EXCEPT | (_ROUND_MASK << _ROUND_SHIFT));
+ __r &= ~(_ENABLE_MASK);
+ __msr_fpsr(__r);
+ return (0);
+}
+
+__fenv_static inline int
+fesetenv(const fenv_t *__envp)
+{
+
+ __msr_fpcr((*__envp) & _ENABLE_MASK);
+ __msr_fpsr((*__envp) & (FE_ALL_EXCEPT | (_ROUND_MASK << _ROUND_SHIFT)));
+ return (0);
+}
+
+__fenv_static inline int
+feupdateenv(const fenv_t *__envp)
+{
+ fexcept_t __r;
+
+ __mrs_fpsr(__r);
+ fesetenv(__envp);
+ feraiseexcept(__r & FE_ALL_EXCEPT);
+ return (0);
+}
+
+#if __BSD_VISIBLE
+
+/* We currently provide no external definitions of the functions below. */
+
+static inline int
+feenableexcept(int __mask)
+{
+ fenv_t __old_r, __new_r;
+
+ __mrs_fpcr(__old_r);
+ __new_r = __old_r | ((__mask & FE_ALL_EXCEPT) << _FPUSW_SHIFT);
+ __msr_fpcr(__new_r);
+ return ((__old_r >> _FPUSW_SHIFT) & FE_ALL_EXCEPT);
+}
+
+static inline int
+fedisableexcept(int __mask)
+{
+ fenv_t __old_r, __new_r;
+
+ __mrs_fpcr(__old_r);
+ __new_r = __old_r & ~((__mask & FE_ALL_EXCEPT) << _FPUSW_SHIFT);
+ __msr_fpcr(__new_r);
+ return ((__old_r >> _FPUSW_SHIFT) & FE_ALL_EXCEPT);
+}
+
+static inline int
+fegetexcept(void)
+{
+ fenv_t __r;
+
+ __mrs_fpcr(__r);
+ return ((__r & _ENABLE_MASK) >> _FPUSW_SHIFT);
+}
+
+#endif /* __BSD_VISIBLE */
+
+__END_DECLS
+
+#endif /* !_FENV_H_ */
diff --git a/lib/msun/ld128/k_expl.h b/lib/msun/ld128/k_expl.h
index a5668fd..e0a48fc 100644
--- a/lib/msun/ld128/k_expl.h
+++ b/lib/msun/ld128/k_expl.h
@@ -322,7 +322,7 @@ __ldexp_cexpl(long double complex z, int expt)
scale2 = 1;
SET_LDBL_EXPSIGN(scale1, BIAS + expt - half_expt);
- return (cpackl(cos(y) * exp_x * scale1 * scale2,
+ return (CMPLXL(cos(y) * exp_x * scale1 * scale2,
sinl(y) * exp_x * scale1 * scale2));
}
#endif /* _COMPLEX_H */
diff --git a/lib/msun/ld80/k_expl.h b/lib/msun/ld80/k_expl.h
index ebfb9a8..9b081fa 100644
--- a/lib/msun/ld80/k_expl.h
+++ b/lib/msun/ld80/k_expl.h
@@ -299,7 +299,7 @@ __ldexp_cexpl(long double complex z, int expt)
scale2 = 1;
SET_LDBL_EXPSIGN(scale1, BIAS + expt - half_expt);
- return (cpackl(cos(y) * exp_x * scale1 * scale2,
+ return (CMPLXL(cos(y) * exp_x * scale1 * scale2,
sinl(y) * exp_x * scale1 * scale2));
}
#endif /* _COMPLEX_H */
diff --git a/lib/msun/man/cexp.3 b/lib/msun/man/cexp.3
index 97e36c1..776e6ce 100644
--- a/lib/msun/man/cexp.3
+++ b/lib/msun/man/cexp.3
@@ -103,7 +103,7 @@ is not finite, the sign of the result is indeterminate.
.Sh SEE ALSO
.Xr complex 3 ,
.Xr exp 3 ,
-.Xr math 3 ,
+.Xr math 3
.Sh STANDARDS
The
.Fn cexp
diff --git a/lib/msun/man/complex.3 b/lib/msun/man/complex.3
index 34eb03e..d286494 100644
--- a/lib/msun/man/complex.3
+++ b/lib/msun/man/complex.3
@@ -103,9 +103,9 @@ ctan tangent
ctanh hyperbolic tangent
.El
.Sh SEE ALSO
-.Xr math 3 ,
.Xr fenv 3 ,
.Xr ieee 3 ,
+.Xr math 3 ,
.Xr tgmath 3
.Rs
.%T "ISO/IEC 9899:TC3"
diff --git a/lib/msun/man/csqrt.3 b/lib/msun/man/csqrt.3
index 1a1dfa0..d8066ae 100644
--- a/lib/msun/man/csqrt.3
+++ b/lib/msun/man/csqrt.3
@@ -85,7 +85,7 @@ an \*(Na is generated, an invalid exception will be thrown.
.Sh SEE ALSO
.Xr cabs 3 ,
.Xr fenv 3 ,
-.Xr math 3 ,
+.Xr math 3
.Sh STANDARDS
The
.Fn csqrt ,
diff --git a/lib/msun/man/j0.3 b/lib/msun/man/j0.3
index 91849da..587b72e 100644
--- a/lib/msun/man/j0.3
+++ b/lib/msun/man/j0.3
@@ -28,7 +28,7 @@
.\" from: @(#)j0.3 6.7 (Berkeley) 4/19/91
.\" $FreeBSD$
.\"
-.Dd February 18, 2008
+.Dd March 10, 2015
.Dt J0 3
.Os
.Sh NAME
@@ -77,24 +77,17 @@
The functions
.Fn j0 ,
.Fn j0f ,
-.Fn j1
+.Fn j1 ,
and
.Fn j1f
-compute the
-.Em Bessel function of the first kind of the order
-0 and the
-.Em order
-1, respectively,
-for the
-real value
+compute the Bessel function of the first kind of orders
+0 and 1 for the real value
.Fa x ;
the functions
.Fn jn
and
.Fn jnf
-compute the
-.Em Bessel function of the first kind of the integer
-.Em order
+compute the Bessel function of the first kind of the integer order
.Fa n
for the real value
.Fa x .
@@ -105,13 +98,8 @@ The functions
.Fn y1 ,
and
.Fn y1f
-compute the linearly independent
-.Em Bessel function of the second kind of the order
-0 and the
-.Em order
-1, respectively,
-for the
-positive
+compute the linearly independent Bessel function of the second kind
+of orders 0 and 1 for the positive
.Em real
value
.Fa x ;
@@ -119,9 +107,7 @@ the functions
.Fn yn
and
.Fn ynf
-compute the
-.Em Bessel function of the second kind for the integer
-.Em order
+compute the Bessel function of the second kind for the integer order
.Fa n
for the positive
.Em real
@@ -141,11 +127,20 @@ and
.Fn ynf .
If
.Fa x
-is negative, these routines will generate an invalid exception and
-return \*(Na.
+is negative, including -\*(If, these routines will generate an invalid
+exception and return \*(Na.
+If
+.Fa x
+is \*(Pm0, these routines
+will generate a divide-by-zero exception and return -\*(If.
If
.Fa x
-is 0 or a sufficiently small positive number, these routines
+is a sufficiently small positive number, then
+.Fn y1 ,
+.Fn y1f ,
+.Fn yn ,
+and
+.Fn ynf
will generate an overflow exception and return -\*(If.
.Sh SEE ALSO
.Xr math 3
diff --git a/lib/msun/man/lgamma.3 b/lib/msun/man/lgamma.3
index d244722..c8a22a2 100644
--- a/lib/msun/man/lgamma.3
+++ b/lib/msun/man/lgamma.3
@@ -99,7 +99,7 @@ returns the sign of \(*G(x).
and
.Fn lgammal_r x signgamp
provide the same functionality as
-.Fn lgamma x ,
+.Fn lgamma x ,
.Fn lgammaf x ,
and
.Fn lgammal x ,
@@ -124,7 +124,6 @@ are deprecated aliases for
and
.Fn lgammaf_r ,
respectively.
-
.Sh IDIOSYNCRASIES
Do not use the expression
.Dq Li signgam\(**exp(lgamma(x))
diff --git a/lib/msun/man/nextafter.3 b/lib/msun/man/nextafter.3
index c8c4aa3..01c472d 100644
--- a/lib/msun/man/nextafter.3
+++ b/lib/msun/man/nextafter.3
@@ -78,11 +78,11 @@ routines conform to
They implement the Nextafter function recommended by
.St -ieee754 ,
with the extension that
-.Fn nextafter +0.0, -0.0
+.Fn nextafter "+0.0" "-0.0"
returns
.Li -0.0 ,
and
-.Fn nextafter -0.0, +0.0
+.Fn nextafter "-0.0" "+0.0"
returns
.Li +0.0 .
.Sh HISTORY
diff --git a/lib/msun/man/sin.3 b/lib/msun/man/sin.3
index c7daf09..4a5352e 100644
--- a/lib/msun/man/sin.3
+++ b/lib/msun/man/sin.3
@@ -70,9 +70,9 @@ functions return the sine value.
.Xr asin 3 ,
.Xr atan 3 ,
.Xr atan2 3 ,
-.Xr csin 3 ,
.Xr cos 3 ,
.Xr cosh 3 ,
+.Xr csin 3 ,
.Xr math 3 ,
.Xr sinh 3 ,
.Xr tan 3 ,
diff --git a/lib/msun/src/catrig.c b/lib/msun/src/catrig.c
index 200977c..c0f5f55 100644
--- a/lib/msun/src/catrig.c
+++ b/lib/msun/src/catrig.c
@@ -286,19 +286,19 @@ casinh(double complex z)
if (isnan(x) || isnan(y)) {
/* casinh(+-Inf + I*NaN) = +-Inf + I*NaN */
if (isinf(x))
- return (cpack(x, y + y));
+ return (CMPLX(x, y + y));
/* casinh(NaN + I*+-Inf) = opt(+-)Inf + I*NaN */
if (isinf(y))
- return (cpack(y, x + x));
+ return (CMPLX(y, x + x));
/* casinh(NaN + I*0) = NaN + I*0 */
if (y == 0)
- return (cpack(x + x, y));
+ return (CMPLX(x + x, y));
/*
* All other cases involving NaN return NaN + I*NaN.
* C99 leaves it optional whether to raise invalid if one of
* the arguments is not NaN, so we opt not to raise it.
*/
- return (cpack(x + 0.0L + (y + 0), x + 0.0L + (y + 0)));
+ return (CMPLX(x + 0.0L + (y + 0), x + 0.0L + (y + 0)));
}
if (ax > RECIP_EPSILON || ay > RECIP_EPSILON) {
@@ -307,7 +307,7 @@ casinh(double complex z)
w = clog_for_large_values(z) + m_ln2;
else
w = clog_for_large_values(-z) + m_ln2;
- return (cpack(copysign(creal(w), x), copysign(cimag(w), y)));
+ return (CMPLX(copysign(creal(w), x), copysign(cimag(w), y)));
}
/* Avoid spuriously raising inexact for z = 0. */
@@ -325,7 +325,7 @@ casinh(double complex z)
ry = asin(B);
else
ry = atan2(new_y, sqrt_A2my2);
- return (cpack(copysign(rx, x), copysign(ry, y)));
+ return (CMPLX(copysign(rx, x), copysign(ry, y)));
}
/*
@@ -335,9 +335,9 @@ casinh(double complex z)
double complex
casin(double complex z)
{
- double complex w = casinh(cpack(cimag(z), creal(z)));
+ double complex w = casinh(CMPLX(cimag(z), creal(z)));
- return (cpack(cimag(w), creal(w)));
+ return (CMPLX(cimag(w), creal(w)));
}
/*
@@ -370,19 +370,19 @@ cacos(double complex z)
if (isnan(x) || isnan(y)) {
/* cacos(+-Inf + I*NaN) = NaN + I*opt(-)Inf */
if (isinf(x))
- return (cpack(y + y, -INFINITY));
+ return (CMPLX(y + y, -INFINITY));
/* cacos(NaN + I*+-Inf) = NaN + I*-+Inf */
if (isinf(y))
- return (cpack(x + x, -y));
+ return (CMPLX(x + x, -y));
/* cacos(0 + I*NaN) = PI/2 + I*NaN with inexact */
if (x == 0)
- return (cpack(pio2_hi + pio2_lo, y + y));
+ return (CMPLX(pio2_hi + pio2_lo, y + y));
/*
* All other cases involving NaN return NaN + I*NaN.
* C99 leaves it optional whether to raise invalid if one of
* the arguments is not NaN, so we opt not to raise it.
*/
- return (cpack(x + 0.0L + (y + 0), x + 0.0L + (y + 0)));
+ return (CMPLX(x + 0.0L + (y + 0), x + 0.0L + (y + 0)));
}
if (ax > RECIP_EPSILON || ay > RECIP_EPSILON) {
@@ -392,18 +392,18 @@ cacos(double complex z)
ry = creal(w) + m_ln2;
if (sy == 0)
ry = -ry;
- return (cpack(rx, ry));
+ return (CMPLX(rx, ry));
}
/* Avoid spuriously raising inexact for z = 1. */
if (x == 1 && y == 0)
- return (cpack(0, -y));
+ return (CMPLX(0, -y));
/* All remaining cases are inexact. */
raise_inexact();
if (ax < SQRT_6_EPSILON / 4 && ay < SQRT_6_EPSILON / 4)
- return (cpack(pio2_hi - (x - pio2_lo), -y));
+ return (CMPLX(pio2_hi - (x - pio2_lo), -y));
do_hard_work(ay, ax, &ry, &B_is_usable, &B, &sqrt_A2mx2, &new_x);
if (B_is_usable) {
@@ -419,7 +419,7 @@ cacos(double complex z)
}
if (sy == 0)
ry = -ry;
- return (cpack(rx, ry));
+ return (CMPLX(rx, ry));
}
/*
@@ -437,15 +437,15 @@ cacosh(double complex z)
ry = cimag(w);
/* cacosh(NaN + I*NaN) = NaN + I*NaN */
if (isnan(rx) && isnan(ry))
- return (cpack(ry, rx));
+ return (CMPLX(ry, rx));
/* cacosh(NaN + I*+-Inf) = +Inf + I*NaN */
/* cacosh(+-Inf + I*NaN) = +Inf + I*NaN */
if (isnan(rx))
- return (cpack(fabs(ry), rx));
+ return (CMPLX(fabs(ry), rx));
/* cacosh(0 + I*NaN) = NaN + I*NaN */
if (isnan(ry))
- return (cpack(ry, ry));
- return (cpack(fabs(ry), copysign(rx, cimag(z))));
+ return (CMPLX(ry, ry));
+ return (CMPLX(fabs(ry), copysign(rx, cimag(z))));
}
/*
@@ -475,16 +475,16 @@ clog_for_large_values(double complex z)
* this method is still poor since it is uneccessarily slow.
*/
if (ax > DBL_MAX / 2)
- return (cpack(log(hypot(x / m_e, y / m_e)) + 1, atan2(y, x)));
+ return (CMPLX(log(hypot(x / m_e, y / m_e)) + 1, atan2(y, x)));
/*
* Avoid overflow when x or y is large. Avoid underflow when x or
* y is small.
*/
if (ax > QUARTER_SQRT_MAX || ay < SQRT_MIN)
- return (cpack(log(hypot(x, y)), atan2(y, x)));
+ return (CMPLX(log(hypot(x, y)), atan2(y, x)));
- return (cpack(log(ax * ax + ay * ay) / 2, atan2(y, x)));
+ return (CMPLX(log(ax * ax + ay * ay) / 2, atan2(y, x)));
}
/*
@@ -575,30 +575,30 @@ catanh(double complex z)
/* This helps handle many cases. */
if (y == 0 && ax <= 1)
- return (cpack(atanh(x), y));
+ return (CMPLX(atanh(x), y));
/* To ensure the same accuracy as atan(), and to filter out z = 0. */
if (x == 0)
- return (cpack(x, atan(y)));
+ return (CMPLX(x, atan(y)));
if (isnan(x) || isnan(y)) {
/* catanh(+-Inf + I*NaN) = +-0 + I*NaN */
if (isinf(x))
- return (cpack(copysign(0, x), y + y));
+ return (CMPLX(copysign(0, x), y + y));
/* catanh(NaN + I*+-Inf) = sign(NaN)0 + I*+-PI/2 */
if (isinf(y))
- return (cpack(copysign(0, x),
+ return (CMPLX(copysign(0, x),
copysign(pio2_hi + pio2_lo, y)));
/*
* All other cases involving NaN return NaN + I*NaN.
* C99 leaves it optional whether to raise invalid if one of
* the arguments is not NaN, so we opt not to raise it.
*/
- return (cpack(x + 0.0L + (y + 0), x + 0.0L + (y + 0)));
+ return (CMPLX(x + 0.0L + (y + 0), x + 0.0L + (y + 0)));
}
if (ax > RECIP_EPSILON || ay > RECIP_EPSILON)
- return (cpack(real_part_reciprocal(x, y),
+ return (CMPLX(real_part_reciprocal(x, y),
copysign(pio2_hi + pio2_lo, y)));
if (ax < SQRT_3_EPSILON / 2 && ay < SQRT_3_EPSILON / 2) {
@@ -623,7 +623,7 @@ catanh(double complex z)
else
ry = atan2(2 * ay, (1 - ax) * (1 + ax) - ay * ay) / 2;
- return (cpack(copysign(rx, x), copysign(ry, y)));
+ return (CMPLX(copysign(rx, x), copysign(ry, y)));
}
/*
@@ -633,7 +633,7 @@ catanh(double complex z)
double complex
catan(double complex z)
{
- double complex w = catanh(cpack(cimag(z), creal(z)));
+ double complex w = catanh(CMPLX(cimag(z), creal(z)));
- return (cpack(cimag(w), creal(w)));
+ return (CMPLX(cimag(w), creal(w)));
}
diff --git a/lib/msun/src/catrigf.c b/lib/msun/src/catrigf.c
index 08ebef7..ca84ce2 100644
--- a/lib/msun/src/catrigf.c
+++ b/lib/msun/src/catrigf.c
@@ -156,12 +156,12 @@ casinhf(float complex z)
if (isnan(x) || isnan(y)) {
if (isinf(x))
- return (cpackf(x, y + y));
+ return (CMPLXF(x, y + y));
if (isinf(y))
- return (cpackf(y, x + x));
+ return (CMPLXF(y, x + x));
if (y == 0)
- return (cpackf(x + x, y));
- return (cpackf(x + 0.0L + (y + 0), x + 0.0L + (y + 0)));
+ return (CMPLXF(x + x, y));
+ return (CMPLXF(x + 0.0L + (y + 0), x + 0.0L + (y + 0)));
}
if (ax > RECIP_EPSILON || ay > RECIP_EPSILON) {
@@ -169,7 +169,7 @@ casinhf(float complex z)
w = clog_for_large_values(z) + m_ln2;
else
w = clog_for_large_values(-z) + m_ln2;
- return (cpackf(copysignf(crealf(w), x),
+ return (CMPLXF(copysignf(crealf(w), x),
copysignf(cimagf(w), y)));
}
@@ -186,15 +186,15 @@ casinhf(float complex z)
ry = asinf(B);
else
ry = atan2f(new_y, sqrt_A2my2);
- return (cpackf(copysignf(rx, x), copysignf(ry, y)));
+ return (CMPLXF(copysignf(rx, x), copysignf(ry, y)));
}
float complex
casinf(float complex z)
{
- float complex w = casinhf(cpackf(cimagf(z), crealf(z)));
+ float complex w = casinhf(CMPLXF(cimagf(z), crealf(z)));
- return (cpackf(cimagf(w), crealf(w)));
+ return (CMPLXF(cimagf(w), crealf(w)));
}
float complex
@@ -214,12 +214,12 @@ cacosf(float complex z)
if (isnan(x) || isnan(y)) {
if (isinf(x))
- return (cpackf(y + y, -INFINITY));
+ return (CMPLXF(y + y, -INFINITY));
if (isinf(y))
- return (cpackf(x + x, -y));
+ return (CMPLXF(x + x, -y));
if (x == 0)
- return (cpackf(pio2_hi + pio2_lo, y + y));
- return (cpackf(x + 0.0L + (y + 0), x + 0.0L + (y + 0)));
+ return (CMPLXF(pio2_hi + pio2_lo, y + y));
+ return (CMPLXF(x + 0.0L + (y + 0), x + 0.0L + (y + 0)));
}
if (ax > RECIP_EPSILON || ay > RECIP_EPSILON) {
@@ -228,16 +228,16 @@ cacosf(float complex z)
ry = crealf(w) + m_ln2;
if (sy == 0)
ry = -ry;
- return (cpackf(rx, ry));
+ return (CMPLXF(rx, ry));
}
if (x == 1 && y == 0)
- return (cpackf(0, -y));
+ return (CMPLXF(0, -y));
raise_inexact();
if (ax < SQRT_6_EPSILON / 4 && ay < SQRT_6_EPSILON / 4)
- return (cpackf(pio2_hi - (x - pio2_lo), -y));
+ return (CMPLXF(pio2_hi - (x - pio2_lo), -y));
do_hard_work(ay, ax, &ry, &B_is_usable, &B, &sqrt_A2mx2, &new_x);
if (B_is_usable) {
@@ -253,7 +253,7 @@ cacosf(float complex z)
}
if (sy == 0)
ry = -ry;
- return (cpackf(rx, ry));
+ return (CMPLXF(rx, ry));
}
float complex
@@ -266,12 +266,12 @@ cacoshf(float complex z)
rx = crealf(w);
ry = cimagf(w);
if (isnan(rx) && isnan(ry))
- return (cpackf(ry, rx));
+ return (CMPLXF(ry, rx));
if (isnan(rx))
- return (cpackf(fabsf(ry), rx));
+ return (CMPLXF(fabsf(ry), rx));
if (isnan(ry))
- return (cpackf(ry, ry));
- return (cpackf(fabsf(ry), copysignf(rx, cimagf(z))));
+ return (CMPLXF(ry, ry));
+ return (CMPLXF(fabsf(ry), copysignf(rx, cimagf(z))));
}
static float complex
@@ -291,13 +291,13 @@ clog_for_large_values(float complex z)
}
if (ax > FLT_MAX / 2)
- return (cpackf(logf(hypotf(x / m_e, y / m_e)) + 1,
+ return (CMPLXF(logf(hypotf(x / m_e, y / m_e)) + 1,
atan2f(y, x)));
if (ax > QUARTER_SQRT_MAX || ay < SQRT_MIN)
- return (cpackf(logf(hypotf(x, y)), atan2f(y, x)));
+ return (CMPLXF(logf(hypotf(x, y)), atan2f(y, x)));
- return (cpackf(logf(ax * ax + ay * ay) / 2, atan2f(y, x)));
+ return (CMPLXF(logf(ax * ax + ay * ay) / 2, atan2f(y, x)));
}
static inline float
@@ -346,22 +346,22 @@ catanhf(float complex z)
ay = fabsf(y);
if (y == 0 && ax <= 1)
- return (cpackf(atanhf(x), y));
+ return (CMPLXF(atanhf(x), y));
if (x == 0)
- return (cpackf(x, atanf(y)));
+ return (CMPLXF(x, atanf(y)));
if (isnan(x) || isnan(y)) {
if (isinf(x))
- return (cpackf(copysignf(0, x), y + y));
+ return (CMPLXF(copysignf(0, x), y + y));
if (isinf(y))
- return (cpackf(copysignf(0, x),
+ return (CMPLXF(copysignf(0, x),
copysignf(pio2_hi + pio2_lo, y)));
- return (cpackf(x + 0.0L + (y + 0), x + 0.0L + (y + 0)));
+ return (CMPLXF(x + 0.0L + (y + 0), x + 0.0L + (y + 0)));
}
if (ax > RECIP_EPSILON || ay > RECIP_EPSILON)
- return (cpackf(real_part_reciprocal(x, y),
+ return (CMPLXF(real_part_reciprocal(x, y),
copysignf(pio2_hi + pio2_lo, y)));
if (ax < SQRT_3_EPSILON / 2 && ay < SQRT_3_EPSILON / 2) {
@@ -381,13 +381,13 @@ catanhf(float complex z)
else
ry = atan2f(2 * ay, (1 - ax) * (1 + ax) - ay * ay) / 2;
- return (cpackf(copysignf(rx, x), copysignf(ry, y)));
+ return (CMPLXF(copysignf(rx, x), copysignf(ry, y)));
}
float complex
catanf(float complex z)
{
- float complex w = catanhf(cpackf(cimagf(z), crealf(z)));
+ float complex w = catanhf(CMPLXF(cimagf(z), crealf(z)));
- return (cpackf(cimagf(w), crealf(w)));
+ return (CMPLXF(cimagf(w), crealf(w)));
}
diff --git a/lib/msun/src/e_j0.c b/lib/msun/src/e_j0.c
index 8320f25..a253ed1 100644
--- a/lib/msun/src/e_j0.c
+++ b/lib/msun/src/e_j0.c
@@ -62,7 +62,9 @@ __FBSDID("$FreeBSD$");
#include "math.h"
#include "math_private.h"
-static double pzero(double), qzero(double);
+static __inline double pzero(double), qzero(double);
+
+static const volatile double vone = 1, vzero = 0;
static const double
huge = 1e300,
@@ -115,7 +117,7 @@ __ieee754_j0(double x)
if(ix<0x3f200000) { /* |x| < 2**-13 */
if(huge+x>one) { /* raise inexact if x != 0 */
if(ix<0x3e400000) return one; /* |x|<2**-27 */
- else return one - 0.25*x*x;
+ else return one - x*x/4;
}
}
z = x*x;
@@ -150,10 +152,16 @@ __ieee754_y0(double x)
EXTRACT_WORDS(hx,lx,x);
ix = 0x7fffffff&hx;
- /* Y0(NaN) is NaN, y0(-inf) is Nan, y0(inf) is 0 */
- if(ix>=0x7ff00000) return one/(x+x*x);
- if((ix|lx)==0) return -one/zero;
- if(hx<0) return zero/zero;
+ /*
+ * y0(NaN) = NaN.
+ * y0(Inf) = 0.
+ * y0(-Inf) = NaN and raise invalid exception.
+ */
+ if(ix>=0x7ff00000) return vone/(x+x*x);
+ /* y0(+-0) = -inf and raise divide-by-zero exception. */
+ if((ix|lx)==0) return -one/vzero;
+ /* y0(x<0) = NaN and raise invalid exception. */
+ if(hx<0) return vzero/vzero;
if(ix >= 0x40000000) { /* |x| >= 2.0 */
/* y0(x) = sqrt(2/(pi*x))*(p0(x)*sin(x0)+q0(x)*cos(x0))
* where x0 = x-pi/4
@@ -268,7 +276,8 @@ static const double pS2[5] = {
1.46576176948256193810e+01, /* 0x402D50B3, 0x44391809 */
};
- static double pzero(double x)
+static __inline double
+pzero(double x)
{
const double *p,*q;
double z,r,s;
@@ -278,7 +287,7 @@ static const double pS2[5] = {
if(ix>=0x40200000) {p = pR8; q= pS8;}
else if(ix>=0x40122E8B){p = pR5; q= pS5;}
else if(ix>=0x4006DB6D){p = pR3; q= pS3;}
- else if(ix>=0x40000000){p = pR2; q= pS2;}
+ else {p = pR2; q= pS2;} /* ix>=0x40000000 */
z = one/(x*x);
r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4]))));
@@ -363,7 +372,8 @@ static const double qS2[6] = {
-5.31095493882666946917e+00, /* 0xC0153E6A, 0xF8B32931 */
};
- static double qzero(double x)
+static __inline double
+qzero(double x)
{
const double *p,*q;
double s,r,z;
@@ -373,7 +383,7 @@ static const double qS2[6] = {
if(ix>=0x40200000) {p = qR8; q= qS8;}
else if(ix>=0x40122E8B){p = qR5; q= qS5;}
else if(ix>=0x4006DB6D){p = qR3; q= qS3;}
- else if(ix>=0x40000000){p = qR2; q= qS2;}
+ else {p = qR2; q= qS2;} /* ix>=0x40000000 */
z = one/(x*x);
r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*(q[4]+z*q[5])))));
diff --git a/lib/msun/src/e_j0f.c b/lib/msun/src/e_j0f.c
index c45faf3..3e2f7e8 100644
--- a/lib/msun/src/e_j0f.c
+++ b/lib/msun/src/e_j0f.c
@@ -16,10 +16,16 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
+/*
+ * See e_j0.c for complete comments.
+ */
+
#include "math.h"
#include "math_private.h"
-static float pzerof(float), qzerof(float);
+static __inline float pzerof(float), qzerof(float);
+
+static const volatile float vone = 1, vzero = 0;
static const float
huge = 1e30,
@@ -62,17 +68,17 @@ __ieee754_j0f(float x)
* j0(x) = 1/sqrt(pi) * (P(0,x)*cc - Q(0,x)*ss) / sqrt(x)
* y0(x) = 1/sqrt(pi) * (P(0,x)*ss + Q(0,x)*cc) / sqrt(x)
*/
- if(ix>0x80000000) z = (invsqrtpi*cc)/sqrtf(x);
+ if(ix>0x58000000) z = (invsqrtpi*cc)/sqrtf(x); /* |x|>2**49 */
else {
u = pzerof(x); v = qzerof(x);
z = invsqrtpi*(u*cc-v*ss)/sqrtf(x);
}
return z;
}
- if(ix<0x39000000) { /* |x| < 2**-13 */
+ if(ix<0x3b000000) { /* |x| < 2**-9 */
if(huge+x>one) { /* raise inexact if x != 0 */
- if(ix<0x32000000) return one; /* |x|<2**-27 */
- else return one - (float)0.25*x*x;
+ if(ix<0x39800000) return one; /* |x|<2**-12 */
+ else return one - x*x/4;
}
}
z = x*x;
@@ -107,10 +113,9 @@ __ieee754_y0f(float x)
GET_FLOAT_WORD(hx,x);
ix = 0x7fffffff&hx;
- /* Y0(NaN) is NaN, y0(-inf) is Nan, y0(inf) is 0 */
- if(ix>=0x7f800000) return one/(x+x*x);
- if(ix==0) return -one/zero;
- if(hx<0) return zero/zero;
+ if(ix>=0x7f800000) return vone/(x+x*x);
+ if(ix==0) return -one/vzero;
+ if(hx<0) return vzero/vzero;
if(ix >= 0x40000000) { /* |x| >= 2.0 */
/* y0(x) = sqrt(2/(pi*x))*(p0(x)*sin(x0)+q0(x)*cos(x0))
* where x0 = x-pi/4
@@ -136,14 +141,14 @@ __ieee754_y0f(float x)
if ((s*c)<zero) cc = z/ss;
else ss = z/cc;
}
- if(ix>0x80000000) z = (invsqrtpi*ss)/sqrtf(x);
+ if(ix>0x58000000) z = (invsqrtpi*ss)/sqrtf(x); /* |x|>2**49 */
else {
u = pzerof(x); v = qzerof(x);
z = invsqrtpi*(u*ss+v*cc)/sqrtf(x);
}
return z;
}
- if(ix<=0x32000000) { /* x < 2**-27 */
+ if(ix<=0x39000000) { /* x < 2**-13 */
return(u00 + tpi*__ieee754_logf(x));
}
z = x*x;
@@ -224,7 +229,8 @@ static const float pS2[5] = {
1.4657617569e+01, /* 0x416a859a */
};
- static float pzerof(float x)
+static __inline float
+pzerof(float x)
{
const float *p,*q;
float z,r,s;
@@ -232,9 +238,9 @@ static const float pS2[5] = {
GET_FLOAT_WORD(ix,x);
ix &= 0x7fffffff;
if(ix>=0x41000000) {p = pR8; q= pS8;}
- else if(ix>=0x40f71c58){p = pR5; q= pS5;}
- else if(ix>=0x4036db68){p = pR3; q= pS3;}
- else if(ix>=0x40000000){p = pR2; q= pS2;}
+ else if(ix>=0x409173eb){p = pR5; q= pS5;}
+ else if(ix>=0x4036d917){p = pR3; q= pS3;}
+ else {p = pR2; q= pS2;} /* ix>=0x40000000 */
z = one/(x*x);
r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4]))));
@@ -319,7 +325,8 @@ static const float qS2[6] = {
-5.3109550476e+00, /* 0xc0a9f358 */
};
- static float qzerof(float x)
+static __inline float
+qzerof(float x)
{
const float *p,*q;
float s,r,z;
@@ -327,9 +334,9 @@ static const float qS2[6] = {
GET_FLOAT_WORD(ix,x);
ix &= 0x7fffffff;
if(ix>=0x41000000) {p = qR8; q= qS8;}
- else if(ix>=0x40f71c58){p = qR5; q= qS5;}
- else if(ix>=0x4036db68){p = qR3; q= qS3;}
- else if(ix>=0x40000000){p = qR2; q= qS2;}
+ else if(ix>=0x409173eb){p = qR5; q= qS5;}
+ else if(ix>=0x4036d917){p = qR3; q= qS3;}
+ else {p = qR2; q= qS2;} /* ix>=0x40000000 */
z = one/(x*x);
r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*(q[4]+z*q[5])))));
diff --git a/lib/msun/src/e_j1.c b/lib/msun/src/e_j1.c
index 63800ad..74a7c69 100644
--- a/lib/msun/src/e_j1.c
+++ b/lib/msun/src/e_j1.c
@@ -62,7 +62,9 @@ __FBSDID("$FreeBSD$");
#include "math.h"
#include "math_private.h"
-static double pone(double), qone(double);
+static __inline double pone(double), qone(double);
+
+static const volatile double vone = 1, vzero = 0;
static const double
huge = 1e300,
@@ -147,10 +149,16 @@ __ieee754_y1(double x)
EXTRACT_WORDS(hx,lx,x);
ix = 0x7fffffff&hx;
- /* if Y1(NaN) is NaN, Y1(-inf) is NaN, Y1(inf) is 0 */
- if(ix>=0x7ff00000) return one/(x+x*x);
- if((ix|lx)==0) return -one/zero;
- if(hx<0) return zero/zero;
+ /*
+ * y1(NaN) = NaN.
+ * y1(Inf) = 0.
+ * y1(-Inf) = NaN and raise invalid exception.
+ */
+ if(ix>=0x7ff00000) return vone/(x+x*x);
+ /* y1(+-0) = -inf and raise divide-by-zero exception. */
+ if((ix|lx)==0) return -one/vzero;
+ /* y1(x<0) = NaN and raise invalid exception. */
+ if(hx<0) return vzero/vzero;
if(ix >= 0x40000000) { /* |x| >= 2.0 */
s = sin(x);
c = cos(x);
@@ -262,7 +270,8 @@ static const double ps2[5] = {
8.36463893371618283368e+00, /* 0x4020BAB1, 0xF44E5192 */
};
- static double pone(double x)
+static __inline double
+pone(double x)
{
const double *p,*q;
double z,r,s;
@@ -272,7 +281,7 @@ static const double ps2[5] = {
if(ix>=0x40200000) {p = pr8; q= ps8;}
else if(ix>=0x40122E8B){p = pr5; q= ps5;}
else if(ix>=0x4006DB6D){p = pr3; q= ps3;}
- else if(ix>=0x40000000){p = pr2; q= ps2;}
+ else {p = pr2; q= ps2;} /* ix>=0x40000000 */
z = one/(x*x);
r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4]))));
@@ -358,7 +367,8 @@ static const double qs2[6] = {
-4.95949898822628210127e+00, /* 0xC013D686, 0xE71BE86B */
};
- static double qone(double x)
+static __inline double
+qone(double x)
{
const double *p,*q;
double s,r,z;
@@ -368,7 +378,7 @@ static const double qs2[6] = {
if(ix>=0x40200000) {p = qr8; q= qs8;}
else if(ix>=0x40122E8B){p = qr5; q= qs5;}
else if(ix>=0x4006DB6D){p = qr3; q= qs3;}
- else if(ix>=0x40000000){p = qr2; q= qs2;}
+ else {p = qr2; q= qs2;} /* ix>=0x40000000 */
z = one/(x*x);
r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*(q[4]+z*q[5])))));
diff --git a/lib/msun/src/e_j1f.c b/lib/msun/src/e_j1f.c
index 88e2d83..ec7f381 100644
--- a/lib/msun/src/e_j1f.c
+++ b/lib/msun/src/e_j1f.c
@@ -16,10 +16,16 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
+/*
+ * See e_j1.c for complete comments.
+ */
+
#include "math.h"
#include "math_private.h"
-static float ponef(float), qonef(float);
+static __inline float ponef(float), qonef(float);
+
+static const volatile float vone = 1, vzero = 0;
static const float
huge = 1e30,
@@ -63,7 +69,7 @@ __ieee754_j1f(float x)
* j1(x) = 1/sqrt(pi) * (P(1,x)*cc - Q(1,x)*ss) / sqrt(x)
* y1(x) = 1/sqrt(pi) * (P(1,x)*ss + Q(1,x)*cc) / sqrt(x)
*/
- if(ix>0x80000000) z = (invsqrtpi*cc)/sqrtf(y);
+ if(ix>0x58000000) z = (invsqrtpi*cc)/sqrtf(y); /* |x|>2**49 */
else {
u = ponef(y); v = qonef(y);
z = invsqrtpi*(u*cc-v*ss)/sqrtf(y);
@@ -71,7 +77,7 @@ __ieee754_j1f(float x)
if(hx<0) return -z;
else return z;
}
- if(ix<0x32000000) { /* |x|<2**-27 */
+ if(ix<0x39000000) { /* |x|<2**-13 */
if(huge+x>one) return (float)0.5*x;/* inexact if x!=0 necessary */
}
z = x*x;
@@ -104,10 +110,9 @@ __ieee754_y1f(float x)
GET_FLOAT_WORD(hx,x);
ix = 0x7fffffff&hx;
- /* if Y1(NaN) is NaN, Y1(-inf) is NaN, Y1(inf) is 0 */
- if(ix>=0x7f800000) return one/(x+x*x);
- if(ix==0) return -one/zero;
- if(hx<0) return zero/zero;
+ if(ix>=0x7f800000) return vone/(x+x*x);
+ if(ix==0) return -one/vzero;
+ if(hx<0) return vzero/vzero;
if(ix >= 0x40000000) { /* |x| >= 2.0 */
s = sinf(x);
c = cosf(x);
@@ -129,14 +134,14 @@ __ieee754_y1f(float x)
* sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
* to compute the worse one.
*/
- if(ix>0x48000000) z = (invsqrtpi*ss)/sqrtf(x);
+ if(ix>0x58000000) z = (invsqrtpi*ss)/sqrtf(x); /* |x|>2**49 */
else {
u = ponef(x); v = qonef(x);
z = invsqrtpi*(u*ss+v*cc)/sqrtf(x);
}
return z;
}
- if(ix<=0x24800000) { /* x < 2**-54 */
+ if(ix<=0x33000000) { /* x < 2**-25 */
return(-tpi/x);
}
z = x*x;
@@ -219,7 +224,8 @@ static const float ps2[5] = {
8.3646392822e+00, /* 0x4105d590 */
};
- static float ponef(float x)
+static __inline float
+ponef(float x)
{
const float *p,*q;
float z,r,s;
@@ -227,9 +233,9 @@ static const float ps2[5] = {
GET_FLOAT_WORD(ix,x);
ix &= 0x7fffffff;
if(ix>=0x41000000) {p = pr8; q= ps8;}
- else if(ix>=0x40f71c58){p = pr5; q= ps5;}
- else if(ix>=0x4036db68){p = pr3; q= ps3;}
- else if(ix>=0x40000000){p = pr2; q= ps2;}
+ else if(ix>=0x409173eb){p = pr5; q= ps5;}
+ else if(ix>=0x4036d917){p = pr3; q= ps3;}
+ else {p = pr2; q= ps2;} /* ix>=0x40000000 */
z = one/(x*x);
r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4]))));
@@ -315,17 +321,18 @@ static const float qs2[6] = {
-4.9594988823e+00, /* 0xc09eb437 */
};
- static float qonef(float x)
+static __inline float
+qonef(float x)
{
const float *p,*q;
float s,r,z;
int32_t ix;
GET_FLOAT_WORD(ix,x);
ix &= 0x7fffffff;
- if(ix>=0x40200000) {p = qr8; q= qs8;}
- else if(ix>=0x40f71c58){p = qr5; q= qs5;}
- else if(ix>=0x4036db68){p = qr3; q= qs3;}
- else if(ix>=0x40000000){p = qr2; q= qs2;}
+ if(ix>=0x41000000) {p = qr8; q= qs8;}
+ else if(ix>=0x409173eb){p = qr5; q= qs5;}
+ else if(ix>=0x4036d917){p = qr3; q= qs3;}
+ else {p = qr2; q= qs2;} /* ix>=0x40000000 */
z = one/(x*x);
r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*(q[4]+z*q[5])))));
diff --git a/lib/msun/src/e_jn.c b/lib/msun/src/e_jn.c
index 8b0bc62..eefd4ff 100644
--- a/lib/msun/src/e_jn.c
+++ b/lib/msun/src/e_jn.c
@@ -43,6 +43,8 @@ __FBSDID("$FreeBSD$");
#include "math.h"
#include "math_private.h"
+static const volatile double vone = 1, vzero = 0;
+
static const double
invsqrtpi= 5.64189583547756279280e-01, /* 0x3FE20DD7, 0x50429B6D */
two = 2.00000000000000000000e+00, /* 0x40000000, 0x00000000 */
@@ -220,10 +222,12 @@ __ieee754_yn(int n, double x)
EXTRACT_WORDS(hx,lx,x);
ix = 0x7fffffff&hx;
- /* if Y(n,NaN) is NaN */
+ /* yn(n,NaN) = NaN */
if((ix|((u_int32_t)(lx|-lx))>>31)>0x7ff00000) return x+x;
- if((ix|lx)==0) return -one/zero;
- if(hx<0) return zero/zero;
+ /* yn(n,+-0) = -inf and raise divide-by-zero exception. */
+ if((ix|lx)==0) return -one/vzero;
+ /* yn(n,x<0) = NaN and raise invalid exception. */
+ if(hx<0) return vzero/vzero;
sign = 1;
if(n<0){
n = -n;
diff --git a/lib/msun/src/e_jnf.c b/lib/msun/src/e_jnf.c
index f564aec..965feeb 100644
--- a/lib/msun/src/e_jnf.c
+++ b/lib/msun/src/e_jnf.c
@@ -16,9 +16,15 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
+/*
+ * See e_jn.c for complete comments.
+ */
+
#include "math.h"
#include "math_private.h"
+static const volatile float vone = 1, vzero = 0;
+
static const float
two = 2.0000000000e+00, /* 0x40000000 */
one = 1.0000000000e+00; /* 0x3F800000 */
@@ -172,10 +178,9 @@ __ieee754_ynf(int n, float x)
GET_FLOAT_WORD(hx,x);
ix = 0x7fffffff&hx;
- /* if Y(n,NaN) is NaN */
if(ix>0x7f800000) return x+x;
- if(ix==0) return -one/zero;
- if(hx<0) return zero/zero;
+ if(ix==0) return -one/vzero;
+ if(hx<0) return vzero/vzero;
sign = 1;
if(n<0){
n = -n;
diff --git a/lib/msun/src/k_exp.c b/lib/msun/src/k_exp.c
index f592f69..ecef54c 100644
--- a/lib/msun/src/k_exp.c
+++ b/lib/msun/src/k_exp.c
@@ -103,6 +103,6 @@ __ldexp_cexp(double complex z, int expt)
half_expt = expt - half_expt;
INSERT_WORDS(scale2, (0x3ff + half_expt) << 20, 0);
- return (cpack(cos(y) * exp_x * scale1 * scale2,
+ return (CMPLX(cos(y) * exp_x * scale1 * scale2,
sin(y) * exp_x * scale1 * scale2));
}
diff --git a/lib/msun/src/k_expf.c b/lib/msun/src/k_expf.c
index 548a008..f8c254d 100644
--- a/lib/msun/src/k_expf.c
+++ b/lib/msun/src/k_expf.c
@@ -82,6 +82,6 @@ __ldexp_cexpf(float complex z, int expt)
half_expt = expt - half_expt;
SET_FLOAT_WORD(scale2, (0x7f + half_expt) << 23);
- return (cpackf(cosf(y) * exp_x * scale1 * scale2,
+ return (CMPLXF(cosf(y) * exp_x * scale1 * scale2,
sinf(y) * exp_x * scale1 * scale2));
}
diff --git a/lib/msun/src/math_private.h b/lib/msun/src/math_private.h
index 8af2c65..afaf201 100644
--- a/lib/msun/src/math_private.h
+++ b/lib/msun/src/math_private.h
@@ -454,9 +454,15 @@ typedef union {
* (0.0+I)*(y+0.0*I) and laboriously computing the full complex product.
* In particular, I*Inf is corrupted to NaN+I*Inf, and I*-0 is corrupted
* to -0.0+I*0.0.
+ *
+ * The C11 standard introduced the macros CMPLX(), CMPLXF() and CMPLXL()
+ * to construct complex values. Compilers that conform to the C99
+ * standard require the following functions to avoid the above issues.
*/
+
+#ifndef CMPLXF
static __inline float complex
-cpackf(float x, float y)
+CMPLXF(float x, float y)
{
float_complex z;
@@ -464,9 +470,11 @@ cpackf(float x, float y)
IMAGPART(z) = y;
return (z.f);
}
+#endif
+#ifndef CMPLX
static __inline double complex
-cpack(double x, double y)
+CMPLX(double x, double y)
{
double_complex z;
@@ -474,9 +482,11 @@ cpack(double x, double y)
IMAGPART(z) = y;
return (z.f);
}
+#endif
+#ifndef CMPLXL
static __inline long double complex
-cpackl(long double x, long double y)
+CMPLXL(long double x, long double y)
{
long_double_complex z;
@@ -484,6 +494,8 @@ cpackl(long double x, long double y)
IMAGPART(z) = y;
return (z.f);
}
+#endif
+
#endif /* _COMPLEX_H */
#ifdef __GNUCLIKE_ASM
diff --git a/lib/msun/src/s_ccosh.c b/lib/msun/src/s_ccosh.c
index 9ea962b..fbe15fc 100644
--- a/lib/msun/src/s_ccosh.c
+++ b/lib/msun/src/s_ccosh.c
@@ -62,23 +62,23 @@ ccosh(double complex z)
/* Handle the nearly-non-exceptional cases where x and y are finite. */
if (ix < 0x7ff00000 && iy < 0x7ff00000) {
if ((iy | ly) == 0)
- return (cpack(cosh(x), x * y));
+ return (CMPLX(cosh(x), x * y));
if (ix < 0x40360000) /* small x: normal case */
- return (cpack(cosh(x) * cos(y), sinh(x) * sin(y)));
+ return (CMPLX(cosh(x) * cos(y), sinh(x) * sin(y)));
/* |x| >= 22, so cosh(x) ~= exp(|x|) */
if (ix < 0x40862e42) {
/* x < 710: exp(|x|) won't overflow */
h = exp(fabs(x)) * 0.5;
- return (cpack(h * cos(y), copysign(h, x) * sin(y)));
+ return (CMPLX(h * cos(y), copysign(h, x) * sin(y)));
} else if (ix < 0x4096bbaa) {
/* x < 1455: scale to avoid overflow */
- z = __ldexp_cexp(cpack(fabs(x), y), -1);
- return (cpack(creal(z), cimag(z) * copysign(1, x)));
+ z = __ldexp_cexp(CMPLX(fabs(x), y), -1);
+ return (CMPLX(creal(z), cimag(z) * copysign(1, x)));
} else {
/* x >= 1455: the result always overflows */
h = huge * x;
- return (cpack(h * h * cos(y), h * sin(y)));
+ return (CMPLX(h * h * cos(y), h * sin(y)));
}
}
@@ -92,7 +92,7 @@ ccosh(double complex z)
* the same as d(NaN).
*/
if ((ix | lx) == 0 && iy >= 0x7ff00000)
- return (cpack(y - y, copysign(0, x * (y - y))));
+ return (CMPLX(y - y, copysign(0, x * (y - y))));
/*
* cosh(+-Inf +- I 0) = +Inf + I (+-)(+-)0.
@@ -102,8 +102,8 @@ ccosh(double complex z)
*/
if ((iy | ly) == 0 && ix >= 0x7ff00000) {
if (((hx & 0xfffff) | lx) == 0)
- return (cpack(x * x, copysign(0, x) * y));
- return (cpack(x * x, copysign(0, (x + x) * y)));
+ return (CMPLX(x * x, copysign(0, x) * y));
+ return (CMPLX(x * x, copysign(0, (x + x) * y)));
}
/*
@@ -115,7 +115,7 @@ ccosh(double complex z)
* nonzero x. Choice = don't raise (except for signaling NaNs).
*/
if (ix < 0x7ff00000 && iy >= 0x7ff00000)
- return (cpack(y - y, x * (y - y)));
+ return (CMPLX(y - y, x * (y - y)));
/*
* cosh(+-Inf + I NaN) = +Inf + I d(NaN).
@@ -128,8 +128,8 @@ ccosh(double complex z)
*/
if (ix >= 0x7ff00000 && ((hx & 0xfffff) | lx) == 0) {
if (iy >= 0x7ff00000)
- return (cpack(x * x, x * (y - y)));
- return (cpack((x * x) * cos(y), x * sin(y)));
+ return (CMPLX(x * x, x * (y - y)));
+ return (CMPLX((x * x) * cos(y), x * sin(y)));
}
/*
@@ -143,7 +143,7 @@ ccosh(double complex z)
* Optionally raises the invalid floating-point exception for finite
* nonzero y. Choice = don't raise (except for signaling NaNs).
*/
- return (cpack((x * x) * (y - y), (x + x) * (y - y)));
+ return (CMPLX((x * x) * (y - y), (x + x) * (y - y)));
}
double complex
@@ -151,5 +151,5 @@ ccos(double complex z)
{
/* ccos(z) = ccosh(I * z) */
- return (ccosh(cpack(-cimag(z), creal(z))));
+ return (ccosh(CMPLX(-cimag(z), creal(z))));
}
diff --git a/lib/msun/src/s_ccoshf.c b/lib/msun/src/s_ccoshf.c
index 1de9ad4..fe8cf89 100644
--- a/lib/msun/src/s_ccoshf.c
+++ b/lib/msun/src/s_ccoshf.c
@@ -55,50 +55,50 @@ ccoshf(float complex z)
if (ix < 0x7f800000 && iy < 0x7f800000) {
if (iy == 0)
- return (cpackf(coshf(x), x * y));
+ return (CMPLXF(coshf(x), x * y));
if (ix < 0x41100000) /* small x: normal case */
- return (cpackf(coshf(x) * cosf(y), sinhf(x) * sinf(y)));
+ return (CMPLXF(coshf(x) * cosf(y), sinhf(x) * sinf(y)));
/* |x| >= 9, so cosh(x) ~= exp(|x|) */
if (ix < 0x42b17218) {
/* x < 88.7: expf(|x|) won't overflow */
h = expf(fabsf(x)) * 0.5f;
- return (cpackf(h * cosf(y), copysignf(h, x) * sinf(y)));
+ return (CMPLXF(h * cosf(y), copysignf(h, x) * sinf(y)));
} else if (ix < 0x4340b1e7) {
/* x < 192.7: scale to avoid overflow */
- z = __ldexp_cexpf(cpackf(fabsf(x), y), -1);
- return (cpackf(crealf(z), cimagf(z) * copysignf(1, x)));
+ z = __ldexp_cexpf(CMPLXF(fabsf(x), y), -1);
+ return (CMPLXF(crealf(z), cimagf(z) * copysignf(1, x)));
} else {
/* x >= 192.7: the result always overflows */
h = huge * x;
- return (cpackf(h * h * cosf(y), h * sinf(y)));
+ return (CMPLXF(h * h * cosf(y), h * sinf(y)));
}
}
if (ix == 0 && iy >= 0x7f800000)
- return (cpackf(y - y, copysignf(0, x * (y - y))));
+ return (CMPLXF(y - y, copysignf(0, x * (y - y))));
if (iy == 0 && ix >= 0x7f800000) {
if ((hx & 0x7fffff) == 0)
- return (cpackf(x * x, copysignf(0, x) * y));
- return (cpackf(x * x, copysignf(0, (x + x) * y)));
+ return (CMPLXF(x * x, copysignf(0, x) * y));
+ return (CMPLXF(x * x, copysignf(0, (x + x) * y)));
}
if (ix < 0x7f800000 && iy >= 0x7f800000)
- return (cpackf(y - y, x * (y - y)));
+ return (CMPLXF(y - y, x * (y - y)));
if (ix >= 0x7f800000 && (hx & 0x7fffff) == 0) {
if (iy >= 0x7f800000)
- return (cpackf(x * x, x * (y - y)));
- return (cpackf((x * x) * cosf(y), x * sinf(y)));
+ return (CMPLXF(x * x, x * (y - y)));
+ return (CMPLXF((x * x) * cosf(y), x * sinf(y)));
}
- return (cpackf((x * x) * (y - y), (x + x) * (y - y)));
+ return (CMPLXF((x * x) * (y - y), (x + x) * (y - y)));
}
float complex
ccosf(float complex z)
{
- return (ccoshf(cpackf(-cimagf(z), crealf(z))));
+ return (ccoshf(CMPLXF(-cimagf(z), crealf(z))));
}
diff --git a/lib/msun/src/s_cexp.c b/lib/msun/src/s_cexp.c
index abe178f..9e11d51 100644
--- a/lib/msun/src/s_cexp.c
+++ b/lib/msun/src/s_cexp.c
@@ -50,22 +50,22 @@ cexp(double complex z)
/* cexp(x + I 0) = exp(x) + I 0 */
if ((hy | ly) == 0)
- return (cpack(exp(x), y));
+ return (CMPLX(exp(x), y));
EXTRACT_WORDS(hx, lx, x);
/* cexp(0 + I y) = cos(y) + I sin(y) */
if (((hx & 0x7fffffff) | lx) == 0)
- return (cpack(cos(y), sin(y)));
+ return (CMPLX(cos(y), sin(y)));
if (hy >= 0x7ff00000) {
if (lx != 0 || (hx & 0x7fffffff) != 0x7ff00000) {
/* cexp(finite|NaN +- I Inf|NaN) = NaN + I NaN */
- return (cpack(y - y, y - y));
+ return (CMPLX(y - y, y - y));
} else if (hx & 0x80000000) {
/* cexp(-Inf +- I Inf|NaN) = 0 + I 0 */
- return (cpack(0.0, 0.0));
+ return (CMPLX(0.0, 0.0));
} else {
/* cexp(+Inf +- I Inf|NaN) = Inf + I NaN */
- return (cpack(x, y - y));
+ return (CMPLX(x, y - y));
}
}
@@ -84,6 +84,6 @@ cexp(double complex z)
* - x = NaN (spurious inexact exception from y)
*/
exp_x = exp(x);
- return (cpack(exp_x * cos(y), exp_x * sin(y)));
+ return (CMPLX(exp_x * cos(y), exp_x * sin(y)));
}
}
diff --git a/lib/msun/src/s_cexpf.c b/lib/msun/src/s_cexpf.c
index 0e30d08..0138cd1 100644
--- a/lib/msun/src/s_cexpf.c
+++ b/lib/msun/src/s_cexpf.c
@@ -50,22 +50,22 @@ cexpf(float complex z)
/* cexp(x + I 0) = exp(x) + I 0 */
if (hy == 0)
- return (cpackf(expf(x), y));
+ return (CMPLXF(expf(x), y));
GET_FLOAT_WORD(hx, x);
/* cexp(0 + I y) = cos(y) + I sin(y) */
if ((hx & 0x7fffffff) == 0)
- return (cpackf(cosf(y), sinf(y)));
+ return (CMPLXF(cosf(y), sinf(y)));
if (hy >= 0x7f800000) {
if ((hx & 0x7fffffff) != 0x7f800000) {
/* cexp(finite|NaN +- I Inf|NaN) = NaN + I NaN */
- return (cpackf(y - y, y - y));
+ return (CMPLXF(y - y, y - y));
} else if (hx & 0x80000000) {
/* cexp(-Inf +- I Inf|NaN) = 0 + I 0 */
- return (cpackf(0.0, 0.0));
+ return (CMPLXF(0.0, 0.0));
} else {
/* cexp(+Inf +- I Inf|NaN) = Inf + I NaN */
- return (cpackf(x, y - y));
+ return (CMPLXF(x, y - y));
}
}
@@ -84,6 +84,6 @@ cexpf(float complex z)
* - x = NaN (spurious inexact exception from y)
*/
exp_x = expf(x);
- return (cpackf(exp_x * cosf(y), exp_x * sinf(y)));
+ return (CMPLXF(exp_x * cosf(y), exp_x * sinf(y)));
}
}
diff --git a/lib/msun/src/s_conj.c b/lib/msun/src/s_conj.c
index 5770c29..d0dd051 100644
--- a/lib/msun/src/s_conj.c
+++ b/lib/msun/src/s_conj.c
@@ -34,5 +34,5 @@ double complex
conj(double complex z)
{
- return (cpack(creal(z), -cimag(z)));
+ return (CMPLX(creal(z), -cimag(z)));
}
diff --git a/lib/msun/src/s_conjf.c b/lib/msun/src/s_conjf.c
index b090760..c4cf127 100644
--- a/lib/msun/src/s_conjf.c
+++ b/lib/msun/src/s_conjf.c
@@ -34,5 +34,5 @@ float complex
conjf(float complex z)
{
- return (cpackf(crealf(z), -cimagf(z)));
+ return (CMPLXF(crealf(z), -cimagf(z)));
}
diff --git a/lib/msun/src/s_conjl.c b/lib/msun/src/s_conjl.c
index 0e431ef..a4604b6 100644
--- a/lib/msun/src/s_conjl.c
+++ b/lib/msun/src/s_conjl.c
@@ -34,5 +34,5 @@ long double complex
conjl(long double complex z)
{
- return (cpackl(creall(z), -cimagl(z)));
+ return (CMPLXL(creall(z), -cimagl(z)));
}
diff --git a/lib/msun/src/s_cproj.c b/lib/msun/src/s_cproj.c
index 8e9404c..2f0db6e 100644
--- a/lib/msun/src/s_cproj.c
+++ b/lib/msun/src/s_cproj.c
@@ -39,7 +39,7 @@ cproj(double complex z)
if (!isinf(creal(z)) && !isinf(cimag(z)))
return (z);
else
- return (cpack(INFINITY, copysign(0.0, cimag(z))));
+ return (CMPLX(INFINITY, copysign(0.0, cimag(z))));
}
#if LDBL_MANT_DIG == 53
diff --git a/lib/msun/src/s_cprojf.c b/lib/msun/src/s_cprojf.c
index 68ea77b..bd27bdc 100644
--- a/lib/msun/src/s_cprojf.c
+++ b/lib/msun/src/s_cprojf.c
@@ -39,5 +39,5 @@ cprojf(float complex z)
if (!isinf(crealf(z)) && !isinf(cimagf(z)))
return (z);
else
- return (cpackf(INFINITY, copysignf(0.0, cimagf(z))));
+ return (CMPLXF(INFINITY, copysignf(0.0, cimagf(z))));
}
diff --git a/lib/msun/src/s_cprojl.c b/lib/msun/src/s_cprojl.c
index 07385bc..5cccc91 100644
--- a/lib/msun/src/s_cprojl.c
+++ b/lib/msun/src/s_cprojl.c
@@ -39,5 +39,5 @@ cprojl(long double complex z)
if (!isinf(creall(z)) && !isinf(cimagl(z)))
return (z);
else
- return (cpackl(INFINITY, copysignl(0.0, cimagl(z))));
+ return (CMPLXL(INFINITY, copysignl(0.0, cimagl(z))));
}
diff --git a/lib/msun/src/s_csinh.c b/lib/msun/src/s_csinh.c
index c192f30..37f46da 100644
--- a/lib/msun/src/s_csinh.c
+++ b/lib/msun/src/s_csinh.c
@@ -62,23 +62,23 @@ csinh(double complex z)
/* Handle the nearly-non-exceptional cases where x and y are finite. */
if (ix < 0x7ff00000 && iy < 0x7ff00000) {
if ((iy | ly) == 0)
- return (cpack(sinh(x), y));
+ return (CMPLX(sinh(x), y));
if (ix < 0x40360000) /* small x: normal case */
- return (cpack(sinh(x) * cos(y), cosh(x) * sin(y)));
+ return (CMPLX(sinh(x) * cos(y), cosh(x) * sin(y)));
/* |x| >= 22, so cosh(x) ~= exp(|x|) */
if (ix < 0x40862e42) {
/* x < 710: exp(|x|) won't overflow */
h = exp(fabs(x)) * 0.5;
- return (cpack(copysign(h, x) * cos(y), h * sin(y)));
+ return (CMPLX(copysign(h, x) * cos(y), h * sin(y)));
} else if (ix < 0x4096bbaa) {
/* x < 1455: scale to avoid overflow */
- z = __ldexp_cexp(cpack(fabs(x), y), -1);
- return (cpack(creal(z) * copysign(1, x), cimag(z)));
+ z = __ldexp_cexp(CMPLX(fabs(x), y), -1);
+ return (CMPLX(creal(z) * copysign(1, x), cimag(z)));
} else {
/* x >= 1455: the result always overflows */
h = huge * x;
- return (cpack(h * cos(y), h * h * sin(y)));
+ return (CMPLX(h * cos(y), h * h * sin(y)));
}
}
@@ -92,7 +92,7 @@ csinh(double complex z)
* the same as d(NaN).
*/
if ((ix | lx) == 0 && iy >= 0x7ff00000)
- return (cpack(copysign(0, x * (y - y)), y - y));
+ return (CMPLX(copysign(0, x * (y - y)), y - y));
/*
* sinh(+-Inf +- I 0) = +-Inf + I +-0.
@@ -101,8 +101,8 @@ csinh(double complex z)
*/
if ((iy | ly) == 0 && ix >= 0x7ff00000) {
if (((hx & 0xfffff) | lx) == 0)
- return (cpack(x, y));
- return (cpack(x, copysign(0, y)));
+ return (CMPLX(x, y));
+ return (CMPLX(x, copysign(0, y)));
}
/*
@@ -114,7 +114,7 @@ csinh(double complex z)
* nonzero x. Choice = don't raise (except for signaling NaNs).
*/
if (ix < 0x7ff00000 && iy >= 0x7ff00000)
- return (cpack(y - y, x * (y - y)));
+ return (CMPLX(y - y, x * (y - y)));
/*
* sinh(+-Inf + I NaN) = +-Inf + I d(NaN).
@@ -129,8 +129,8 @@ csinh(double complex z)
*/
if (ix >= 0x7ff00000 && ((hx & 0xfffff) | lx) == 0) {
if (iy >= 0x7ff00000)
- return (cpack(x * x, x * (y - y)));
- return (cpack(x * cos(y), INFINITY * sin(y)));
+ return (CMPLX(x * x, x * (y - y)));
+ return (CMPLX(x * cos(y), INFINITY * sin(y)));
}
/*
@@ -144,7 +144,7 @@ csinh(double complex z)
* Optionally raises the invalid floating-point exception for finite
* nonzero y. Choice = don't raise (except for signaling NaNs).
*/
- return (cpack((x * x) * (y - y), (x + x) * (y - y)));
+ return (CMPLX((x * x) * (y - y), (x + x) * (y - y)));
}
double complex
@@ -152,6 +152,6 @@ csin(double complex z)
{
/* csin(z) = -I * csinh(I * z) */
- z = csinh(cpack(-cimag(z), creal(z)));
- return (cpack(cimag(z), -creal(z)));
+ z = csinh(CMPLX(-cimag(z), creal(z)));
+ return (CMPLX(cimag(z), -creal(z)));
}
diff --git a/lib/msun/src/s_csinhf.c b/lib/msun/src/s_csinhf.c
index c523125..6348272 100644
--- a/lib/msun/src/s_csinhf.c
+++ b/lib/msun/src/s_csinhf.c
@@ -55,51 +55,51 @@ csinhf(float complex z)
if (ix < 0x7f800000 && iy < 0x7f800000) {
if (iy == 0)
- return (cpackf(sinhf(x), y));
+ return (CMPLXF(sinhf(x), y));
if (ix < 0x41100000) /* small x: normal case */
- return (cpackf(sinhf(x) * cosf(y), coshf(x) * sinf(y)));
+ return (CMPLXF(sinhf(x) * cosf(y), coshf(x) * sinf(y)));
/* |x| >= 9, so cosh(x) ~= exp(|x|) */
if (ix < 0x42b17218) {
/* x < 88.7: expf(|x|) won't overflow */
h = expf(fabsf(x)) * 0.5f;
- return (cpackf(copysignf(h, x) * cosf(y), h * sinf(y)));
+ return (CMPLXF(copysignf(h, x) * cosf(y), h * sinf(y)));
} else if (ix < 0x4340b1e7) {
/* x < 192.7: scale to avoid overflow */
- z = __ldexp_cexpf(cpackf(fabsf(x), y), -1);
- return (cpackf(crealf(z) * copysignf(1, x), cimagf(z)));
+ z = __ldexp_cexpf(CMPLXF(fabsf(x), y), -1);
+ return (CMPLXF(crealf(z) * copysignf(1, x), cimagf(z)));
} else {
/* x >= 192.7: the result always overflows */
h = huge * x;
- return (cpackf(h * cosf(y), h * h * sinf(y)));
+ return (CMPLXF(h * cosf(y), h * h * sinf(y)));
}
}
if (ix == 0 && iy >= 0x7f800000)
- return (cpackf(copysignf(0, x * (y - y)), y - y));
+ return (CMPLXF(copysignf(0, x * (y - y)), y - y));
if (iy == 0 && ix >= 0x7f800000) {
if ((hx & 0x7fffff) == 0)
- return (cpackf(x, y));
- return (cpackf(x, copysignf(0, y)));
+ return (CMPLXF(x, y));
+ return (CMPLXF(x, copysignf(0, y)));
}
if (ix < 0x7f800000 && iy >= 0x7f800000)
- return (cpackf(y - y, x * (y - y)));
+ return (CMPLXF(y - y, x * (y - y)));
if (ix >= 0x7f800000 && (hx & 0x7fffff) == 0) {
if (iy >= 0x7f800000)
- return (cpackf(x * x, x * (y - y)));
- return (cpackf(x * cosf(y), INFINITY * sinf(y)));
+ return (CMPLXF(x * x, x * (y - y)));
+ return (CMPLXF(x * cosf(y), INFINITY * sinf(y)));
}
- return (cpackf((x * x) * (y - y), (x + x) * (y - y)));
+ return (CMPLXF((x * x) * (y - y), (x + x) * (y - y)));
}
float complex
csinf(float complex z)
{
- z = csinhf(cpackf(-cimagf(z), crealf(z)));
- return (cpackf(cimagf(z), -crealf(z)));
+ z = csinhf(CMPLXF(-cimagf(z), crealf(z)));
+ return (CMPLXF(cimagf(z), -crealf(z)));
}
diff --git a/lib/msun/src/s_csqrt.c b/lib/msun/src/s_csqrt.c
index 18a7ae3..75e12d8 100644
--- a/lib/msun/src/s_csqrt.c
+++ b/lib/msun/src/s_csqrt.c
@@ -58,12 +58,12 @@ csqrt(double complex z)
/* Handle special cases. */
if (z == 0)
- return (cpack(0, b));
+ return (CMPLX(0, b));
if (isinf(b))
- return (cpack(INFINITY, b));
+ return (CMPLX(INFINITY, b));
if (isnan(a)) {
t = (b - b) / (b - b); /* raise invalid if b is not a NaN */
- return (cpack(a, t)); /* return NaN + NaN i */
+ return (CMPLX(a, t)); /* return NaN + NaN i */
}
if (isinf(a)) {
/*
@@ -73,9 +73,9 @@ csqrt(double complex z)
* csqrt(-inf + y i) = 0 + inf i
*/
if (signbit(a))
- return (cpack(fabs(b - b), copysign(a, b)));
+ return (CMPLX(fabs(b - b), copysign(a, b)));
else
- return (cpack(a, copysign(b - b, b)));
+ return (CMPLX(a, copysign(b - b, b)));
}
/*
* The remaining special case (b is NaN) is handled just fine by
@@ -94,10 +94,10 @@ csqrt(double complex z)
/* Algorithm 312, CACM vol 10, Oct 1967. */
if (a >= 0) {
t = sqrt((a + hypot(a, b)) * 0.5);
- result = cpack(t, b / (2 * t));
+ result = CMPLX(t, b / (2 * t));
} else {
t = sqrt((-a + hypot(a, b)) * 0.5);
- result = cpack(fabs(b) / (2 * t), copysign(t, b));
+ result = CMPLX(fabs(b) / (2 * t), copysign(t, b));
}
/* Rescale. */
diff --git a/lib/msun/src/s_csqrtf.c b/lib/msun/src/s_csqrtf.c
index da7fe18..7ee513f 100644
--- a/lib/msun/src/s_csqrtf.c
+++ b/lib/msun/src/s_csqrtf.c
@@ -49,12 +49,12 @@ csqrtf(float complex z)
/* Handle special cases. */
if (z == 0)
- return (cpackf(0, b));
+ return (CMPLXF(0, b));
if (isinf(b))
- return (cpackf(INFINITY, b));
+ return (CMPLXF(INFINITY, b));
if (isnan(a)) {
t = (b - b) / (b - b); /* raise invalid if b is not a NaN */
- return (cpackf(a, t)); /* return NaN + NaN i */
+ return (CMPLXF(a, t)); /* return NaN + NaN i */
}
if (isinf(a)) {
/*
@@ -64,9 +64,9 @@ csqrtf(float complex z)
* csqrtf(-inf + y i) = 0 + inf i
*/
if (signbit(a))
- return (cpackf(fabsf(b - b), copysignf(a, b)));
+ return (CMPLXF(fabsf(b - b), copysignf(a, b)));
else
- return (cpackf(a, copysignf(b - b, b)));
+ return (CMPLXF(a, copysignf(b - b, b)));
}
/*
* The remaining special case (b is NaN) is handled just fine by
@@ -80,9 +80,9 @@ csqrtf(float complex z)
*/
if (a >= 0) {
t = sqrt((a + hypot(a, b)) * 0.5);
- return (cpackf(t, b / (2.0 * t)));
+ return (CMPLXF(t, b / (2.0 * t)));
} else {
t = sqrt((-a + hypot(a, b)) * 0.5);
- return (cpackf(fabsf(b) / (2.0 * t), copysignf(t, b)));
+ return (CMPLXF(fabsf(b) / (2.0 * t), copysignf(t, b)));
}
}
diff --git a/lib/msun/src/s_csqrtl.c b/lib/msun/src/s_csqrtl.c
index dd18e1e..ea2ef27 100644
--- a/lib/msun/src/s_csqrtl.c
+++ b/lib/msun/src/s_csqrtl.c
@@ -58,12 +58,12 @@ csqrtl(long double complex z)
/* Handle special cases. */
if (z == 0)
- return (cpackl(0, b));
+ return (CMPLXL(0, b));
if (isinf(b))
- return (cpackl(INFINITY, b));
+ return (CMPLXL(INFINITY, b));
if (isnan(a)) {
t = (b - b) / (b - b); /* raise invalid if b is not a NaN */
- return (cpackl(a, t)); /* return NaN + NaN i */
+ return (CMPLXL(a, t)); /* return NaN + NaN i */
}
if (isinf(a)) {
/*
@@ -73,9 +73,9 @@ csqrtl(long double complex z)
* csqrt(-inf + y i) = 0 + inf i
*/
if (signbit(a))
- return (cpackl(fabsl(b - b), copysignl(a, b)));
+ return (CMPLXL(fabsl(b - b), copysignl(a, b)));
else
- return (cpackl(a, copysignl(b - b, b)));
+ return (CMPLXL(a, copysignl(b - b, b)));
}
/*
* The remaining special case (b is NaN) is handled just fine by
@@ -94,10 +94,10 @@ csqrtl(long double complex z)
/* Algorithm 312, CACM vol 10, Oct 1967. */
if (a >= 0) {
t = sqrtl((a + hypotl(a, b)) * 0.5);
- result = cpackl(t, b / (2 * t));
+ result = CMPLXL(t, b / (2 * t));
} else {
t = sqrtl((-a + hypotl(a, b)) * 0.5);
- result = cpackl(fabsl(b) / (2 * t), copysignl(t, b));
+ result = CMPLXL(fabsl(b) / (2 * t), copysignl(t, b));
}
/* Rescale. */
diff --git a/lib/msun/src/s_ctanh.c b/lib/msun/src/s_ctanh.c
index d427e28..b15c814 100644
--- a/lib/msun/src/s_ctanh.c
+++ b/lib/msun/src/s_ctanh.c
@@ -102,9 +102,9 @@ ctanh(double complex z)
*/
if (ix >= 0x7ff00000) {
if ((ix & 0xfffff) | lx) /* x is NaN */
- return (cpack(x, (y == 0 ? y : x * y)));
+ return (CMPLX(x, (y == 0 ? y : x * y)));
SET_HIGH_WORD(x, hx - 0x40000000); /* x = copysign(1, x) */
- return (cpack(x, copysign(0, isinf(y) ? y : sin(y) * cos(y))));
+ return (CMPLX(x, copysign(0, isinf(y) ? y : sin(y) * cos(y))));
}
/*
@@ -112,7 +112,7 @@ ctanh(double complex z)
* ctanh(x +- i Inf) = NaN + i NaN
*/
if (!isfinite(y))
- return (cpack(y - y, y - y));
+ return (CMPLX(y - y, y - y));
/*
* ctanh(+-huge + i +-y) ~= +-1 +- i 2sin(2y)/exp(2x), using the
@@ -121,7 +121,7 @@ ctanh(double complex z)
*/
if (ix >= 0x40360000) { /* x >= 22 */
double exp_mx = exp(-fabs(x));
- return (cpack(copysign(1, x),
+ return (CMPLX(copysign(1, x),
4 * sin(y) * cos(y) * exp_mx * exp_mx));
}
@@ -131,7 +131,7 @@ ctanh(double complex z)
s = sinh(x);
rho = sqrt(1 + s * s); /* = cosh(x) */
denom = 1 + beta * s * s;
- return (cpack((beta * rho * s) / denom, t / denom));
+ return (CMPLX((beta * rho * s) / denom, t / denom));
}
double complex
@@ -139,6 +139,6 @@ ctan(double complex z)
{
/* ctan(z) = -I * ctanh(I * z) */
- z = ctanh(cpack(-cimag(z), creal(z)));
- return (cpack(cimag(z), -creal(z)));
+ z = ctanh(CMPLX(-cimag(z), creal(z)));
+ return (CMPLX(cimag(z), -creal(z)));
}
diff --git a/lib/msun/src/s_ctanhf.c b/lib/msun/src/s_ctanhf.c
index 4be28d8..9b0cda1 100644
--- a/lib/msun/src/s_ctanhf.c
+++ b/lib/msun/src/s_ctanhf.c
@@ -51,18 +51,18 @@ ctanhf(float complex z)
if (ix >= 0x7f800000) {
if (ix & 0x7fffff)
- return (cpackf(x, (y == 0 ? y : x * y)));
+ return (CMPLXF(x, (y == 0 ? y : x * y)));
SET_FLOAT_WORD(x, hx - 0x40000000);
- return (cpackf(x,
+ return (CMPLXF(x,
copysignf(0, isinf(y) ? y : sinf(y) * cosf(y))));
}
if (!isfinite(y))
- return (cpackf(y - y, y - y));
+ return (CMPLXF(y - y, y - y));
if (ix >= 0x41300000) { /* x >= 11 */
float exp_mx = expf(-fabsf(x));
- return (cpackf(copysignf(1, x),
+ return (CMPLXF(copysignf(1, x),
4 * sinf(y) * cosf(y) * exp_mx * exp_mx));
}
@@ -71,14 +71,14 @@ ctanhf(float complex z)
s = sinhf(x);
rho = sqrtf(1 + s * s);
denom = 1 + beta * s * s;
- return (cpackf((beta * rho * s) / denom, t / denom));
+ return (CMPLXF((beta * rho * s) / denom, t / denom));
}
float complex
ctanf(float complex z)
{
- z = ctanhf(cpackf(-cimagf(z), crealf(z)));
- return (cpackf(cimagf(z), -crealf(z)));
+ z = ctanhf(CMPLXF(-cimagf(z), crealf(z)));
+ return (CMPLXF(cimagf(z), -crealf(z)));
}
diff --git a/lib/msun/src/s_scalbln.c b/lib/msun/src/s_scalbln.c
index d609d4e..5e4e42e 100644
--- a/lib/msun/src/s_scalbln.c
+++ b/lib/msun/src/s_scalbln.c
@@ -27,50 +27,28 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
-#include <limits.h>
#include <math.h>
+#define NMAX 65536
+#define NMIN -65536
+
double
-scalbln (double x, long n)
+scalbln(double x, long n)
{
- int in;
- in = (int)n;
- if (in != n) {
- if (n > 0)
- in = INT_MAX;
- else
- in = INT_MIN;
- }
- return (scalbn(x, in));
+ return (scalbn(x, (n > NMAX) ? NMAX : (n < NMIN) ? NMIN : (int)n));
}
float
-scalblnf (float x, long n)
+scalblnf(float x, long n)
{
- int in;
- in = (int)n;
- if (in != n) {
- if (n > 0)
- in = INT_MAX;
- else
- in = INT_MIN;
- }
- return (scalbnf(x, in));
+ return (scalbnf(x, (n > NMAX) ? NMAX : (n < NMIN) ? NMIN : (int)n));
}
long double
-scalblnl (long double x, long n)
+scalblnl(long double x, long n)
{
- int in;
- in = (int)n;
- if (in != n) {
- if (n > 0)
- in = INT_MAX;
- else
- in = INT_MIN;
- }
- return (scalbnl(x, (int)n));
+ return (scalbnl(x, (n > NMAX) ? NMAX : (n < NMIN) ? NMIN : (int)n));
}
diff --git a/lib/msun/tests/Makefile b/lib/msun/tests/Makefile
index 4261e48..0479cfb 100644
--- a/lib/msun/tests/Makefile
+++ b/lib/msun/tests/Makefile
@@ -6,13 +6,12 @@ TESTSRC= ${SRCTOP}/contrib/netbsd-tests/lib/libm
TESTSDIR= ${TESTSBASE}/lib/msun
-.if ${MACHINE} == "sparc" || ${MACHINE} == "i386" \
- || ${MACHINE} == "amd64" || ${MACHINE_CPU} == "arm" \
- || ${MACHINE} == "sparc64"
+# All architectures on FreeBSD have fenv.h
CFLAGS+= -DHAVE_FENV_H
-.endif
-.if ${MACHINE} == "amd64" || ${MACHINE} == "i386"
+# Not sure why this isn't defined for all architectures, since most
+# have long double.
+.if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386"
CFLAGS+= -D__HAVE_LONG_DOUBLE
.endif
@@ -41,8 +40,7 @@ NETBSD_ATF_TESTS_C+= tanh_test
CSTD= c99
-LDADD+= -lm
-DPADD+= ${LIBM}
+LIBADD+= m
#COPTS+= -Wfloat-equal
# Copied from lib/msun/Makefile
diff --git a/lib/ncurses/Makefile b/lib/ncurses/Makefile
index 05cd7a2..a5a19dea 100644
--- a/lib/ncurses/Makefile
+++ b/lib/ncurses/Makefile
@@ -3,4 +3,11 @@
SUBDIR= ncurses form menu panel \
ncursesw formw menuw panelw
+SUBDIR_PARALLEL=
+
+.for subdir in ${SUBDIR:Nncurses*:N*w}
+SUBDIR_DEPEND_${subdir}= ncurses
+SUBDIR_DEPEND_${subdir}w= ncursesw
+.endfor
+
.include <bsd.subdir.mk>
diff --git a/lib/ncurses/form/Makefile b/lib/ncurses/form/Makefile
index dd903b0..beefb2c 100644
--- a/lib/ncurses/form/Makefile
+++ b/lib/ncurses/form/Makefile
@@ -54,8 +54,7 @@ CLEANFILES= ncurses_def.h
CFLAGS+= -I${SRCDIR}
CFLAGS+= -I${NCURSES_DIR}/menu
-DPADD= ${LIBNCURSES${LIB_SUFFIX:tu}}
-LDADD= -lncurses${LIB_SUFFIX}
+LIBADD+= ncurses${LIB_SUFFIX}
.if defined(ENABLE_WIDEC)
INCS= form.h
diff --git a/lib/ncurses/form/Makefile.depend b/lib/ncurses/form/Makefile.depend
index bca7368..c3295ff 100644
--- a/lib/ncurses/form/Makefile.depend
+++ b/lib/ncurses/form/Makefile.depend
@@ -3,7 +3,6 @@
DEP_RELDIR := ${_PARSEDIR:S,${SRCTOP}/,,}
DIRDEPS = \
- bin/cat.host \
gnu/lib/csu \
gnu/lib/libgcc \
include \
diff --git a/lib/ncurses/formw/Makefile.depend b/lib/ncurses/formw/Makefile.depend
index 63cf559..d56ffbb 100644
--- a/lib/ncurses/formw/Makefile.depend
+++ b/lib/ncurses/formw/Makefile.depend
@@ -3,7 +3,6 @@
DEP_RELDIR := ${_PARSEDIR:S,${SRCTOP}/,,}
DIRDEPS = \
- bin/cat.host \
gnu/lib/csu \
gnu/lib/libgcc \
include \
diff --git a/lib/ncurses/menu/Makefile b/lib/ncurses/menu/Makefile
index 3aac081..d3890de7 100644
--- a/lib/ncurses/menu/Makefile
+++ b/lib/ncurses/menu/Makefile
@@ -40,8 +40,7 @@ CLEANFILES= ncurses_def.h
CFLAGS+= -I${SRCDIR}
-DPADD= ${LIBNCURSES${LIB_SUFFIX:tu}}
-LDADD= -lncurses${LIB_SUFFIX}
+LIBADD+= ncurses${LIB_SUFFIX}
.if defined(ENABLE_WIDEC)
INCS= menu.h eti.h
diff --git a/lib/ncurses/menu/Makefile.depend b/lib/ncurses/menu/Makefile.depend
index 01b1fd0..5c8368f 100644
--- a/lib/ncurses/menu/Makefile.depend
+++ b/lib/ncurses/menu/Makefile.depend
@@ -3,7 +3,6 @@
DEP_RELDIR := ${_PARSEDIR:S,${SRCTOP}/,,}
DIRDEPS = \
- bin/cat.host \
gnu/lib/csu \
gnu/lib/libgcc \
include \
diff --git a/lib/ncurses/menuw/Makefile.depend b/lib/ncurses/menuw/Makefile.depend
index 1033d6e..49f1882 100644
--- a/lib/ncurses/menuw/Makefile.depend
+++ b/lib/ncurses/menuw/Makefile.depend
@@ -3,7 +3,6 @@
DEP_RELDIR := ${_PARSEDIR:S,${SRCTOP}/,,}
DIRDEPS = \
- bin/cat.host \
gnu/lib/csu \
gnu/lib/libgcc \
include \
diff --git a/lib/ncurses/panel/Makefile b/lib/ncurses/panel/Makefile
index 7929aed..b075bcf 100644
--- a/lib/ncurses/panel/Makefile
+++ b/lib/ncurses/panel/Makefile
@@ -29,8 +29,7 @@ CLEANFILES= ncurses_def.h
CFLAGS+= -I${SRCDIR}
-DPADD= ${LIBNCURSES${LIB_SUFFIX:tu}}
-LDADD= -lncurses${LIB_SUFFIX}
+LIBADD+= ncurses${LIB_SUFFIX}
.if defined(ENABLE_WIDEC)
INCS= panel.h
diff --git a/lib/ncurses/panel/Makefile.depend b/lib/ncurses/panel/Makefile.depend
index 4e0baeb..2359930 100644
--- a/lib/ncurses/panel/Makefile.depend
+++ b/lib/ncurses/panel/Makefile.depend
@@ -3,7 +3,6 @@
DEP_RELDIR := ${_PARSEDIR:S,${SRCTOP}/,,}
DIRDEPS = \
- bin/cat.host \
gnu/lib/csu \
gnu/lib/libgcc \
include \
diff --git a/lib/ncurses/panelw/Makefile.depend b/lib/ncurses/panelw/Makefile.depend
index fa11519..2ec6472 100644
--- a/lib/ncurses/panelw/Makefile.depend
+++ b/lib/ncurses/panelw/Makefile.depend
@@ -3,7 +3,6 @@
DEP_RELDIR := ${_PARSEDIR:S,${SRCTOP}/,,}
DIRDEPS = \
- bin/cat.host \
gnu/lib/csu \
gnu/lib/libgcc \
include \
OpenPOWER on IntegriCloud